inspect_utils, handle bracketed IPv6 redfish addr

If redfish_address is in brackets, unwrap it and check
that it is a valid IPv6 address. If that is the case use
the unwrapped address to avoid "Name or service not known".

Also add a unit test for normal_ipv6_as_url.

Closes-Bug: #2036455
Change-Id: I8df20e85e40d8321bd5f88c09fae33b6015bcf51
This commit is contained in:
Harald Jensås 2023-09-19 13:19:49 +02:00
parent 88fd22de79
commit 21e3e71ea3
No known key found for this signature in database
GPG Key ID: 693852E00DCEA408
3 changed files with 21 additions and 0 deletions

View File

@ -342,6 +342,9 @@ def _get_bmc_addresses(node):
if '//' in address: if '//' in address:
address = urllib.parse.urlparse(address).hostname address = urllib.parse.urlparse(address).hostname
# Strip brackets in case used on IPv6 address.
address = address.strip('[').strip(']')
try: try:
addrinfo = socket.getaddrinfo(address, None, proto=socket.SOL_TCP) addrinfo = socket.getaddrinfo(address, None, proto=socket.SOL_TCP)
except socket.gaierror as exc: except socket.gaierror as exc:

View File

@ -442,6 +442,12 @@ class GetBMCAddressesTestCase(db_base.DbTestCase):
driver_info={'redfish_address': 'https://192.0.2.1/redfish'}) driver_info={'redfish_address': 'https://192.0.2.1/redfish'})
self.assertEqual({'192.0.2.1'}, utils._get_bmc_addresses(node)) 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) @mock.patch.object(socket, 'getaddrinfo', autospec=True)
def test_resolved_host(self, mock_getaddrinfo): def test_resolved_host(self, mock_getaddrinfo):
mock_getaddrinfo.return_value = [ mock_getaddrinfo.return_value = [
@ -474,6 +480,12 @@ class GetBMCAddressesTestCase(db_base.DbTestCase):
mock_getaddrinfo.assert_called_once_with( mock_getaddrinfo.assert_called_once_with(
'example.com', None, proto=socket.SOL_TCP) '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): class LookupCacheTestCase(db_base.DbTestCase):

View File

@ -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 <https://bugs.launchpad.net/ironic/+bug/2036455>`_.