From bd56ca97b3a551b0c314c45f13a7fe270f385721 Mon Sep 17 00:00:00 2001 From: Dragomir Penev <6687393+dragomirp@users.noreply.github.com> Date: Fri, 5 Jul 2024 17:31:03 +0300 Subject: [PATCH] [DPE-4816] Add jinja2 as a dependency (#276) * Add jinja2 as a dependency * Bump libs * Increate connections for landscape test --- lib/charms/postgresql_k8s/v0/postgresql.py | 16 +++++++++++++++- poetry.lock | 2 +- pyproject.toml | 2 +- tests/integration/relations/test_db_admin.py | 2 +- 4 files changed, 18 insertions(+), 4 deletions(-) diff --git a/lib/charms/postgresql_k8s/v0/postgresql.py b/lib/charms/postgresql_k8s/v0/postgresql.py index 08b559649..071643841 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 = 29 +LIBPATCH = 30 INVALID_EXTRA_USER_ROLE_BLOCKING_MESSAGE = "invalid role(s) for extra user roles" @@ -79,6 +79,10 @@ class PostgreSQLEnableDisableExtensionError(Exception): """Exception raised when enabling/disabling an extension fails.""" +class PostgreSQLGetLastArchivedWALError(Exception): + """Exception raised when retrieving last archived WAL fails.""" + + class PostgreSQLGetPostgreSQLVersionError(Exception): """Exception raised when retrieving PostgreSQL version fails.""" @@ -383,6 +387,16 @@ def _generate_database_privileges_statements( ) return statements + def get_last_archived_wal(self) -> str: + """Get the name of the last archived wal for the current PostgreSQL cluster.""" + try: + with self._connect_to_database() as connection, connection.cursor() as cursor: + cursor.execute("SELECT last_archived_wal FROM pg_stat_archiver;") + return cursor.fetchone()[0] + except psycopg2.Error as e: + logger.error(f"Failed to get PostgreSQL last archived WAL: {e}") + raise PostgreSQLGetLastArchivedWALError() + def get_postgresql_text_search_configs(self) -> Set[str]: """Returns the PostgreSQL available text search configs. diff --git a/poetry.lock b/poetry.lock index 744f08f9f..dbcf2b9bd 100644 --- a/poetry.lock +++ b/poetry.lock @@ -2399,4 +2399,4 @@ test = ["big-O", "importlib-resources", "jaraco.functools", "jaraco.itertools", [metadata] lock-version = "2.0" python-versions = "^3.8.10" -content-hash = "4e1961d37303bed2681b20c6827ad354275590291c9fbc0512a3c89e56fcead8" +content-hash = "73ee2893213779ef4f1a27d834143a3047c765168d2fde8486f6fb7235684e37" diff --git a/pyproject.toml b/pyproject.toml index 0e731dc9e..ec0f303ea 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -23,6 +23,7 @@ cryptography = "^42.0.8" jsonschema = "^4.22.0" psycopg2 = "^2.9.9" psycopg = {extras = ["c"], version = "^3.2.1"} +jinja2 = "^3.1.4" [tool.poetry.group.charm-libs.dependencies] # data_platform_libs/v0/data_interfaces.py @@ -60,7 +61,6 @@ optional = true coverage = {extras = ["toml"], version = "^7.5.4"} pytest = "^8.2.2" pytest-asyncio = "*" -jinja2 = "^3.1.4" parameterized = "^0.9.0" [tool.poetry.group.integration] diff --git a/tests/integration/relations/test_db_admin.py b/tests/integration/relations/test_db_admin.py index 4100f9e2a..f52ba99a1 100644 --- a/tests/integration/relations/test_db_admin.py +++ b/tests/integration/relations/test_db_admin.py @@ -38,7 +38,7 @@ async def test_landscape_scalable_bundle_db(ops_test: OpsTest, pgb_charm_jammy: db_units=DATABASE_UNITS, pgb_series="jammy", pg_config={"profile": "testing"}, - pgb_config={"max_db_connections": "20", "pool_mode": "transaction"}, + pgb_config={"max_db_connections": "40", "pool_mode": "transaction"}, ) # Deploy and test the Landscape Scalable bundle (using this PostgreSQL charm).