diff --git a/charms/worker/k8s/src/inspector.py b/charms/worker/k8s/src/inspector.py index 783b5ea1..1a73b4de 100644 --- a/charms/worker/k8s/src/inspector.py +++ b/charms/worker/k8s/src/inspector.py @@ -44,7 +44,7 @@ def _get_client(self) -> Client: self.client = Client(config=config.get()) return self.client - def get_nodes(self, labels: LabelSelector) -> Optional[List[Node]]: + def get_nodes(self, labels: Optional[LabelSelector] = None) -> Optional[List[Node]]: """Get nodes from the cluster. Args: @@ -56,6 +56,7 @@ def get_nodes(self, labels: LabelSelector) -> Optional[List[Node]]: Raises: ClusterInspectorError: If the nodes cannot be retrieved. """ + labels = labels or {} client = self._get_client() try: diff --git a/charms/worker/k8s/src/upgrade.py b/charms/worker/k8s/src/upgrade.py index f85e5122..520a1f7a 100644 --- a/charms/worker/k8s/src/upgrade.py +++ b/charms/worker/k8s/src/upgrade.py @@ -89,10 +89,11 @@ def pre_upgrade_check(self) -> None: Raises: ClusterNotReadyError: If the cluster is not ready for an upgrade. """ + if self.charm.is_worker: + log.info("TODO: Find some pre-upgrade checks for worker application.") + return try: - nodes = self.cluster_inspector.get_nodes( - labels={"juju-charm": "k8s-worker" if self.charm.is_worker else "k8s"} - ) + nodes = self.cluster_inspector.get_nodes() failing_pods = self.cluster_inspector.verify_pods_running(["kube-system"]) except ClusterInspector.ClusterInspectorError as e: raise ClusterNotReadyError( diff --git a/tests/integration/conftest.py b/tests/integration/conftest.py index 9e269810..c55b9922 100644 --- a/tests/integration/conftest.py +++ b/tests/integration/conftest.py @@ -20,7 +20,7 @@ from pytest_operator.plugin import OpsTest from .cos_substrate import LXDSubstrate -from .helpers import Bundle, Charm, cloud_type, get_unit_cidrs, is_deployed +from .helpers import Bundle, CharmUrl, cloud_type, get_unit_cidrs, is_deployed log = logging.getLogger(__name__) TEST_DATA = Path(__file__).parent / "data" @@ -72,7 +72,8 @@ def pytest_configure(config): config.addinivalue_line("markers", "cos: mark COS integration tests.") config.addinivalue_line( "markers", - "bundle(file='', apps_local={}, apps_channel={}, apps_resources={}): specify a YAML bundle file for a test.", + "bundle(file='', apps_local={}, apps_channel={}, apps_resources={}): " + "specify a YAML bundle file for a test.", ) @@ -202,7 +203,7 @@ async def grafana_agent(kubernetes_cluster: Model): machine_series = juju.utils.get_version_series(data["base"].split("@")[1]) await kubernetes_cluster.deploy( - Charm.craft_url("grafana-agent", machine_series, machine_arch), + str(CharmUrl.craft("grafana-agent", machine_series, machine_arch)), channel="stable", series=machine_series, ) diff --git a/tests/integration/helpers.py b/tests/integration/helpers.py index 97819d00..03a22054 100644 --- a/tests/integration/helpers.py +++ b/tests/integration/helpers.py @@ -14,7 +14,7 @@ from functools import cache, cached_property from itertools import chain from pathlib import Path -from typing import Dict, List, Mapping, Optional, Sequence, Tuple +from typing import Dict, List, Mapping, Optional, Tuple import yaml from juju import unit @@ -326,6 +326,7 @@ def find(cls, name: str) -> Optional["Charm"]: """ if charmcraft := CHARMCRAFT_DIRS.get(name): return cls(charmcraft) + return None async def resolve(self, ops_test: OpsTest, arch: str) -> "Charm": """Build or find the charm with ops_test. @@ -440,7 +441,6 @@ async def discover_charm_files(self, ops_test: OpsTest) -> Dict[str, Charm]: Args: ops_test: Instance of the pytest-operator plugin - arch: Cloud architecture Returns: Mapping: application name to Charm object @@ -457,6 +457,7 @@ async def apply_marking(self, ops_test: OpsTest, markings: Markings): Args: ops_test: Instance of the pytest-operator plugin + markings: Markings from the test """ _type, _vms = await cloud_type(ops_test) if _type == "lxd" and not _vms: @@ -496,7 +497,7 @@ def switch( resources (dict): Optional resources to add Raises: - ValueError: if both path and channel are provided, or neither are provided + FileNotFoundError: if the local charm file is not found """ app = self.applications.get(name) if not app: diff --git a/tests/integration/test_upgrade.py b/tests/integration/test_upgrade.py index 1d22c9e1..55f5ddb8 100644 --- a/tests/integration/test_upgrade.py +++ b/tests/integration/test_upgrade.py @@ -15,7 +15,7 @@ import yaml from pytest_operator.plugin import OpsTest -from .helpers import Bundle, Charm, get_leader +from .helpers import Bundle, get_leader # This pytest mark configures the test environment to use the Canonical Kubernetes # deploying charms from the edge channels, then upgrading them to the built charm. @@ -53,7 +53,7 @@ async def _refresh(app_name: str): app: Optional[juju.application.Application] = kubernetes_cluster.applications[app_name] assert app is not None, f"Application {app_name} not found" - log.info(f"Refreshing {app_name}") + log.info("Refreshing %s", app_name) leader_idx: int = await get_leader(app) leader: juju.unit.Unit = app.units[leader_idx] action = await leader.run_action("pre-upgrade-check")