Merge "Enable agent_ilo for uefi-bios switching"

This commit is contained in:
Jenkins 2015-03-17 14:47:40 +00:00 committed by Gerrit Code Review
commit b865538d0b
4 changed files with 55 additions and 46 deletions

View File

@ -327,14 +327,23 @@ def set_boot_mode(node, boot_mode):
{'uuid': node.uuid, 'boot_mode': boot_mode}) {'uuid': node.uuid, 'boot_mode': boot_mode})
def update_boot_mode_capability(task): def update_boot_mode(task):
"""Update 'boot_mode' capability value of node's 'capabilities' property. """Update 'boot_mode' capability value of node's 'capabilities' property.
This method updates the 'boot_mode' capability in node's 'capabilities'
property if not set.
It also sets the boot mode to be used in the next boot.
:param task: Task object. :param task: Task object.
:raises: IloOperationError if setting boot mode failed.
""" """
ilo_object = get_ilo_object(task.node) boot_mode = driver_utils.get_node_capability(task.node, 'boot_mode')
if boot_mode is not None:
set_boot_mode(task.node, boot_mode)
return
ilo_object = get_ilo_object(task.node)
try: try:
p_boot_mode = ilo_object.get_pending_boot_mode() p_boot_mode = ilo_object.get_pending_boot_mode()
if p_boot_mode == 'UNKNOWN': if p_boot_mode == 'UNKNOWN':

View File

@ -340,11 +340,7 @@ class IloVirtualMediaIscsiDeploy(base.DeployInterface):
:param task: a TaskManager instance containing the node to act on. :param task: a TaskManager instance containing the node to act on.
:raises: IloOperationError, if some operation on iLO failed. :raises: IloOperationError, if some operation on iLO failed.
""" """
boot_mode = driver_utils.get_node_capability(task.node, 'boot_mode') ilo_common.update_boot_mode(task)
if boot_mode is not None:
ilo_common.set_boot_mode(task.node, boot_mode)
else:
ilo_common.update_boot_mode_capability(task)
def clean_up(self, task): def clean_up(self, task):
"""Clean up the deployment environment for the task's node. """Clean up the deployment environment for the task's node.
@ -415,6 +411,7 @@ class IloVirtualMediaAgentDeploy(base.DeployInterface):
node = task.node node = task.node
node.instance_info = agent.build_instance_info_for_deploy(task) node.instance_info = agent.build_instance_info_for_deploy(task)
node.save() node.save()
ilo_common.update_boot_mode(task)
def clean_up(self, task): def clean_up(self, task):
"""Clean up the deployment environment for this node. """Clean up the deployment environment for this node.
@ -448,11 +445,7 @@ class IloPXEDeploy(pxe.PXEDeploy):
:param task: a TaskManager instance containing the node to act on. :param task: a TaskManager instance containing the node to act on.
""" """
boot_mode = driver_utils.get_node_capability(task.node, 'boot_mode') ilo_common.update_boot_mode(task)
if boot_mode is None:
ilo_common.update_boot_mode_capability(task)
else:
ilo_common.set_boot_mode(task.node, boot_mode)
super(IloPXEDeploy, self).prepare(task) super(IloPXEDeploy, self).prepare(task)
def deploy(self, task): def deploy(self, task):

View File

