Merge "Follow-up for deploy steps for Redfish BIOS interface"

This commit is contained in:
Zuul 2019-08-28 20:42:52 +00:00 committed by Gerrit Code Review
commit 72f36719a1
3 changed files with 111 additions and 14 deletions

View File

@ -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()

View File

@ -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.

View File

@ -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)