diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index ebd2d39dad..38c2ae04ae 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -45,18 +45,16 @@ jobs: build: name: Build charm - uses: canonical/data-platform-workflows/.github/workflows/build_charm.yaml@v23.1.1 + uses: canonical/data-platform-workflows/.github/workflows/build_charm.yaml@lucas/fix-collect-bases with: - cache: true + cache: false + charmcraft-snap-channel: 3.x/stable integration-test: strategy: fail-fast: false matrix: juju: - - agent: 2.9.51 # renovate: juju-agent-pin-minor - libjuju: ==2.9.49.0 # renovate: latest libjuju 2 - allure_on_amd64: false - agent: 3.4.6 # renovate: juju-agent-pin-minor allure_on_amd64: true - snap_channel: 3.6/stable @@ -84,7 +82,6 @@ jobs: cloud: lxd juju-agent-version: ${{ matrix.juju.agent }} juju-snap-channel: ${{ matrix.juju.snap_channel }} - libjuju-version-constraint: ${{ matrix.juju.libjuju }} _beta_allure_report: ${{ matrix.juju.allure_on_amd64 && matrix.architecture == 'amd64' }} secrets: integration-test: | diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 43b7b8c462..c5eaa04465 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -5,7 +5,7 @@ name: Release to Charmhub on: push: branches: - - main + - 16/edge paths-ignore: - 'tests/**' - 'docs/**' @@ -14,27 +14,70 @@ on: - '.github/workflows/ci.yaml' - '.github/workflows/lib-check.yaml' - '.github/workflows/sync_docs.yaml' + # for testing purposes: + workflow_dispatch: jobs: - ci-tests: - name: Tests - uses: ./.github/workflows/ci.yaml - secrets: inherit - permissions: - contents: write # Needed for Allure Report beta - build: name: Build charm - uses: canonical/data-platform-workflows/.github/workflows/build_charm.yaml@v23.1.1 + uses: canonical/data-platform-workflows/.github/workflows/build_charm.yaml@lucas/fix-collect-bases + with: + cache: false + charmcraft-snap-channel: 3.x/stable + + integration-test: + strategy: + fail-fast: false + matrix: + juju: + - agent: 3.4.6 # renovate: juju-agent-pin-minor + allure_on_amd64: true + - snap_channel: 3.6/candidate + allure_on_amd64: false + architecture: + - amd64 + include: + - juju: + agent: 3.4.6 # renovate: juju-agent-pin-minor + allure_on_amd64: true + architecture: arm64 + - juju: + snap_channel: 3.6/candidate + allure_on_amd64: false + architecture: arm64 + name: Integration | ${{ matrix.juju.agent || matrix.juju.snap_channel }} | ${{ matrix.architecture }} + needs: + - build + uses: canonical/data-platform-workflows/.github/workflows/integration_test_charm.yaml@v23.0.5 + with: + artifact-prefix: ${{ needs.build.outputs.artifact-prefix }} + architecture: ${{ matrix.architecture }} + cloud: lxd + juju-agent-version: ${{ matrix.juju.agent }} + juju-snap-channel: ${{ matrix.juju.snap_channel }} + _beta_allure_report: ${{ matrix.juju.allure_on_amd64 && matrix.architecture == 'amd64' }} + secrets: + integration-test: | + { + "AWS_ACCESS_KEY": "${{ secrets.AWS_ACCESS_KEY }}", + "AWS_SECRET_KEY": "${{ secrets.AWS_SECRET_KEY }}", + "GCP_ACCESS_KEY": "${{ secrets.GCP_ACCESS_KEY }}", + "GCP_SECRET_KEY": "${{ secrets.GCP_SECRET_KEY }}", + "UBUNTU_PRO_TOKEN" : "${{ secrets.UBUNTU_PRO_TOKEN }}", + "LANDSCAPE_ACCOUNT_NAME": "${{ secrets.LANDSCAPE_ACCOUNT_NAME }}", + "LANDSCAPE_REGISTRATION_KEY": "${{ secrets.LANDSCAPE_REGISTRATION_KEY }}", + } + permissions: + contents: write # Needed for Allure Report beta release: name: Release charm needs: - - ci-tests + - integration-test - build - uses: canonical/data-platform-workflows/.github/workflows/release_charm.yaml@v23.1.1 + uses: canonical/data-platform-workflows/.github/workflows/release_charm.yaml@lucas/fix-collect-bases with: - channel: 14/edge + channel: 16/edge artifact-prefix: ${{ needs.build.outputs.artifact-prefix }} secrets: charmhub-token: ${{ secrets.CHARMHUB_TOKEN }} diff --git a/README.md b/README.md index 7c3e83c644..db0c8bb6b1 100644 --- a/README.md +++ b/README.md @@ -29,7 +29,7 @@ juju add-model sample-model To deploy a single unit of PostgreSQL using its [default configuration](config.yaml), run the following command: ```shell -juju deploy postgresql --channel 14/stable +juju deploy postgresql --channel 16/stable ``` It is customary to use PostgreSQL with replication to ensure high availability. A replica is equivalent to a juju unit. @@ -37,7 +37,7 @@ It is customary to use PostgreSQL with replication to ensure high availability. To deploy PostgreSQL with multiple replicas, specify the number of desired units with the `-n` option: ```shell -juju deploy postgresql --channel 14/stable -n +juju deploy postgresql --channel 16/stable -n ``` To add replicas to an existing deployment, see the [Add replicas](#add-replicas) section. diff --git a/charmcraft.yaml b/charmcraft.yaml index e5e0208749..15efefa9d5 100644 --- a/charmcraft.yaml +++ b/charmcraft.yaml @@ -2,13 +2,15 @@ # See LICENSE file for licensing details. type: charm -bases: - - name: ubuntu - channel: "22.04" - architectures: [amd64] - - name: ubuntu - channel: "22.04" - architectures: [arm64] +base: ubuntu@24.04 + +platforms: + amd64: + build-on: amd64 + build-for: amd64 + arm64: + build-on: arm64 + build-for: arm64 parts: charm: build-snaps: diff --git a/lib/charms/postgresql_k8s/v0/postgresql.py b/lib/charms/postgresql_k8s/v0/postgresql.py index 4d8d6dc30c..e55cf00ff8 100644 --- a/lib/charms/postgresql_k8s/v0/postgresql.py +++ b/lib/charms/postgresql_k8s/v0/postgresql.py @@ -36,7 +36,7 @@ # Increment this PATCH version before using `charmcraft publish-lib` or reset # to 0 if you are raising the major API version -LIBPATCH = 39 +LIBPATCH = 40 INVALID_EXTRA_USER_ROLE_BLOCKING_MESSAGE = "invalid role(s) for extra user roles" @@ -339,10 +339,12 @@ def enable_disable_extensions(self, extensions: Dict[str, bool], database: str = # Enable/disabled the extension in each database. for database in databases: - with self._connect_to_database( - database=database - ) as connection, connection.cursor() as cursor: + connection = self._connect_to_database(database=database) + connection.autocommit = True + with connection.cursor() as cursor: for extension, enable in ordered_extensions.items(): + if extension == "postgis": + cursor.execute("SET pgaudit.log = 'none';") cursor.execute( f"CREATE EXTENSION IF NOT EXISTS {extension};" if enable @@ -364,6 +366,7 @@ def _generate_database_privileges_statements( ) -> List[Composed]: """Generates a list of databases privileges statements.""" statements = [] + statements.append(sql.SQL("GRANT USAGE, CREATE ON SCHEMA public TO admin;")) if relations_accessing_this_database == 1: statements.append( sql.SQL( @@ -418,11 +421,11 @@ def _generate_database_privileges_statements( sql.SQL("GRANT ALL PRIVILEGES ON ALL FUNCTIONS IN SCHEMA {} TO {};").format( schema, sql.Identifier(user) ), - sql.SQL("GRANT USAGE ON SCHEMA {} TO {};").format( + sql.SQL("GRANT USAGE, CREATE ON SCHEMA {} TO {};").format( schema, sql.Identifier(user) ), - sql.SQL("GRANT CREATE ON SCHEMA {} TO {};").format( - schema, sql.Identifier(user) + sql.SQL("GRANT USAGE, CREATE ON SCHEMA {} TO admin;").format( + schema ), ]) return statements diff --git a/poetry.lock b/poetry.lock index eebd5b0dd2..2369a7d35e 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1882,8 +1882,8 @@ pyyaml = "*" [package.source] type = "git" url = "https://github.com/canonical/data-platform-workflows" -reference = "v23.1.1" -resolved_reference = "7dc172891bf274e74eef2a4d822450ca00f55188" +reference = "lucas/fix-collect-bases" +resolved_reference = "c5e624e285315bac740d8c7cd9404ebc981a280d" subdirectory = "python/pytest_plugins/pytest_operator_cache" [[package]] @@ -1901,8 +1901,8 @@ pytest = "*" [package.source] type = "git" url = "https://github.com/canonical/data-platform-workflows" -reference = "v23.1.1" -resolved_reference = "7dc172891bf274e74eef2a4d822450ca00f55188" +reference = "v23.0.5" +resolved_reference = "e3f522c648375decee87fc0982c012e46ffb0b98" subdirectory = "python/pytest_plugins/pytest_operator_groups" [[package]] @@ -2575,4 +2575,4 @@ type = ["pytest-mypy"] [metadata] lock-version = "2.0" python-versions = "^3.10" -content-hash = "69c49d41492f0bfd2a2981d0315645e26bc88f5d1bdb6479fed3733b578be719" +content-hash = "e8d69ec1f3f25200e55166ef04f4ea31444a8ae1bf9eedb9405cc7e21f94745e" diff --git a/pyproject.toml b/pyproject.toml index 17aaf5a7f4..f3bb0190cf 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -65,8 +65,8 @@ optional = true pytest = "^8.3.3" pytest-github-secrets = {git = "https://github.com/canonical/data-platform-workflows", tag = "v23.1.1", subdirectory = "python/pytest_plugins/github_secrets"} pytest-operator = "^0.38.0" -pytest-operator-cache = {git = "https://github.com/canonical/data-platform-workflows", tag = "v23.1.1", subdirectory = "python/pytest_plugins/pytest_operator_cache"} -pytest-operator-groups = {git = "https://github.com/canonical/data-platform-workflows", tag = "v23.1.1", subdirectory = "python/pytest_plugins/pytest_operator_groups"} +pytest-operator-cache = {git = "https://github.com/canonical/data-platform-workflows", branch = "lucas/fix-collect-bases", subdirectory = "python/pytest_plugins/pytest_operator_cache"} +pytest-operator-groups = {git = "https://github.com/canonical/data-platform-workflows", tag = "v23.0.5", subdirectory = "python/pytest_plugins/pytest_operator_groups"} # renovate caret doesn't work: https://github.com/renovatebot/renovate/issues/26940 juju = "<=3.5.0.0" boto3 = "*" diff --git a/src/charm.py b/src/charm.py index afc46729d9..8d9d532026 100755 --- a/src/charm.py +++ b/src/charm.py @@ -1724,6 +1724,12 @@ def update_config(self, is_creating_backup: bool = False) -> bool: return True if not self._patroni.member_started: + if enable_tls: + logger.debug( + "Early exit update_config: patroni not responding but TLS is enabled." + ) + self._handle_postgresql_restart_need(True) + return True logger.debug("Early exit update_config: Patroni not started yet") return False @@ -1780,8 +1786,14 @@ def _validate_config_options(self) -> None: def _handle_postgresql_restart_need(self, enable_tls: bool) -> None: """Handle PostgreSQL restart need based on the TLS configuration and configuration changes.""" - restart_postgresql = self.is_tls_enabled != self.postgresql.is_tls_enabled() - self._patroni.reload_patroni_configuration() + if self._can_connect_to_postgresql: + restart_postgresql = self.is_tls_enabled != self.postgresql.is_tls_enabled() + else: + restart_postgresql = False + try: + self._patroni.reload_patroni_configuration() + except Exception as e: + logger.error(f"Reload patroni call failed! error: {e!s}") # Wait for some more time than the Patroni's loop_wait default value (10 seconds), # which tells how much time Patroni will wait before checking the configuration # file again to reload it. diff --git a/src/cluster.py b/src/cluster.py index 374964a5e5..463a44853d 100644 --- a/src/cluster.py +++ b/src/cluster.py @@ -791,7 +791,7 @@ def remove_raft_member(self, member_ip: str) -> None: if not result.startswith("SUCCESS"): raise RemoveRaftMemberFailedError() - @retry(stop=stop_after_attempt(10), wait=wait_exponential(multiplier=1, min=2, max=10)) + @retry(stop=stop_after_attempt(20), wait=wait_exponential(multiplier=1, min=2, max=10)) def reload_patroni_configuration(self): """Reload Patroni configuration after it was changed.""" requests.post( diff --git a/src/constants.py b/src/constants.py index f55769ec0b..6de25f4cd6 100644 --- a/src/constants.py +++ b/src/constants.py @@ -34,7 +34,7 @@ SNAP_PACKAGES = [ ( POSTGRESQL_SNAP_NAME, - {"revision": {"aarch64": "132", "x86_64": "133"}}, + {"revision": {"aarch64": "138", "x86_64": "139"}}, ) ] diff --git a/src/dependency.json b/src/dependency.json index 8071abbc37..cc4e9f524d 100644 --- a/src/dependency.json +++ b/src/dependency.json @@ -8,7 +8,7 @@ "snap": { "dependencies": {}, "name": "charmed-postgresql", - "upgrade_supported": "^14", - "version": "14.12" + "upgrade_supported": "^16", + "version": "16.6" } } diff --git a/src/locales.py b/src/locales.py index 7fd67a0ee8..d9422a958b 100644 --- a/src/locales.py +++ b/src/locales.py @@ -8,7 +8,6 @@ "aa_DJ", "aa_DJ.utf8", "aa_ER", - "aa_ER@saaho", "aa_ET", "af_ZA", "af_ZA.utf8", @@ -97,6 +96,7 @@ "chr_US", "ckb_IQ", "cmn_TW", + "crh_RU", "crh_UA", "cs_CZ", "cs_CZ.utf8", @@ -248,6 +248,7 @@ "ga_IE", "ga_IE.utf8", "ga_IE@euro", + "gbm_IN", "gd_GB", "gd_GB.utf8", "gez_ER", @@ -308,6 +309,7 @@ "ks_IN@devanagari", "ku_TR", "ku_TR.utf8", + "kv_RU", "kw_GB", "kw_GB.utf8", "ky_KG", @@ -389,6 +391,7 @@ "pt_PT@euro", "quz_PE", "raj_IN", + "rif_MA", "ro_RO", "ro_RO.utf8", "ru_RU", @@ -430,8 +433,10 @@ "sr_RS", "sr_RS@latin", "ss_ZA", + "ssy_ER", "st_ZA", "st_ZA.utf8", + "su_ID", "sv_FI", "sv_FI.utf8", "sv_FI@euro", @@ -440,6 +445,7 @@ "sv_SE.utf8", "sw_KE", "sw_TZ", + "syr", "szl_PL", "ta_IN", "ta_LK", @@ -458,6 +464,7 @@ "tl_PH.utf8", "tn_ZA", "to_TO", + "tok", "tpi_PG", "tr_CY", "tr_CY.utf8", @@ -491,6 +498,7 @@ "yo_NG", "yue_HK", "yuw_PG", + "zgh_MA", "zh_CN", "zh_CN.gb18030", "zh_CN.gbk", diff --git a/src/upgrade.py b/src/upgrade.py index 629ba06fa8..3f7c183e16 100644 --- a/src/upgrade.py +++ b/src/upgrade.py @@ -114,8 +114,8 @@ def _on_upgrade_charm_check_legacy(self) -> None: fixed_dependencies["snap"] = { "dependencies": {}, "name": "charmed-postgresql", - "upgrade_supported": "^14", - "version": "14.9", + "upgrade_supported": "^16", + "version": "16.6", } self.peer_relation.data[self.charm.app].update({ "dependencies": json.dumps(fixed_dependencies) diff --git a/templates/patroni.yml.j2 b/templates/patroni.yml.j2 index bd3f87154a..accb64e639 100644 --- a/templates/patroni.yml.j2 +++ b/templates/patroni.yml.j2 @@ -182,12 +182,27 @@ postgresql: replication: username: replication password: {{ replication_password }} + {%- if enable_tls %} + sslrootcert: {{ conf_path }}/ca.pem + sslcert: {{ conf_path }}/cert.pem + sslkey: {{ conf_path }}/key.pem + {%- endif %} rewind: username: {{ rewind_user }} password: {{ rewind_password }} + {%- if enable_tls %} + sslrootcert: {{ conf_path }}/ca.pem + sslcert: {{ conf_path }}/cert.pem + sslkey: {{ conf_path }}/key.pem + {%- endif %} superuser: username: {{ superuser }} password: {{ superuser_password }} + {%- if enable_tls %} + sslrootcert: {{ conf_path }}/ca.pem + sslcert: {{ conf_path }}/cert.pem + sslkey: {{ conf_path }}/key.pem + {%- endif %} use_unix_socket: true {%- if is_creating_backup %} tags: diff --git a/terraform/variables.tf b/terraform/variables.tf index ede475f37a..d3ceba0c1e 100644 --- a/terraform/variables.tf +++ b/terraform/variables.tf @@ -12,7 +12,7 @@ variable "app_name" { variable "channel" { description = "Charm channel to use when deploying" type = string - default = "14/stable" + default = "16/stable" } variable "revision" { @@ -24,7 +24,7 @@ variable "revision" { variable "base" { description = "Application base" type = string - default = "ubuntu@22.04" + default = "ubuntu@24.04" } variable "units" { diff --git a/tests/integration/ha_tests/test_replication.py b/tests/integration/ha_tests/test_replication.py index dd924948da..64539a0561 100644 --- a/tests/integration/ha_tests/test_replication.py +++ b/tests/integration/ha_tests/test_replication.py @@ -42,7 +42,6 @@ async def test_build_and_deploy(ops_test: OpsTest) -> None: await ops_test.model.deploy( APPLICATION_NAME, application_name=APPLICATION_NAME, - base=CHARM_BASE, channel="edge", ) diff --git a/tests/integration/ha_tests/test_self_healing.py b/tests/integration/ha_tests/test_self_healing.py index 8f197f1a94..5e6a26da58 100644 --- a/tests/integration/ha_tests/test_self_healing.py +++ b/tests/integration/ha_tests/test_self_healing.py @@ -87,7 +87,6 @@ async def test_build_and_deploy(ops_test: OpsTest) -> None: await ops_test.model.deploy( APPLICATION_NAME, application_name=APPLICATION_NAME, - base=CHARM_BASE, channel="edge", ) diff --git a/tests/integration/ha_tests/test_upgrade.py b/tests/integration/ha_tests/test_upgrade.py index 497c7ace9a..749615825c 100644 --- a/tests/integration/ha_tests/test_upgrade.py +++ b/tests/integration/ha_tests/test_upgrade.py @@ -36,7 +36,7 @@ async def test_deploy_latest(ops_test: OpsTest) -> None: await ops_test.model.deploy( DATABASE_APP_NAME, num_units=3, - channel="14/edge", + channel="16/edge", config={"profile": "testing"}, ) await ops_test.model.deploy( diff --git a/tests/integration/ha_tests/test_upgrade_from_stable.py b/tests/integration/ha_tests/test_upgrade_from_stable.py index fd75c93f2b..1339fd8e48 100644 --- a/tests/integration/ha_tests/test_upgrade_from_stable.py +++ b/tests/integration/ha_tests/test_upgrade_from_stable.py @@ -26,6 +26,7 @@ @pytest.mark.group(1) +@pytest.mark.unstable @pytest.mark.abort_on_fail async def test_deploy_stable(ops_test: OpsTest) -> None: """Simple test to ensure that the PostgreSQL and application charms get deployed.""" @@ -35,33 +36,33 @@ async def test_deploy_stable(ops_test: OpsTest) -> None: # Revisions lower than 315 have a currently broken workaround for chown. parsed_charm_info = json.loads(charm_info) revision = ( - parsed_charm_info["channels"]["14"]["stable"][0]["revision"] + parsed_charm_info["channels"]["16"]["stable"][0]["revision"] if "channels" in parsed_charm_info - else parsed_charm_info["channel-map"]["14/stable"]["revision"] + else parsed_charm_info["channel-map"]["16/stable"]["revision"] ) - logger.info(f"14/stable revision: {revision}") + logger.info(f"16/stable revision: {revision}") if int(revision) < 315: original_charm_name = "./postgresql.charm" return_code, _, stderr = await ops_test.juju( "download", "postgresql", - "--channel=14/stable", + "--channel=16/stable", f"--filepath={original_charm_name}", ) if return_code != 0: raise Exception( - f"failed to download charm from 14/stable channel with error: {stderr}" + f"failed to download charm from 16/stable channel with error: {stderr}" ) patched_charm_name = "./modified_postgresql.charm" remove_chown_workaround(original_charm_name, patched_charm_name) return_code, _, stderr = await ops_test.juju("deploy", patched_charm_name, "-n", "3") if return_code != 0: - raise Exception(f"failed to deploy charm from 14/stable channel with error: {stderr}") + raise Exception(f"failed to deploy charm from 16/stable channel with error: {stderr}") else: await ops_test.model.deploy( DATABASE_APP_NAME, num_units=3, - channel="14/stable", + channel="16/stable", ) await ops_test.model.deploy( APPLICATION_NAME, @@ -77,12 +78,13 @@ async def test_deploy_stable(ops_test: OpsTest) -> None: @pytest.mark.group(1) +@pytest.mark.unstable @pytest.mark.abort_on_fail async def test_pre_upgrade_check(ops_test: OpsTest) -> None: """Test that the pre-upgrade-check action runs successfully.""" application = ops_test.model.applications[DATABASE_APP_NAME] if "pre-upgrade-check" not in await application.get_actions(): - logger.info("skipping the test because the charm from 14/stable doesn't support upgrade") + logger.info("skipping the test because the charm from 16/stable doesn't support upgrade") return logger.info("Get leader unit") @@ -95,6 +97,7 @@ async def test_pre_upgrade_check(ops_test: OpsTest) -> None: @pytest.mark.group(1) +@pytest.mark.unstable @pytest.mark.abort_on_fail async def test_upgrade_from_stable(ops_test: OpsTest): """Test updating from stable channel.""" diff --git a/tests/integration/helpers.py b/tests/integration/helpers.py index 2d587b38d5..d0a32e58c6 100644 --- a/tests/integration/helpers.py +++ b/tests/integration/helpers.py @@ -30,7 +30,7 @@ wait_fixed, ) -CHARM_BASE = "ubuntu@22.04" +CHARM_BASE = "ubuntu@24.04" METADATA = yaml.safe_load(Path("./metadata.yaml").read_text()) DATABASE_APP_NAME = METADATA["name"] STORAGE_PATH = METADATA["storage"]["pgdata"]["location"] diff --git a/tests/integration/new_relations/test_new_relations.py b/tests/integration/new_relations/test_new_relations.py index 09cf292805..cc3b5169a8 100644 --- a/tests/integration/new_relations/test_new_relations.py +++ b/tests/integration/new_relations/test_new_relations.py @@ -59,7 +59,6 @@ async def test_deploy_charms(ops_test: OpsTest, charm): APPLICATION_APP_NAME, application_name=APPLICATION_APP_NAME, num_units=2, - base=CHARM_BASE, channel="edge", ), ops_test.model.deploy( @@ -257,7 +256,6 @@ async def test_two_applications_doesnt_share_the_same_relation_data(ops_test: Op APPLICATION_APP_NAME, application_name=another_application_app_name, channel="edge", - base=CHARM_BASE, ) await ops_test.model.wait_for_idle(apps=all_app_names, status="active") @@ -488,7 +486,7 @@ async def test_admin_role(ops_test: OpsTest): all_app_names = [DATA_INTEGRATOR_APP_NAME] all_app_names.extend(APP_NAMES) async with ops_test.fast_forward(): - await ops_test.model.deploy(DATA_INTEGRATOR_APP_NAME, base=CHARM_BASE) + await ops_test.model.deploy(DATA_INTEGRATOR_APP_NAME) await ops_test.model.wait_for_idle(apps=[DATA_INTEGRATOR_APP_NAME], status="blocked") await ops_test.model.applications[DATA_INTEGRATOR_APP_NAME].set_config({ "database-name": DATA_INTEGRATOR_APP_NAME.replace("-", "_"), @@ -579,7 +577,6 @@ async def test_invalid_extra_user_roles(ops_test: OpsTest): await ops_test.model.deploy( DATA_INTEGRATOR_APP_NAME, application_name=another_data_integrator_app_name, - base=CHARM_BASE, ) await ops_test.model.wait_for_idle( apps=[another_data_integrator_app_name], status="blocked" @@ -644,7 +641,6 @@ async def test_nextcloud_db_blocked(ops_test: OpsTest, charm: str) -> None: channel="edge", application_name="nextcloud", num_units=1, - base=CHARM_BASE, ), ) await asyncio.gather( diff --git a/tests/integration/new_relations/test_relations_coherence.py b/tests/integration/new_relations/test_relations_coherence.py index 1f2a751922..67117c6bb6 100644 --- a/tests/integration/new_relations/test_relations_coherence.py +++ b/tests/integration/new_relations/test_relations_coherence.py @@ -35,7 +35,7 @@ async def test_relations(ops_test: OpsTest, charm): await ops_test.model.wait_for_idle(apps=[DATABASE_APP_NAME], status="active", timeout=3000) # Creating first time relation with user role - await ops_test.model.deploy(DATA_INTEGRATOR_APP_NAME, base=CHARM_BASE) + await ops_test.model.deploy(DATA_INTEGRATOR_APP_NAME) await ops_test.model.applications[DATA_INTEGRATOR_APP_NAME].set_config({ "database-name": DATA_INTEGRATOR_APP_NAME.replace("-", "_"), }) diff --git a/tests/integration/relations/test_relations.py b/tests/integration/relations/test_relations.py index b3a542decc..277c1e9cd9 100644 --- a/tests/integration/relations/test_relations.py +++ b/tests/integration/relations/test_relations.py @@ -37,7 +37,6 @@ async def test_deploy_charms(ops_test: OpsTest, charm): APPLICATION_APP_NAME, application_name=DATABASE_APP_NAME, num_units=1, - base=CHARM_BASE, channel="edge", ), ops_test.model.deploy( @@ -55,7 +54,6 @@ async def test_deploy_charms(ops_test: OpsTest, charm): APPLICATION_APP_NAME, application_name=DB_APP_NAME, num_units=1, - base=CHARM_BASE, channel="edge", ), ) diff --git a/tests/integration/test_db.py b/tests/integration/test_db.py index 88f87c1536..8da8b707ea 100644 --- a/tests/integration/test_db.py +++ b/tests/integration/test_db.py @@ -198,14 +198,12 @@ async def test_roles_blocking(ops_test: OpsTest, charm: str) -> None: APPLICATION_NAME, application_name=APPLICATION_NAME, config={"legacy_roles": True}, - base=CHARM_BASE, channel="edge", ) await ops_test.model.deploy( APPLICATION_NAME, application_name=f"{APPLICATION_NAME}2", config={"legacy_roles": True}, - base=CHARM_BASE, channel="edge", ) diff --git a/tests/integration/test_plugins.py b/tests/integration/test_plugins.py index 7b3d5d3ce1..f5f7a3d5df 100644 --- a/tests/integration/test_plugins.py +++ b/tests/integration/test_plugins.py @@ -62,8 +62,10 @@ HYPOPG_EXTENSION_STATEMENT = "CREATE TABLE hypopg_test (id integer, val text); SELECT hypopg_create_index('CREATE INDEX ON hypopg_test (id)');" IP4R_EXTENSION_STATEMENT = "CREATE TABLE ip4r_test (ip ip4);" JSONB_PLPERL_EXTENSION_STATEMENT = "CREATE OR REPLACE FUNCTION jsonb_plperl_test(val jsonb) RETURNS jsonb TRANSFORM FOR TYPE jsonb LANGUAGE plperl as $$ return $_[0]; $$;" -ORAFCE_EXTENSION_STATEMENT = "SELECT add_months(date '2005-05-31',1);" -PG_SIMILARITY_EXTENSION_STATEMENT = "SHOW pg_similarity.levenshtein_threshold;" +ORAFCE_EXTENSION_STATEMENT = "SELECT oracle.add_months(date '2005-05-31',1);" +PG_SIMILARITY_EXTENSION_STATEMENT = ( + "SET pg_similarity.levenshtein_threshold = 0.7; SELECT 'aaa', 'aab', lev('aaa','aab');" +) PLPERL_EXTENSION_STATEMENT = "CREATE OR REPLACE FUNCTION plperl_test(name text) RETURNS text AS $$ return $_SHARED{$_[0]}; $$ LANGUAGE plperl;" PREFIX_EXTENSION_STATEMENT = "SELECT '123'::prefix_range @> '123456';" RDKIT_EXTENSION_STATEMENT = "SELECT is_valid_smiles('CCC');" diff --git a/tests/integration/test_subordinates.py b/tests/integration/test_subordinates.py index be9be926cc..b2efdaf979 100644 --- a/tests/integration/test_subordinates.py +++ b/tests/integration/test_subordinates.py @@ -15,7 +15,6 @@ DATABASE_APP_NAME = "pg" LS_CLIENT = "landscape-client" -UBUNTU_PRO_APP_NAME = "ubuntu-advantage" logger = logging.getLogger(__name__) @@ -30,13 +29,6 @@ async def test_deploy(ops_test: OpsTest, charm: str, github_secrets): num_units=3, base=CHARM_BASE, ), - ops_test.model.deploy( - UBUNTU_PRO_APP_NAME, - config={"token": github_secrets["UBUNTU_PRO_TOKEN"]}, - channel="latest/edge", - num_units=0, - base=CHARM_BASE, - ), ops_test.model.deploy( LS_CLIENT, config={ @@ -46,18 +38,12 @@ async def test_deploy(ops_test: OpsTest, charm: str, github_secrets): }, channel="latest/edge", num_units=0, - base=CHARM_BASE, ), ) await ops_test.model.wait_for_idle(apps=[DATABASE_APP_NAME], status="active", timeout=2000) await ops_test.model.relate(f"{DATABASE_APP_NAME}:juju-info", f"{LS_CLIENT}:container") - await ops_test.model.relate( - f"{DATABASE_APP_NAME}:juju-info", f"{UBUNTU_PRO_APP_NAME}:juju-info" - ) - await ops_test.model.wait_for_idle( - apps=[LS_CLIENT, UBUNTU_PRO_APP_NAME, DATABASE_APP_NAME], status="active" - ) + await ops_test.model.wait_for_idle(apps=[LS_CLIENT, DATABASE_APP_NAME], status="active") @pytest.mark.group(1) @@ -65,7 +51,7 @@ async def test_scale_up(ops_test: OpsTest, github_secrets): await scale_application(ops_test, DATABASE_APP_NAME, 4) await ops_test.model.wait_for_idle( - apps=[LS_CLIENT, UBUNTU_PRO_APP_NAME, DATABASE_APP_NAME], status="active", timeout=1500 + apps=[LS_CLIENT, DATABASE_APP_NAME], status="active", timeout=1500 ) @@ -74,5 +60,5 @@ async def test_scale_down(ops_test: OpsTest, github_secrets): await scale_application(ops_test, DATABASE_APP_NAME, 3) await ops_test.model.wait_for_idle( - apps=[LS_CLIENT, UBUNTU_PRO_APP_NAME, DATABASE_APP_NAME], status="active", timeout=1500 + apps=[LS_CLIENT, DATABASE_APP_NAME], status="active", timeout=1500 ) diff --git a/tests/integration/test_tls.py b/tests/integration/test_tls.py index 7408a8352f..4116746dd3 100644 --- a/tests/integration/test_tls.py +++ b/tests/integration/test_tls.py @@ -66,7 +66,7 @@ async def test_tls_enabled(ops_test: OpsTest) -> None: async with ops_test.fast_forward(): # Deploy TLS Certificates operator. await ops_test.model.deploy( - tls_certificates_app_name, config=tls_config, channel=tls_channel, base=CHARM_BASE + tls_certificates_app_name, config=tls_config, channel=tls_channel ) # Relate it to the PostgreSQL to enable TLS. @@ -148,7 +148,7 @@ async def test_tls_enabled(ops_test: OpsTest) -> None: await run_command_on_unit( ops_test, primary, - "pkill --signal SIGKILL -f /snap/charmed-postgresql/current/usr/lib/postgresql/14/bin/postgres", + "pkill --signal SIGKILL -f /snap/charmed-postgresql/current/usr/lib/postgresql/16/bin/postgres", ) await run_command_on_unit( ops_test, diff --git a/tests/unit/test_backups.py b/tests/unit/test_backups.py index 509f391cf4..ae81d8f517 100644 --- a/tests/unit/test_backups.py +++ b/tests/unit/test_backups.py @@ -202,7 +202,7 @@ def test_can_use_s3_repository(harness): patch("charm.Patroni.member_started", new_callable=PropertyMock) as _member_started, patch("charm.PostgresqlOperatorCharm.update_config") as _update_config, patch( - "charm.Patroni.get_postgresql_version", return_value="14.10" + "charm.Patroni.get_postgresql_version", return_value="16.6" ) as _get_postgresql_version, patch("charm.PostgresqlOperatorCharm.postgresql") as _postgresql, patch( diff --git a/tests/unit/test_charm.py b/tests/unit/test_charm.py index 650dbe689d..d6a158d24e 100644 --- a/tests/unit/test_charm.py +++ b/tests/unit/test_charm.py @@ -623,7 +623,7 @@ def test_on_start(harness): side_effect=[False, True, True, True, True, True], ) as _is_storage_attached, ): - _get_postgresql_version.return_value = "14.0" + _get_postgresql_version.return_value = "16.6" # Test without storage. harness.charm.on.start.emit() @@ -709,7 +709,7 @@ def test_on_start_replica(harness): return_value=True, ) as _is_storage_attached, ): - _get_postgresql_version.return_value = "14.0" + _get_postgresql_version.return_value = "16.6" # Set the current unit to be a replica (non leader unit). harness.set_leader(False) @@ -768,7 +768,7 @@ def test_on_start_no_patroni_member(harness): bootstrap_cluster = patroni.return_value.bootstrap_cluster bootstrap_cluster.return_value = True - patroni.return_value.get_postgresql_version.return_value = "14.0" + patroni.return_value.get_postgresql_version.return_value = "16.6" harness.set_leader() harness.charm.on.start.emit() @@ -1119,29 +1119,29 @@ def test_install_snap_packages(harness): # Test for problem with snap update. with pytest.raises(snap.SnapError): - harness.charm._install_snap_packages([("postgresql", {"channel": "14/edge"})]) + harness.charm._install_snap_packages([("postgresql", {"channel": "16/edge"})]) _snap_cache.return_value.__getitem__.assert_called_once_with("postgresql") _snap_cache.assert_called_once_with() - _snap_package.ensure.assert_called_once_with(snap.SnapState.Latest, channel="14/edge") + _snap_package.ensure.assert_called_once_with(snap.SnapState.Latest, channel="16/edge") # Test with a not found package. _snap_cache.reset_mock() _snap_package.reset_mock() _snap_package.ensure.side_effect = snap.SnapNotFoundError with pytest.raises(snap.SnapNotFoundError): - harness.charm._install_snap_packages([("postgresql", {"channel": "14/edge"})]) + harness.charm._install_snap_packages([("postgresql", {"channel": "16/edge"})]) _snap_cache.return_value.__getitem__.assert_called_once_with("postgresql") _snap_cache.assert_called_once_with() - _snap_package.ensure.assert_called_once_with(snap.SnapState.Latest, channel="14/edge") + _snap_package.ensure.assert_called_once_with(snap.SnapState.Latest, channel="16/edge") # Then test a valid one. _snap_cache.reset_mock() _snap_package.reset_mock() _snap_package.ensure.side_effect = None - harness.charm._install_snap_packages([("postgresql", {"channel": "14/edge"})]) + harness.charm._install_snap_packages([("postgresql", {"channel": "16/edge"})]) _snap_cache.assert_called_once_with() _snap_cache.return_value.__getitem__.assert_called_once_with("postgresql") - _snap_package.ensure.assert_called_once_with(snap.SnapState.Latest, channel="14/edge") + _snap_package.ensure.assert_called_once_with(snap.SnapState.Latest, channel="16/edge") _snap_package.hold.assert_not_called() # Test revision @@ -1338,6 +1338,7 @@ def test_update_config(harness): harness.update_relation_data( rel_id, harness.charm.unit.name, {"tls": ""} ) # Mock some data in the relation to test that it doesn't change. + _is_tls_enabled.return_value = False harness.charm.update_config() _handle_postgresql_restart_need.assert_not_called() assert "tls" not in harness.get_relation_data(rel_id, harness.charm.unit.name) diff --git a/tests/unit/test_cluster.py b/tests/unit/test_cluster.py index 9cb737f0bf..180db17274 100644 --- a/tests/unit/test_cluster.py +++ b/tests/unit/test_cluster.py @@ -165,11 +165,11 @@ def test_get_postgresql_version(peers_ips, patroni): _get_installed_snaps = _snap_client.return_value.get_installed_snaps _get_installed_snaps.return_value = [ {"name": "something"}, - {"name": "charmed-postgresql", "version": "14.0"}, + {"name": "charmed-postgresql", "version": "16.6"}, ] version = patroni.get_postgresql_version() - assert version == "14.0" + assert version == "16.6" _snap_client.assert_called_once_with() _get_installed_snaps.assert_called_once_with() @@ -314,7 +314,7 @@ def test_render_patroni_yml_file(peers_ips, patroni): patch("charm.Patroni.render_file") as _render_file, patch("charm.Patroni._create_directory"), ): - _get_postgresql_version.return_value = "14.7" + _get_postgresql_version.return_value = "16.6" # Define variables to render in the template. member_name = "postgresql-0" @@ -324,7 +324,7 @@ def test_render_patroni_yml_file(peers_ips, patroni): rewind_password = "fake-rewind-password" raft_password = "fake-raft-password" patroni_password = "fake-patroni-password" - postgresql_version = "14" + postgresql_version = "16" # Get the expected content from a file. with open("templates/patroni.yml.j2") as file: