Skip to content

Commit 69e4db0

Browse files
authored
[MISC] Rollback Patroni update (#456)
* Wait for PG to be back up when restarting * Update snaps
1 parent 0f2c8c2 commit 69e4db0

File tree

4 files changed

+20
-10
lines changed

4 files changed

+20
-10
lines changed

src/charm.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1428,6 +1428,14 @@ def _restart(self, event: RunWithLock) -> None:
14281428
self.unit.status = BlockedStatus(error_message)
14291429
return
14301430

1431+
try:
1432+
for attempt in Retrying(wait=wait_fixed(3), stop_after_delay=stop_after_delay(300)):
1433+
with attempt:
1434+
if not self._can_connect_to_postgresql:
1435+
assert False
1436+
except Exception:
1437+
logger.exception("Unable to reconnect to postgresql")
1438+
14311439
# Start or stop the pgBackRest TLS server service when TLS certificate change.
14321440
self.backup.start_stop_pgbackrest_service()
14331441

src/constants.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
SNAP_PACKAGES = [
3737
(
3838
POSTGRESQL_SNAP_NAME,
39-
{"revision": {"aarch64": "110", "x86_64": "111"}, "channel": "14/stable"},
39+
{"revision": {"aarch64": "112", "x86_64": "113"}, "channel": "14/stable"},
4040
)
4141
]
4242

tests/integration/test_charm.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -182,9 +182,11 @@ async def test_postgresql_parameters_change(ops_test: OpsTest) -> None:
182182
for unit_id in UNIT_IDS:
183183
host = get_unit_address(ops_test, f"{DATABASE_APP_NAME}/{unit_id}")
184184
logger.info("connecting to the database host: %s", host)
185-
with db_connect(host, password) as connection:
186-
settings_names = ["max_prepared_transactions", "shared_buffers", "lc_monetary"]
187-
with connection.cursor() as cursor:
185+
try:
186+
with psycopg2.connect(
187+
f"dbname='postgres' user='operator' host='{host}' password='{password}' connect_timeout=1"
188+
) as connection, connection.cursor() as cursor:
189+
settings_names = ["max_prepared_transactions", "shared_buffers", "lc_monetary"]
188190
cursor.execute(
189191
sql.SQL("SELECT name,setting FROM pg_settings WHERE name IN ({});").format(
190192
sql.SQL(", ").join(sql.Placeholder() * len(settings_names))
@@ -193,12 +195,13 @@ async def test_postgresql_parameters_change(ops_test: OpsTest) -> None:
193195
)
194196
records = cursor.fetchall()
195197
settings = convert_records_to_dict(records)
196-
connection.close()
197198

198-
# Validate each configuration set by Patroni on PostgreSQL.
199-
assert settings["max_prepared_transactions"] == "100"
200-
assert settings["shared_buffers"] == "128"
201-
assert settings["lc_monetary"] == "en_GB.utf8"
199+
# Validate each configuration set by Patroni on PostgreSQL.
200+
assert settings["max_prepared_transactions"] == "100"
201+
assert settings["shared_buffers"] == "128"
202+
assert settings["lc_monetary"] == "en_GB.utf8"
203+
finally:
204+
connection.close()
202205

203206

204207
@pytest.mark.group(1)

tox.ini

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ allowlist_externals =
2626
charmcraft
2727
charmcraftcache
2828
mv
29-
psycopg2-binary
3029
commands_pre =
3130
poetry export --only main,charm-libs --output requirements.txt
3231
commands =

0 commit comments

Comments
 (0)