@ -302,15 +302,15 @@ class IloCommonMethodsTestCase(db_base.DbTestCase):
@mock.patch.object(driver_utils, 'rm_node_capability') @mock.patch.object(driver_utils, 'rm_node_capability')
@mock.patch.object(driver_utils, 'add_node_capability') @mock.patch.object(driver_utils, 'add_node_capability')
@mock.patch.object(ilo_common, 'get_ilo_object') @mock.patch.object(ilo_common, 'get_ilo_object')
def test_update_boot_mode_capability(self, get_ilo_object_mock, def test_update_boot_mode(self, get_ilo_object_mock,
add_node_capability_mock, add_node_capability_mock,
rm_node_capability_mock): rm_node_capability_mock):
ilo_mock_obj = get_ilo_object_mock.return_value ilo_mock_obj = get_ilo_object_mock.return_value
ilo_mock_obj.get_pending_boot_mode.return_value = 'legacy' ilo_mock_obj.get_pending_boot_mode.return_value = 'legacy'
with task_manager.acquire(self.context, self.node.uuid, with task_manager.acquire(self.context, self.node.uuid,
shared=False) as task: shared=False) as task:
ilo_common.update_boot_mode_capability(task) ilo_common.update_boot_mode(task)
get_ilo_object_mock.assert_called_once_with(task.node) get_ilo_object_mock.assert_called_once_with(task.node)
ilo_mock_obj.get_pending_boot_mode.assert_called_once_with() ilo_mock_obj.get_pending_boot_mode.assert_called_once_with()
rm_node_capability_mock.assert_called_once_with(task, 'boot_mode') rm_node_capability_mock.assert_called_once_with(task, 'boot_mode')
@ -320,16 +320,16 @@ class IloCommonMethodsTestCase(db_base.DbTestCase):
@mock.patch.object(driver_utils, 'add_node_capability') @mock.patch.object(driver_utils, 'add_node_capability')
@mock.patch.object(ilo_common, 'get_ilo_object') @mock.patch.object(ilo_common, 'get_ilo_object')
def test_update_boot_mode_capability_unknown(self, def test_update_boot_mode_unknown(self,
get_ilo_object_mock, get_ilo_object_mock,
add_node_capability_mock): add_node_capability_mock):
ilo_mock_obj = get_ilo_object_mock.return_value ilo_mock_obj = get_ilo_object_mock.return_value
ilo_mock_obj.get_pending_boot_mode.return_value = 'UNKNOWN' ilo_mock_obj.get_pending_boot_mode.return_value = 'UNKNOWN'
set_pending_boot_mode_mock = ilo_mock_obj.set_pending_boot_mode set_pending_boot_mode_mock = ilo_mock_obj.set_pending_boot_mode
with task_manager.acquire(self.context, self.node.uuid, with task_manager.acquire(self.context, self.node.uuid,
shared=False) as task: shared=False) as task:
ilo_common.update_boot_mode_capability(task) ilo_common.update_boot_mode(task)
get_ilo_object_mock.assert_called_once_with(task.node) get_ilo_object_mock.assert_called_once_with(task.node)
ilo_mock_obj.get_pending_boot_mode.assert_called_once_with() ilo_mock_obj.get_pending_boot_mode.assert_called_once_with()
set_pending_boot_mode_mock.assert_called_once_with('UEFI') set_pending_boot_mode_mock.assert_called_once_with('UEFI')
@ -339,22 +339,33 @@ class IloCommonMethodsTestCase(db_base.DbTestCase):
@mock.patch.object(driver_utils, 'add_node_capability') @mock.patch.object(driver_utils, 'add_node_capability')
@mock.patch.object(ilo_common, 'get_ilo_object') @mock.patch.object(ilo_common, 'get_ilo_object')
def test_update_boot_mode_capability_legacy(self, def test_update_boot_mode_legacy(self,
get_ilo_object_mock, get_ilo_object_mock,
add_node_capability_mock): add_node_capability_mock):
ilo_mock_obj = get_ilo_object_mock.return_value ilo_mock_obj = get_ilo_object_mock.return_value
exc = ilo_error.IloCommandNotSupportedError('error') exc = ilo_error.IloCommandNotSupportedError('error')
ilo_mock_obj.get_pending_boot_mode.side_effect = exc ilo_mock_obj.get_pending_boot_mode.side_effect = exc
with task_manager.acquire(self.context, self.node.uuid, with task_manager.acquire(self.context, self.node.uuid,
shared=False) as task: shared=False) as task:
ilo_common.update_boot_mode_capability(task) ilo_common.update_boot_mode(task)
get_ilo_object_mock.assert_called_once_with(task.node) get_ilo_object_mock.assert_called_once_with(task.node)
ilo_mock_obj.get_pending_boot_mode.assert_called_once_with() ilo_mock_obj.get_pending_boot_mode.assert_called_once_with()
add_node_capability_mock.assert_called_once_with(task, add_node_capability_mock.assert_called_once_with(task,
'boot_mode', 'boot_mode',
'bios') 'bios')
@mock.patch.object(ilo_common, 'set_boot_mode')
def test_update_boot_mode_prop_boot_mode_exist(self,
set_boot_mode_mock):
properties = {'capabilities': 'boot_mode:uefi'}
with task_manager.acquire(self.context, self.node.uuid,
shared=False) as task:
task.node.properties = properties
ilo_common.update_boot_mode(task)
set_boot_mode_mock.assert_called_once_with(task.node, 'uefi')
@mock.patch.object(images, 'get_temp_url_for_glance_image') @mock.patch.object(images, 'get_temp_url_for_glance_image')
@mock.patch.object(ilo_common, 'attach_vmedia') @mock.patch.object(ilo_common, 'attach_vmedia')
@mock.patch.object(ilo_common, '_prepare_floppy_image') @mock.patch.object(ilo_common, '_prepare_floppy_image')

