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
This commit is contained in:
parent
8fa488ccfc
commit
40a50e1ee9
doc/source/drivers
ironic
@ -46,8 +46,10 @@ set to ``redfish``.
|
||||
The following properties are specified in the node's ``driver_info``
|
||||
field:
|
||||
|
||||
- ``redfish_address``: The URL address to the Redfish controller. It should
|
||||
include scheme and authority portion of the URL.
|
||||
- ``redfish_address``: The URL address to the Redfish controller. It must
|
||||
include the authority portion of the URL, and can
|
||||
optionally include the scheme. If the scheme is
|
||||
missing, https is assumed.
|
||||
For example: https://mgmt.vendor.com. This is required.
|
||||
|
||||
- ``redfish_system_id``: The canonical path to the System resource that
|
||||
|
@ -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') %
|
||||
|
@ -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"
|
||||
|
@ -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):
|
||||
|
Loading…
x
Reference in New Issue
Block a user