Skip to content

Commit ba1a260

Browse files
committed
Add suppression test
1 parent 8e9d9ee commit ba1a260

File tree

2 files changed

+63
-3
lines changed

2 files changed

+63
-3
lines changed

src/relations/async_replication.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,7 @@ def is_primary_cluster(self) -> bool:
485485
return self.charm.app == self._get_primary_cluster()
486486

487487
def _on_async_relation_broken(self, _) -> None:
488-
if "departing" in self.charm._peers.data[self.charm.unit]:
488+
if not self.charm._peers or "departing" in self.charm._peers.data[self.charm.unit]:
489489
logger.debug("Early exit on_async_relation_broken: Skipping departing unit.")
490490
return
491491

tests/integration/ha_tests/test_async_replication.py

+62-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import contextlib
55
import logging
66
import subprocess
7-
from asyncio import gather
7+
from asyncio import gather, sleep
88
from typing import Optional
99

1010
import psycopg2
@@ -41,6 +41,8 @@
4141
IDLE_PERIOD = 5
4242
TIMEOUT = 2000
4343

44+
DATA_INTEGRATOR_APP_NAME = "data-integrator"
45+
4446

4547
@contextlib.asynccontextmanager
4648
async def fast_forward(
@@ -115,6 +117,14 @@ async def test_deploy_async_replication_setup(
115117
num_units=CLUSTER_SIZE,
116118
config={"profile": "testing"},
117119
)
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)
118128
if not await app_name(ops_test, model=second_model):
119129
charm = await ops_test.build_charm(".")
120130
await second_model.deploy(
@@ -128,7 +138,7 @@ async def test_deploy_async_replication_setup(
128138
async with ops_test.fast_forward(), fast_forward(second_model):
129139
await gather(
130140
first_model.wait_for_idle(
131-
apps=[DATABASE_APP_NAME, APPLICATION_NAME],
141+
apps=[DATABASE_APP_NAME, APPLICATION_NAME, DATA_INTEGRATOR_APP_NAME],
132142
status="active",
133143
timeout=TIMEOUT,
134144
),
@@ -218,6 +228,19 @@ async def test_async_replication(
218228
await check_writes(ops_test, extra_model=second_model)
219229

220230

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+
221244
@pytest.mark.group(1)
222245
@markers.juju3
223246
@pytest.mark.abort_on_fail
@@ -273,6 +296,43 @@ async def test_switchover(
273296
await are_writes_increasing(ops_test, extra_model=second_model)
274297

275298

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+
276336
@pytest.mark.group(1)
277337
@markers.juju3
278338
@pytest.mark.abort_on_fail

0 commit comments

Comments
 (0)