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 6fbf1e7
Show file tree
Hide file tree
Showing 3 changed files with 328 additions and 288 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ jobs:

build:
name: Build charms
needs:
- lint
# needs:
# - lint
- unit-test
uses: canonical/data-platform-workflows/.github/workflows/build_charms_with_cache.yaml@v2

Expand Down Expand Up @@ -78,7 +78,7 @@ jobs:
libjuju-version: "3.2.2"}}
name: ${{ matrix.tox-environments }} Juju ${{ matrix.juju-version.juju-snap-channel}} -- libjuju ${{ matrix.juju-version.libjuju-version }}
needs:
- lint
# - lint
- unit-test
- build
runs-on: ubuntu-latest
Expand Down Expand Up @@ -116,7 +116,7 @@ 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: juju switch testing; juju debug-log --replay --no-tail | grep SECRET
- name: Dump logs
uses: canonical/charm-logdump-action@main
if: failure()
Expand Down
45 changes: 45 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,15 @@ 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)
logger.info(
f"[SECRET] Added secret "
f"{self.meta.id}, {self.meta.label}, {self.meta.get_info().revision}, {self.meta.__dict__}"
)
self._secret_uri = secret.id
self._secret_meta = secret
return self._secret_meta
Expand All @@ -514,19 +521,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 +568,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 6fbf1e7

Please sign in to comment.