Merge "redfish_address - wrap_ipv6 address" into stable/xena

This commit is contained in:
Zuul 2023-10-12 11:52:38 +00:00 committed by Gerrit Code Review
commit 519c1d49eb
4 changed files with 22 additions and 3 deletions

View File

@ -572,8 +572,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

@ -27,6 +27,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')
@ -96,7 +97,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()