From 5ed27276ca008bed9140cff3308f16102981fb00 Mon Sep 17 00:00:00 2001 From: Judit Novak Date: Fri, 3 Nov 2023 12:10:07 +0100 Subject: [PATCH] Running previously xfailed test with an attempted fix + extra logs --- .github/workflows/ci.yaml | 5 ++- .../data_platform_libs/v0/data_interfaces.py | 43 +++++++++++++++++++ tests/integration/database-charm/src/charm.py | 3 ++ tests/integration/test_charm.py | 13 ++---- 4 files changed, 54 insertions(+), 10 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 844244d4..8832c0c0 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -116,7 +116,10 @@ jobs: CI_PACKED_CHARMS: ${{ needs.build.outputs.charms }} LIBJUJU_VERSION_SPECIFIER: "==${{ matrix.juju-version.libjuju-version }}" - name: Print debug-log - run: juju switch testing; juju debug-log --replay --no-tail + if: failure() + run: | + lines=`juju switch testing; juju debug-log --replay --no-tail | grep SECRET` + echo "lines = ${lines}" - name: Dump logs uses: canonical/charm-logdump-action@main if: failure() diff --git a/lib/charms/data_platform_libs/v0/data_interfaces.py b/lib/charms/data_platform_libs/v0/data_interfaces.py index 5d1691d9..0a6f6db5 100644 --- a/lib/charms/data_platform_libs/v0/data_interfaces.py +++ b/lib/charms/data_platform_libs/v0/data_interfaces.py @@ -501,8 +501,13 @@ def add_secret(self, content: Dict[str, str], relation: Relation) -> Secret: "Secret is already defined with uri %s", self._secret_uri ) + logger.info(f"[SECRET] Adding secret {self.label} {content}") secret = self.charm.app.add_secret(content, label=self.label) secret.grant(relation) + if self.meta: + logger.info( + f"[SECRET] Added secret {self.meta.id}, {self.meta.label}, {self.meta.__dict__}" + ) self._secret_uri = secret.id self._secret_meta = secret return self._secret_meta @@ -514,19 +519,44 @@ def meta(self) -> Optional[Secret]: if not (self._secret_uri or self.label): return try: + logger.info(f"[SECRET] Getting secret by label {self.label} ") self._secret_meta = self.charm.model.get_secret(label=self.label) + logger.info( + f"[SECRET] Received secret {self._secret_meta.id}, " + f"{self.label}, {self._secret_meta.get_info().revision}, {self._secret_meta.__dict__}" + ) except SecretNotFoundError: + logger.info(f"[SECRET] Couldn't get secret by label {self.label} {self.__dict__}") if self._secret_uri: self._secret_meta = self.charm.model.get_secret( id=self._secret_uri, label=self.label ) + logger.info( + f"[SECRET] Received secret {self._secret_meta.id}, " + f"{self.label}, {self._secret_meta.__dict__}" + ) return self._secret_meta def get_content(self) -> Dict[str, str]: """Getting cached secret content.""" if not self._secret_content: if self.meta: + logger.info("[SECRET] Getting secret contents") self._secret_content = self.meta.get_content() + logger.info( + f"[SECRET] Got secret contents " + f"{self.meta.id}, {self.meta.label}, {self.meta.__dict__}" + ) + # try: + # logger.info("[SECRET] Peeking content contents") + # self._secret_content = self.meta.peek_content() + # logger.info( + # f"[SECRET] Peeked secret contents " + # f"{self.meta.id}, {self.meta.label}, {self.meta.__dict__}" + # ) + # except Exception: + # pass + return self._secret_content def set_content(self, content: Dict[str, str]) -> None: @@ -536,13 +566,26 @@ def set_content(self, content: Dict[str, str]) -> None: if content: self.meta.set_content(content) + logger.info( + f"[SECRET] Setting secret" + f"{self.meta.id}, {self.meta.label}, {self.meta.__dict__}" + f"with content {content}" + ) self._secret_content = content else: self.meta.remove_all_revisions() + logger.info( + f"[SECRET] Deleting secret" + f"{self.meta.id}, {self.meta.label}, {self.meta.__dict__}" + ) def get_info(self) -> Optional[SecretInfo]: """Wrapper function to apply the corresponding call on the Secret object within CachedSecret if any.""" if self.meta: + logger.info( + f"[SECRET] Getting info about secret" + f"{self.meta.id}, {self.meta.label}, {self.meta.__dict__}" + ) return self.meta.get_info() diff --git a/tests/integration/database-charm/src/charm.py b/tests/integration/database-charm/src/charm.py index 88921669..f2bea762 100755 --- a/tests/integration/database-charm/src/charm.py +++ b/tests/integration/database-charm/src/charm.py @@ -193,6 +193,9 @@ def _on_set_relation_field(self, event: ActionEvent): relation = self._get_relation(event.params["relation_id"]) # Charms should be compatible with old vesrions, to simulate rolling upgrade if DATA_INTERFACES_VERSION > 17: + logger.info( + "*************************************** Setting (secret?) field ***************************************" + ) self.database.update_relation_data( relation.id, {event.params["field"]: event.params["value"]} ) diff --git a/tests/integration/test_charm.py b/tests/integration/test_charm.py index 6ba92005..b800eb9e 100644 --- a/tests/integration/test_charm.py +++ b/tests/integration/test_charm.py @@ -431,14 +431,7 @@ async def test_provider_get_set_delete_fields(field, value, ops_test: OpsTest): "field,value,relation_field", [ ("new_field", "blah", "new_field"), - pytest.param( - "tls", - "True", - "secret-tls", - marks=pytest.mark.xfail( - reason="https://github.com/canonical/data-platform-libs/issues/108" - ), - ), + ("tls", "True", "secret-tls"), ], ) @pytest.mark.usefixtures("only_with_juju_secrets") @@ -461,6 +454,7 @@ async def test_provider_get_set_delete_fields_secrets( assert await get_application_relation_data( ops_test, APPLICATION_APP_NAME, SECOND_DATABASE_RELATION_NAME, relation_field ) + sleep(10) # Check all application units can read remote relation data for unit in ops_test.model.applications[APPLICATION_APP_NAME].units: @@ -486,13 +480,14 @@ async def test_provider_get_set_delete_fields_secrets( await action.wait() assert action.results.get("value") == value - # Delete normal field + # Delete field action = await ops_test.model.units.get(leader_name).run_action( "delete-relation-field", **{"relation_id": pytest.second_database_relation.id, "field": field}, ) await action.wait() + sleep(2) assert ( await get_application_relation_data( ops_test, APPLICATION_APP_NAME, SECOND_DATABASE_RELATION_NAME, relation_field