Skip to content

Commit c2c5223

Browse files
committed
check deploy postgresql
1 parent 2413462 commit c2c5223

File tree

2 files changed

+75
-85
lines changed

2 files changed

+75
-85
lines changed

src/relations/postgresql_provider.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,8 +196,6 @@ def update_endpoints(self, event: DatabaseRequestedEvent = None) -> None:
196196
def _check_multiple_endpoints(self) -> bool:
197197
"""Checks if there are relations with other endpoints."""
198198
relation_names = {relation.name for relation in self.charm.client_relations}
199-
for relation_name in relation_names:
200-
logger.info(f" ------------------------- {relation_name} ----------")
201199
if "database" in relation_names and len(relation_names) > 1:
202200
return True
203201
return False

tests/integration/relations/test_relations.py

Lines changed: 75 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -38,107 +38,99 @@ async def test_deploy_charms(ops_test: OpsTest, charm):
3838
series=CHARM_SERIES,
3939
channel="edge",
4040
),
41-
ops_test.model.deploy(
42-
APPLICATION_APP_NAME,
43-
application_name=APPLICATION_APP_NAME+"-second",
44-
num_units=1,
45-
series=CHARM_SERIES,
46-
channel="edge",
47-
),
4841
ops_test.model.deploy(
4942
charm,
5043
application_name=APP_NAME,
5144
num_units=1,
5245
series=CHARM_SERIES,
5346
config={"profile": "testing"},
5447
),
55-
# ops_test.model.deploy(
56-
# MAILMAN3_CORE_APP_NAME,
57-
# application_name=MAILMAN3_CORE_APP_NAME,
58-
# channel="stable",
59-
# series="focal",
60-
# config={"hostname": "example.org"},
61-
# ),
48+
ops_test.model.deploy(
49+
MAILMAN3_CORE_APP_NAME,
50+
application_name=MAILMAN3_CORE_APP_NAME,
51+
channel="stable",
52+
series="focal",
53+
config={"hostname": "example.org"},
54+
),
6255
)
6356

64-
await ops_test.model.wait_for_idle(apps=[APP_NAME, APPLICATION_APP_NAME, APPLICATION_APP_NAME+"-second"], status="active", timeout=3000)
57+
await ops_test.model.wait_for_idle(apps=APP_NAMES, status="active", timeout=3000)
6558

6659

6760
@pytest.mark.group(1)
6861
async def test_legacy_endpoint_with_multiple_related_endpoints(ops_test: OpsTest):
69-
# await ops_test.model.relate(MAILMAN3_CORE_APP_NAME, f"{APP_NAME}:{DB_RELATION}")
62+
await ops_test.model.relate(MAILMAN3_CORE_APP_NAME, f"{APP_NAME}:{DB_RELATION}")
7063
await ops_test.model.relate(APP_NAME, f"{APPLICATION_APP_NAME}:{FIRST_DATABASE_RELATION}")
71-
await ops_test.model.relate(APP_NAME, f"{APPLICATION_APP_NAME}-second:{FIRST_DATABASE_RELATION}")
7264

7365
app = ops_test.model.applications[APP_NAME]
7466
await ops_test.model.block_until(
7567
lambda: "blocked" in {unit.workload_status for unit in app.units},
7668
timeout=1500,
7769
)
7870

