Skip to content

Commit 1ffb94a

Browse files
[MISC] Cleanup Jubilant leftovers (#705)
1 parent 64330f6 commit 1ffb94a

File tree

4 files changed

+29
-53
lines changed

4 files changed

+29
-53
lines changed

tests/integration/high_availability/high_availability_helpers_new.py

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
import jubilant_backports
1111
from jubilant_backports import Juju
12-
from jubilant_backports.statustypes import Status, UnitStatus
12+
from jubilant_backports.statustypes import Status
1313
from tenacity import (
1414
Retrying,
1515
retry,
@@ -29,21 +29,30 @@
2929
JujuAppsStatusFn = Callable[[Status, str], bool]
3030

3131

32-
def check_mysql_instances_online(juju: Juju, app_name: str) -> bool:
32+
def check_mysql_instances_online(
33+
juju: Juju,
34+
app_name: str,
35+
app_units: list[str] | None = None,
36+
) -> bool:
3337
"""Checks whether all MySQL cluster instances are online.
3438
3539
Args:
3640
juju: The Juju instance
3741
app_name: The name of the application
42+
app_units: The list of application units to check
3843
"""
39-
mysql_app_leader = get_app_leader(juju, app_name)
40-
mysql_app_units = get_app_units(juju, app_name)
44+
if not app_units:
45+
app_units = get_app_units(juju, app_name)
4146

42-
mysql_cluster_status = get_mysql_cluster_status(juju, mysql_app_leader)
47+
mysql_cluster_status = get_mysql_cluster_status(juju, app_units[0])
4348
mysql_cluster_topology = mysql_cluster_status["defaultreplicaset"]["topology"]
44-
assert len(mysql_cluster_topology) == len(mysql_app_units)
4549

46-
return all(member["status"] == "online" for member in mysql_cluster_topology.values())
50+
for unit_name in app_units:
51+
unit_label = get_mysql_instance_label(unit_name)
52+
if mysql_cluster_topology[unit_label]["status"] != "online":
53+
return False
54+
55+
return True
4756

4857

4958
async def check_mysql_units_writes_increment(
@@ -57,7 +66,7 @@ async def check_mysql_units_writes_increment(
5766
if not app_units:
5867
app_units = get_app_units(juju, app_name)
5968

60-
app_primary = get_mysql_primary_unit(juju, app_name)
69+
app_primary = get_mysql_primary_unit(juju, app_name, app_units[0])
6170
app_max_value = await get_mysql_max_written_value(juju, app_name, app_primary)
6271

6372
for unit_name in app_units:
@@ -94,16 +103,16 @@ def get_app_name(juju: Juju, charm_name: str) -> str | None:
94103
raise Exception("No application name found")
95104

96105

97-
def get_app_units(juju: Juju, app_name: str) -> dict[str, UnitStatus]:
106+
def get_app_units(juju: Juju, app_name: str) -> list[str]:
98107
"""Get the units for the given application."""
99108
model_status = juju.status()
100109
app_status = model_status.apps[app_name]
101-
return app_status.units
110+
return list(app_status.units)
102111

103112

104113
def scale_app_units(juju: Juju, app_name: str, num_units: int) -> None:
105114
"""Scale a given application to a number of units."""
106-
app_units = list(get_app_units(juju, app_name))
115+
app_units = get_app_units(juju, app_name)
107116
app_units_diff = num_units - len(app_units)
108117

109118
if app_units_diff > 0:
@@ -234,6 +243,11 @@ def get_mysql_cluster_status(juju: Juju, unit: str, cluster_set: bool = False) -
234243
return task.results["status"]
235244

236245

246+
def get_mysql_instance_label(unit_name: str) -> str:
247+
"""Builds a MySQL instance label out of a Juju unit name."""
248+
return "-".join(unit_name.rsplit("/", 1))
249+
250+
237251
def get_mysql_unit_name(instance_label: str) -> str:
238252
"""Builds a Juju unit name out of a MySQL instance label."""
239253
return "/".join(instance_label.rsplit("-", 1))
@@ -307,9 +321,6 @@ async def get_mysql_variable_value(
307321

308322
def start_mysql_process_gracefully(juju: Juju, unit_name: str) -> None:
309323
"""Start a MySQL process within a machine."""
310-
# TODO:
311-
# Rely on Jubilant exec command once they fix it
312-
# https://github.com/canonical/jubilant/issues/206
313324
juju.ssh(
314325
command="sudo snap start charmed-mysql.mysqld",
315326
target=unit_name,
@@ -324,9 +335,6 @@ def start_mysql_process_gracefully(juju: Juju, unit_name: str) -> None:
324335

325336
def stop_mysql_process_gracefully(juju: Juju, unit_name: str) -> None:
326337
"""Gracefully stop MySQL process."""
327-
# TODO:
328-
# Rely on Jubilant exec command once they fix it
329-
# https://github.com/canonical/jubilant/issues/206
330338
juju.ssh(
331339
command="sudo pkill mysqld --signal SIGTERM",
332340
target=unit_name,

tests/integration/high_availability/test_replication_logs_rotation.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -220,9 +220,6 @@ def write_unit_file(juju: Juju, unit_name: str, file_path: str, file_data: str):
220220

221221
def start_unit_flush_logs_job(juju: Juju, unit_name: str) -> None:
222222
"""Start running the logrotate job."""
223-
# TODO:
224-
# Rely on Jubilant exec command once they fix it
225-
# https://github.com/canonical/jubilant/issues/206
226223
juju.ssh(
227224
command="sudo logrotate -f /etc/logrotate.d/flush_mysql_logs",
228225
target=unit_name,
@@ -231,9 +228,6 @@ def start_unit_flush_logs_job(juju: Juju, unit_name: str) -> None:
231228

232229
def stop_unit_flush_logs_job(juju: Juju, unit_name: str) -> None:
233230
"""Stop running any logrotate jobs that may have been triggered by cron."""
234-
# TODO:
235-
# Rely on Jubilant exec command once they fix it
236-
# https://github.com/canonical/jubilant/issues/206
237231
juju.ssh(
238232
command="sudo pkill -f 'logrotate -f /etc/logrotate.d/flush_mysql_logs' --signal SIGTERM",
239233
target=unit_name,

tests/integration/high_availability/test_self_healing_restart_forceful.py

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,16 @@
66
import jubilant_backports
77
import pytest
88
from jubilant_backports import Juju
9-
from tenacity import (
10-
retry,
11-
stop_after_attempt,
12-
wait_fixed,
13-
)
149

1510
from constants import SERVER_CONFIG_USERNAME
1611

1712
from ..helpers import generate_random_string
1813
from .high_availability_helpers_new import (
14+
check_mysql_instances_online,
1915
check_mysql_units_writes_increment,
2016
execute_queries_on_unit,
21-
get_app_leader,
2217
get_app_units,
23-
get_mysql_cluster_status,
2418
get_mysql_primary_unit,
25-
get_mysql_unit_name,
2619
get_unit_ip,
2720
insert_mysql_test_data,
2821
remove_mysql_test_data,
@@ -119,7 +112,7 @@ async def test_sst_test(juju: Juju, continuous_writes):
119112

120113
# Verify instance is part of the cluster
121114
logging.info("Check if instance in cluster")
122-
assert check_unit_in_mysql_cluster(juju, new_mysql_primary_unit)
115+
assert check_mysql_instances_online(juju, MYSQL_APP_NAME, [new_mysql_primary_unit])
123116

124117
# Ensure continuous writes still incrementing for all units
125118
await check_mysql_units_writes_increment(juju, MYSQL_APP_NAME)
@@ -133,25 +126,6 @@ async def test_sst_test(juju: Juju, continuous_writes):
133126
await remove_mysql_test_data(juju, MYSQL_APP_NAME, table_name)
134127

135128

136-
@retry(stop=stop_after_attempt(12), wait=wait_fixed(15), reraise=True)
137-
def check_unit_in_mysql_cluster(juju: Juju, unit_name: str) -> bool:
138-
"""Check is unit is online in the cluster.
139-
140-
Args:
141-
juju: The Juju model.
142-
unit_name: The unit name to check.
143-
"""
144-
mysql_app_leader = get_app_leader(juju, MYSQL_APP_NAME)
145-
mysql_cluster_status = get_mysql_cluster_status(juju, mysql_app_leader)
146-
mysql_cluster_topology = mysql_cluster_status["defaultreplicaset"]["topology"]
147-
148-
for k, v in mysql_cluster_topology.items():
149-
if get_mysql_unit_name(k) == unit_name and v.get("status") == "online":
150-
return True
151-
152-
return False
153-
154-
155129
async def purge_mysql_binary_logs(juju: Juju, app_name: str, unit_name: str) -> None:
156130
"""Purge MySQL instance binary logs.
157131

tests/integration/high_availability/test_upgrade.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ async def test_fail_and_rollback(juju: Juju, charm: str, continuous_writes) -> N
140140
)
141141

142142
logging.info("Ensure continuous writes on all units")
143-
await check_mysql_units_writes_increment(juju, MYSQL_APP_NAME, list(mysql_app_units))
143+
await check_mysql_units_writes_increment(juju, MYSQL_APP_NAME, mysql_app_units)
144144

145145
logging.info("Re-run pre-upgrade-check action")
146146
task = juju.run(unit=mysql_app_leader, action="pre-upgrade-check")
@@ -162,7 +162,7 @@ async def test_fail_and_rollback(juju: Juju, charm: str, continuous_writes) -> N
162162
)
163163

164164
logging.info("Ensure continuous writes after rollback procedure")
165-
await check_mysql_units_writes_increment(juju, MYSQL_APP_NAME, list(mysql_app_units))
165+
await check_mysql_units_writes_increment(juju, MYSQL_APP_NAME, mysql_app_units)
166166

167167
# Remove fault charm file
168168
tmp_folder_charm.unlink()

0 commit comments

Comments
 (0)