Skip to content

Commit ac88aca

Browse files
[DPE-4820] Fix GCP backup test (#521)
* Fix GCP backup test Signed-off-by: Marcelo Henrique Neppel <[email protected]> * Reset restore flag Signed-off-by: Marcelo Henrique Neppel <[email protected]> * Correctly access application peer data Signed-off-by: Marcelo Henrique Neppel <[email protected]> * Remove unnecessary code Signed-off-by: Marcelo Henrique Neppel <[email protected]> * Fix leader check Signed-off-by: Marcelo Henrique Neppel <[email protected]> * Update library Signed-off-by: Marcelo Henrique Neppel <[email protected]> --------- Signed-off-by: Marcelo Henrique Neppel <[email protected]>
1 parent def028c commit ac88aca

File tree

4 files changed

+15
-4
lines changed

4 files changed

+15
-4
lines changed

lib/charms/postgresql_k8s/v0/postgresql.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,10 @@ class PostgreSQLEnableDisableExtensionError(Exception):
7979
"""Exception raised when enabling/disabling an extension fails."""
8080

8181

82+
class PostgreSQLGetLastArchivedWALError(Exception):
83+
"""Exception raised when retrieving last archived WAL fails."""
84+
85+
8286
class PostgreSQLGetPostgreSQLVersionError(Exception):
8387
"""Exception raised when retrieving PostgreSQL version fails."""
8488

@@ -391,7 +395,7 @@ def get_last_archived_wal(self) -> str:
391395
return cursor.fetchone()[0]
392396
except psycopg2.Error as e:
393397
logger.error(f"Failed to get PostgreSQL last archived WAL: {e}")
394-
raise PostgreSQLGetPostgreSQLVersionError()
398+
raise PostgreSQLGetLastArchivedWALError()
395399

396400
def get_postgresql_text_search_configs(self) -> Set[str]:
397401
"""Returns the PostgreSQL available text search configs.

src/backups.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -594,12 +594,13 @@ def _on_s3_credential_changed(self, event: CredentialsChangedEvent):
594594
event.defer()
595595
return
596596

597+
if self.charm.unit.is_leader():
598+
self.charm.app_peer_data.pop("require-change-bucket-after-restore", None)
599+
597600
# Verify the s3 relation only on the primary.
598601
if not self.charm.is_primary:
599602
return
600603

601-
self.charm.app_peer_data.pop("require-change-bucket-after-restore", None)
602-
603604
try:
604605
self._create_bucket_if_not_exists()
605606
except (ClientError, ValueError):

src/charm.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1410,6 +1410,12 @@ def _set_primary_status_message(self) -> None:
14101410
"""Display 'Primary' in the unit status message if the current unit is the primary."""
14111411
try:
14121412
if "require-change-bucket-after-restore" in self.app_peer_data:
1413+
if self.unit.is_leader():
1414+
self.app_peer_data.update({
1415+
"restoring-backup": "",
1416+
"restore-stanza": "",
1417+
"restore-to-time": "",
1418+
})
14131419
self.unit.status = BlockedStatus(MOVE_RESTORED_CLUSTER_TO_ANOTHER_BUCKET)
14141420
return
14151421
if self._patroni.get_primary(unit_name_pattern=True) == self.unit.name:

tests/integration/test_backups.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ async def test_restore_on_new_cluster(ops_test: OpsTest, github_secrets, charm)
287287
async with ops_test.fast_forward():
288288
unit = ops_test.model.units.get(f"{database_app_name}/0")
289289
await ops_test.model.block_until(
290-
lambda: unit.workload_status_message == ANOTHER_CLUSTER_REPOSITORY_ERROR_MESSAGE
290+
lambda: unit.workload_status_message == MOVE_RESTORED_CLUSTER_TO_ANOTHER_BUCKET
291291
)
292292

293293
# Check that the backup was correctly restored by having only the first created table.

0 commit comments

Comments
 (0)