From 1a31af50f51fa7efa75914c658c498352bb9acc0 Mon Sep 17 00:00:00 2001 From: Jonathan Snell Date: Wed, 8 Jan 2025 16:59:53 +0000 Subject: [PATCH] Fix deployment with ipv6 management network --- sunbeam-python/sunbeam/provider/local/deployment.py | 3 +++ sunbeam-python/tests/unit/sunbeam/test_clusterd.py | 10 ++++++++++ 2 files changed, 13 insertions(+) diff --git a/sunbeam-python/sunbeam/provider/local/deployment.py b/sunbeam-python/sunbeam/provider/local/deployment.py index 8c4aea5d..340bdd41 100644 --- a/sunbeam-python/sunbeam/provider/local/deployment.py +++ b/sunbeam-python/sunbeam/provider/local/deployment.py @@ -13,6 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +import ipaddress import logging import petname # type: ignore [import-untyped] @@ -154,6 +155,8 @@ def get_management_cidr(self) -> str: def get_clusterd_http_address(self) -> str: """Return the address of the clusterd server.""" local_ip = utils.get_local_ip_by_cidr(self.get_management_cidr()) + if ipaddress.ip_address(local_ip).version == 6: + local_ip = f"[{local_ip}]" address = f"https://{local_ip}:{CLUSTERD_PORT}" return address diff --git a/sunbeam-python/tests/unit/sunbeam/test_clusterd.py b/sunbeam-python/tests/unit/sunbeam/test_clusterd.py index d5ffc07c..00ccd2d2 100644 --- a/sunbeam-python/tests/unit/sunbeam/test_clusterd.py +++ b/sunbeam-python/tests/unit/sunbeam/test_clusterd.py @@ -69,6 +69,16 @@ def test_init_step(self, cclient, mocker): assert result.result_type == ResultType.COMPLETED init_step.client.cluster.bootstrap.assert_called_once() + def test_init_step_ipv6(self, cclient, mocker): + role = "control" + init_step = ClusterInitStep(cclient, [role], 0, "fd00::/108") + init_step.client = MagicMock() + init_step.fqdn = "node1" + mocker.patch("sunbeam.utils.get_local_ip_by_cidr", return_value="fd00::2") + result = init_step.run() + assert result.result_type == ResultType.COMPLETED + init_step.client.cluster.bootstrap.assert_called_once() + def test_add_node_step(self, cclient): add_node_step = ClusterAddNodeStep(cclient, name="node-1") add_node_step.client = MagicMock()