Skip to content

Commit

Permalink
Running previously xfailed test with an attempted fix + extra logs
Browse files Browse the repository at this point in the history
  • Loading branch information
juditnovak committed Nov 7, 2023
1 parent e4bb320 commit 5ed2727
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 10 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
43 changes: 43 additions & 0 deletions lib/charms/data_platform_libs/v0/data_interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand All @@ -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()


Expand Down
3 changes: 3 additions & 0 deletions tests/integration/database-charm/src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]}
)
Expand Down
13 changes: 4 additions & 9 deletions tests/integration/test_charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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:
Expand All @@ -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
Expand Down

0 comments on commit 5ed2727

Please sign in to comment.