Skip to content

Commit 7f15831

Browse files
author
Lucas Gameiro
authored
[DPE-5244] Split PITR backup test in AWS and GCP (#664)
* refactor PITR tests * move helper function * nits
1 parent 63057a7 commit 7f15831

File tree

1 file changed

+57
-19
lines changed

1 file changed

+57
-19
lines changed

tests/integration/test_backups_pitr.py

Lines changed: 57 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,6 @@
2525
from .juju_ import juju_major_version
2626

2727
CANNOT_RESTORE_PITR = "cannot restore PITR, juju debug-log for details"
28-
ANOTHER_CLUSTER_REPOSITORY_ERROR_MESSAGE = "the S3 repository has backups from another cluster"
29-
FAILED_TO_ACCESS_CREATE_BUCKET_ERROR_MESSAGE = (
30-
"failed to access/create the bucket, check your S3 settings"
31-
)
32-
FAILED_TO_INITIALIZE_STANZA_ERROR_MESSAGE = "failed to initialize stanza, check your S3 settings"
3328
S3_INTEGRATOR_APP_NAME = "s3-integrator"
3429
if juju_major_version < 3:
3530
tls_certificates_app_name = "tls-certificates-operator"
@@ -97,16 +92,19 @@ async def cloud_configs(ops_test: OpsTest, github_secrets) -> None:
9792
bucket_object.delete()
9893

9994

100-
@pytest.mark.group(1)
101-
@pytest.mark.abort_on_fail
102-
async def test_pitr_backup(ops_test: OpsTest, cloud_configs: Tuple[Dict, Dict]) -> None:
103-
"""Build and deploy two units of PostgreSQL in AWS and then test the backup and restore actions."""
104-
config = cloud_configs[0][AWS]
105-
credentials = cloud_configs[1][AWS]
106-
cloud = AWS.lower()
107-
95+
async def pitr_backup_operations(
96+
ops_test: OpsTest,
97+
s3_integrator_app_name: str,
98+
tls_certificates_app_name: str,
99+
tls_config,
100+
tls_channel,
101+
credentials,
102+
cloud,
103+
config,
104+
) -> None:
105+
"""Utility function containing PITR backup operations for both cloud tests."""
108106
# Deploy S3 Integrator and TLS Certificates Operator.
109-
await ops_test.model.deploy(S3_INTEGRATOR_APP_NAME)
107+
await ops_test.model.deploy(s3_integrator_app_name)
110108
await ops_test.model.deploy(tls_certificates_app_name, config=tls_config, channel=tls_channel)
111109
# Deploy and relate PostgreSQL to S3 integrator (one database app for each cloud for now
112110
# as archivo_mode is disabled after restoring the backup) and to TLS Certificates Operator
@@ -119,19 +117,19 @@ async def test_pitr_backup(ops_test: OpsTest, cloud_configs: Tuple[Dict, Dict])
119117
await ops_test.model.wait_for_idle(
120118
apps=[database_app_name], status="active", timeout=1000, raise_on_error=False
121119
)
122-
await ops_test.model.relate(database_app_name, S3_INTEGRATOR_APP_NAME)
120+
await ops_test.model.relate(database_app_name, s3_integrator_app_name)
123121

124122
# Configure and set access and secret keys.
125123
logger.info(f"configuring S3 integrator for {cloud}")
126-
await ops_test.model.applications[S3_INTEGRATOR_APP_NAME].set_config(config)
127-
action = await ops_test.model.units.get(f"{S3_INTEGRATOR_APP_NAME}/0").run_action(
124+
await ops_test.model.applications[s3_integrator_app_name].set_config(config)
125+
action = await ops_test.model.units.get(f"{s3_integrator_app_name}/0").run_action(
128126
"sync-s3-credentials",
129127
**credentials,
130128
)
131129
await action.wait()
132130
async with ops_test.fast_forward(fast_interval="60s"):
133131
await ops_test.model.wait_for_idle(
134-
apps=[database_app_name, S3_INTEGRATOR_APP_NAME], status="active", timeout=1000
132+
apps=[database_app_name, s3_integrator_app_name], status="active", timeout=1000
135133
)
136134

137135
primary = await get_primary(ops_test, database_app_name)
@@ -278,7 +276,7 @@ async def test_pitr_backup(ops_test: OpsTest, cloud_configs: Tuple[Dict, Dict])
278276

279277
# Remove S3 relation to ensure "move to another cluster" blocked status is gone
280278
await ops_test.model.applications[database_app_name].remove_relation(
281-
f"{database_app_name}:s3-parameters", f"{S3_INTEGRATOR_APP_NAME}:s3-credentials"
279+
f"{database_app_name}:s3-parameters", f"{s3_integrator_app_name}:s3-credentials"
282280
)
283281

284282
await ops_test.model.wait_for_idle(status="active", timeout=1000)
@@ -287,3 +285,43 @@ async def test_pitr_backup(ops_test: OpsTest, cloud_configs: Tuple[Dict, Dict])
287285
await ops_test.model.remove_application(database_app_name, block_until_done=True)
288286
# Remove the TLS operator.
289287
await ops_test.model.remove_application(tls_certificates_app_name, block_until_done=True)
288+
289+
290+
@pytest.mark.group(1)
291+
@pytest.mark.abort_on_fail
292+
async def test_pitr_backup_aws(ops_test: OpsTest, cloud_configs: Tuple[Dict, Dict]) -> None:
293+
"""Build and deploy two units of PostgreSQL in AWS and then test PITR backup and restore actions."""
294+
config = cloud_configs[0][AWS]
295+
credentials = cloud_configs[1][AWS]
296+
cloud = AWS.lower()
297+
298+
await pitr_backup_operations(
299+
ops_test,
300+
S3_INTEGRATOR_APP_NAME,
301+
tls_certificates_app_name,
302+
tls_config,
303+
tls_channel,
304+
credentials,
305+
cloud,
306+
config,
307+
)
308+
309+
310+
@pytest.mark.group(2)
311+
@pytest.mark.abort_on_fail
312+
async def test_pitr_backup_gcp(ops_test: OpsTest, cloud_configs: Tuple[Dict, Dict]) -> None:
313+
"""Build and deploy two units of PostgreSQL in GCP and then test PITR backup and restore actions."""
314+
config = cloud_configs[0][GCP]
315+
credentials = cloud_configs[1][GCP]
316+
cloud = GCP.lower()
317+
318+
await pitr_backup_operations(
319+
ops_test,
320+
S3_INTEGRATOR_APP_NAME,
321+
tls_certificates_app_name,
322+
tls_config,
323+
tls_channel,
324+
credentials,
325+
cloud,
326+
config,
327+
)

0 commit comments

Comments
 (0)