View File

@ -336,6 +336,14 @@ class IloVirtualMediaIscsiDeployTestCase(db_base.DbTestCase):
destroy_images_mock.assert_called_once_with(task.node.uuid) destroy_images_mock.assert_called_once_with(task.node.uuid)
clean_up_boot_mock.assert_called_once_with(task.node) clean_up_boot_mock.assert_called_once_with(task.node)
@mock.patch.object(ilo_common, 'update_boot_mode')
def test_prepare(self,
update_boot_mode_mock):
with task_manager.acquire(self.context, self.node.uuid,
shared=False) as task:
task.driver.deploy.prepare(task)
update_boot_mode_mock.assert_called_once_with(task)
class IloVirtualMediaAgentDeployTestCase(db_base.DbTestCase): class IloVirtualMediaAgentDeployTestCase(db_base.DbTestCase):
@ -378,13 +386,17 @@ class IloVirtualMediaAgentDeployTestCase(db_base.DbTestCase):
states.POWER_OFF) states.POWER_OFF)
self.assertEqual(states.DELETED, returned_state) self.assertEqual(states.DELETED, returned_state)
@mock.patch.object(ilo_common, 'update_boot_mode')
@mock.patch.object(agent, 'build_instance_info_for_deploy') @mock.patch.object(agent, 'build_instance_info_for_deploy')
def test_prepare(self, build_instance_info_mock): def test_prepare(self,
build_instance_info_mock,
update_boot_mode_mock):
deploy_opts = {'a': 'b'} deploy_opts = {'a': 'b'}
build_instance_info_mock.return_value = deploy_opts build_instance_info_mock.return_value = deploy_opts
with task_manager.acquire(self.context, self.node.uuid, with task_manager.acquire(self.context, self.node.uuid,
shared=False) as task: shared=False) as task:
task.driver.deploy.prepare(task) task.driver.deploy.prepare(task)
update_boot_mode_mock.assert_called_once_with(task)
self.assertEqual(deploy_opts, task.node.instance_info) self.assertEqual(deploy_opts, task.node.instance_info)
@ -653,30 +665,14 @@ class IloPXEDeployTestCase(db_base.DbTestCase):
pxe_validate_mock.assert_called_once_with(task) pxe_validate_mock.assert_called_once_with(task)
@mock.patch.object(pxe.PXEDeploy, 'prepare') @mock.patch.object(pxe.PXEDeploy, 'prepare')
@mock.patch.object(ilo_common, 'set_boot_mode') @mock.patch.object(ilo_common, 'update_boot_mode')
@mock.patch.object(driver_utils, 'get_node_capability') def test_prepare(self,
def test_prepare(self, node_capability_mock, update_boot_mode_mock,
set_boot_mode_mock, pxe_prepare_mock): pxe_prepare_mock):
with task_manager.acquire(self.context, self.node.uuid, with task_manager.acquire(self.context, self.node.uuid,
shared=False) as task: shared=False) as task:
node_capability_mock.return_value = 'uefi'
task.driver.deploy.prepare(task) task.driver.deploy.prepare(task)
node_capability_mock.assert_called_once_with(task.node, update_boot_mode_mock.assert_called_once_with(task)
'boot_mode')
set_boot_mode_mock.assert_called_once_with(task.node, 'uefi')
pxe_prepare_mock.assert_called_once_with(task)
@mock.patch.object(pxe.PXEDeploy, 'prepare')
@mock.patch.object(ilo_common, 'update_boot_mode_capability')
@mock.patch.object(driver_utils, 'get_node_capability')
def test_prepare_boot_mode_doesnt_exist(self, node_capability_mock,
update_capability_mock,
pxe_prepare_mock):
with task_manager.acquire(self.context, self.node.uuid,
shared=False) as task:
node_capability_mock.return_value = None
task.driver.deploy.prepare(task)
update_capability_mock.assert_called_once_with(task)
pxe_prepare_mock.assert_called_once_with(task) pxe_prepare_mock.assert_called_once_with(task)
@mock.patch.object(pxe.PXEDeploy, 'deploy') @mock.patch.object(pxe.PXEDeploy, 'deploy')