Skip to content

Commit c40bccf

Browse files
committed
Fix spaces replication test
1 parent 1b430e0 commit c40bccf

File tree

2 files changed

+56
-46
lines changed

2 files changed

+56
-46
lines changed

tests/integration/spaces/test_spaced_async_replication.py

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from tenacity import Retrying, stop_after_attempt
1313

1414
from .. import architecture
15-
from ..high_availability_helpers_new import (
15+
from ..high_availability.high_availability_helpers_new import (
1616
get_app_leader,
1717
get_app_units,
1818
get_db_max_written_value,
@@ -43,7 +43,7 @@ def second_model(juju: Juju, lxd_spaces, request: pytest.FixtureRequest) -> Gene
4343

4444
logging.info(f"Creating model: {model_name}")
4545
juju.add_model(model_name)
46-
model_2 = Juju(model=first_model)
46+
model_2 = Juju(model=model_name)
4747
model_2.cli("reload-spaces")
4848
model_2.cli("add-space", "client", "10.0.0.1/24")
4949
model_2.cli("add-space", "peers", "10.10.10.1/24")
@@ -102,8 +102,6 @@ def test_deploy(first_model: str, second_model: str, lxd_spaces, charm) -> None:
102102
bind=bind,
103103
num_units=3,
104104
)
105-
# TODO switch to 1/stable
106-
model_1.deploy(charm="self-signed-certificates", channel="latest/stable", base="ubuntu@22.04")
107105

108106
model_2 = Juju(model=second_model)
109107
model_2.deploy(
@@ -115,20 +113,34 @@ def test_deploy(first_model: str, second_model: str, lxd_spaces, charm) -> None:
115113
bind=bind,
116114
num_units=3,
117115
)
116+
118117
# TODO switch to 1/stable
119-
model_2.deploy(charm="self-signed-certificates", channel="latest/stable", base="ubuntu@22.04")
118+
logging.info("Deploying tls operators")
119+
constraints = {"arch": architecture.architecture}
120+
model_1.deploy(
121+
charm="self-signed-certificates",
122+
channel="latest/stable",
123+
constraints=constraints,
124+
base="ubuntu@22.04",
125+
)
126+
model_2.deploy(
127+
charm="self-signed-certificates",
128+
channel="latest/stable",
129+
constraints=constraints,
130+
base="ubuntu@22.04",
131+
)
120132

121-
model_1.integrate(f"{DB_TEST_APP_1}:client-certificates", "self-signed-certificates")
122-
model_1.integrate(f"{DB_TEST_APP_1}:peer-certificates", "self-signed-certificates")
123-
model_2.integrate(f"{DB_TEST_APP_2}:client-certificates", "self-signed-certificates")
124-
model_2.integrate(f"{DB_TEST_APP_2}:peer-certificates", "self-signed-certificates")
133+
model_1.integrate(f"{DB_APP_1}:client-certificates", "self-signed-certificates")
134+
model_1.integrate(f"{DB_APP_1}:peer-certificates", "self-signed-certificates")
135+
model_2.integrate(f"{DB_APP_2}:client-certificates", "self-signed-certificates")
136+
model_2.integrate(f"{DB_APP_2}:peer-certificates", "self-signed-certificates")
125137

126138
model_1.offer(f"{first_model}.self-signed-certificates", endpoint="send-ca-cert")
127139
model_2.consume(f"{first_model}.self-signed-certificates", "send-ca-offer")
128-
model_2.integrate(DB_TEST_APP_2, "send-ca-offer")
140+
model_2.integrate(DB_APP_2, "send-ca-offer")
129141
model_2.offer(f"{second_model}.self-signed-certificates", endpoint="send-ca-cert")
130142
model_1.consume(f"{second_model}.self-signed-certificates", "send-ca-offer")
131-
model_1.integrate(DB_TEST_APP_1, "send-ca-offer")
143+
model_1.integrate(DB_APP_1, "send-ca-offer")
132144

133145
logging.info("Deploying test application")
134146
constraints = {"arch": architecture.architecture, "spaces": "client"}

tests/integration/test_charm.py

Lines changed: 33 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -194,41 +194,39 @@ async def test_postgresql_parameters_change(ops_test: OpsTest) -> None:
194194
await ops_test.model.wait_for_idle(apps=[DATABASE_APP_NAME], status="active", idle_period=30)
195195
password = await get_password(ops_test)
196196

197-
for attempt in Retrying(stop=stop_after_attempt(10), wait=wait_fixed(6), reraise=True):
198-
with attempt:
199-
# Connect to PostgreSQL.
200-
for unit_id in UNIT_IDS:
201-
host = get_unit_address(ops_test, f"{DATABASE_APP_NAME}/{unit_id}")
202-
logger.info("connecting to the database host: %s", host)
203-
try:
204-
with (
205-
psycopg2.connect(
206-
f"dbname='postgres' user='operator' host='{host}' password='{password}' connect_timeout=1"
207-
) as connection,
208-
connection.cursor() as cursor,
209-
):
210-
settings_names = [
211-
"max_prepared_transactions",
212-
"shared_buffers",
213-
"lc_monetary",
214-
"max_connections",
215-
]
216-
cursor.execute(
217-
sql.SQL(
218-
"SELECT name,setting FROM pg_settings WHERE name IN ({});"
219-
).format(sql.SQL(", ").join(sql.Placeholder() * len(settings_names))),
220-
settings_names,
221-
)
222-
records = cursor.fetchall()
223-
settings = convert_records_to_dict(records)
224-
225-
# Validate each configuration set by Patroni on PostgreSQL.
226-
assert settings["max_prepared_transactions"] == "100"
227-
assert settings["shared_buffers"] == "32768"
228-
assert settings["lc_monetary"] == "en_GB.utf8"
229-
assert settings["max_connections"] == "200"
230-
finally:
231-
connection.close()
197+
# Connect to PostgreSQL.
198+
for unit_id in UNIT_IDS:
199+
host = get_unit_address(ops_test, f"{DATABASE_APP_NAME}/{unit_id}")
200+
logger.info("connecting to the database host: %s", host)
201+
try:
202+
with (
203+
psycopg2.connect(
204+
f"dbname='postgres' user='operator' host='{host}' password='{password}' connect_timeout=1"
205+
) as connection,
206+
connection.cursor() as cursor,
207+
):
208+
settings_names = [
209+
"max_prepared_transactions",
210+
"shared_buffers",
211+
"lc_monetary",
212+
"max_connections",
213+
]
214+
cursor.execute(
215+
sql.SQL("SELECT name,setting FROM pg_settings WHERE name IN ({});").format(
216+
sql.SQL(", ").join(sql.Placeholder() * len(settings_names))
217+
),
218+
settings_names,
219+
)
220+
records = cursor.fetchall()
221+
settings = convert_records_to_dict(records)
222+
223+
# Validate each configuration set by Patroni on PostgreSQL.
224+
assert settings["max_prepared_transactions"] == "100"
225+
assert settings["shared_buffers"] == "32768"
226+
assert settings["lc_monetary"] == "en_GB.utf8"
227+
assert settings["max_connections"] == "200"
228+
finally:
229+
connection.close()
232230

233231

234232
async def test_scale_down_and_up(ops_test: OpsTest):

0 commit comments

Comments
 (0)