From c6185882c7fc2d2579dfea69da6972d9eea0ac67 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Juli=C3=A1n=20Espina?= Date: Tue, 28 Jan 2025 15:15:45 -0600 Subject: [PATCH] fix: split mgs_nids when setting the info --- .../tests/unit/test_charm.py | 27 ++++++++++++++++--- charms/lustre-server-proxy/src/charm.py | 2 +- .../tests/unit/test_charm.py | 23 +++++++++++++--- .../nfs-server-proxy/tests/unit/test_charm.py | 25 ++++++++++++++--- 4 files changed, 64 insertions(+), 13 deletions(-) diff --git a/charms/cephfs-server-proxy/tests/unit/test_charm.py b/charms/cephfs-server-proxy/tests/unit/test_charm.py index 709ef6d..e601c0c 100644 --- a/charms/cephfs-server-proxy/tests/unit/test_charm.py +++ b/charms/cephfs-server-proxy/tests/unit/test_charm.py @@ -1,11 +1,13 @@ #!/usr/bin/env python3 -# Copyright 2024 Canonical Ltd. +# Copyright 2024-2025 Canonical Ltd. # See LICENSE file for licensing details. """Test base charm events such as Install, ConfigChanged, etc.""" from charm import CephFSServerProxyCharm from ops import testing +from charms.filesystem_client.v0.filesystem_info import CephfsInfo + def test_config_missing_all(): """Test config-changed handler when there is no configured hostname.""" @@ -63,14 +65,31 @@ def test_config_invalid_auth_info(): def test_config_full(): """Test config-changed handler with full config parameters.""" - context = testing.Context(CephFSServerProxyCharm) + rel = testing.PeerRelation( + endpoint="server-peers", + ) state = testing.State( config={ "fsid": "354ca7c4-f10d-11ee-93f8-1f85f87b7845", "sharepoint": "ceph-fs:/", "monitor-hosts": "10.5.0.80:6789 10.5.2.23:6789 10.5.2.17:6789", "auth-info": "ceph-client:AQAPdQldX264KBAAOyaxen/y0XBl1qxlGPTabw==", - } + }, + relations={rel}, + leader=True, ) - out = context.run(context.on.config_changed(), state) + context = testing.Context(CephFSServerProxyCharm) + + with context(context.on.config_changed(), state) as manager: + out = manager.run() + info = CephfsInfo.from_uri( + out.get_relation(rel.id).local_app_data["endpoint"], manager.charm.model + ) + assert out.unit_status == testing.ActiveStatus() + assert info.fsid == "354ca7c4-f10d-11ee-93f8-1f85f87b7845" + assert info.name == "ceph-fs" + assert info.path == "/" + assert info.monitor_hosts == ["10.5.0.80:6789", "10.5.2.23:6789", "10.5.2.17:6789"] + assert info.user == "ceph-client" + assert info.key == "AQAPdQldX264KBAAOyaxen/y0XBl1qxlGPTabw==" diff --git a/charms/lustre-server-proxy/src/charm.py b/charms/lustre-server-proxy/src/charm.py index 6905568..e6ec118 100755 --- a/charms/lustre-server-proxy/src/charm.py +++ b/charms/lustre-server-proxy/src/charm.py @@ -32,7 +32,7 @@ def _on_config_changed(self, _) -> None: self.unit.status = ops.BlockedStatus("No configured fs-name") return - self._filesystem.set_info(LustreInfo(mgs_ids=mgs_nids, fs_name=fs_name)) + self._filesystem.set_info(LustreInfo(mgs_ids=mgs_nids.split(), fs_name=fs_name)) self.unit.status = ops.ActiveStatus() diff --git a/charms/lustre-server-proxy/tests/unit/test_charm.py b/charms/lustre-server-proxy/tests/unit/test_charm.py index 2a1157d..acad662 100644 --- a/charms/lustre-server-proxy/tests/unit/test_charm.py +++ b/charms/lustre-server-proxy/tests/unit/test_charm.py @@ -1,12 +1,13 @@ #!/usr/bin/env python3 # Copyright 2025 Canonical Ltd. # See LICENSE file for licensing details. - """Test base charm events such as Install, ConfigChanged, etc.""" from charm import LustreServerProxyCharm from ops import testing +from charms.filesystem_client.v0.filesystem_info import LustreInfo + def test_config_none(): """Test config-changed handler when there are no configs.""" @@ -34,9 +35,23 @@ def test_config_no_mgs_ids(): def test_config_full(): """Test config-changed handler with full config parameters.""" - context = testing.Context(LustreServerProxyCharm) + rel = testing.PeerRelation( + endpoint="server-peers", + ) state = testing.State( - config={"mgs-nids": "demo-mgs1@tcp1 demo-mgs2@tcp1", "fs-name": "lustre"} + config={"mgs-nids": "demo-mgs1@tcp1 demo-mgs2@tcp1", "fs-name": "lustre"}, + relations={rel}, + leader=True, ) - out = context.run(context.on.config_changed(), state) + context = testing.Context(LustreServerProxyCharm) + + with context(context.on.config_changed(), state) as manager: + out = manager.run() + info = LustreInfo.from_uri( + out.get_relation(rel.id).local_app_data["endpoint"], manager.charm.model + ) + assert out.unit_status == testing.ActiveStatus() + + assert info.fs_name == "lustre" + assert info.mgs_ids == ["demo-mgs1@tcp1", "demo-mgs2@tcp1"] diff --git a/charms/nfs-server-proxy/tests/unit/test_charm.py b/charms/nfs-server-proxy/tests/unit/test_charm.py index 4b64452..ca064a9 100644 --- a/charms/nfs-server-proxy/tests/unit/test_charm.py +++ b/charms/nfs-server-proxy/tests/unit/test_charm.py @@ -1,12 +1,13 @@ #!/usr/bin/env python3 -# Copyright 2023 Canonical Ltd. +# Copyright 2023-2025 Canonical Ltd. # See LICENSE file for licensing details. - """Test base charm events such as Install, ConfigChanged, etc.""" from charm import NFSServerProxyCharm from ops import testing +from charms.filesystem_client.v0.filesystem_info import NfsInfo + def test_config_no_hostname(): """Test config-changed handler when there is no configured hostname.""" @@ -33,7 +34,23 @@ def test_config_no_port(): def test_config_full(): """Test config-changed handler with full config parameters.""" + rel = testing.PeerRelation( + endpoint="server-peers", + ) + state = testing.State( + config={"hostname": "127.0.0.1", "path": "/srv", "port": 1234}, + relations={rel}, + leader=True, + ) context = testing.Context(NFSServerProxyCharm) - state = testing.State(config={"hostname": "127.0.0.1", "path": "/srv", "port": 1234}) - out = context.run(context.on.config_changed(), state) + + with context(context.on.config_changed(), state) as manager: + out = manager.run() + info = NfsInfo.from_uri( + out.get_relation(rel.id).local_app_data["endpoint"], manager.charm.model + ) + assert out.unit_status == testing.ActiveStatus() + assert info.hostname == "127.0.0.1" + assert info.port == 1234 + assert info.path == "/srv"