Skip to content

Commit

Permalink
fix: split mgs_nids when setting the info
Browse files Browse the repository at this point in the history
  • Loading branch information
jedel1043 authored and NucciTheBoss committed Jan 29, 2025
1 parent 980c087 commit c618588
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 13 deletions.
27 changes: 23 additions & 4 deletions charms/cephfs-server-proxy/tests/unit/test_charm.py
Original file line number Diff line number Diff line change
@@ -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."""
Expand Down Expand Up @@ -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=="
2 changes: 1 addition & 1 deletion charms/lustre-server-proxy/src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
23 changes: 19 additions & 4 deletions charms/lustre-server-proxy/tests/unit/test_charm.py
Original file line number Diff line number Diff line change
@@ -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."""
Expand Down Expand Up @@ -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"]
25 changes: 21 additions & 4 deletions charms/nfs-server-proxy/tests/unit/test_charm.py
Original file line number Diff line number Diff line change
@@ -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."""
Expand All @@ -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"

0 comments on commit c618588

Please sign in to comment.