From 15d0045483902d886badbe706c15679218f62788 Mon Sep 17 00:00:00 2001 From: phvalguima Date: Mon, 15 Jan 2024 21:58:34 +0100 Subject: [PATCH] Add secret fix for 3.1.7 (#161) This PR extends opensearch_secrets.py to react to new secret-changed behavior in Juju 3.1.7+, as described in [LP#2037120](https://bugs.launchpad.net/juju/+bug/2037120). --- .github/workflows/integration.yaml | 2 -- lib/charms/opensearch/v0/opensearch_secrets.py | 3 +++ tests/unit/lib/test_opensearch_secrets.py | 2 ++ 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/.github/workflows/integration.yaml b/.github/workflows/integration.yaml index e2bc14ab9..940de57bd 100644 --- a/.github/workflows/integration.yaml +++ b/.github/workflows/integration.yaml @@ -76,7 +76,6 @@ jobs: with: provider: lxd juju-channel: ${{ inputs.juju-snap-channel }} - bootstrap-options: "--agent-version=3.1.6" - name: Download packed charm(s) uses: actions/download-artifact@v3 @@ -147,7 +146,6 @@ jobs: with: provider: lxd juju-channel: ${{ inputs.juju-snap-channel }} - bootstrap-options: "--agent-version=3.1.6" - name: Download packed charm(s) uses: actions/download-artifact@v3 diff --git a/lib/charms/opensearch/v0/opensearch_secrets.py b/lib/charms/opensearch/v0/opensearch_secrets.py index 11d3159f2..5bf323eb8 100644 --- a/lib/charms/opensearch/v0/opensearch_secrets.py +++ b/lib/charms/opensearch/v0/opensearch_secrets.py @@ -56,6 +56,9 @@ def __init__(self, charm, peer_relation: str): def _on_secret_changed(self, event: SecretChangedEvent): """Refresh secret and re-run corresponding actions if needed.""" + secret = event.secret + secret.get_content(refresh=True) + if not event.secret.label: logger.info("Secret %s has no label, ignoring it.", event.secret.id) return diff --git a/tests/unit/lib/test_opensearch_secrets.py b/tests/unit/lib/test_opensearch_secrets.py index 1dc77cc18..60fa01103 100644 --- a/tests/unit/lib/test_opensearch_secrets.py +++ b/tests/unit/lib/test_opensearch_secrets.py @@ -27,6 +27,8 @@ class TestOpenSearchSecrets(TestOpenSearchInternalData): def setUp(self): self.harness = Harness(OpenSearchOperatorCharm) self.addCleanup(self.harness.cleanup) + # self.charm._on_leader_elected = Mock() + self.harness.set_leader(is_leader=True) self.harness.begin() self.charm = self.harness.charm