From adb04782a1c8947568dfb8c501bbe2fb92f1b67f Mon Sep 17 00:00:00 2001 From: Benjamin Schimke Date: Fri, 19 Apr 2024 10:45:02 +0200 Subject: [PATCH] fix tests --- .../k8s/lib/charms/k8s/v0/k8sd_api_manager.py | 4 +-- tests/integration/test_etcd.py | 26 ++++++++++++++++--- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/charms/worker/k8s/lib/charms/k8s/v0/k8sd_api_manager.py b/charms/worker/k8s/lib/charms/k8s/v0/k8sd_api_manager.py index 20e3a695..c5c2e731 100644 --- a/charms/worker/k8s/lib/charms/k8s/v0/k8sd_api_manager.py +++ b/charms/worker/k8s/lib/charms/k8s/v0/k8sd_api_manager.py @@ -290,7 +290,7 @@ class UserFacingClusterConfig(BaseModel): metrics_server: MetricsServerConfig = Field(None, alias="metrics-server") -class UserFacingDatastoreConfig(BaseModel): +class UserFacingDatastoreConfig(BaseModel, allow_population_by_field_name=True): """Aggregated configuration model for the user-facing datastore aspects of a cluster. Attributes: @@ -647,7 +647,7 @@ def update_cluster_config(self, config: UpdateClusterConfigRequest): config (UpdateClusterConfigRequest): The cluster configuration. """ endpoint = "/1.0/k8sd/cluster/config" - body = config.dict(exclude_none=True) + body = config.dict(exclude_none=True, by_alias=True) self._send_request(endpoint, "PUT", EmptyResponse, body) def get_cluster_status(self) -> GetClusterStatusResponse: diff --git a/tests/integration/test_etcd.py b/tests/integration/test_etcd.py index 6955eff1..c0870c9a 100644 --- a/tests/integration/test_etcd.py +++ b/tests/integration/test_etcd.py @@ -40,6 +40,26 @@ async def test_etcd_datastore(kubernetes_cluster: model.Model): status = json.loads(result.results["stdout"]) assert status["ready"], "Cluster isn't ready" assert status["datastore"]["type"] == "external", "Not bootstrapped against etcd" - assert status["datastore"]["servers"] == [ - f"https://{etcd.public_address}:{etcd_port}" - ] + assert status["datastore"]["servers"] == [f"https://{etcd.public_address}:{etcd_port}"] + + +@pytest.mark.abort_on_fail +async def test_update_etcd_cluster(kubernetes_cluster: model.Model): + """Test that adding etcd clusters are propagated to the k8s cluster.""" + k8s: unit.Unit = kubernetes_cluster.applications["k8s"].units[0] + etcd = kubernetes_cluster.applications["etcd"] + + await etcd.add_unit() + await etcd.add_unit() + + expected_servers = [] + for u in etcd.units: + etcd_port = u.safe_data["ports"][0]["number"] + expected_servers.append(f"https://{u.public_address}:{etcd_port}") + + event = await k8s.run("k8s status --output-format json") + result = await event.wait() + status = json.loads(result.results["stdout"]) + assert status["ready"], "Cluster isn't ready" + assert status["datastore"]["type"] == "external", "Not bootstrapped against etcd" + assert set(status["datastore"]["servers"]) == set(expected_servers)