diff --git a/ironic/drivers/modules/inspect_utils.py b/ironic/drivers/modules/inspect_utils.py index 2a66edce9e..14caa05491 100644 --- a/ironic/drivers/modules/inspect_utils.py +++ b/ironic/drivers/modules/inspect_utils.py @@ -342,6 +342,9 @@ def _get_bmc_addresses(node): if '//' in address: address = urllib.parse.urlparse(address).hostname + # Strip brackets in case used on IPv6 address. + address = address.strip('[').strip(']') + try: addrinfo = socket.getaddrinfo(address, None, proto=socket.SOL_TCP) except socket.gaierror as exc: diff --git a/ironic/tests/unit/drivers/modules/test_inspect_utils.py b/ironic/tests/unit/drivers/modules/test_inspect_utils.py index f6f5ab0190..a7b2ac2fde 100644 --- a/ironic/tests/unit/drivers/modules/test_inspect_utils.py +++ b/ironic/tests/unit/drivers/modules/test_inspect_utils.py @@ -442,6 +442,12 @@ class GetBMCAddressesTestCase(db_base.DbTestCase): driver_info={'redfish_address': 'https://192.0.2.1/redfish'}) self.assertEqual({'192.0.2.1'}, utils._get_bmc_addresses(node)) + def test_normal_ipv6_as_url(self): + node = obj_utils.create_test_node( + self.context, + driver_info={'redfish_address': 'https://[2001:db8::42]/redfish'}) + self.assertEqual({'2001:db8::42'}, utils._get_bmc_addresses(node)) + @mock.patch.object(socket, 'getaddrinfo', autospec=True) def test_resolved_host(self, mock_getaddrinfo): mock_getaddrinfo.return_value = [ @@ -474,6 +480,12 @@ class GetBMCAddressesTestCase(db_base.DbTestCase): mock_getaddrinfo.assert_called_once_with( 'example.com', None, proto=socket.SOL_TCP) + def test_redfish_bmc_address_ipv6_brackets_no_scheme(self): + node = obj_utils.create_test_node( + self.context, + driver_info={'redfish_address': '[2001:db8::42]'}) + self.assertEqual({'2001:db8::42'}, utils._get_bmc_addresses(node)) + class LookupCacheTestCase(db_base.DbTestCase): diff --git a/releasenotes/notes/bug-2036455-edd0e97335579684.yaml b/releasenotes/notes/bug-2036455-edd0e97335579684.yaml new file mode 100644 index 0000000000..72a000b07f --- /dev/null +++ b/releasenotes/notes/bug-2036455-edd0e97335579684.yaml @@ -0,0 +1,6 @@ +--- +fixes: + - | + Fixes an issue where inspection would fail if an IPv6 address wrapped in + brackets is used for the redfish BMC address. See bug: + `2036455 `_.