redfish_address - wrap_ipv6 address

When parsing redfish driver info wrap IPv6 address in brackets
before appending default scheme/authority.

Updated common.utils.wrap_ipv6() to ignore ValueError, e.g
simply return the string if ip is not an ipv6 address string.

Related: RHBZ#2239356
Closes-Bug: #2036454
Change-Id: Icefd96d6873474b4cfb7fbf3d8337cd42fd63ca6
This commit is contained in:
Harald Jensås 2023-09-18 20:56:29 +02:00
parent 88fd22de79
commit 72037b596a
No known key found for this signature in database
GPG Key ID: 693852E00DCEA408
4 changed files with 22 additions and 3 deletions

View File

@ -578,8 +578,12 @@ def pop_node_nested_field(node, collection, field, default=None):
def wrap_ipv6(ip):
"""Wrap the address in square brackets if it's an IPv6 address."""
if ipaddress.ip_address(ip).version == 6:
return "[%s]" % ip
try:
if ipaddress.ip_address(ip).version == 6:
return "[%s]" % ip
except ValueError:
pass
return ip

View File

@ -28,6 +28,7 @@ import tenacity
from ironic.common import exception
from ironic.common.i18n import _
from ironic.common import utils
from ironic.conf import CONF
sushy = importutils.try_import('sushy')
@ -97,7 +98,7 @@ def parse_driver_info(node):
'info': missing_info})
# Validate the Redfish address
address = driver_info['redfish_address']
address = utils.wrap_ipv6(driver_info['redfish_address'])
try:
parsed = rfc3986.uri_reference(address)
except TypeError:

View File

@ -321,6 +321,12 @@ class GenericUtilsTestCase(base.TestCase):
self.assertFalse(utils.is_fips_enabled())
m.assert_called_once_with('/proc/sys/crypto/fips_enabled', 'r')
def test_wrap_ipv6(self):
self.assertEqual('[2001:DB8::1]', utils.wrap_ipv6('2001:DB8::1'))
self.assertEqual('example.com', utils.wrap_ipv6('example.com'))
self.assertEqual('192.168.24.1', utils.wrap_ipv6('192.168.24.1'))
self.assertEqual('[2001:DB8::1]', utils.wrap_ipv6('[2001:DB8::1]'))
class TempFilesTestCase(base.TestCase):

View File

@ -168,6 +168,14 @@ class RedfishUtilsTestCase(db_base.DbTestCase):
response = redfish_utils.parse_driver_info(self.node)
self.assertEqual(self.parsed_driver_info, response)
def test_parse_driver_info_default_scheme_ipv6_brackets_added(self):
test_redfish_address = '2001:DB8::1'
self.node.driver_info['redfish_address'] = test_redfish_address
response = redfish_utils.parse_driver_info(self.node)
self.parsed_driver_info['address'] = ("https://[%s]"
% test_redfish_address)
self.assertEqual(self.parsed_driver_info, response)
def test_get_task_monitor(self):
redfish_utils._get_connection = mock.Mock()
fake_monitor = mock.Mock()