Remove inventory time workaround for WS-man BIOS

The workaround was necessary for older versions to be backportable.

Change-Id: Ifd0d66ad4ed191fafd58090f92e4ee44814f4b86
This commit is contained in:
Aija Jauntēva 2021-05-19 08:53:04 -04:00
parent 9a8b501e5c
commit 28a9478038
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__) 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): class DracRedfishBIOS(redfish_bios.RedfishBIOS):
"""iDRAC Redfish interface for BIOS settings-related actions. """iDRAC Redfish interface for BIOS settings-related actions.
@ -254,8 +222,8 @@ class DracWSManBIOS(base.BIOSInterface):
# reset start time # reset start time
time_difference = 0 time_difference = 0
# Get the last system inventory time after reboot # Get the last system inventory time after reboot
factory_reset_time_endof_reboot = _get_last_system_inventory_time( factory_reset_time_endof_reboot = (client.get_system()
client, task) .last_system_inventory_time)
LOG.debug("Factory resetting node %(node_uuid)s " LOG.debug("Factory resetting node %(node_uuid)s "
"last inventory reboot time after factory reset " "last inventory reboot time after factory reset "
@ -443,7 +411,7 @@ class DracWSManBIOS(base.BIOSInterface):
reboot_needed = True reboot_needed = True
try: try:
factory_reset_time_before_reboot =\ 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 " LOG.debug("Factory resetting node %(node_uuid)s "
"last inventory reboot time before factory reset " "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 from unittest import mock
import dracclient.client
from dracclient import exceptions as drac_exceptions from dracclient import exceptions as drac_exceptions
import dracclient.utils
from oslo_utils import timeutils from oslo_utils import timeutils
from ironic.common import exception from ironic.common import exception
@ -124,8 +122,6 @@ class DracWSManBIOSConfigurationTestCase(test_utils.BaseDracTest):
self.assertRaises(exception.DracOperationError, self.assertRaises(exception.DracOperationError,
task.driver.bios.cache_bios_settings, task) 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', @mock.patch.object(deploy_utils, 'get_async_step_return_state',
autospec=True) autospec=True)
@mock.patch.object(deploy_utils, 'set_async_step_flags', 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, @mock.patch.object(drac_job, 'validate_job_queue', spec_set=True,
autospec=True) autospec=True)
def _test_step(self, mock_validate_job_queue, mock_cache_bios_settings, def _test_step(self, mock_validate_job_queue, mock_cache_bios_settings,
mock_set_async_step_flags, mock_get_async_step_return_state, mock_set_async_step_flags,
mock_findxml, mock_wsmanclient, attribute_error=False): mock_get_async_step_return_state):
if self.node.clean_step: if self.node.clean_step:
step_data = self.node.clean_step step_data = self.node.clean_step
expected_state = states.CLEANWAIT expected_state = states.CLEANWAIT
@ -156,16 +152,9 @@ class DracWSManBIOSConfigurationTestCase(test_utils.BaseDracTest):
mock_system = None mock_system = None
factory_reset_time_before_reboot = None factory_reset_time_before_reboot = None
if attribute_error: mock_system = mock.Mock()
mock_system = mock.Mock(spec=[]) factory_reset_time_before_reboot = "20200910233024"
mock_xml = mock.Mock() mock_system.last_system_inventory_time = "20200910233024"
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"
self.mock_client.get_system.return_value = mock_system 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.\ self.mock_client.commit_pending_lifecycle_changes.\
assert_called_once_with(reboot=True) assert_called_once_with(reboot=True)
self.mock_client.get_system.assert_called_once() self.mock_client.get_system.assert_called_once()
if attribute_error: self.assertEqual(factory_reset_time_before_reboot,
mock_findxml.assert_called_once() info['factory_reset_time_before_reboot'])
else:
self.assertEqual(factory_reset_time_before_reboot,
info['factory_reset_time_before_reboot'])
mock_findxml.assert_not_called()
if step == 'apply_configuration': if step == 'apply_configuration':
ret_state = task.driver.bios.apply_configuration(task, data) ret_state = task.driver.bios.apply_configuration(task, data)
@ -206,24 +192,12 @@ class DracWSManBIOSConfigurationTestCase(test_utils.BaseDracTest):
self.node.save() self.node.save()
self._test_step() 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): def test_factory_reset_deploy(self):
self.node.deploy_step = {'priority': 100, 'interface': 'bios', self.node.deploy_step = {'priority': 100, 'interface': 'bios',
'step': 'factory_reset', 'argsinfo': {}} 'step': 'factory_reset', 'argsinfo': {}}
self.node.save() self.node.save()
self._test_step() 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): def test_apply_configuration_clean(self):
settings = [{'name': 'ProcVirtualization', 'value': 'Enabled'}] settings = [{'name': 'ProcVirtualization', 'value': 'Enabled'}]
self.node.clean_step = {'priority': 100, 'interface': 'bios', self.node.clean_step = {'priority': 100, 'interface': 'bios',

View File

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

View File

@ -99,20 +99,11 @@ if not dracclient:
spec_set=mock_specs.DRACCLIENT_CONSTANTS_RAID_STATUS_MOD_SPEC, spec_set=mock_specs.DRACCLIENT_CONSTANTS_RAID_STATUS_MOD_SPEC,
jbod=mock.sentinel.jbod, jbod=mock.sentinel.jbod,
raid=mock.sentinel.raid) 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'] = dracclient
sys.modules['dracclient.client'] = dracclient.client sys.modules['dracclient.client'] = dracclient.client
sys.modules['dracclient.constants'] = dracclient.constants sys.modules['dracclient.constants'] = dracclient.constants
sys.modules['dracclient.exceptions'] = dracclient.exceptions 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', dracclient.exceptions.BaseClientException = type('BaseClientException',
(Exception,), {}) (Exception,), {})