From 74354b7a7b4bac545d9edea05dcf5c9befc68b2d Mon Sep 17 00:00:00 2001 From: Shivanand Tendulker Date: Wed, 21 Aug 2019 07:12:55 -0400 Subject: [PATCH] Follow-up for deploy steps for Redfish BIOS interface This is follow-up to commit 991f9ccec1679fee02a8db0ec96adaf050fa6af6 Change-Id: I67af43d3d1f2f2944de514087a69654b3671cd1c Story: 1722275 Task: 29904 --- ironic/drivers/modules/deploy_utils.py | 38 +++++++++++ ironic/drivers/modules/redfish/bios.py | 20 ++---- .../unit/drivers/modules/test_deploy_utils.py | 67 +++++++++++++++++++ 3 files changed, 111 insertions(+), 14 deletions(-) diff --git a/ironic/drivers/modules/deploy_utils.py b/ironic/drivers/modules/deploy_utils.py index c872ccf717..6ba3555052 100644 --- a/ironic/drivers/modules/deploy_utils.py +++ b/ironic/drivers/modules/deploy_utils.py @@ -1456,3 +1456,41 @@ get_boot_mode_for_deploy = boot_mode_utils.get_boot_mode_for_deploy parse_instance_info_capabilities = ( utils.parse_instance_info_capabilities ) + + +def get_async_step_return_state(node): + """Returns state based on operation (cleaning/deployment) being invoked + + :param node: an ironic node object. + :returns: states.CLEANWAIT if cleaning operation in progress + or states.DEPLOYWAIT if deploy operation in progress. + """ + return states.CLEANWAIT if node.clean_step else states.DEPLOYWAIT + + +def set_async_step_flags(node, reboot=None, skip_current_step=None): + """Sets appropriate reboot flags in driver_internal_info based on operation + + :param node: an ironic node object. + :param reboot: Boolean value to set for node's driver_internal_info flag + cleaning_reboot or deployment_reboot based on cleaning or deployment + operation in progress. If it is None, corresponding reboot flag is + not set in node's driver_internal_info. + :param skip_current_step: Boolean value to set for node's + driver_internal_info flag skip_current_clean_step or + skip_current_deploy_step based on cleaning or deployment operation + in progress. If it is None, corresponding skip step flag is not set + in node's driver_internal_info. + """ + info = node.driver_internal_info + cleaning = {'reboot': 'cleaning_reboot', + 'skip': 'skip_current_clean_step'} + deployment = {'reboot': 'deployment_reboot', + 'skip': 'skip_current_deploy_step'} + fields = cleaning if node.clean_step else deployment + if reboot is not None: + info[fields['reboot']] = reboot + if skip_current_step is not None: + info[fields['skip']] = skip_current_step + node.driver_internal_info = info + node.save() diff --git a/ironic/drivers/modules/redfish/bios.py b/ironic/drivers/modules/redfish/bios.py index a05179555b..825f876f1b 100644 --- a/ironic/drivers/modules/redfish/bios.py +++ b/ironic/drivers/modules/redfish/bios.py @@ -134,8 +134,7 @@ class RedfishBIOS(base.BIOSInterface): self.post_reset(task) self._set_reboot(task) - return (states.CLEANWAIT if - task.node.clean_step else states.DEPLOYWAIT) + return deploy_utils.get_async_step_return_state(task.node) else: current_attrs = bios.attributes LOG.debug('Post factory reset, BIOS configuration for node ' @@ -187,8 +186,7 @@ class RedfishBIOS(base.BIOSInterface): self.post_configuration(task, settings) self._set_reboot_requested(task, attributes) - return (states.CLEANWAIT if - task.node.clean_step else states.DEPLOYWAIT) + return deploy_utils.get_async_step_return_state(task.node) else: # Step 2: Verify requested BIOS settings applied requested_attrs = info.get('requested_bios_attrs') @@ -284,13 +282,10 @@ class RedfishBIOS(base.BIOSInterface): """ info = task.node.driver_internal_info info['post_factory_reset_reboot_requested'] = True - cleaning = ['cleaning_reboot', 'skip_current_clean_step'] - deployment = ['deployment_reboot', 'skip_current_deploy_step'] - field_name = cleaning if task.node.clean_step else deployment - info[field_name[0]] = True - info[field_name[1]] = False task.node.driver_internal_info = info task.node.save() + deploy_utils.set_async_step_flags(task.node, reboot=True, + skip_current_step=False) def _set_reboot_requested(self, task, attributes): """Set driver_internal_info flags for reboot requested. @@ -301,13 +296,10 @@ class RedfishBIOS(base.BIOSInterface): info = task.node.driver_internal_info info['post_config_reboot_requested'] = True info['requested_bios_attrs'] = attributes - cleaning = ['cleaning_reboot', 'skip_current_clean_step'] - deployment = ['deployment_reboot', 'skip_current_deploy_step'] - field_name = cleaning if task.node.clean_step else deployment - info[field_name[0]] = True - info[field_name[1]] = False task.node.driver_internal_info = info task.node.save() + deploy_utils.set_async_step_flags(task.node, reboot=True, + skip_current_step=False) def _clear_reboot_requested(self, task): """Clear driver_internal_info flags after reboot completed. diff --git a/ironic/tests/unit/drivers/modules/test_deploy_utils.py b/ironic/tests/unit/drivers/modules/test_deploy_utils.py index aeea96261e..6b464aa607 100644 --- a/ironic/tests/unit/drivers/modules/test_deploy_utils.py +++ b/ironic/tests/unit/drivers/modules/test_deploy_utils.py @@ -2854,3 +2854,70 @@ class InstanceImageCacheTestCase(db_base.DbTestCase): mock_ensure_tree.assert_not_called() self.assertEqual(500 * 1024 * 1024, cache._cache_size) self.assertEqual(30 * 60, cache._cache_ttl) + + +class AsyncStepTestCase(db_base.DbTestCase): + + def setUp(self): + super(AsyncStepTestCase, self).setUp() + self.node = obj_utils.create_test_node(self.context, + driver="fake-hardware") + + def _test_get_async_step_return_state(self): + result = utils.get_async_step_return_state(self.node) + if self.node.clean_step: + self.assertEqual(states.CLEANWAIT, result) + else: + self.assertEqual(states.DEPLOYWAIT, result) + + def test_get_async_step_return_state_cleaning(self): + self.node.clean_step = {'step': 'create_configuration', + 'interface': 'raid'} + self.node.save() + self._test_get_async_step_return_state() + + def test_get_async_step_return_state_deploying(self): + self.node.deploy_step = {'step': 'create_configuration', + 'interface': 'raid'} + self.node.save() + self._test_get_async_step_return_state() + + def test_set_async_step_flags_cleaning_set_both(self): + self.node.clean_step = {'step': 'create_configuration', + 'interface': 'raid'} + self.node.driver_internal_info = {} + expected = {'cleaning_reboot': True, + 'skip_current_clean_step': True} + self.node.save() + utils.set_async_step_flags(self.node, reboot=True, + skip_current_step=True) + self.assertEqual(expected, self.node.driver_internal_info) + + def test_set_async_step_flags_cleaning_set_one(self): + self.node.clean_step = {'step': 'create_configuration', + 'interface': 'raid'} + self.node.driver_internal_info = {} + self.node.save() + utils.set_async_step_flags(self.node, reboot=True) + self.assertEqual({'cleaning_reboot': True}, + self.node.driver_internal_info) + + def test_set_async_step_flags_deploying_set_both(self): + self.node.deploy_step = {'step': 'create_configuration', + 'interface': 'raid'} + self.node.driver_internal_info = {} + expected = {'deployment_reboot': True, + 'skip_current_deploy_step': True} + self.node.save() + utils.set_async_step_flags(self.node, reboot=True, + skip_current_step=True) + self.assertEqual(expected, self.node.driver_internal_info) + + def test_set_async_step_flags_deploying_set_one(self): + self.node.deploy_step = {'step': 'create_configuration', + 'interface': 'raid'} + self.node.driver_internal_info = {} + self.node.save() + utils.set_async_step_flags(self.node, reboot=True) + self.assertEqual({'deployment_reboot': True}, + self.node.driver_internal_info)