Merge "Optimize: HUAWEI iBMC driver utils"
This commit is contained in:
commit
2288990c7b
|
@ -78,11 +78,11 @@ def parse_driver_info(node):
|
||||||
# Validate the iBMC address
|
# Validate the iBMC address
|
||||||
address = driver_info['ibmc_address']
|
address = driver_info['ibmc_address']
|
||||||
parsed = netutils.urlsplit(address)
|
parsed = netutils.urlsplit(address)
|
||||||
if parsed.scheme == '':
|
if not parsed.scheme:
|
||||||
address = 'https://%s' % address
|
address = 'https://%s' % address
|
||||||
parsed = netutils.urlsplit(address)
|
parsed = netutils.urlsplit(address)
|
||||||
|
|
||||||
if parsed.netloc == '':
|
if not parsed.netloc:
|
||||||
raise exception.InvalidParameterValue(
|
raise exception.InvalidParameterValue(
|
||||||
_('Invalid iBMC address %(address)s set in '
|
_('Invalid iBMC address %(address)s set in '
|
||||||
'driver_info/ibmc_address on node %(node)s') %
|
'driver_info/ibmc_address on node %(node)s') %
|
||||||
|
@ -91,9 +91,7 @@ def parse_driver_info(node):
|
||||||
# Check if verify_ca is a Boolean or a file/directory in the file-system
|
# Check if verify_ca is a Boolean or a file/directory in the file-system
|
||||||
verify_ca = driver_info.get('ibmc_verify_ca', True)
|
verify_ca = driver_info.get('ibmc_verify_ca', True)
|
||||||
if isinstance(verify_ca, six.string_types):
|
if isinstance(verify_ca, six.string_types):
|
||||||
if os.path.isdir(verify_ca) or os.path.isfile(verify_ca):
|
if not os.path.exists(verify_ca):
|
||||||
pass
|
|
||||||
else:
|
|
||||||
try:
|
try:
|
||||||
verify_ca = strutils.bool_from_string(verify_ca, strict=True)
|
verify_ca = strutils.bool_from_string(verify_ca, strict=True)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
|
@ -103,10 +101,7 @@ def parse_driver_info(node):
|
||||||
'The value should be a Boolean or the path '
|
'The value should be a Boolean or the path '
|
||||||
'to a file/directory, not "%(value)s"'
|
'to a file/directory, not "%(value)s"'
|
||||||
) % {'value': verify_ca, 'node': node.uuid})
|
) % {'value': verify_ca, 'node': node.uuid})
|
||||||
elif isinstance(verify_ca, bool):
|
elif not isinstance(verify_ca, bool):
|
||||||
# If it's a boolean it's grand, we don't need to do anything
|
|
||||||
pass
|
|
||||||
else:
|
|
||||||
raise exception.InvalidParameterValue(
|
raise exception.InvalidParameterValue(
|
||||||
_('Invalid value type set in driver_info/ibmc_verify_ca '
|
_('Invalid value type set in driver_info/ibmc_verify_ca '
|
||||||
'on node %(node)s. The value should be a Boolean or the path '
|
'on node %(node)s. The value should be a Boolean or the path '
|
||||||
|
|
|
@ -70,7 +70,7 @@ class IBMCUtilsTestCase(base.IBMCTestCase):
|
||||||
'Invalid iBMC address',
|
'Invalid iBMC address',
|
||||||
utils.parse_driver_info, self.node)
|
utils.parse_driver_info, self.node)
|
||||||
|
|
||||||
@mock.patch.object(os.path, 'isdir', autospec=True)
|
@mock.patch.object(os.path, 'exists', autospec=True)
|
||||||
def test_parse_driver_info_path_verify_ca(self,
|
def test_parse_driver_info_path_verify_ca(self,
|
||||||
mock_isdir):
|
mock_isdir):
|
||||||
mock_isdir.return_value = True
|
mock_isdir.return_value = True
|
||||||
|
@ -82,7 +82,7 @@ class IBMCUtilsTestCase(base.IBMCTestCase):
|
||||||
self.assertEqual(self.parsed_driver_info, response)
|
self.assertEqual(self.parsed_driver_info, response)
|
||||||
mock_isdir.assert_called_once_with(fake_path)
|
mock_isdir.assert_called_once_with(fake_path)
|
||||||
|
|
||||||
@mock.patch.object(os.path, 'isfile', autospec=True)
|
@mock.patch.object(os.path, 'exists', autospec=True)
|
||||||
def test_parse_driver_info_valid_capath(self, mock_isfile):
|
def test_parse_driver_info_valid_capath(self, mock_isfile):
|
||||||
mock_isfile.return_value = True
|
mock_isfile.return_value = True
|
||||||
fake_path = '/path/to/a/valid/CA.pem'
|
fake_path = '/path/to/a/valid/CA.pem'
|
||||||
|
|
Loading…
Reference in New Issue