From 14658f0187e4616d8f9275abea604ebea3add591 Mon Sep 17 00:00:00 2001 From: Adam Dyess Date: Fri, 9 Feb 2024 23:42:08 -0600 Subject: [PATCH] Address new linting issues --- charms/worker/k8s/src/charm.py | 21 ++++++++++++++++++--- tests/integration/test_k8s.py | 6 +++--- tox.ini | 1 + 3 files changed, 22 insertions(+), 6 deletions(-) diff --git a/charms/worker/k8s/src/charm.py b/charms/worker/k8s/src/charm.py index f1096b7d..9624a352 100755 --- a/charms/worker/k8s/src/charm.py +++ b/charms/worker/k8s/src/charm.py @@ -20,7 +20,6 @@ import shlex import socket import subprocess -from functools import cache from typing import Optional import charms.contextual_status as status @@ -73,9 +72,12 @@ def is_control_plane(self) -> bool: """Returns true if the unit is not a worker.""" return not self.is_worker - @cache def _get_node_name(self) -> str: - """Return the lowercase hostname.""" + """Return the lowercase hostname. + + Returns: + the hostname of the machine. + """ return socket.gethostname().lower() @on_error(WaitingStatus("Failed to apply snap requirements"), subprocess.CalledProcessError) @@ -199,9 +201,22 @@ def _join_cluster(self): status.add(ops.MaintenanceStatus("Joining cluster")) def _req_cluster_token(relation: ops.Relation): + """Provide a requested node-name. + + Args: + relation: juju relation on which to operate + """ relation.data[self.unit]["node-name"] = self._get_node_name() def _rec_cluster_token(relation: ops.Relation) -> str: + """Recover token from cluster-secret. + + Args: + relation: juju relation on which to operate + + Returns: + str: The token recovered from the juju provided by k8s leader + """ sec_databags, sec_key = [], f"{self.unit.name}-cluster-secret" for potential in relation.data.values(): if sec_key in potential: diff --git a/tests/integration/test_k8s.py b/tests/integration/test_k8s.py index 46a71edb..728c7067 100644 --- a/tests/integration/test_k8s.py +++ b/tests/integration/test_k8s.py @@ -20,7 +20,7 @@ async def ready_nodes(k8s, expected_count): Args: k8s: k8s unit - expected_count: numer of expected nodes + expected_count: number of expected nodes Returns: list of nodes @@ -44,7 +44,7 @@ async def ready_nodes(k8s, expected_count): @pytest.mark.abort_on_fail -async def test_nodes_ready(ops_test): +async def test_nodes_ready(kubernetes_cluster): """Deploy the charm and wait for active/idle status.""" - k8s = ops_test.model.applications["k8s"] + k8s = kubernetes_cluster.applications["k8s"] await ready_nodes(k8s.units[0], 3) diff --git a/tox.ini b/tox.ini index 44fa6a26..6d3dab61 100644 --- a/tox.ini +++ b/tox.ini @@ -52,6 +52,7 @@ deps = pytest-asyncio pytest-operator requests + tenacity types-PyYAML types-requests commands =