Merge "[Refactor] Make caching BIOS settings explicit"
This commit is contained in:
commit
4404292276
@ -1004,32 +1004,22 @@ class InspectInterface(BaseInterface):
|
|||||||
driver=task.node.driver, extension='abort')
|
driver=task.node.driver, extension='abort')
|
||||||
|
|
||||||
|
|
||||||
|
def cache_bios_settings(func):
|
||||||
|
"""A decorator to cache bios settings after running the function.
|
||||||
|
|
||||||
|
:param func: Function or method to wrap.
|
||||||
|
"""
|
||||||
|
@six.wraps(func)
|
||||||
|
def wrapped(self, task, *args, **kwargs):
|
||||||
|
result = func(self, task, *args, **kwargs)
|
||||||
|
self.cache_bios_settings(task)
|
||||||
|
return result
|
||||||
|
return wrapped
|
||||||
|
|
||||||
|
|
||||||
class BIOSInterface(BaseInterface):
|
class BIOSInterface(BaseInterface):
|
||||||
interface_type = 'bios'
|
interface_type = 'bios'
|
||||||
|
|
||||||
def __new__(cls, *args, **kwargs):
|
|
||||||
# Wrap the apply_configuration and factory_reset into a decorator
|
|
||||||
# which call cache_bios_settings() to update the node's BIOS setting
|
|
||||||
# table after apply_configuration and factory_reset have finished.
|
|
||||||
|
|
||||||
super_new = super(BIOSInterface, cls).__new__
|
|
||||||
instance = super_new(cls, *args, **kwargs)
|
|
||||||
|
|
||||||
def wrapper(func):
|
|
||||||
@six.wraps(func)
|
|
||||||
def wrapped(task, *args, **kwargs):
|
|
||||||
result = func(task, *args, **kwargs)
|
|
||||||
instance.cache_bios_settings(task)
|
|
||||||
return result
|
|
||||||
return wrapped
|
|
||||||
|
|
||||||
for n, method in inspect.getmembers(instance, inspect.ismethod):
|
|
||||||
if n == "apply_configuration":
|
|
||||||
instance.apply_configuration = wrapper(method)
|
|
||||||
elif n == "factory_reset":
|
|
||||||
instance.factory_reset = wrapper(method)
|
|
||||||
return instance
|
|
||||||
|
|
||||||
@abc.abstractmethod
|
@abc.abstractmethod
|
||||||
def apply_configuration(self, task, settings):
|
def apply_configuration(self, task, settings):
|
||||||
"""Validate & apply BIOS settings on the given node.
|
"""Validate & apply BIOS settings on the given node.
|
||||||
|
@ -154,6 +154,7 @@ class IloBIOS(base.BIOSInterface):
|
|||||||
'required': True
|
'required': True
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@base.cache_bios_settings
|
||||||
def apply_configuration(self, task, settings):
|
def apply_configuration(self, task, settings):
|
||||||
"""Applies the provided configuration on the node.
|
"""Applies the provided configuration on the node.
|
||||||
|
|
||||||
@ -177,6 +178,7 @@ class IloBIOS(base.BIOSInterface):
|
|||||||
|
|
||||||
@METRICS.timer('IloBIOS.factory_reset')
|
@METRICS.timer('IloBIOS.factory_reset')
|
||||||
@base.clean_step(priority=0, abortable=False)
|
@base.clean_step(priority=0, abortable=False)
|
||||||
|
@base.cache_bios_settings
|
||||||
def factory_reset(self, task):
|
def factory_reset(self, task):
|
||||||
"""Reset the BIOS settings to factory configuration.
|
"""Reset the BIOS settings to factory configuration.
|
||||||
|
|
||||||
|
@ -61,6 +61,7 @@ class IRMCBIOS(base.BIOSInterface):
|
|||||||
'required': True
|
'required': True
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@base.cache_bios_settings
|
||||||
def apply_configuration(self, task, settings):
|
def apply_configuration(self, task, settings):
|
||||||
"""Applies BIOS configuration on the given node.
|
"""Applies BIOS configuration on the given node.
|
||||||
|
|
||||||
@ -98,6 +99,7 @@ class IRMCBIOS(base.BIOSInterface):
|
|||||||
operation='Apply BIOS configuration', error=e)
|
operation='Apply BIOS configuration', error=e)
|
||||||
|
|
||||||
@METRICS.timer('IRMCBIOS.factory_reset')
|
@METRICS.timer('IRMCBIOS.factory_reset')
|
||||||
|
@base.cache_bios_settings
|
||||||
def factory_reset(self, task):
|
def factory_reset(self, task):
|
||||||
"""Reset BIOS configuration to factory default on the given node.
|
"""Reset BIOS configuration to factory default on the given node.
|
||||||
|
|
||||||
|
@ -79,6 +79,7 @@ class RedfishBIOS(base.BIOSInterface):
|
|||||||
task.context, node_id, delete_names)
|
task.context, node_id, delete_names)
|
||||||
|
|
||||||
@base.clean_step(priority=0)
|
@base.clean_step(priority=0)
|
||||||
|
@base.cache_bios_settings
|
||||||
def factory_reset(self, task):
|
def factory_reset(self, task):
|
||||||
"""Reset the BIOS settings of the node to the factory default.
|
"""Reset the BIOS settings of the node to the factory default.
|
||||||
|
|
||||||
@ -110,6 +111,7 @@ class RedfishBIOS(base.BIOSInterface):
|
|||||||
'required': True
|
'required': True
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@base.cache_bios_settings
|
||||||
def apply_configuration(self, task, settings):
|
def apply_configuration(self, task, settings):
|
||||||
"""Apply the BIOS settings to the node.
|
"""Apply the BIOS settings to the node.
|
||||||
|
|
||||||
|
@ -68,12 +68,15 @@ class IloBiosTestCase(test_common.BaseIloTest):
|
|||||||
called_method["name"].assert_called_once_with(
|
called_method["name"].assert_called_once_with(
|
||||||
*called_method["args"])
|
*called_method["args"])
|
||||||
|
|
||||||
|
@mock.patch.object(ilo_bios.IloBIOS, 'cache_bios_settings',
|
||||||
|
autospec=True)
|
||||||
@mock.patch.object(ilo_bios.IloBIOS, '_execute_post_boot_bios_step',
|
@mock.patch.object(ilo_bios.IloBIOS, '_execute_post_boot_bios_step',
|
||||||
autospec=True)
|
autospec=True)
|
||||||
@mock.patch.object(ilo_bios.IloBIOS, '_execute_pre_boot_bios_step',
|
@mock.patch.object(ilo_bios.IloBIOS, '_execute_pre_boot_bios_step',
|
||||||
autospec=True)
|
autospec=True)
|
||||||
def test_apply_configuration_pre_boot(self, exe_pre_boot_mock,
|
def test_apply_configuration_pre_boot(self, exe_pre_boot_mock,
|
||||||
exe_post_boot_mock):
|
exe_post_boot_mock,
|
||||||
|
cache_settings_mock):
|
||||||
settings = [
|
settings = [
|
||||||
{
|
{
|
||||||
"name": "SET_A", "value": "VAL_A",
|
"name": "SET_A", "value": "VAL_A",
|
||||||
@ -101,13 +104,17 @@ class IloBiosTestCase(test_common.BaseIloTest):
|
|||||||
exe_pre_boot_mock.assert_called_once_with(
|
exe_pre_boot_mock.assert_called_once_with(
|
||||||
task.driver.bios, task, 'apply_configuration', actual_settings)
|
task.driver.bios, task, 'apply_configuration', actual_settings)
|
||||||
self.assertFalse(exe_post_boot_mock.called)
|
self.assertFalse(exe_post_boot_mock.called)
|
||||||
|
cache_settings_mock.assert_called_once_with(task.driver.bios, task)
|
||||||
|
|
||||||
|
@mock.patch.object(ilo_bios.IloBIOS, 'cache_bios_settings',
|
||||||
|
autospec=True)
|
||||||
@mock.patch.object(ilo_bios.IloBIOS, '_execute_post_boot_bios_step',
|
@mock.patch.object(ilo_bios.IloBIOS, '_execute_post_boot_bios_step',
|
||||||
autospec=True)
|
autospec=True)
|
||||||
@mock.patch.object(ilo_bios.IloBIOS, '_execute_pre_boot_bios_step',
|
@mock.patch.object(ilo_bios.IloBIOS, '_execute_pre_boot_bios_step',
|
||||||
autospec=True)
|
autospec=True)
|
||||||
def test_apply_configuration_post_boot(self, exe_pre_boot_mock,
|
def test_apply_configuration_post_boot(self, exe_pre_boot_mock,
|
||||||
exe_post_boot_mock):
|
exe_post_boot_mock,
|
||||||
|
cache_settings_mock):
|
||||||
settings = [
|
settings = [
|
||||||
{
|
{
|
||||||
"name": "SET_A", "value": "VAL_A",
|
"name": "SET_A", "value": "VAL_A",
|
||||||
@ -133,6 +140,7 @@ class IloBiosTestCase(test_common.BaseIloTest):
|
|||||||
exe_post_boot_mock.assert_called_once_with(
|
exe_post_boot_mock.assert_called_once_with(
|
||||||
task.driver.bios, task, 'apply_configuration')
|
task.driver.bios, task, 'apply_configuration')
|
||||||
self.assertFalse(exe_pre_boot_mock.called)
|
self.assertFalse(exe_pre_boot_mock.called)
|
||||||
|
cache_settings_mock.assert_called_once_with(task.driver.bios, task)
|
||||||
|
|
||||||
@mock.patch.object(ilo_boot.IloVirtualMediaBoot, 'prepare_ramdisk',
|
@mock.patch.object(ilo_boot.IloVirtualMediaBoot, 'prepare_ramdisk',
|
||||||
spec_set=True, autospec=True)
|
spec_set=True, autospec=True)
|
||||||
|
@ -539,9 +539,11 @@ class MyBIOSInterface(driver_base.BIOSInterface):
|
|||||||
def validate(self, task):
|
def validate(self, task):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@driver_base.cache_bios_settings
|
||||||
def apply_configuration(self, task, settings):
|
def apply_configuration(self, task, settings):
|
||||||
return "return_value_apply_configuration"
|
return "return_value_apply_configuration"
|
||||||
|
|
||||||
|
@driver_base.cache_bios_settings
|
||||||
def factory_reset(self, task):
|
def factory_reset(self, task):
|
||||||
return "return_value_factory_reset"
|
return "return_value_factory_reset"
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user