Skip to content

Commit 0eeb5a2

Browse files
committed
Try to disable pgaudit before changing exts
1 parent 68ef417 commit 0eeb5a2

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

lib/charms/postgresql_k8s/v0/postgresql.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535

3636
# Increment this PATCH version before using `charmcraft publish-lib` or reset
3737
# to 0 if you are raising the major API version
38-
LIBPATCH = 48
38+
LIBPATCH = 50
3939

4040
# Groups to distinguish HBA access
4141
ACCESS_GROUP_IDENTITY = "identity_access"
@@ -435,6 +435,7 @@ def enable_disable_extensions(
435435
for extension, enable in extensions.items():
436436
ordered_extensions[extension] = enable
437437

438+
self._configure_pgaudit(False)
438439
# Enable/disabled the extension in each database.
439440
for database in databases:
440441
with self._connect_to_database(
@@ -446,14 +447,14 @@ def enable_disable_extensions(
446447
if enable
447448
else f"DROP EXTENSION IF EXISTS {extension};"
448449
)
449-
self._configure_pgaudit(ordered_extensions.get("pgaudit", False))
450450
except psycopg2.errors.UniqueViolation:
451451
pass
452452
except psycopg2.errors.DependentObjectsStillExist:
453453
raise
454454
except psycopg2.Error as e:
455455
raise PostgreSQLEnableDisableExtensionError() from e
456456
finally:
457+
self._configure_pgaudit(ordered_extensions.get("pgaudit", False))
457458
if connection is not None:
458459
connection.close()
459460

@@ -626,6 +627,7 @@ def list_access_groups(self) -> Set[str]:
626627
Returns:
627628
List of PostgreSQL database access groups.
628629
"""
630+
connection = None
629631
try:
630632
with self._connect_to_database() as connection, connection.cursor() as cursor:
631633
cursor.execute(
@@ -646,6 +648,7 @@ def list_users(self) -> Set[str]:
646648
Returns:
647649
List of PostgreSQL database users.
648650
"""
651+
connection = None
649652
try:
650653
with self._connect_to_database() as connection, connection.cursor() as cursor:
651654
cursor.execute("SELECT usename FROM pg_catalog.pg_user;")
@@ -664,6 +667,7 @@ def list_users_from_relation(self) -> Set[str]:
664667
Returns:
665668
List of PostgreSQL database users.
666669
"""
670+
connection = None
667671
try:
668672
with self._connect_to_database() as connection, connection.cursor() as cursor:
669673
cursor.execute(

tests/integration/test_plugins.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ async def test_plugins(ops_test: OpsTest, charm) -> None:
9696
# Build and deploy the PostgreSQL charm.
9797
async with ops_test.fast_forward():
9898
# TODO Figure out how to deal with pgaudit
99-
await build_and_deploy(ops_test, charm, 2, extra_config={"plugin_audit_enable": "False"})
99+
await build_and_deploy(ops_test, charm, 2)
100100

101101
sql_tests = {
102102
"plugin_citext_enable": CITEXT_EXTENSION_STATEMENT,

0 commit comments

Comments
 (0)