From 3f3fc7dca0493da31187bc7f0532fa4ed5c5e279 Mon Sep 17 00:00:00 2001 From: maelk Date: Wed, 12 Feb 2020 11:06:09 +0200 Subject: [PATCH] Redfish: Add root_prefix to Sushy Adds the root_prefix parameter to the sushy context, based on the user input for `redfish_address` parameter. This is needed if the Redfish API is not located in the default /redfish/v1/ endpoint. Change-Id: Ie886040fef9bc75197a99fe7cc7495c6147edb38 --- ironic/drivers/modules/redfish/utils.py | 34 +++++++++++++------ .../drivers/modules/redfish/test_utils.py | 7 ++++ ...fish-add-root-prefix-03b5f31ec6bbd146.yaml | 7 ++++ 3 files changed, 38 insertions(+), 10 deletions(-) create mode 100644 releasenotes/notes/redfish-add-root-prefix-03b5f31ec6bbd146.yaml diff --git a/ironic/drivers/modules/redfish/utils.py b/ironic/drivers/modules/redfish/utils.py index 758323f71e..9decac47cb 100644 --- a/ironic/drivers/modules/redfish/utils.py +++ b/ironic/drivers/modules/redfish/utils.py @@ -36,7 +36,9 @@ REQUIRED_PROPERTIES = { 'redfish_address': _('The URL address to the Redfish controller. It ' 'must include the authority portion of the URL. ' 'If the scheme is missing, https is assumed. ' - 'For example: https://mgmt.vendor.com. Required'), + 'For example: https://mgmt.vendor.com. ' + 'If a path is added, it will be used as the API ' + 'endpoint root_prefix. Required'), } OPTIONAL_PROPERTIES = { @@ -111,6 +113,11 @@ def parse_driver_info(node): _('Invalid Redfish address %(address)s set in ' 'driver_info/redfish_address on node %(node)s') % {'address': address, 'node': node.uuid}) + address = '{}://{}'.format(parsed.scheme, parsed.authority) + + # Obtain the Redfish root prefix from the address path + # If not specified, default to '/redfish/v1/' + root_prefix = parsed.path redfish_system_id = driver_info.get('redfish_system_id') if redfish_system_id is not None: @@ -158,13 +165,17 @@ def parse_driver_info(node): 'The value should be one of "basic", "session" or "auto".') % {'value': auth_type, 'node': node.uuid}) - return {'address': address, - 'system_id': redfish_system_id, - 'username': driver_info.get('redfish_username'), - 'password': driver_info.get('redfish_password'), - 'verify_ca': verify_ca, - 'auth_type': auth_type, - 'node_uuid': node.uuid} + sushy_params = {'address': address, + 'system_id': redfish_system_id, + 'username': driver_info.get('redfish_username'), + 'password': driver_info.get('redfish_password'), + 'verify_ca': verify_ca, + 'auth_type': auth_type, + 'node_uuid': node.uuid} + if root_prefix: + sushy_params['root_prefix'] = root_prefix + + return sushy_params class SessionCache(object): @@ -200,10 +211,13 @@ class SessionCache(object): password=self._driver_info['password'] ) + sushy_params = {'verify': self._driver_info['verify_ca'], + 'auth': authenticator} + if 'root_prefix' in self._driver_info: + sushy_params['root_prefix'] = self._driver_info['root_prefix'] conn = sushy.Sushy( self._driver_info['address'], - verify=self._driver_info['verify_ca'], - auth=authenticator + **sushy_params ) if CONF.redfish.connection_cache_size: diff --git a/ironic/tests/unit/drivers/modules/redfish/test_utils.py b/ironic/tests/unit/drivers/modules/redfish/test_utils.py index ae40d0e40a..7107a8ab23 100644 --- a/ironic/tests/unit/drivers/modules/redfish/test_utils.py +++ b/ironic/tests/unit/drivers/modules/redfish/test_utils.py @@ -160,6 +160,13 @@ class RedfishUtilsTestCase(db_base.DbTestCase): 'The value should be one of ', redfish_utils.parse_driver_info, self.node) + def test_parse_driver_info_with_root_prefix(self): + test_redfish_address = 'https://example.com/test/redfish/v0/' + self.node.driver_info['redfish_address'] = test_redfish_address + self.parsed_driver_info['root_prefix'] = '/test/redfish/v0/' + response = redfish_utils.parse_driver_info(self.node) + self.assertEqual(self.parsed_driver_info, response) + @mock.patch.object(sushy, 'Sushy', autospec=True) @mock.patch('ironic.drivers.modules.redfish.utils.' 'SessionCache._sessions', {}) diff --git a/releasenotes/notes/redfish-add-root-prefix-03b5f31ec6bbd146.yaml b/releasenotes/notes/redfish-add-root-prefix-03b5f31ec6bbd146.yaml new file mode 100644 index 0000000000..beae61f687 --- /dev/null +++ b/releasenotes/notes/redfish-add-root-prefix-03b5f31ec6bbd146.yaml @@ -0,0 +1,7 @@ +--- +features: + - | + Add `root_prefix` parameter to the sushy context based on the path of + `redfish_address`. Defaults to sushy root_prefix default (`/redfish/v1/`). + This is needed if the Redfish API is not located in the default + /redfish/v1/ endpoint.