79-
# logger.info(" remove relation with modern endpoints")
80-
# await ops_test.model.applications[APP_NAME].remove_relation(
81-
# f"{APP_NAME}:{DATABASE_RELATION}", f"{APPLICATION_APP_NAME}:{FIRST_DATABASE_RELATION}"
82-
# )
83-
# async with ops_test.fast_forward():
84-
# await ops_test.model.wait_for_idle(
85-
# status="active",
86-
# timeout=1500,
87-
# raise_on_error=False,
88-
# )
89-
#
90-
# legacy_interface_connect = await get_legacy_db_connection_str(
91-
# ops_test, MAILMAN3_CORE_APP_NAME, DB_RELATION, remote_unit_name=f"{APP_NAME}/0"
92-
# )
93-
# logger.info(f" check connect to = {legacy_interface_connect}")
94-
# for attempt in Retrying(stop=stop_after_delay(60 * 3), wait=wait_fixed(10)):
95-
# with attempt:
96-
# with psycopg2.connect(legacy_interface_connect) as connection:
97-
# assert connection.status == psycopg2.extensions.STATUS_READY
98-
#
99-
# logger.info(" remove relation mailman3-core")
100-
# async with ops_test.fast_forward():
101-
# await ops_test.model.applications[APP_NAME].remove_relation(
102-
# f"{APP_NAME}:{DB_RELATION}", f"{MAILMAN3_CORE_APP_NAME}:{DB_RELATION}"
103-
# )
104-
# await ops_test.model.wait_for_idle(apps=[APP_NAME], status="active", timeout=1000)
105-
# with pytest.raises(psycopg2.OperationalError):
106-
# psycopg2.connect(legacy_interface_connect)
107-
#
108-
#
109-
# async def test_modern_endpoint_with_multiple_related_endpoints(ops_test: OpsTest):
110-
# await ops_test.model.relate(MAILMAN3_CORE_APP_NAME, f"{APP_NAME}:{DB_RELATION}")
111-
# await ops_test.model.relate(APP_NAME, f"{APPLICATION_APP_NAME}:{FIRST_DATABASE_RELATION}")
112-
#
113-
# app = ops_test.model.applications[APP_NAME]
114-
# await ops_test.model.block_until(
115-
# lambda: "blocked" in {unit.workload_status for unit in app.units},
116-
# timeout=1500,
117-
# )
118-
#
119-
# logger.info(" remove relation with legacy endpoints")
120-
# await ops_test.model.applications[APP_NAME].remove_relation(
121-
# f"{MAILMAN3_CORE_APP_NAME}:{DB_RELATION}", f"{APP_NAME}:{DB_RELATION}"
122-
# )
123-
# async with ops_test.fast_forward():
124-
# await ops_test.model.wait_for_idle(status="active", timeout=3000, raise_on_error=False)
125-
#
126-
# modern_interface_connect = await build_connection_string(
127-
# ops_test, APPLICATION_APP_NAME, FIRST_DATABASE_RELATION
128-
# )
129-
# logger.info(f" check connect to = {modern_interface_connect}")
130-
# for attempt in Retrying(stop=stop_after_delay(60 * 3), wait=wait_fixed(10)):
131-
# with attempt:
132-
# with psycopg2.connect(modern_interface_connect) as connection:
133-
# assert connection.status == psycopg2.extensions.STATUS_READY
134-
#
135-
# logger.info(f" remove relation {APPLICATION_APP_NAME}")
136-
# async with ops_test.fast_forward():
137-
# await ops_test.model.applications[APP_NAME].remove_relation(
138-
# f"{APP_NAME}:{DATABASE_RELATION}", f"{APPLICATION_APP_NAME}:{FIRST_DATABASE_RELATION}"
139-
# )
140-
# await ops_test.model.wait_for_idle(apps=[APP_NAME], status="active", timeout=1000)
141-
# for attempt in Retrying(stop=stop_after_delay(60 * 5), wait=wait_fixed(10)):
142-
# with attempt:
143-
# with pytest.raises(psycopg2.OperationalError):
144-
# psycopg2.connect(modern_interface_connect)
71+
logger.info(" remove relation with modern endpoints")
72+
await ops_test.model.applications[APP_NAME].remove_relation(
73+
f"{APP_NAME}:{DATABASE_RELATION}", f"{APPLICATION_APP_NAME}:{FIRST_DATABASE_RELATION}"
74+
)
75+
async with ops_test.fast_forward():
76+
await ops_test.model.wait_for_idle(
77+
status="active",
78+
timeout=1500,
79+
raise_on_error=False,
80+
)
81+
82+
legacy_interface_connect = await get_legacy_db_connection_str(
83+
ops_test, MAILMAN3_CORE_APP_NAME, DB_RELATION, remote_unit_name=f"{APP_NAME}/0"
84+
)
85+
logger.info(f" check connect to = {legacy_interface_connect}")
86+
for attempt in Retrying(stop=stop_after_delay(60 * 3), wait=wait_fixed(10)):
87+
with attempt:
88+
with psycopg2.connect(legacy_interface_connect) as connection:
89+
assert connection.status == psycopg2.extensions.STATUS_READY
90+
91+
logger.info(" remove relation mailman3-core")
92+
async with ops_test.fast_forward():
93+
await ops_test.model.applications[APP_NAME].remove_relation(
94+
f"{APP_NAME}:{DB_RELATION}", f"{MAILMAN3_CORE_APP_NAME}:{DB_RELATION}"
95+
)
96+
await ops_test.model.wait_for_idle(apps=[APP_NAME], status="active", timeout=1000)
97+
with pytest.raises(psycopg2.OperationalError):
98+
psycopg2.connect(legacy_interface_connect)
99+
100+
101+
async def test_modern_endpoint_with_multiple_related_endpoints(ops_test: OpsTest):
102+
await ops_test.model.relate(MAILMAN3_CORE_APP_NAME, f"{APP_NAME}:{DB_RELATION}")
103+
await ops_test.model.relate(APP_NAME, f"{APPLICATION_APP_NAME}:{FIRST_DATABASE_RELATION}")
104+
105+
app = ops_test.model.applications[APP_NAME]
106+
await ops_test.model.block_until(
107+
lambda: "blocked" in {unit.workload_status for unit in app.units},
108+
timeout=1500,
109+
)
110+
111+
logger.info(" remove relation with legacy endpoints")
112+
await ops_test.model.applications[APP_NAME].remove_relation(
113+
f"{MAILMAN3_CORE_APP_NAME}:{DB_RELATION}", f"{APP_NAME}:{DB_RELATION}"
114+
)
115+
async with ops_test.fast_forward():
116+
await ops_test.model.wait_for_idle(status="active", timeout=3000, raise_on_error=False)
117+
118+
modern_interface_connect = await build_connection_string(
119+
ops_test, APPLICATION_APP_NAME, FIRST_DATABASE_RELATION
120+
)
121+
logger.info(f" check connect to = {modern_interface_connect}")
122+
for attempt in Retrying(stop=stop_after_delay(60 * 3), wait=wait_fixed(10)):
123+
with attempt:
124+
with psycopg2.connect(modern_interface_connect) as connection:
125+
assert connection.status == psycopg2.extensions.STATUS_READY
126+
127+
logger.info(f" remove relation {APPLICATION_APP_NAME}")
128+
async with ops_test.fast_forward():
129+
await ops_test.model.applications[APP_NAME].remove_relation(
130+
f"{APP_NAME}:{DATABASE_RELATION}", f"{APPLICATION_APP_NAME}:{FIRST_DATABASE_RELATION}"
131+
)
132+
await ops_test.model.wait_for_idle(apps=[APP_NAME], status="active", timeout=1000)
133+
for attempt in Retrying(stop=stop_after_delay(60 * 5), wait=wait_fixed(10)):
134+
with attempt:
135+
with pytest.raises(psycopg2.OperationalError):
136+
psycopg2.connect(modern_interface_connect)

0 commit comments

Comments
 (0)