Skip to content

Commit

Permalink
Rename kubernetes_charm.py to charm.py
Browse files Browse the repository at this point in the history
Needed for upcoming charmcraft 3 migration because of canonical/charmcraft#1994
  • Loading branch information
carlcsaposs-canonical committed Jan 9, 2025
1 parent d7141af commit cd1ea4a
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 20 deletions.
2 changes: 1 addition & 1 deletion charmcraft.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,4 @@ parts:
- -charm_version
charm-strict-dependencies: true
charm-requirements: [requirements.txt]
charm-entrypoint: src/kubernetes_charm.py
charm-entrypoint: src/charm.py
File renamed without changes.
6 changes: 3 additions & 3 deletions src/relations/tls.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import relations.secrets

if typing.TYPE_CHECKING:
import kubernetes_charm
import charm

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -48,7 +48,7 @@ def _generate_private_key() -> str:
class _Relation:
"""Relation to TLS certificate provider"""

_charm: "kubernetes_charm.KubernetesRouterCharm"
_charm: "charm.KubernetesRouterCharm"
_interface: tls_certificates.TLSCertificatesRequiresV2
_secrets: relations.secrets.RelationSecrets

Expand Down Expand Up @@ -181,7 +181,7 @@ class RelationEndpoint(ops.Object):

NAME = "certificates"

def __init__(self, charm_: "kubernetes_charm.KubernetesRouterCharm") -> None:
def __init__(self, charm_: "charm.KubernetesRouterCharm") -> None:
super().__init__(charm_, self.NAME)
self._charm = charm_
self._interface = tls_certificates.TLSCertificatesRequiresV2(self._charm, self.NAME)
Expand Down
12 changes: 6 additions & 6 deletions tests/unit/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def disable_tenacity_retry(monkeypatch):
@pytest.fixture(autouse=True)
def patch(monkeypatch):
monkeypatch.setattr(
"kubernetes_charm.KubernetesRouterCharm.wait_until_mysql_router_ready",
"charm.KubernetesRouterCharm.wait_until_mysql_router_ready",
lambda *args, **kwargs: None,
)
monkeypatch.setattr("workload.AuthenticatedWorkload._router_username", "")
Expand All @@ -45,7 +45,7 @@ def patch(monkeypatch):
@pytest.fixture(autouse=True)
def kubernetes_patch(monkeypatch):
monkeypatch.setattr(
"kubernetes_charm.KubernetesRouterCharm.model_service_domain", "my-model.svc.cluster.local"
"charm.KubernetesRouterCharm.model_service_domain", "my-model.svc.cluster.local"
)
monkeypatch.setattr(
"rock.Rock._run_command",
Expand All @@ -58,20 +58,20 @@ def kubernetes_patch(monkeypatch):
monkeypatch.setattr("rock._Path.rmtree", lambda *args, **kwargs: None)
monkeypatch.setattr("lightkube.Client", lambda *args, **kwargs: None)
monkeypatch.setattr(
"kubernetes_charm.KubernetesRouterCharm._reconcile_service", lambda *args, **kwargs: None
"charm.KubernetesRouterCharm._reconcile_service", lambda *args, **kwargs: None
)
monkeypatch.setattr(
"kubernetes_charm.KubernetesRouterCharm._get_hosts_ports",
"charm.KubernetesRouterCharm._get_hosts_ports",
lambda _, port_type: "mysql-router-k8s-service.my-model.svc.cluster.local:6446"
if port_type == "rw"
else "mysql-router-k8s-service.my-model.svc.cluster.local:6447",
)
monkeypatch.setattr(
"kubernetes_charm.KubernetesRouterCharm._check_service_connectivity",
"charm.KubernetesRouterCharm._check_service_connectivity",
lambda *args, **kwargs: True,
)
monkeypatch.setattr(
"kubernetes_charm.KubernetesRouterCharm.get_all_k8s_node_hostnames_and_ips",
"charm.KubernetesRouterCharm.get_all_k8s_node_hostnames_and_ips",
lambda *args, **kwargs: None,
)
monkeypatch.setattr("kubernetes_upgrade._Partition.get", lambda *args, **kwargs: 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,16 @@
import pytest
import scenario

import kubernetes_charm
import charm

from . import combinations


@pytest.fixture(params=["my-model.svc.cluster.local", "foo.svc.cluster.local"])
def model_service_domain(monkeypatch, request):
monkeypatch.setattr("charm.KubernetesRouterCharm.model_service_domain", request.param)
monkeypatch.setattr(
"kubernetes_charm.KubernetesRouterCharm.model_service_domain", request.param
)
monkeypatch.setattr(
"kubernetes_charm.KubernetesRouterCharm._get_hosts_ports",
"charm.KubernetesRouterCharm._get_hosts_ports",
lambda _, port_type: f"mysql-router-k8s-service.{request.param}:6446"
if port_type == "rw"
else f"mysql-router-k8s-service.{request.param}:6447",
Expand All @@ -35,7 +33,7 @@ def output_states(*, relations: list[scenario.Relation]) -> typing.Iterable[scen
The output state of each test should be identical for all events.
"""
context = scenario.Context(kubernetes_charm.KubernetesRouterCharm)
context = scenario.Context(charm.KubernetesRouterCharm)
container = scenario.Container("mysql-router", can_connect=True)
input_state = scenario.State(
relations=[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@
import pytest
import scenario

import kubernetes_charm
import charm

from . import combinations


def output_state(
*, relations: list[scenario.Relation], secrets: list[scenario.Secret], event: scenario.Event
) -> scenario.State:
context = scenario.Context(kubernetes_charm.KubernetesRouterCharm)
context = scenario.Context(charm.KubernetesRouterCharm)
container = scenario.Container("mysql-router", can_connect=True)
input_state = scenario.State(
relations=[
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/scenario_/test_start.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import pytest
import scenario

import kubernetes_charm
import charm


@pytest.mark.parametrize(
Expand All @@ -14,7 +14,7 @@
)
@pytest.mark.parametrize("leader", [False, True])
def test_start_sets_status_if_no_relations(leader, can_connect, unit_status):
context = scenario.Context(kubernetes_charm.KubernetesRouterCharm)
context = scenario.Context(charm.KubernetesRouterCharm)
input_state = scenario.State(
containers=[scenario.Container("mysql-router", can_connect=can_connect)],
leader=leader,
Expand Down

0 comments on commit cd1ea4a

Please sign in to comment.