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 69f5f68
Show file tree
Hide file tree
Showing 3 changed files with 325 additions and 285 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,9 @@ 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
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 without 'refresh=True'")
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
Loading

0 comments on commit 69f5f68

Please sign in to comment.