Skip to content

Commit 9e62f1a

Browse files
BON4Zvirovyi
andauthored
[DPE-8731] Add unit kill ha test (#31)
* Add unit kill test. * Add seed check in integration kill test. --------- Co-authored-by: Vladyslav Tarasenko <vladyslav.tarasenko@canonical.com>
1 parent 0f56e3c commit 9e62f1a

File tree

3 files changed

+105
-1
lines changed

3 files changed

+105
-1
lines changed

tests/integration/test_kill.py

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
#!/usr/bin/env python3
2+
# Copyright 2025 Canonical Ltd.
3+
# See LICENSE file for licensing details.
4+
5+
import logging
6+
from pathlib import Path
7+
8+
import jubilant
9+
import yaml
10+
11+
from integration.helpers.cassandra import OPERATOR_PASSWORD
12+
from integration.helpers.continuous_writes import ContinuousWrites
13+
from integration.helpers.juju import (
14+
app_secret_extract,
15+
get_hosts,
16+
get_leader_unit,
17+
get_non_leader_units,
18+
scale_sequentially_to,
19+
)
20+
21+
logger = logging.getLogger(__name__)
22+
23+
24+
def test_deploy(juju: jubilant.Juju, cassandra_charm: Path, app_name: str) -> None:
25+
juju.deploy(
26+
cassandra_charm,
27+
app=app_name,
28+
config={"profile": "testing"},
29+
num_units=3,
30+
)
31+
juju.wait(
32+
ready=lambda status: jubilant.all_agents_idle(status) and jubilant.all_active(status),
33+
delay=20,
34+
timeout=2400,
35+
)
36+
37+
38+
def test_seed_primary(juju: jubilant.Juju, app_name: str) -> None:
39+
_, leader_status = get_leader_unit(juju, app_name)
40+
for unit, _ in juju.status().apps[app_name].units.items():
41+
assert f"{leader_status.public_address}:7000" in get_seeds(juju, unit)
42+
43+
44+
def test_kill_primary(
45+
juju: jubilant.Juju, app_name: str, continuous_writes: ContinuousWrites
46+
) -> None:
47+
continuous_writes.start(
48+
hosts=get_hosts(juju, app_name),
49+
password=app_secret_extract(juju, app_name, OPERATOR_PASSWORD),
50+
replication_factor=3,
51+
)
52+
53+
leader, _ = get_leader_unit(juju, app_name)
54+
kill_unit(juju, leader)
55+
56+
juju.wait(
57+
ready=lambda status: jubilant.all_agents_idle(status) and jubilant.all_active(status),
58+
delay=20,
59+
timeout=1800,
60+
)
61+
continuous_writes.assert_new_writes()
62+
63+
new_leader, _ = get_leader_unit(juju, app_name)
64+
assert leader != new_leader
65+
66+
67+
def test_seed_new_primary(juju: jubilant.Juju, app_name: str) -> None:
68+
_, leader_status = get_leader_unit(juju, app_name)
69+
for unit, _ in juju.status().apps[app_name].units.items():
70+
assert f"{leader_status.public_address}:7000" in get_seeds(juju, unit)
71+
72+
73+
def test_kill_subordinate(
74+
juju: jubilant.Juju, app_name: str, continuous_writes: ContinuousWrites
75+
) -> None:
76+
scale_sequentially_to(juju, app_name, 3)
77+
78+
subordinate = get_non_leader_units(juju, app_name)[0]
79+
kill_unit(juju, subordinate)
80+
81+
juju.wait(
82+
ready=lambda status: jubilant.all_agents_idle(status) and jubilant.all_active(status),
83+
delay=20,
84+
timeout=1200,
85+
)
86+
continuous_writes.stop_and_assert_writes()
87+
88+
89+
def kill_unit(juju: jubilant.Juju, unit: str) -> None:
90+
juju.cli("remove-unit", "--force", "--no-wait", "--no-prompt", "--destroy-storage", unit)
91+
92+
93+
def get_seeds(juju: jubilant.Juju, unit: str) -> list[str]:
94+
config_file = juju.ssh(
95+
unit, "cat /var/snap/charmed-cassandra/current/etc/cassandra/cassandra.yaml"
96+
)
97+
config = yaml.load(config_file, yaml.Loader)
98+
return config["seed_provider"][0]["parameters"][0]["seeds"].split(",")
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
summary: test_kill.py
2+
execute: |
3+
tox run -e integration-kill -- --alluredir="$SPREAD_TASK/allure-results" --model-name=test-cas --keep-models
4+
artifacts:
5+
- allure-results

tox.ini

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ commands =
6767
{[vars]tests_path}/unit
6868
poetry run coverage report
6969

70-
[testenv:integration-{authentication,charm,config,restart,multinode,scaling,tls,cos,provider,multicluster,network}]
70+
[testenv:integration-{authentication,charm,config,restart,multinode,scaling,tls,cos,provider,multicluster,network,kill}]
7171
description = Run integration tests
7272
pass_env =
7373
CI
@@ -83,6 +83,7 @@ set_env =
8383
provider: TESTFILE=test_provider.py
8484
multicluster: TESTFILE=test_multicluster.py
8585
network: TESTFILE=test_network.py
86+
kill: TESTFILE=test_kill.py
8687
commands_pre =
8788
poetry install --only integration
8889
commands =

0 commit comments

Comments
 (0)