Improve driver_info/redfish_system_id value validation

This patch making sure that the value passed to
driver_info/redfish_system_id is a string. The value of that property
should be a canonical path to the System resource (in RedFish) that
Ironic will manage.

Change-Id: Ifb9e6e0cdb2b32370068fcee78edd136ff5ed7ce
Closes-Bug: #1687658
This commit is contained in:
Lucas Alvares Gomes
2017-05-05 11:01:27 +01:00
parent 7aeb993760
commit daf3083228
2 changed files with 18 additions and 1 deletions
+11 -1
View File
@@ -21,6 +21,7 @@ from oslo_utils import importutils
import retrying
import rfc3986
import six
from six.moves import urllib
from ironic.common import exception
from ironic.common.i18n import _
@@ -102,7 +103,16 @@ def parse_driver_info(node):
'driver_info/redfish_address on node %(node)s') %
{'address': address, 'node': node.uuid})
system_id = driver_info['redfish_system_id']
try:
system_id = urllib.parse.quote(driver_info['redfish_system_id'])
except (TypeError, AttributeError):
raise exception.InvalidParameterValue(
_('Invalid value "%(value)s" set in '
'driver_info/redfish_system_id on node %(node)s. '
'The value should be a path (string) to the resource '
'that the driver will interact with. For example: '
'/redfish/v1/Systems/1') %
{'value': driver_info['redfish_system_id'], 'node': node.uuid})
# Check if verify_ca is a Boolean or a file/directory in the file-system
verify_ca = driver_info.get('redfish_verify_ca', True)
@@ -115,6 +115,13 @@ class RedfishUtilsTestCase(db_base.DbTestCase):
'Invalid value type',
redfish_utils.parse_driver_info, self.node)
def test_parse_driver_info_invalid_system_id(self):
# Integers are not supported
self.node.driver_info['redfish_system_id'] = 123
self.assertRaisesRegex(exception.InvalidParameterValue,
'The value should be a path',
redfish_utils.parse_driver_info, self.node)
@mock.patch('ironic.drivers.modules.redfish.utils.sushy')
def test_get_system(self, mock_sushy):
fake_conn = mock_sushy.Sushy.return_value