|
8 | 8 | import pytest
|
9 | 9 | import yaml
|
10 | 10 |
|
11 |
| -from ..helpers import delete_file_or_directory_in_unit, write_content_to_file_in_unit |
12 |
| -from .high_availability_helpers import CLUSTER_NAME, delete_pod |
| 11 | +from .high_availability_helpers import CLUSTER_NAME, delete_pod, scale_application |
13 | 12 |
|
14 | 13 | logger = logging.getLogger(__name__)
|
15 | 14 |
|
|
21 | 20 | @pytest.mark.group(1)
|
22 | 21 | @pytest.mark.abort_on_fail
|
23 | 22 | async def test_crash_during_cluster_setup(ops_test) -> None:
|
| 23 | + """Test primary crash during startup. |
| 24 | +
|
| 25 | + It must recover/end setup when the primary got offline. |
| 26 | + """ |
24 | 27 | mysql_charm = await ops_test.build_charm(".")
|
25 | 28 |
|
26 | 29 | config = {"cluster-name": CLUSTER_NAME, "profile": "testing"}
|
27 | 30 | resources = {"mysql-image": METADATA["resources"]["mysql-image"]["upstream-source"]}
|
28 | 31 |
|
29 |
| - logger.info("Deploying 3 units of mysql-k8s") |
| 32 | + logger.info("Deploying 1 units of mysql-k8s") |
30 | 33 | mysql_application = await ops_test.model.deploy(
|
31 | 34 | mysql_charm,
|
32 | 35 | application_name=APP_NAME,
|
33 | 36 | config=config,
|
34 | 37 | resources=resources,
|
35 |
| - num_units=3, |
| 38 | + num_units=1, |
36 | 39 |
|
37 | 40 | trust=True,
|
38 | 41 | )
|
39 | 42 |
|
40 |
| - logger.info("Waiting until application enters maintenance status") |
41 |
| - await ops_test.model.block_until( |
42 |
| - lambda: mysql_application.status == "maintenance", timeout=TIMEOUT |
43 |
| - ) |
| 43 | + logger.info("Waiting for single unit to be ready") |
| 44 | + await ops_test.model.block_until(lambda: mysql_application.status == "active", timeout=TIMEOUT) |
44 | 45 |
|
45 |
| - leader_unit = None |
46 |
| - non_leader_units = [] |
| 46 | + # leader unit is the 1st unit |
| 47 | + leader_unit = mysql_application.units[0] |
47 | 48 |
|
48 |
| - for unit in mysql_application.units: |
49 |
| - if not await unit.is_leader_from_status(): |
50 |
| - non_leader_units.append(unit) |
51 |
| - else: |
52 |
| - leader_unit = unit |
| 49 | + logger.info("Scale to 3 units") |
| 50 | + await scale_application(ops_test, APP_NAME, 3, False) |
53 | 51 |
|
54 |
| - logger.info("Waiting until leader unit is creating cluster") |
| 52 | + logger.info("Waiting until application enters waiting status") |
55 | 53 | await ops_test.model.block_until(
|
56 |
| - lambda: leader_unit.workload_status == "maintenance" |
57 |
| - and leader_unit.agent_status == "executing" |
58 |
| - and "Creating cluster" in leader_unit.workload_status_message, |
59 |
| - timeout=TIMEOUT, |
| 54 | + lambda: mysql_application.status == "waiting", timeout=TIMEOUT |
60 | 55 | )
|
61 | 56 |
|
62 |
| - logger.info("Disabling non-leader units to avoid joining the cluster") |
63 |
| - for unit in non_leader_units: |
64 |
| - unit_label = unit.name.replace("/", "-") |
65 |
| - await write_content_to_file_in_unit( |
66 |
| - ops_test, |
67 |
| - unit, |
68 |
| - f"/var/lib/juju/agents/unit-{unit_label}/charm/disable", |
69 |
| - "", |
70 |
| - container_name="charm", |
71 |
| - ) |
72 |
| - |
73 | 57 | logger.info("Deleting pod")
|
74 | 58 | delete_pod(ops_test, leader_unit)
|
75 | 59 |
|
76 |
| - logger.info("Waiting until pod rescheduled and cluster is set up again") |
77 | 60 | async with ops_test.fast_forward("60s"):
|
78 |
| - await ops_test.model.block_until( |
79 |
| - lambda: leader_unit.workload_status == "active" |
80 |
| - and leader_unit.workload_status_message == "Primary", |
81 |
| - timeout=TIMEOUT, |
82 |
| - ) |
83 |
| - |
84 |
| - logger.info("Removing disabled flag from non-leader units") |
85 |
| - for unit in non_leader_units: |
86 |
| - unit_label = unit.name.replace("/", "-") |
87 |
| - await delete_file_or_directory_in_unit( |
88 |
| - ops_test, |
89 |
| - unit.name, |
90 |
| - f"/var/lib/juju/agents/unit-{unit_label}/charm/disable", |
91 |
| - container_name="charm", |
92 |
| - ) |
93 |
| - |
94 | 61 | logger.info("Waiting until cluster is fully active")
|
95 | 62 | await ops_test.model.wait_for_idle(
|
96 | 63 | apps=[APP_NAME],
|
|
0 commit comments