Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bschimke95 committed Apr 19, 2024
1 parent fd12c7a commit adb0478
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
4 changes: 2 additions & 2 deletions charms/worker/k8s/lib/charms/k8s/v0/k8sd_api_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
26 changes: 23 additions & 3 deletions tests/integration/test_etcd.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit adb0478

Please sign in to comment.