|
15 | 15 |
|
16 | 16 | """Test lldpd charm deployment.""" |
17 | 17 |
|
18 | | -import asyncio |
19 | 18 | import logging |
20 | | -import pytest |
| 19 | +import pathlib |
21 | 20 |
|
22 | | -from pytest_operator.plugin import OpsTest |
| 21 | +import jubilant |
| 22 | +import pytest |
23 | 23 |
|
24 | 24 | logger = logging.getLogger(__name__) |
25 | 25 |
|
26 | 26 | NUM_UNITS = 2 |
27 | 27 |
|
28 | | -# The charmhub "ubuntu" charm is published as a separate revision per base, and |
29 | | -# libjuju resolves the bare "ubuntu" name to the 24.04 revision regardless of the |
30 | | -# requested base. Pin the latest/stable revision that matches each base so the |
31 | | -# subordinate can be tested on every base. Refresh these if the charm is |
32 | | -# republished (charmhub.io/ubuntu, Releases tab). |
33 | | -UBUNTU_REVISION = { |
34 | | - "ubuntu@20.04": 26, |
35 | | - "ubuntu@22.04": 77, |
36 | | - "ubuntu@24.04": 79, |
37 | | - "ubuntu@26.04": 81, |
38 | | -} |
39 | 28 |
|
40 | | - |
41 | | -@pytest.mark.abort_on_fail |
42 | | -@pytest.mark.skip_if_deployed |
43 | 29 | @pytest.mark.order(1) |
44 | | -async def test_build_and_deploy( |
45 | | - ops_test: OpsTest, charm_base: str, lldpd_charm |
| 30 | +def test_build_and_deploy( |
| 31 | + juju: jubilant.Juju, charm_base: str, lldpd_charm: pathlib.Path |
46 | 32 | ) -> None: |
47 | 33 | """Test the lldpd charm builds and deploys.""" |
48 | 34 | logger.info(f"Building and deploying lldp charms for base: {charm_base}") |
49 | | - lldpd = lldpd_charm |
50 | | - |
51 | | - logger.info(f"lldpd charm is located at: {lldpd}") |
| 35 | + logger.info(f"lldpd charm is located at: {lldpd_charm}") |
52 | 36 |
|
53 | | - # Deploy ubuntu and lldpd charms. |
54 | | - await asyncio.gather( |
55 | | - ops_test.model.deploy( |
56 | | - "ubuntu", |
57 | | - application_name="ubuntu", |
58 | | - num_units=NUM_UNITS, |
59 | | - base=charm_base, |
60 | | - channel="latest/stable", |
61 | | - revision=UBUNTU_REVISION[charm_base], |
62 | | - ), |
63 | | - ops_test.model.deploy( |
64 | | - str(lldpd), |
65 | | - application_name="lldpd", |
66 | | - num_units=0, |
67 | | - base=charm_base, |
68 | | - ), |
69 | | - ) |
| 37 | + # Deploy the ubuntu principal and the lldpd subordinate. The juju CLI |
| 38 | + # resolves the ubuntu charm revision for the requested base. |
| 39 | + juju.deploy("ubuntu", "ubuntu", num_units=NUM_UNITS, base=charm_base) |
| 40 | + juju.deploy(lldpd_charm, "lldpd", num_units=0, base=charm_base) |
70 | 41 |
|
71 | | - # Integrate lldpd with ubuntu |
72 | | - await ops_test.model.integrate("ubuntu:juju-info", "lldpd:juju-info") |
73 | | - async with ops_test.fast_forward(): |
74 | | - await ops_test.model.wait_for_idle( |
75 | | - apps=["lldpd", "ubuntu"], status="active", timeout=1800 |
76 | | - ) |
77 | | - for unit in range(NUM_UNITS): |
78 | | - uname = f"lldpd/{unit}" |
79 | | - assert ops_test.model.units.get(uname).workload_status == "active" |
| 42 | + juju.integrate("ubuntu:juju-info", "lldpd:juju-info") |
| 43 | + juju.wait(jubilant.all_active, timeout=1800) |
80 | 44 |
|
81 | 45 |
|
82 | 46 | @pytest.mark.order(2) |
83 | | -async def test_lldpd_is_active(ops_test: OpsTest) -> None: |
| 47 | +def test_lldpd_is_active(juju: jubilant.Juju) -> None: |
84 | 48 | """Test that the lldpd services are active in each juju unit.""" |
85 | 49 | logger.info("Validating that lldpd is active inside each juju unit.") |
86 | | - for unit in ops_test.model.applications["lldpd"].units: |
87 | | - status = (await unit.ssh("systemctl is-active lldpd")).strip() |
88 | | - assert status == "active", f"{unit.name} lldpd is not active" |
| 50 | + status = juju.status() |
| 51 | + for unit in status.apps["lldpd"].units: |
| 52 | + result = juju.ssh(unit, "systemctl is-active lldpd").strip() |
| 53 | + assert result == "active", f"{unit} lldpd is not active" |
0 commit comments