|
| 1 | +#!/usr/bin/env python3 |
| 2 | +# Copyright 2024 Canonical Ltd. |
| 3 | +# |
| 4 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +# you may not use this file except in compliance with the License. |
| 6 | +# You may obtain a copy of the License at |
| 7 | +# |
| 8 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +# |
| 10 | +# Unless required by applicable law or agreed to in writing, software |
| 11 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +# See the License for the specific language governing permissions and |
| 14 | +# limitations under the License. |
| 15 | + |
| 16 | +"""Test lldpd charm deployment.""" |
| 17 | + |
| 18 | +import asyncio |
| 19 | +import logging |
| 20 | +import pytest |
| 21 | + |
| 22 | +from pytest_operator.plugin import OpsTest |
| 23 | + |
| 24 | + |
| 25 | +logger = logging.getLogger(__name__) |
| 26 | + |
| 27 | +NUM_UNITS = 2 |
| 28 | + |
| 29 | + |
| 30 | +@pytest.mark.abort_on_fail |
| 31 | +@pytest.mark.skip_if_deployed |
| 32 | +@pytest.mark.order(1) |
| 33 | +async def test_build_and_deploy( |
| 34 | + ops_test: OpsTest, charm_base: str, lldpd_charm |
| 35 | +) -> None: |
| 36 | + """Test the lldpd charm builds and deploys.""" |
| 37 | + logger.info(f"Building and deploying lldp charms for base: {charm_base}") |
| 38 | + lldpd = await lldpd_charm |
| 39 | + |
| 40 | + logger.info(f"lldpd charm is located at: {lldpd}") |
| 41 | + |
| 42 | + # Deploy ubuntu and lldpd charms. |
| 43 | + await asyncio.gather( |
| 44 | + ops_test.model.deploy( |
| 45 | + "ubuntu", |
| 46 | + application_name="ubuntu", |
| 47 | + num_units=NUM_UNITS, |
| 48 | + base=charm_base, |
| 49 | + ), |
| 50 | + ops_test.model.deploy( |
| 51 | + str(lldpd), |
| 52 | + application_name="lldpd", |
| 53 | + num_units=0, |
| 54 | + base=charm_base, |
| 55 | + ), |
| 56 | + ) |
| 57 | + |
| 58 | + # Integrate lldpd with ubuntu |
| 59 | + await ops_test.model.integrate("ubuntu:juju-info", "lldpd:juju-info") |
| 60 | + async with ops_test.fast_forward(): |
| 61 | + await ops_test.model.wait_for_idle( |
| 62 | + apps=["lldpd", "ubuntu"], status="active", timeout=1800 |
| 63 | + ) |
| 64 | + for unit in range(NUM_UNITS): |
| 65 | + uname = f"lldpd/{unit}" |
| 66 | + assert ops_test.model.units.get(uname).workload_status == "active" |
| 67 | + |
| 68 | + |
| 69 | +@pytest.mark.order(2) |
| 70 | +async def test_lldpd_is_active(ops_test: OpsTest) -> None: |
| 71 | + """Test that the lldpd services are active in each juju unit.""" |
| 72 | + logger.info("Validating that lldpd is active inside each juju unit.") |
| 73 | + for unit in ops_test.model.applications["lldpd"].units: |
| 74 | + status = (await unit.ssh("systemctl is-active lldpd")).strip() |
| 75 | + assert status == "active", f"{unit.name} lldpd is not active" |
0 commit comments