Merge "Added revert to delete LPAR from destination host on failed rebuild"

This commit is contained in:
Jenkins 2016-08-10 19:10:26 +00:00 committed by Gerrit Code Review
commit 236fdfaa7f
2 changed files with 49 additions and 4 deletions

View File

@ -16,10 +16,15 @@
import mock
from nova.compute import task_states
from nova import exception
from nova import test
from nova_powervm.virt.powervm.tasks import vm as tf_vm
from taskflow import engines as tf_eng
from taskflow.patterns import linear_flow as tf_lf
class TestVMTasks(test.TestCase):
def setUp(self):
@ -46,6 +51,30 @@ class TestVMTasks(test.TestCase):
self.assertEqual(lpar_entry, crt_entry)
nvram_mgr.fetch.assert_called_once_with(self.instance)
@mock.patch('nova_powervm.virt.powervm.vm.get_pvm_uuid')
@mock.patch('nova_powervm.virt.powervm.tasks.vm.Create.execute')
@mock.patch('nova_powervm.virt.powervm.vm.dlt_lpar')
def test_create_revert(self, mock_vm_dlt, mock_crt_exc,
mock_get_pvm_uuid):
mock_crt_exc.side_effect = exception.NovaException()
crt = tf_vm.Create(self.apt, 'host_wrapper', self.instance,
'flavor', 'stg_ftsk', None)
# Assert that a failure while building does not revert
crt.instance.task_state = task_states.SPAWNING
flow_test = tf_lf.Flow("test_revert")
flow_test.add(crt)
self.assertRaises(exception.NovaException, tf_eng.run, flow_test)
mock_vm_dlt.assert_not_called()
# Assert that a failure when rebuild results in revert
crt.instance.task_state = task_states.REBUILD_SPAWNING
flow_test = tf_lf.Flow("test_revert")
flow_test.add(crt)
self.assertRaises(exception.NovaException, tf_eng.run, flow_test)
mock_vm_dlt.assert_called()
@mock.patch('nova_powervm.virt.powervm.vm.update')
def test_resize(self, mock_vm_update):

View File

@ -26,6 +26,8 @@ from nova_powervm.virt.powervm.i18n import _LW
from nova_powervm.virt.powervm.tasks import base as pvm_task
from nova_powervm.virt.powervm import vm
from nova.compute import task_states
LOG = logging.getLogger(__name__)
@ -58,10 +60,14 @@ class Create(pvm_task.PowerVMTask):
nvram_mgr=None, slot_mgr=None):
"""Creates the Task for creating a VM.
The revert method is not implemented because the compute manager
calls the driver destroy operation for spawn errors. By not deleting
the lpar, it's a cleaner flow through the destroy operation and
accomplishes the same result.
The revert method only needs to do something for failed rebuilds.
Since the rebuild and build methods have different flows, it is
necessary to clean up the destination LPAR on fails during rebuild.
The revert method is not implemented for build because the compute
manager calls the driver destroy operation for spawn errors. By
not deleting the lpar, it's a cleaner flow through the destroy
operation and accomplishes the same result.
Any stale storage associated with the new VM's (possibly recycled) ID
will be cleaned up. The cleanup work will be delegated to the FeedTask
@ -102,6 +108,16 @@ class Create(pvm_task.PowerVMTask):
lpars_exist=True)
return wrap
def revert_impl(self, result, flow_failures, **kwargs):
# Only reverts failed rebuilds, because the revert
# for a failed build is handled in the manager.
if self.instance.task_state == task_states.REBUILD_SPAWNING:
LOG.info(_LI('Rebuild of instance %s failed. '
'Deleting instance from destination.'),
self.instance.name, instance=self.instance)
vm.dlt_lpar(self.adapter, vm.get_pvm_uuid(self.instance))
class Resize(pvm_task.PowerVMTask):