diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 6a0ac5a8e..b75c240a9 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -22,7 +22,7 @@ on: jobs: lint: name: Lint - uses: canonical/data-platform-workflows/.github/workflows/lint.yaml@v13.0.0 + uses: canonical/data-platform-workflows/.github/workflows/lint.yaml@v13.1.1 unit-test: name: Unit test charm @@ -42,7 +42,7 @@ jobs: build: name: Build charm - uses: canonical/data-platform-workflows/.github/workflows/build_charm.yaml@v13.0.0 + uses: canonical/data-platform-workflows/.github/workflows/build_charm.yaml@v13.1.1 with: cache: true @@ -51,17 +51,17 @@ jobs: fail-fast: false matrix: juju: - - agent: 2.9.47 # renovate: latest juju 2 + - agent: 2.9.49 # renovate: latest juju 2 libjuju: ==2.9.46.1 # renovate: latest libjuju 2 allure: false - - agent: 3.1.7 # renovate: latest juju 3 + - agent: 3.1.8 # renovate: latest juju 3 allure: true name: Integration test charm | ${{ matrix.juju.agent }} needs: - lint - unit-test - build - uses: canonical/data-platform-workflows/.github/workflows/integration_test_charm.yaml@v13.0.0 + uses: canonical/data-platform-workflows/.github/workflows/integration_test_charm.yaml@v13.1.1 with: artifact-prefix: ${{ needs.build.outputs.artifact-prefix }} cloud: microk8s diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index c93d40db2..f17dff436 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -52,14 +52,14 @@ jobs: build: name: Build charm - uses: canonical/data-platform-workflows/.github/workflows/build_charm.yaml@v13.0.0 + uses: canonical/data-platform-workflows/.github/workflows/build_charm.yaml@v13.1.1 release: name: Release charm needs: - ci-tests - build - uses: canonical/data-platform-workflows/.github/workflows/release_charm.yaml@v13.0.0 + uses: canonical/data-platform-workflows/.github/workflows/release_charm.yaml@v13.1.1 with: channel: 1/edge artifact-prefix: ${{ needs.build.outputs.artifact-prefix }} diff --git a/.github/workflows/sync_issue_to_jira.yaml b/.github/workflows/sync_issue_to_jira.yaml index c47e78772..5ed7cd3e4 100644 --- a/.github/workflows/sync_issue_to_jira.yaml +++ b/.github/workflows/sync_issue_to_jira.yaml @@ -9,7 +9,7 @@ on: jobs: sync: name: Sync GitHub issue to Jira - uses: canonical/data-platform-workflows/.github/workflows/sync_issue_to_jira.yaml@v13.0.0 + uses: canonical/data-platform-workflows/.github/workflows/sync_issue_to_jira.yaml@v13.1.1 with: jira-base-url: https://warthogs.atlassian.net jira-project-key: DPE diff --git a/metadata.yaml b/metadata.yaml index df7db2436..3394c71e4 100644 --- a/metadata.yaml +++ b/metadata.yaml @@ -28,7 +28,7 @@ resources: pgbouncer-image: type: oci-image description: OCI image for pgbouncer - upstream-source: ghcr.io/canonical/charmed-postgresql@sha256:a9b6f25cc6a12b0cb81cb19be76804f4a9452e4388ab2a11efd2d57a316977c5 + upstream-source: ghcr.io/canonical/charmed-postgresql@sha256:b7db85555240c4e6f2df51badba69d9d8255c6d1e41b37ccb3dd0efcaef59030 provides: database: diff --git a/poetry.lock b/poetry.lock index 52f29a378..42fcda13f 100644 --- a/poetry.lock +++ b/poetry.lock @@ -394,13 +394,13 @@ files = [ [[package]] name = "cosl" -version = "0.0.10" +version = "0.0.11" description = "Utils for COS Lite charms" optional = false python-versions = ">=3.8" files = [ - {file = "cosl-0.0.10-py3-none-any.whl", hash = "sha256:9bbfb85917460075780cb8f94774c41dc2a8890ae06d35ad9b4c78d2a20fe803"}, - {file = "cosl-0.0.10.tar.gz", hash = "sha256:fe45ef7086a4948f5f9546e620b001822104b7c89a4a34f297d4d1acc117356f"}, + {file = "cosl-0.0.11-py3-none-any.whl", hash = "sha256:46d78d6441ba628bae386cd8c10b8144558ab208115522020e7858f97837988d"}, + {file = "cosl-0.0.11.tar.gz", hash = "sha256:15cac6ed20b65e9d33cda3c3da32e299c82f9feea64e393448cd3d3cf2bef32a"}, ] [package.dependencies] @@ -666,13 +666,13 @@ parser = ["pyhcl (>=0.4.4,<0.5.0)"] [[package]] name = "idna" -version = "3.6" +version = "3.7" description = "Internationalized Domain Names in Applications (IDNA)" optional = false python-versions = ">=3.5" files = [ - {file = "idna-3.6-py3-none-any.whl", hash = "sha256:c05567e9c24a6b9faaa835c4821bad0590fbb9d5779e7caa6e1cc4978e7eb24f"}, - {file = "idna-3.6.tar.gz", hash = "sha256:9ecdbbd083b06798ae1e86adcbfe8ab1479cf864e4ee30fe4e46a003d12491ca"}, + {file = "idna-3.7-py3-none-any.whl", hash = "sha256:82fee1fc78add43492d3a1898bfa6d8a904cc97d8427f683ed8e798d07761aa0"}, + {file = "idna-3.7.tar.gz", hash = "sha256:028ff3aadf0609c1fd278d8ea3089299412a7a8b9bd005dd08b9f8285bcb5cfc"}, ] [[package]] @@ -999,13 +999,13 @@ files = [ [[package]] name = "matplotlib-inline" -version = "0.1.6" +version = "0.1.7" description = "Inline Matplotlib backend for Jupyter" optional = false -python-versions = ">=3.5" +python-versions = ">=3.8" files = [ - {file = "matplotlib-inline-0.1.6.tar.gz", hash = "sha256:f887e5f10ba98e8d2b150ddcf4702c1e5f8b3a20005eb0f74bfdbd360ee6f304"}, - {file = "matplotlib_inline-0.1.6-py3-none-any.whl", hash = "sha256:f1f41aab5328aa5aaea9b16d083b128102f8712542f819fe7e6a420ff581b311"}, + {file = "matplotlib_inline-0.1.7-py3-none-any.whl", hash = "sha256:df192d39a4ff8f21b1895d72e6a13f5fcc5099f00fa84384e0ea28c2cc0653ca"}, + {file = "matplotlib_inline-0.1.7.tar.gz", hash = "sha256:8423b23ec666be3d16e16b60bdd8ac4e86e840ebd1dd11a30b9f117f2fa0ab90"}, ] [package.dependencies] @@ -1104,18 +1104,18 @@ invoke = ["invoke (>=2.0)"] [[package]] name = "parso" -version = "0.8.3" +version = "0.8.4" description = "A Python Parser" optional = false python-versions = ">=3.6" files = [ - {file = "parso-0.8.3-py2.py3-none-any.whl", hash = "sha256:c001d4636cd3aecdaf33cbb40aebb59b094be2a74c556778ef5576c175e19e75"}, - {file = "parso-0.8.3.tar.gz", hash = "sha256:8c07be290bb59f03588915921e29e8a50002acaf2cdc5fa0e0114f91709fafa0"}, + {file = "parso-0.8.4-py2.py3-none-any.whl", hash = "sha256:a418670a20291dacd2dddc80c377c5c3791378ee1e8d12bffc35420643d43f18"}, + {file = "parso-0.8.4.tar.gz", hash = "sha256:eb3a7b58240fb99099a345571deecc0f9540ea5f4dd2fe14c2a99d6b281ab92d"}, ] [package.extras] -qa = ["flake8 (==3.8.3)", "mypy (==0.782)"] -testing = ["docopt", "pytest (<6.0.0)"] +qa = ["flake8 (==5.0.4)", "mypy (==0.971)", "types-setuptools (==67.2.0.1)"] +testing = ["docopt", "pytest"] [[package]] name = "pexpect" @@ -1586,8 +1586,8 @@ develop = false [package.source] type = "git" url = "https://github.com/canonical/data-platform-workflows" -reference = "v13.0.0" -resolved_reference = "b662fd727b538a4b2a65f25d9c25b9bd76e197ad" +reference = "v13.1.1" +resolved_reference = "52f3d97ebb97f4f37ec9678af850ecfb97fcf71a" subdirectory = "python/pytest_plugins/github_secrets" [[package]] @@ -1624,8 +1624,8 @@ pyyaml = "*" [package.source] type = "git" url = "https://github.com/canonical/data-platform-workflows" -reference = "v13.0.0" -resolved_reference = "b662fd727b538a4b2a65f25d9c25b9bd76e197ad" +reference = "v13.1.1" +resolved_reference = "52f3d97ebb97f4f37ec9678af850ecfb97fcf71a" subdirectory = "python/pytest_plugins/pytest_operator_cache" [[package]] @@ -1643,8 +1643,8 @@ pytest = "*" [package.source] type = "git" url = "https://github.com/canonical/data-platform-workflows" -reference = "v13.0.0" -resolved_reference = "b662fd727b538a4b2a65f25d9c25b9bd76e197ad" +reference = "v13.1.1" +resolved_reference = "52f3d97ebb97f4f37ec9678af850ecfb97fcf71a" subdirectory = "python/pytest_plugins/pytest_operator_groups" [[package]] @@ -1909,28 +1909,28 @@ pyasn1 = ">=0.1.3" [[package]] name = "ruff" -version = "0.3.5" +version = "0.3.7" description = "An extremely fast Python linter and code formatter, written in Rust." optional = false python-versions = ">=3.7" files = [ - {file = "ruff-0.3.5-py3-none-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl", hash = "sha256:aef5bd3b89e657007e1be6b16553c8813b221ff6d92c7526b7e0227450981eac"}, - {file = "ruff-0.3.5-py3-none-macosx_10_12_x86_64.whl", hash = "sha256:89b1e92b3bd9fca249153a97d23f29bed3992cff414b222fcd361d763fc53f12"}, - {file = "ruff-0.3.5-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:5e55771559c89272c3ebab23326dc23e7f813e492052391fe7950c1a5a139d89"}, - {file = "ruff-0.3.5-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:dabc62195bf54b8a7876add6e789caae0268f34582333cda340497c886111c39"}, - {file = "ruff-0.3.5-py3-none-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:3a05f3793ba25f194f395578579c546ca5d83e0195f992edc32e5907d142bfa3"}, - {file = "ruff-0.3.5-py3-none-manylinux_2_17_ppc64.manylinux2014_ppc64.whl", hash = "sha256:dfd3504e881082959b4160ab02f7a205f0fadc0a9619cc481982b6837b2fd4c0"}, - {file = "ruff-0.3.5-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:87258e0d4b04046cf1d6cc1c56fadbf7a880cc3de1f7294938e923234cf9e498"}, - {file = "ruff-0.3.5-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:712e71283fc7d9f95047ed5f793bc019b0b0a29849b14664a60fd66c23b96da1"}, - {file = "ruff-0.3.5-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:a532a90b4a18d3f722c124c513ffb5e5eaff0cc4f6d3aa4bda38e691b8600c9f"}, - {file = "ruff-0.3.5-py3-none-musllinux_1_2_aarch64.whl", hash = "sha256:122de171a147c76ada00f76df533b54676f6e321e61bd8656ae54be326c10296"}, - {file = "ruff-0.3.5-py3-none-musllinux_1_2_armv7l.whl", hash = "sha256:d80a6b18a6c3b6ed25b71b05eba183f37d9bc8b16ace9e3d700997f00b74660b"}, - {file = "ruff-0.3.5-py3-none-musllinux_1_2_i686.whl", hash = "sha256:a7b6e63194c68bca8e71f81de30cfa6f58ff70393cf45aab4c20f158227d5936"}, - {file = "ruff-0.3.5-py3-none-musllinux_1_2_x86_64.whl", hash = "sha256:a759d33a20c72f2dfa54dae6e85e1225b8e302e8ac655773aff22e542a300985"}, - {file = "ruff-0.3.5-py3-none-win32.whl", hash = "sha256:9d8605aa990045517c911726d21293ef4baa64f87265896e491a05461cae078d"}, - {file = "ruff-0.3.5-py3-none-win_amd64.whl", hash = "sha256:dc56bb16a63c1303bd47563c60482a1512721053d93231cf7e9e1c6954395a0e"}, - {file = "ruff-0.3.5-py3-none-win_arm64.whl", hash = "sha256:faeeae9905446b975dcf6d4499dc93439b131f1443ee264055c5716dd947af55"}, - {file = "ruff-0.3.5.tar.gz", hash = "sha256:a067daaeb1dc2baf9b82a32dae67d154d95212080c80435eb052d95da647763d"}, + {file = "ruff-0.3.7-py3-none-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl", hash = "sha256:0e8377cccb2f07abd25e84fc5b2cbe48eeb0fea9f1719cad7caedb061d70e5ce"}, + {file = "ruff-0.3.7-py3-none-macosx_10_12_x86_64.whl", hash = "sha256:15a4d1cc1e64e556fa0d67bfd388fed416b7f3b26d5d1c3e7d192c897e39ba4b"}, + {file = "ruff-0.3.7-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:d28bdf3d7dc71dd46929fafeec98ba89b7c3550c3f0978e36389b5631b793663"}, + {file = "ruff-0.3.7-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:379b67d4f49774ba679593b232dcd90d9e10f04d96e3c8ce4a28037ae473f7bb"}, + {file = "ruff-0.3.7-py3-none-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:c060aea8ad5ef21cdfbbe05475ab5104ce7827b639a78dd55383a6e9895b7c51"}, + {file = "ruff-0.3.7-py3-none-manylinux_2_17_ppc64.manylinux2014_ppc64.whl", hash = "sha256:ebf8f615dde968272d70502c083ebf963b6781aacd3079081e03b32adfe4d58a"}, + {file = "ruff-0.3.7-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:d48098bd8f5c38897b03604f5428901b65e3c97d40b3952e38637b5404b739a2"}, + {file = "ruff-0.3.7-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:da8a4fda219bf9024692b1bc68c9cff4b80507879ada8769dc7e985755d662ea"}, + {file = "ruff-0.3.7-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:6c44e0149f1d8b48c4d5c33d88c677a4aa22fd09b1683d6a7ff55b816b5d074f"}, + {file = "ruff-0.3.7-py3-none-musllinux_1_2_aarch64.whl", hash = "sha256:3050ec0af72b709a62ecc2aca941b9cd479a7bf2b36cc4562f0033d688e44fa1"}, + {file = "ruff-0.3.7-py3-none-musllinux_1_2_armv7l.whl", hash = "sha256:a29cc38e4c1ab00da18a3f6777f8b50099d73326981bb7d182e54a9a21bb4ff7"}, + {file = "ruff-0.3.7-py3-none-musllinux_1_2_i686.whl", hash = "sha256:5b15cc59c19edca917f51b1956637db47e200b0fc5e6e1878233d3a938384b0b"}, + {file = "ruff-0.3.7-py3-none-musllinux_1_2_x86_64.whl", hash = "sha256:e491045781b1e38b72c91247cf4634f040f8d0cb3e6d3d64d38dcf43616650b4"}, + {file = "ruff-0.3.7-py3-none-win32.whl", hash = "sha256:bc931de87593d64fad3a22e201e55ad76271f1d5bfc44e1a1887edd0903c7d9f"}, + {file = "ruff-0.3.7-py3-none-win_amd64.whl", hash = "sha256:5ef0e501e1e39f35e03c2acb1d1238c595b8bb36cf7a170e7c1df1b73da00e74"}, + {file = "ruff-0.3.7-py3-none-win_arm64.whl", hash = "sha256:789e144f6dc7019d1f92a812891c645274ed08af6037d11fc65fcbc183b7d59f"}, + {file = "ruff-0.3.7.tar.gz", hash = "sha256:d5c1aebee5162c2226784800ae031f660c350e7a3402c4d1f8ea4e97e232e3ba"}, ] [[package]] @@ -2027,13 +2027,13 @@ test = ["argcomplete (>=3.0.3)", "mypy (>=1.7.0)", "pre-commit", "pytest (>=7.0, [[package]] name = "typing-extensions" -version = "4.10.0" +version = "4.11.0" description = "Backported and Experimental Type Hints for Python 3.8+" optional = false python-versions = ">=3.8" files = [ - {file = "typing_extensions-4.10.0-py3-none-any.whl", hash = "sha256:69b1a937c3a517342112fb4c6df7e72fc39a38e7891a5730ed4985b5214b5475"}, - {file = "typing_extensions-4.10.0.tar.gz", hash = "sha256:b0abd7c89e8fb96f98db18d86106ff1d90ab692004eb746cf6eda2682f91b3cb"}, + {file = "typing_extensions-4.11.0-py3-none-any.whl", hash = "sha256:c1f94d72897edaf4ce775bb7558d5b79d8126906a14ea5ed1635921406c0387a"}, + {file = "typing_extensions-4.11.0.tar.gz", hash = "sha256:83f085bd5ca59c80295fc2a82ab5dac679cbe02b9f33f7d83af68e241bea51b0"}, ] [[package]] @@ -2205,4 +2205,4 @@ testing = ["big-O", "jaraco.functools", "jaraco.itertools", "more-itertools", "p [metadata] lock-version = "2.0" python-versions = "^3.8.10" -content-hash = "04964273355e0889070fe89e8dab3c23658e3e9c8aea73bfb9626416d7ad6aed" +content-hash = "724d918b4569f3c19efcba69fde2e069273bb26bdb59de2697df29d85bd2a0a3" diff --git a/pyproject.toml b/pyproject.toml index c73181b60..3b4af6b7e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -17,7 +17,7 @@ ops = "^2.12.0" cryptography = "^42.0.5" jsonschema = "^4.21.1" tenacity = "^8.2.3" -cosl = "^0.0.10" +cosl = "^0.0.11" poetry-core = "^1.9.0" lightkube = "^0.15.2" lightkube-models = "^1.29.0.6" @@ -40,7 +40,7 @@ cosl = "*" optional = true [tool.poetry.group.format.dependencies] -ruff = "^0.3.5" +ruff = "^0.3.7" [tool.poetry.group.lint] optional = true @@ -64,10 +64,10 @@ optional = true [tool.poetry.group.integration.dependencies] lightkube = "*" pytest = "^8.1.1" -pytest-github-secrets = {git = "https://github.com/canonical/data-platform-workflows", tag = "v13.0.0", subdirectory = "python/pytest_plugins/github_secrets"} +pytest-github-secrets = {git = "https://github.com/canonical/data-platform-workflows", tag = "v13.1.1", subdirectory = "python/pytest_plugins/github_secrets"} pytest-operator = "^0.34.0" -pytest-operator-cache = {git = "https://github.com/canonical/data-platform-workflows", tag = "v13.0.0", subdirectory = "python/pytest_plugins/pytest_operator_cache"} -pytest-operator-groups = {git = "https://github.com/canonical/data-platform-workflows", tag = "v13.0.0", subdirectory = "python/pytest_plugins/pytest_operator_groups"} +pytest-operator-cache = {git = "https://github.com/canonical/data-platform-workflows", tag = "v13.1.1", subdirectory = "python/pytest_plugins/pytest_operator_cache"} +pytest-operator-groups = {git = "https://github.com/canonical/data-platform-workflows", tag = "v13.1.1", subdirectory = "python/pytest_plugins/pytest_operator_groups"} # renovate caret doesn't work: https://github.com/renovatebot/renovate/issues/26940 juju = "<=3.4.0.0" tenacity = "*" diff --git a/src/charm.py b/src/charm.py index 1815b9dc5..9577d427a 100755 --- a/src/charm.py +++ b/src/charm.py @@ -445,6 +445,9 @@ def _on_update_status(self, _) -> None: def update_status(self): """Health check to update pgbouncer status based on charm state.""" + if self.unit.status.message == EXTENSIONS_BLOCKING_MESSAGE: + return + if self.backend.postgres is None: self.unit.status = BlockedStatus("waiting for backend database relation to initialise") return @@ -453,9 +456,6 @@ def update_status(self): self.unit.status = BlockedStatus("backend database relation not ready") return - if self.unit.status.message == EXTENSIONS_BLOCKING_MESSAGE: - return - try: if self.check_pgb_running(): self.unit.status = ActiveStatus() @@ -528,7 +528,8 @@ def check_pgb_running(self): """Checks that pgbouncer pebble service is running, and updates status accordingly.""" pgb_container = self.unit.get_container(PGB) if not pgb_container.can_connect(): - self.unit.status = WaitingStatus(CONTAINER_UNAVAILABLE_MESSAGE) + if self.unit.status.message != EXTENSIONS_BLOCKING_MESSAGE: + self.unit.status = WaitingStatus(CONTAINER_UNAVAILABLE_MESSAGE) logger.warning(CONTAINER_UNAVAILABLE_MESSAGE) return False @@ -545,7 +546,8 @@ def check_pgb_running(self): pgb_service_status = pgb_container.get_services().get(service).current if pgb_service_status != ServiceStatus.ACTIVE: pgb_not_running = f"PgBouncer service {service} not running: service status = {pgb_service_status}" - self.unit.status = BlockedStatus(pgb_not_running) + if self.unit.status.message != EXTENSIONS_BLOCKING_MESSAGE: + self.unit.status = BlockedStatus(pgb_not_running) logger.warning(pgb_not_running) return False @@ -715,14 +717,12 @@ def generate_relation_databases(self) -> Dict[str, Dict[str, Union[str, bool]]]: """Generates a mapping between relation and database and sets it in the app databag.""" if not self.unit.is_leader(): return {} - if dbs := self.get_relation_databases(): - return dbs databases = {} for relation in self.model.relations.get("db", []): database = self.legacy_db_relation.get_databags(relation)[0].get("database") if database: - databases[relation.id] = { + databases[str(relation.id)] = { "name": database, "legacy": True, } @@ -730,7 +730,7 @@ def generate_relation_databases(self) -> Dict[str, Dict[str, Union[str, bool]]]: for relation in self.model.relations.get("db-admin", []): database = self.legacy_db_admin_relation.get_databags(relation)[0].get("database") if database: - databases[relation.id] = { + databases[str(relation.id)] = { "name": database, "legacy": True, } @@ -740,7 +740,7 @@ def generate_relation_databases(self) -> Dict[str, Dict[str, Union[str, bool]]]: ).items(): database = data.get("database") if database: - databases[rel_id] = { + databases[str(rel_id)] = { "name": database, "legacy": False, } diff --git a/src/relations/backend_database.py b/src/relations/backend_database.py index ba6d9d2a3..312c1be1c 100644 --- a/src/relations/backend_database.py +++ b/src/relations/backend_database.py @@ -50,7 +50,6 @@ from ops.charm import CharmBase, RelationBrokenEvent, RelationDepartedEvent from ops.framework import Object from ops.model import ( - ActiveStatus, Application, BlockedStatus, MaintenanceStatus, @@ -232,7 +231,7 @@ def _on_database_created(self, event: DatabaseCreatedEvent) -> None: self.charm.render_auth_file(auth_file) self.charm.render_pgb_config(reload_pgbouncer=True) self.charm.toggle_monitoring_layer(True) - self.charm.unit.status = ActiveStatus() + self.charm.update_status() return logger.info("initialising pgbouncer backend relation") @@ -274,7 +273,7 @@ def _on_database_created(self, event: DatabaseCreatedEvent) -> None: self.charm.render_pgb_config(reload_pgbouncer=True) self.charm.toggle_monitoring_layer(True) - self.charm.unit.status = ActiveStatus("backend-database relation initialised.") + self.charm.update_status() def _on_endpoints_changed(self, _): self.charm.render_pgb_config(reload_pgbouncer=True) @@ -300,7 +299,8 @@ def _on_relation_departed(self, event: RelationDepartedEvent): the postgres relation-broken hook removes the user needed to remove authentication for the users we create. """ - self.charm.render_pgb_config(reload_pgbouncer=True) + if self.charm.peers.relation: + self.charm.render_pgb_config(reload_pgbouncer=True) self.charm.update_client_connection_info() if event.departing_unit == self.charm.unit: @@ -335,7 +335,6 @@ def _on_relation_departed(self, event: RelationDepartedEvent): return self.postgres.delete_user(self.auth_user) - self.charm.peers.remove_user(self.auth_user) logger.info("pgbouncer auth user removed") def _on_relation_broken(self, event: RelationBrokenEvent): @@ -344,11 +343,11 @@ def _on_relation_broken(self, event: RelationBrokenEvent): Removes all traces of this relation from pgbouncer config. """ depart_flag = f"{BACKEND_RELATION_NAME}_{event.relation.id}_departing" - self.charm.toggle_monitoring_layer(False) if self.charm.peers.unit_databag.get(depart_flag, False): logging.info("exiting relation-broken hook - nothing to do") return + self.charm.toggle_monitoring_layer(False) try: self.charm.delete_file(f"{PGB_DIR}/userlist.txt") except PathError: diff --git a/src/relations/db.py b/src/relations/db.py index 808ab0bae..883b120ca 100644 --- a/src/relations/db.py +++ b/src/relations/db.py @@ -237,7 +237,7 @@ def _on_relation_joined(self, join_event: RelationJoinedEvent): return dbs = self.charm.generate_relation_databases() - dbs[join_event.relation.id] = {"name": database, "legacy": True} + dbs[str(join_event.relation.id)] = {"name": database, "legacy": True} self.charm.set_relation_databases(dbs) self.update_databags( @@ -252,6 +252,7 @@ def _on_relation_joined(self, join_event: RelationJoinedEvent): # Create user and database in backend postgresql database try: init_msg = f"initialising database and user for {self.relation_name} relation" + initial_status = self.charm.unit.status self.charm.unit.status = MaintenanceStatus(init_msg) logger.info(init_msg) @@ -259,7 +260,8 @@ def _on_relation_joined(self, join_event: RelationJoinedEvent): self.charm.backend.postgres.create_database(database, user) created_msg = f"database and user for {self.relation_name} relation created" - self.charm.unit.status = ActiveStatus() + self.charm.unit.status = initial_status + self.charm.update_status() logger.info(created_msg) except (PostgreSQLCreateDatabaseError, PostgreSQLCreateUserError): err_msg = f"failed to create database or user for {self.relation_name}" @@ -323,6 +325,9 @@ def _on_relation_changed(self, change_event: RelationChangedEvent): def update_connection_info(self, relation: Relation, port: str): """Updates databag connection information.""" + if not port: + port = self.charm.config["listen_port"] + databag = self.get_databags(relation)[0] database = databag.get("database") user = databag.get("user") diff --git a/src/relations/pgbouncer_provider.py b/src/relations/pgbouncer_provider.py index 7991668d6..477df9d27 100644 --- a/src/relations/pgbouncer_provider.py +++ b/src/relations/pgbouncer_provider.py @@ -153,7 +153,7 @@ def _on_database_requested(self, event: DatabaseRequestedEvent) -> None: return dbs = self.charm.generate_relation_databases() - dbs[event.relation.id] = {"name": database, "legacy": False} + dbs[str(event.relation.id)] = {"name": database, "legacy": False} self.charm.set_relation_databases(dbs) # Share the credentials and updated connection info with the client application. diff --git a/tests/integration/relations/test_db.py b/tests/integration/relations/test_db.py index 82345aa58..a23831b3a 100644 --- a/tests/integration/relations/test_db.py +++ b/tests/integration/relations/test_db.py @@ -30,7 +30,6 @@ FINOS_WALTZ = "finos-waltz" ANOTHER_FINOS_WALTZ = "another-finos-waltz" -OPENLDAP = "openldap" logger = logging.getLogger(__name__) @@ -198,15 +197,3 @@ async def test_extensions_blocking(ops_test: OpsTest) -> None: raise_on_blocked=False, timeout=3000, ) - - -@pytest.mark.group(1) -@pytest.mark.unstable -async def test_relation_with_openldap(ops_test: OpsTest): - """Test the relation with OpenLDAP charm.""" - await ops_test.model.deploy( - "openldap-charmers-openldap", application_name=OPENLDAP, channel="edge" - ) - await ops_test.model.add_relation(f"{PGB}:db", f"{OPENLDAP}:db") - wait_for_relation_joined_between(ops_test, PGB, OPENLDAP) - await ops_test.model.wait_for_idle(apps=[PG, PGB, OPENLDAP], status="active", timeout=1000) diff --git a/tests/unit/relations/test_db.py b/tests/unit/relations/test_db.py index fbc627135..c1ec5ce09 100644 --- a/tests/unit/relations/test_db.py +++ b/tests/unit/relations/test_db.py @@ -106,7 +106,7 @@ def test_on_relation_joined( _set_rel_dbs.reset_mock() self.db_admin_relation._on_relation_joined(mock_event) - _set_rel_dbs.assert_called_once_with({1: {"name": "test_db", "legacy": True}}) + _set_rel_dbs.assert_called_once_with({"1": {"name": "test_db", "legacy": True}}) _create_user.assert_called_with(user, password, admin=True) _create_database.assert_called_with(database, user) @@ -121,7 +121,7 @@ def test_on_relation_joined( _set_rel_dbs.reset_mock() self.db_relation._on_relation_joined(mock_event) _create_user.assert_called_with(user, password, admin=False) - _set_rel_dbs.assert_called_once_with({1: {"name": "test_db", "legacy": True}}) + _set_rel_dbs.assert_called_once_with({"1": {"name": "test_db", "legacy": True}}) @patch("relations.backend_database.BackendDatabaseRequires.check_backend", return_value=True) @patch( diff --git a/tests/unit/relations/test_pgbouncer_provider.py b/tests/unit/relations/test_pgbouncer_provider.py index abbf611cd..85886d58a 100644 --- a/tests/unit/relations/test_pgbouncer_provider.py +++ b/tests/unit/relations/test_pgbouncer_provider.py @@ -107,7 +107,7 @@ def test_on_database_requested( rel_id, f"{self.charm.leader_hostname}:{self.charm.config['listen_port']}" ) _set_read_only_endpoints.assert_called() - _set_rel_dbs.assert_called_once_with({1: {"name": "test-db", "legacy": False}}) + _set_rel_dbs.assert_called_once_with({"1": {"name": "test-db", "legacy": False}}) @patch("relations.backend_database.BackendDatabaseRequires.check_backend", return_value=True) @patch(