Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/relations/async_replication.py
Original file line number Diff line number Diff line change
Expand Up @@ -567,6 +567,13 @@ def _on_create_replication(self, event: ActionEvent) -> None:
event.fail("There is already a replication set up.")
return

if self._relation is None:
event.fail(
"No async-replication relation has been established."
" Create the offer and relate the two clusters before running this action."
)
return

if self._relation.name == REPLICATION_CONSUMER_RELATION:
event.fail("This action must be run in the cluster where the offer was created.")
return
Expand Down
19 changes: 19 additions & 0 deletions tests/unit/test_async_replication.py
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,25 @@ def test_on_create_replication():

assert result is None

# 5. No async-replication relation established (regression for #1675).
mock_charm = MagicMock()
mock_event = MagicMock()

relation = PostgreSQLAsyncReplication(mock_charm)

relation._get_primary_cluster = MagicMock(return_value=None)

with patch.object(
PostgreSQLAsyncReplication, "_relation", new_callable=PropertyMock, return_value=None
):
result = relation._on_create_replication(mock_event)

assert result is None
mock_event.fail.assert_called_once_with(
"No async-replication relation has been established."
" Create the offer and relate the two clusters before running this action."
)


def test_promote_to_primary():
# 1.
Expand Down
Loading