4
4
import contextlib
5
5
import logging
6
6
import subprocess
7
- from asyncio import gather
7
+ from asyncio import gather , sleep
8
8
from typing import Optional
9
9
10
10
import psycopg2
41
41
IDLE_PERIOD = 5
42
42
TIMEOUT = 2000
43
43
44
+ DATA_INTEGRATOR_APP_NAME = "data-integrator"
45
+
44
46
45
47
@contextlib .asynccontextmanager
46
48
async def fast_forward (
@@ -115,6 +117,14 @@ async def test_deploy_async_replication_setup(
115
117
num_units = CLUSTER_SIZE ,
116
118
config = {"profile" : "testing" },
117
119
)
120
+ if not await app_name (ops_test , DATA_INTEGRATOR_APP_NAME ):
121
+ await ops_test .model .deploy (
122
+ DATA_INTEGRATOR_APP_NAME ,
123
+ num_units = 1 ,
124
+ channel = "latest/edge" ,
125
+ config = {"database-name" : "testdb" },
126
+ )
127
+ await ops_test .model .relate (DATABASE_APP_NAME , DATA_INTEGRATOR_APP_NAME )
118
128
if not await app_name (ops_test , model = second_model ):
119
129
charm = await ops_test .build_charm ("." )
120
130
await second_model .deploy (
@@ -128,7 +138,7 @@ async def test_deploy_async_replication_setup(
128
138
async with ops_test .fast_forward (), fast_forward (second_model ):
129
139
await gather (
130
140
first_model .wait_for_idle (
131
- apps = [DATABASE_APP_NAME , APPLICATION_NAME ],
141
+ apps = [DATABASE_APP_NAME , APPLICATION_NAME , DATA_INTEGRATOR_APP_NAME ],
132
142
status = "active" ,
133
143
timeout = TIMEOUT ,
134
144
),
@@ -218,6 +228,19 @@ async def test_async_replication(
218
228
await check_writes (ops_test , extra_model = second_model )
219
229
220
230
231
+ @pytest .mark .group (1 )
232
+ @markers .juju3
233
+ @pytest .mark .abort_on_fail
234
+ async def test_get_data_integrator_credentials (
235
+ ops_test : OpsTest ,
236
+ ):
237
+ unit = ops_test .model .applications [DATA_INTEGRATOR_APP_NAME ].units [0 ]
238
+ action = await unit .run_action (action_name = "get-credentials" )
239
+ result = await action .wait ()
240
+ global data_integrator_credentials
241
+ data_integrator_credentials = result .results
242
+
243
+
221
244
@pytest .mark .group (1 )
222
245
@markers .juju3
223
246
@pytest .mark .abort_on_fail
@@ -273,6 +296,43 @@ async def test_switchover(
273
296
await are_writes_increasing (ops_test , extra_model = second_model )
274
297
275
298
299
+ @pytest .mark .group (1 )
300
+ @markers .juju3
301
+ @pytest .mark .abort_on_fail
302
+ async def test_data_integrator_creds_keep_on_working (
303
+ ops_test : OpsTest ,
304
+ second_model : Model ,
305
+ ) -> None :
306
+ user = data_integrator_credentials ["postgresql" ]["username" ]
307
+ password = data_integrator_credentials ["postgresql" ]["password" ]
308
+ database = data_integrator_credentials ["postgresql" ]["database" ]
309
+
310
+ any_unit = second_model .applications [DATABASE_APP_NAME ].units [0 ].name
311
+ primary = await get_primary (ops_test , any_unit )
312
+ address = get_unit_address (ops_test , primary )
313
+
314
+ connstr = f"dbname='{ database } ' user='{ user } ' host='{ address } ' port='5432' password='{ password } ' connect_timeout=1"
315
+ try :
316
+ with psycopg2 .connect (connstr ) as connection :
317
+ pass
318
+ finally :
319
+ connection .close ()
320
+
321
+ logger .info ("Re-enable oversee users" )
322
+ action = await primary .run_action (action_name = "reenable-oversee-users" )
323
+ await action .wait ()
324
+
325
+ async with ops_test .fast_forward ():
326
+ await sleep (20 )
327
+ try :
328
+ with psycopg2 .connect (connstr ) as connection :
329
+ assert False
330
+ except psycopg2 .errors .InsufficientPrivilege :
331
+ logger .info ("Data integrator creds purged" )
332
+ finally :
333
+ connection .close ()
334
+
335
+
276
336
@pytest .mark .group (1 )
277
337
@markers .juju3
278
338
@pytest .mark .abort_on_fail
0 commit comments