diff options
author | Dmitry Tantsur <divius.inside@gmail.com> | 2017-04-28 14:04:33 +0200 |
---|---|---|
committer | Dmitry Tantsur <divius.inside@gmail.com> | 2017-04-28 14:04:33 +0200 |
commit | 40a50e1ee9c045ec73eadca78337b3e9e404ac48 (patch) | |
tree | 4a3ae3a69641ace5d18c719761b5eeca0521c024 /ironic | |
parent | 8fa488ccfca200e5719de44c72730ac9efb5889c (diff) | |
download | ironic-40a50e1ee9c045ec73eadca78337b3e9e404ac48.tar.gz |
Bring the redfish driver address parameter closer to one of other drivers
All of the drivers assume driver_address is a host name or IP, but for redfish
it's scheme://authority. This change allows to provide only host name here too.
Change-Id: Id392b79375b37b8ca8be63bec4818b8d9a3982d4
Diffstat (limited to 'ironic')
-rw-r--r-- | ironic/drivers/modules/redfish/utils.py | 20 | ||||
-rw-r--r-- | ironic/tests/unit/db/utils.py | 2 | ||||
-rw-r--r-- | ironic/tests/unit/drivers/modules/redfish/test_utils.py | 22 |
3 files changed, 33 insertions, 11 deletions
diff --git a/ironic/drivers/modules/redfish/utils.py b/ironic/drivers/modules/redfish/utils.py index c70fbfeb8..276da6e43 100644 --- a/ironic/drivers/modules/redfish/utils.py +++ b/ironic/drivers/modules/redfish/utils.py @@ -32,9 +32,9 @@ LOG = log.getLogger(__name__) REQUIRED_PROPERTIES = { 'redfish_address': _('The URL address to the Redfish controller. It ' - 'should include scheme and authority portion of ' - 'the URL. For example: https://mgmt.vendor.com. ' - 'Required'), + 'must include the authority portion of the URL. ' + 'If the scheme is missing, https is assumed. ' + 'For example: https://mgmt.vendor.com. Required'), 'redfish_system_id': _('The canonical path to the ComputerSystem ' 'resource that the driver will interact with. ' 'It should include the root service, version and ' @@ -85,8 +85,18 @@ def parse_driver_info(node): # Validate the Redfish address address = driver_info['redfish_address'] - if not rfc3986.is_valid_uri(address, require_scheme=True, - require_authority=True): + try: + parsed = rfc3986.uri_reference(address) + except TypeError: + raise exception.InvalidParameterValue( + _('Invalid Redfish address %(address)s set in ' + 'driver_info/redfish_address on node %(node)s') % + {'address': address, 'node': node.uuid}) + + if not parsed.scheme or not parsed.authority: + address = 'https://%s' % address + parsed = rfc3986.uri_reference(address) + if not parsed.is_valid(require_scheme=True, require_authority=True): raise exception.InvalidParameterValue( _('Invalid Redfish address %(address)s set in ' 'driver_info/redfish_address on node %(node)s') % diff --git a/ironic/tests/unit/db/utils.py b/ironic/tests/unit/db/utils.py index 581e3a530..0d00f3d96 100644 --- a/ironic/tests/unit/db/utils.py +++ b/ironic/tests/unit/db/utils.py @@ -419,7 +419,7 @@ def get_test_oneview_driver_info(): def get_test_redfish_info(): return { - "redfish_address": "http://example.com", + "redfish_address": "https://example.com", "redfish_system_id": "/redfish/v1/Systems/FAKESYSTEM", "redfish_username": "username", "redfish_password": "password" diff --git a/ironic/tests/unit/drivers/modules/redfish/test_utils.py b/ironic/tests/unit/drivers/modules/redfish/test_utils.py index 24bc44050..d9b6fcc2c 100644 --- a/ironic/tests/unit/drivers/modules/redfish/test_utils.py +++ b/ironic/tests/unit/drivers/modules/redfish/test_utils.py @@ -50,7 +50,7 @@ class RedfishUtilsTestCase(db_base.DbTestCase): self.node = obj_utils.create_test_node( self.context, driver='redfish', driver_info=INFO_DICT) self.parsed_driver_info = { - 'address': 'http://example.com', + 'address': 'https://example.com', 'system_id': '/redfish/v1/Systems/FAKESYSTEM', 'username': 'username', 'password': 'password', @@ -62,6 +62,17 @@ 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(self): + self.node.driver_info['redfish_address'] = 'example.com' + response = redfish_utils.parse_driver_info(self.node) + self.assertEqual(self.parsed_driver_info, response) + + def test_parse_driver_info_default_scheme_with_port(self): + self.node.driver_info['redfish_address'] = 'example.com:42' + self.parsed_driver_info['address'] = 'https://example.com:42' + response = redfish_utils.parse_driver_info(self.node) + self.assertEqual(self.parsed_driver_info, response) + def test_parse_driver_info_missing_info(self): for prop in redfish_utils.REQUIRED_PROPERTIES: self.node.driver_info = INFO_DICT.copy() @@ -70,10 +81,11 @@ class RedfishUtilsTestCase(db_base.DbTestCase): redfish_utils.parse_driver_info, self.node) def test_parse_driver_info_invalid_address(self): - self.node.driver_info['redfish_address'] = 'this-is-a-bad-address' - self.assertRaisesRegex(exception.InvalidParameterValue, - 'Invalid Redfish address', - redfish_utils.parse_driver_info, self.node) + for value in ['/banana!', 42]: + self.node.driver_info['redfish_address'] = value + self.assertRaisesRegex(exception.InvalidParameterValue, + 'Invalid Redfish address', + redfish_utils.parse_driver_info, self.node) @mock.patch.object(os.path, 'exists', autospec=True) def test_parse_driver_info_path_verify_ca(self, mock_path_exists): |