From 544e6246b58630ac66bf87b21fb9a6bcd3735c85 Mon Sep 17 00:00:00 2001 From: Marcelo Henrique Neppel Date: Thu, 20 Jun 2024 11:54:13 -0300 Subject: [PATCH 1/4] Show status and debug logs from multiple models Signed-off-by: Marcelo Henrique Neppel --- .github/workflows/ci.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 6693508153..ddd18e0d09 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -70,7 +70,7 @@ jobs: - lint - unit-test - build - uses: canonical/data-platform-workflows/.github/workflows/integration_test_charm.yaml@v16.0.0 + uses: canonical/data-platform-workflows/.github/workflows/integration_test_charm.yaml@dpe-4685-multiple-models-status-and-logs with: artifact-prefix: ${{ needs.build.outputs.artifact-prefix }} architecture: ${{ matrix.architecture }} From 7e9266f69a5d1b273b294147e6df561718abb9ff Mon Sep 17 00:00:00 2001 From: Marcelo Henrique Neppel Date: Thu, 20 Jun 2024 15:40:59 -0300 Subject: [PATCH 2/4] Test async replication tests fix Signed-off-by: Marcelo Henrique Neppel --- src/relations/async_replication.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/relations/async_replication.py b/src/relations/async_replication.py index e2adab6d8e..77a40ddeb9 100644 --- a/src/relations/async_replication.py +++ b/src/relations/async_replication.py @@ -481,7 +481,7 @@ def is_primary_cluster(self) -> bool: return self.charm.app == self._get_primary_cluster() def _on_async_relation_broken(self, _) -> None: - if "departing" in self.charm._peers.data[self.charm.unit]: + if self.charm._peers is None or "departing" in self.charm._peers.data[self.charm.unit]: logger.debug("Early exit on_async_relation_broken: Skipping departing unit.") return From d5f69d5070e667bf2b1ff02b31da050bebb5fe51 Mon Sep 17 00:00:00 2001 From: Marcelo Henrique Neppel Date: Thu, 20 Jun 2024 17:41:29 -0300 Subject: [PATCH 3/4] Test async replication tests fix Signed-off-by: Marcelo Henrique Neppel --- src/relations/async_replication.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/relations/async_replication.py b/src/relations/async_replication.py index 77a40ddeb9..7531649968 100644 --- a/src/relations/async_replication.py +++ b/src/relations/async_replication.py @@ -67,12 +67,12 @@ def __init__(self, charm): super().__init__(charm, "postgresql") self.charm = charm self.framework.observe( - self.charm.on[REPLICATION_OFFER_RELATION].relation_joined, - self._on_async_relation_joined, + self.charm.on[REPLICATION_OFFER_RELATION].relation_created, + self._on_async_relation_created, ) self.framework.observe( - self.charm.on[REPLICATION_CONSUMER_RELATION].relation_joined, - self._on_async_relation_joined, + self.charm.on[REPLICATION_CONSUMER_RELATION].relation_created, + self._on_async_relation_created, ) self.framework.observe( self.charm.on[REPLICATION_OFFER_RELATION].relation_changed, @@ -546,13 +546,7 @@ def _on_async_relation_changed(self, event: RelationChangedEvent) -> None: self._handle_database_start(event) - def _on_async_relation_departed(self, event: RelationDepartedEvent) -> None: - """Set a flag to avoid setting a wrong status message on relation broken event handler.""" - # This is needed because of https://bugs.launchpad.net/juju/+bug/1979811. - if event.departing_unit == self.charm.unit and self.charm._peers is not None: - self.charm._peers.data[self.charm.unit].update({"departing": "True"}) - - def _on_async_relation_joined(self, _) -> None: + def _on_async_relation_created(self, _) -> None: """Publish this unit address in the relation data.""" self._relation.data[self.charm.unit].update({"unit-address": self.charm._unit_ip}) @@ -563,6 +557,12 @@ def _on_async_relation_joined(self, _) -> None: "unit-promoted-cluster-counter": highest_promoted_cluster_counter }) + def _on_async_relation_departed(self, event: RelationDepartedEvent) -> None: + """Set a flag to avoid setting a wrong status message on relation broken event handler.""" + # This is needed because of https://bugs.launchpad.net/juju/+bug/1979811. + if event.departing_unit == self.charm.unit and self.charm._peers is not None: + self.charm._peers.data[self.charm.unit].update({"departing": "True"}) + def _on_create_replication(self, event: ActionEvent) -> None: """Set up asynchronous replication between two clusters.""" if self._get_primary_cluster() is not None: From ed2a5740d144cea551ff625e373232c795f47180 Mon Sep 17 00:00:00 2001 From: Marcelo Henrique Neppel Date: Fri, 21 Jun 2024 17:30:44 -0300 Subject: [PATCH 4/4] Retry on sync-standby change check Signed-off-by: Marcelo Henrique Neppel --- tests/integration/ha_tests/test_async_replication.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/tests/integration/ha_tests/test_async_replication.py b/tests/integration/ha_tests/test_async_replication.py index 96bdb3afa4..ccae617ac8 100644 --- a/tests/integration/ha_tests/test_async_replication.py +++ b/tests/integration/ha_tests/test_async_replication.py @@ -438,9 +438,11 @@ async def test_async_replication_failover_in_main_cluster( ) # Check that the sync-standby unit is not the same as before. - new_sync_standby = await get_sync_standby(ops_test, first_model, DATABASE_APP_NAME) - logger.info(f"New sync-standby: {new_sync_standby}") - assert new_sync_standby != sync_standby, "Sync-standby is the same as before" + for attempt in Retrying(stop=stop_after_delay(90), wait=wait_fixed(10), reraise=True): + with attempt: + new_sync_standby = await get_sync_standby(ops_test, first_model, DATABASE_APP_NAME) + logger.info(f"New sync-standby: {new_sync_standby}") + assert new_sync_standby != sync_standby, "Sync-standby is the same as before" logger.info("Ensure continuous_writes after the crashed unit") await are_writes_increasing(ops_test)