Skip to content

Commit

Permalink
Address new linting issues
Browse files Browse the repository at this point in the history
  • Loading branch information
addyess committed Feb 10, 2024
1 parent c55bef7 commit 14658f0
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
21 changes: 18 additions & 3 deletions charms/worker/k8s/src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import shlex
import socket
import subprocess
from functools import cache
from typing import Optional

import charms.contextual_status as status
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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:
Expand Down
6 changes: 3 additions & 3 deletions tests/integration/test_k8s.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
1 change: 1 addition & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ deps =
pytest-asyncio
pytest-operator
requests
tenacity
types-PyYAML
types-requests
commands =
Expand Down

0 comments on commit 14658f0

Please sign in to comment.