25
25
from .juju_ import juju_major_version
26
26
27
27
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"
33
28
S3_INTEGRATOR_APP_NAME = "s3-integrator"
34
29
if juju_major_version < 3 :
35
30
tls_certificates_app_name = "tls-certificates-operator"
@@ -97,16 +92,19 @@ async def cloud_configs(ops_test: OpsTest, github_secrets) -> None:
97
92
bucket_object .delete ()
98
93
99
94
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."""
108
106
# 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 )
110
108
await ops_test .model .deploy (tls_certificates_app_name , config = tls_config , channel = tls_channel )
111
109
# Deploy and relate PostgreSQL to S3 integrator (one database app for each cloud for now
112
110
# 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])
119
117
await ops_test .model .wait_for_idle (
120
118
apps = [database_app_name ], status = "active" , timeout = 1000 , raise_on_error = False
121
119
)
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 )
123
121
124
122
# Configure and set access and secret keys.
125
123
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 (
128
126
"sync-s3-credentials" ,
129
127
** credentials ,
130
128
)
131
129
await action .wait ()
132
130
async with ops_test .fast_forward (fast_interval = "60s" ):
133
131
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
135
133
)
136
134
137
135
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])
278
276
279
277
# Remove S3 relation to ensure "move to another cluster" blocked status is gone
280
278
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"
282
280
)
283
281
284
282
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])
287
285
await ops_test .model .remove_application (database_app_name , block_until_done = True )
288
286
# Remove the TLS operator.
289
287
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