Merge "Remove inventory time workaround for WS-man BIOS"

This commit is contained in:
Zuul 2021-05-25 18:25:28 +00:00 committed by Gerrit Code Review
commit a1e96ca699
4 changed files with 11 additions and 89 deletions

View File

@ -43,38 +43,6 @@ LOG = logging.getLogger(__name__)
METRICS = metrics_utils.get_metrics_logger(__name__)
def _get_last_system_inventory_time(client, task):
"""Gets last system inventory time
Uses last_system_inventory_time, if that is not available, then fall
backs to raw requests. Warns user about option to update
python-dracclient.
:param client: python-dracclient instance
:param task: a TaskManager instance with the node to act on
:returns: Last system inventory time
"""
try:
return client.get_system().last_system_inventory_time
except AttributeError as ae:
LOG.warning("Failed to get the last system inventory time for node "
"%(node_uuid)s. Update the python-dracclient to the "
"latest version. Reason: %(error)s",
{"node_uuid": task.node.uuid, "error": ae})
driver_info = drac_common.parse_driver_info(task.node)
client = drac_client.WSManClient(
driver_info['drac_address'], driver_info['drac_username'],
driver_info['drac_password'], driver_info['drac_port'],
driver_info['drac_path'], driver_info['drac_protocol'])
doc = client.enumerate(
drac_uris.DCIM_SystemView, filter_query=(
'select LastSystemInventoryTime from DCIM_SystemView'))
return drac_utils.find_xml(
doc, 'LastSystemInventoryTime',
drac_uris.DCIM_SystemView).text.split('.')[0]
class DracRedfishBIOS(redfish_bios.RedfishBIOS):
"""iDRAC Redfish interface for BIOS settings-related actions.
@ -254,8 +222,8 @@ class DracWSManBIOS(base.BIOSInterface):
# reset start time
time_difference = 0
# Get the last system inventory time after reboot
factory_reset_time_endof_reboot = _get_last_system_inventory_time(
client, task)
factory_reset_time_endof_reboot = (client.get_system()
.last_system_inventory_time)
LOG.debug("Factory resetting node %(node_uuid)s "
"last inventory reboot time after factory reset "
@ -443,7 +411,7 @@ class DracWSManBIOS(base.BIOSInterface):
reboot_needed = True
try:
factory_reset_time_before_reboot =\
_get_last_system_inventory_time(client, task)
client.get_system().last_system_inventory_time
LOG.debug("Factory resetting node %(node_uuid)s "
"last inventory reboot time before factory reset "

View File

@ -21,9 +21,7 @@ Test class for DRAC BIOS configuration specific methods
from unittest import mock
import dracclient.client
from dracclient import exceptions as drac_exceptions
import dracclient.utils
from oslo_utils import timeutils
from ironic.common import exception
@ -124,8 +122,6 @@ class DracWSManBIOSConfigurationTestCase(test_utils.BaseDracTest):
self.assertRaises(exception.DracOperationError,
task.driver.bios.cache_bios_settings, task)
@mock.patch.object(dracclient.client, 'WSManClient', autospec=True)
@mock.patch.object(dracclient.utils, 'find_xml', autospec=True)
@mock.patch.object(deploy_utils, 'get_async_step_return_state',
autospec=True)
@mock.patch.object(deploy_utils, 'set_async_step_flags', autospec=True)
@ -134,8 +130,8 @@ class DracWSManBIOSConfigurationTestCase(test_utils.BaseDracTest):
@mock.patch.object(drac_job, 'validate_job_queue', spec_set=True,
autospec=True)
def _test_step(self, mock_validate_job_queue, mock_cache_bios_settings,
mock_set_async_step_flags, mock_get_async_step_return_state,
mock_findxml, mock_wsmanclient, attribute_error=False):
mock_set_async_step_flags,
mock_get_async_step_return_state):
if self.node.clean_step:
step_data = self.node.clean_step
expected_state = states.CLEANWAIT
@ -156,16 +152,9 @@ class DracWSManBIOSConfigurationTestCase(test_utils.BaseDracTest):
mock_system = None
factory_reset_time_before_reboot = None
if attribute_error:
mock_system = mock.Mock(spec=[])
mock_xml = mock.Mock()
mock_xml.text = '20200910233024.000000+000'
mock_findxml.return_value = mock_xml
else:
mock_system = mock.Mock()
factory_reset_time_before_reboot = "20200910233024"
mock_system.last_system_inventory_time =\
"20200910233024"
mock_system = mock.Mock()
factory_reset_time_before_reboot = "20200910233024"
mock_system.last_system_inventory_time = "20200910233024"
self.mock_client.get_system.return_value = mock_system
@ -177,12 +166,9 @@ class DracWSManBIOSConfigurationTestCase(test_utils.BaseDracTest):
self.mock_client.commit_pending_lifecycle_changes.\
assert_called_once_with(reboot=True)
self.mock_client.get_system.assert_called_once()
if attribute_error:
mock_findxml.assert_called_once()
else:
self.assertEqual(factory_reset_time_before_reboot,
info['factory_reset_time_before_reboot'])
mock_findxml.assert_not_called()
self.assertEqual(factory_reset_time_before_reboot,
info['factory_reset_time_before_reboot'])
if step == 'apply_configuration':
ret_state = task.driver.bios.apply_configuration(task, data)
@ -206,24 +192,12 @@ class DracWSManBIOSConfigurationTestCase(test_utils.BaseDracTest):
self.node.save()
self._test_step()
def test_factory_reset_clean_attribute_error(self):
self.node.clean_step = {'priority': 100, 'interface': 'bios',
'step': 'factory_reset', 'argsinfo': {}}
self.node.save()
self._test_step(attribute_error=True)
def test_factory_reset_deploy(self):
self.node.deploy_step = {'priority': 100, 'interface': 'bios',
'step': 'factory_reset', 'argsinfo': {}}
self.node.save()
self._test_step()
def test_factory_reset_deploy_attribute_error(self):
self.node.deploy_step = {'priority': 100, 'interface': 'bios',
'step': 'factory_reset', 'argsinfo': {}}
self.node.save()
self._test_step(attribute_error=True)
def test_apply_configuration_clean(self):
settings = [{'name': 'ProcVirtualization', 'value': 'Enabled'}]
self.node.clean_step = {'priority': 100, 'interface': 'bios',

View File

@ -21,13 +21,10 @@ DRACCLIENT_SPEC = (
'client',
'constants',
'exceptions',
'resources',
'utils'
)
DRACCLIENT_CLIENT_MOD_SPEC = (
'DRACClient',
'WSManClient'
)
DRACCLIENT_CONSTANTS_MOD_SPEC = (
@ -49,14 +46,6 @@ DRACCLIENT_CONSTANTS_RAID_STATUS_MOD_SPEC = (
'raid'
)
DRACCLIENT_RESOURCES_URIS_MOD_SPEC = (
'DCIM_SystemView',
)
DRACCLIENT_UTILS_MOD_SPEC = (
'find_xml',
)
# proliantutils
PROLIANTUTILS_SPEC = (
'exception',

View File

@ -99,20 +99,11 @@ if not dracclient:
spec_set=mock_specs.DRACCLIENT_CONSTANTS_RAID_STATUS_MOD_SPEC,
jbod=mock.sentinel.jbod,
raid=mock.sentinel.raid)
dracclient.resources.uris = mock.MagicMock(
spec_set=mock_specs.DRACCLIENT_RESOURCES_URIS_MOD_SPEC,
DCIM_SystemView=mock.sentinel.DCIM_SystemView
)
dracclient.utils = mock.MagicMock(
spec_set=mock_specs.DRACCLIENT_UTILS_MOD_SPEC
)
sys.modules['dracclient'] = dracclient
sys.modules['dracclient.client'] = dracclient.client
sys.modules['dracclient.constants'] = dracclient.constants
sys.modules['dracclient.exceptions'] = dracclient.exceptions
sys.modules['dracclient.resources.uris'] = dracclient.resources.uris
sys.modules['dracclient.utils'] = dracclient.utils
dracclient.exceptions.BaseClientException = type('BaseClientException',
(Exception,), {})