Use correct arguments in task inits
The CreateAndConnectCfgDrive and DeleteVOpt tasks were passing the instance into the task.Task init as the first argument. The first arg for the Task init is actually the task name [1]. This means that those task names were string representations of the instance which will cause failures if there are any non-ascii characters. This corrects the Task init calls by removing instance as the first argument. The name kwarg is now being used throughout the PowerVM tasks to avoid similar issues in the future. [1] https://github.com/openstack/taskflow/blob/3.1.0/taskflow/task.py#L62 Change-Id: I991a5ea33daa9a21f774fe24882ed40f990b8e0e Closes-Bug: #1748950
This commit is contained in:
parent
c966524672
commit
db686fe185
|
@ -78,6 +78,11 @@ class TestNetwork(test.NoDBTestCase):
|
|||
# code was called
|
||||
self.assertEqual(3, mock_unplug.call_count)
|
||||
|
||||
# Validate args on taskflow.task.Task instantiation
|
||||
with mock.patch('taskflow.task.Task.__init__') as tf:
|
||||
tf_net.UnplugVifs(self.apt, inst, net_info)
|
||||
tf.assert_called_once_with(name='unplug_vifs')
|
||||
|
||||
@mock.patch('nova.virt.powervm.vm.get_instance_wrapper')
|
||||
def test_unplug_vifs_invalid_state(self, mock_get_wrap):
|
||||
"""Tests that the delete raises an exception if bad VM state."""
|
||||
|
@ -129,6 +134,12 @@ class TestNetwork(test.NoDBTestCase):
|
|||
# created.
|
||||
self.assertEqual(pre_cnas + [mock_new_cna], all_cnas)
|
||||
|
||||
# Validate args on taskflow.task.Task instantiation
|
||||
with mock.patch('taskflow.task.Task.__init__') as tf:
|
||||
tf_net.PlugVifs(mock.MagicMock(), self.apt, inst, net_info)
|
||||
tf.assert_called_once_with(
|
||||
name='plug_vifs', provides='vm_cnas', requires=['lpar_wrap'])
|
||||
|
||||
@mock.patch('nova.virt.powervm.vif.plug')
|
||||
@mock.patch('nova.virt.powervm.vm.get_cnas')
|
||||
def test_plug_vifs_rmc_no_create(self, mock_vm_get, mock_plug):
|
||||
|
@ -288,6 +299,12 @@ class TestNetwork(test.NoDBTestCase):
|
|||
mock_vm_get.assert_not_called()
|
||||
mock_crt_cna.assert_not_called()
|
||||
|
||||
# Validate args on taskflow.task.Task instantiation
|
||||
with mock.patch('taskflow.task.Task.__init__') as tf:
|
||||
tf_net.PlugMgmtVif(self.apt, inst)
|
||||
tf.assert_called_once_with(
|
||||
name='plug_mgmt_vif', provides='mgmt_cna', requires=['vm_cnas'])
|
||||
|
||||
def test_get_vif_events(self):
|
||||
# Set up common mocks.
|
||||
inst = powervm.TEST_INSTANCE
|
||||
|
|
|
@ -63,6 +63,13 @@ class TestStorage(test.NoDBTestCase):
|
|||
task.revert('mgmt_cna', 'result', 'flow_failures')
|
||||
self.mock_mb.assert_not_called()
|
||||
|
||||
# Validate args on taskflow.task.Task instantiation
|
||||
with mock.patch('taskflow.task.Task.__init__') as tf:
|
||||
tf_stg.CreateAndConnectCfgDrive(
|
||||
self.adapter, self.instance, 'injected_files',
|
||||
'network_info', 'stg_ftsk', admin_pass='admin_pass')
|
||||
tf.assert_called_once_with(name='cfg_drive', requires=['mgmt_cna'])
|
||||
|
||||
def test_delete_vopt(self):
|
||||
# Test with no FeedTask
|
||||
task = tf_stg.DeleteVOpt(self.adapter, self.instance)
|
||||
|
@ -81,6 +88,11 @@ class TestStorage(test.NoDBTestCase):
|
|||
self.mock_mb.dlt_vopt.assert_called_once_with(
|
||||
self.instance, stg_ftsk='ftsk')
|
||||
|
||||
# Validate args on taskflow.task.Task instantiation
|
||||
with mock.patch('taskflow.task.Task.__init__') as tf:
|
||||
tf_stg.DeleteVOpt(self.adapter, self.instance)
|
||||
tf.assert_called_once_with(name='vopt_delete')
|
||||
|
||||
def test_delete_disk(self):
|
||||
stor_adpt_mappings = mock.Mock()
|
||||
|
||||
|
@ -88,11 +100,23 @@ class TestStorage(test.NoDBTestCase):
|
|||
task.execute(stor_adpt_mappings)
|
||||
self.disk_dvr.delete_disks.assert_called_once_with(stor_adpt_mappings)
|
||||
|
||||
# Validate args on taskflow.task.Task instantiation
|
||||
with mock.patch('taskflow.task.Task.__init__') as tf:
|
||||
tf_stg.DeleteDisk(self.disk_dvr)
|
||||
tf.assert_called_once_with(
|
||||
name='delete_disk', requires=['stor_adpt_mappings'])
|
||||
|
||||
def test_detach_disk(self):
|
||||
task = tf_stg.DetachDisk(self.disk_dvr, self.instance)
|
||||
task.execute()
|
||||
self.disk_dvr.detach_disk.assert_called_once_with(self.instance)
|
||||
|
||||
# Validate args on taskflow.task.Task instantiation
|
||||
with mock.patch('taskflow.task.Task.__init__') as tf:
|
||||
tf_stg.DetachDisk(self.disk_dvr, self.instance)
|
||||
tf.assert_called_once_with(
|
||||
name='detach_disk', provides='stor_adpt_mappings')
|
||||
|
||||
def test_attach_disk(self):
|
||||
stg_ftsk = mock.Mock()
|
||||
disk_dev_info = mock.Mock()
|
||||
|
@ -113,6 +137,12 @@ class TestStorage(test.NoDBTestCase):
|
|||
task.revert(disk_dev_info, 'result', 'flow failures')
|
||||
self.disk_dvr.detach_disk.assert_called_once_with(self.instance)
|
||||
|
||||
# Validate args on taskflow.task.Task instantiation
|
||||
with mock.patch('taskflow.task.Task.__init__') as tf:
|
||||
tf_stg.AttachDisk(self.disk_dvr, self.instance, stg_ftsk)
|
||||
tf.assert_called_once_with(
|
||||
name='attach_disk', requires=['disk_dev_info'])
|
||||
|
||||
def test_create_disk_for_img(self):
|
||||
image_meta = mock.Mock()
|
||||
|
||||
|
@ -136,3 +166,10 @@ class TestStorage(test.NoDBTestCase):
|
|||
"timed out")
|
||||
task.revert('result', 'flow failures')
|
||||
self.disk_dvr.delete_disks.assert_called_once_with(['result'])
|
||||
|
||||
# Validate args on taskflow.task.Task instantiation
|
||||
with mock.patch('taskflow.task.Task.__init__') as tf:
|
||||
tf_stg.CreateDiskForImg(
|
||||
self.disk_dvr, self.context, self.instance, image_meta)
|
||||
tf.assert_called_once_with(
|
||||
name='create_disk_from_img', provides='disk_dev_info')
|
||||
|
|
|
@ -47,12 +47,22 @@ class TestVMTasks(test.NoDBTestCase):
|
|||
mock_stg.assert_called_once_with([mock_vm_crt.return_value.id], 'ftsk',
|
||||
lpars_exist=True)
|
||||
|
||||
# Validate args on taskflow.task.Task instantiation
|
||||
with mock.patch('taskflow.task.Task.__init__') as tf:
|
||||
tf_vm.Create(self.apt, 'host_wrapper', self.instance, 'ftsk')
|
||||
tf.assert_called_once_with(name='crt_vm', provides='lpar_wrap')
|
||||
|
||||
@mock.patch('nova.virt.powervm.vm.power_on')
|
||||
def test_power_on(self, mock_pwron):
|
||||
pwron = tf_vm.PowerOn(self.apt, self.instance)
|
||||
pwron.execute()
|
||||
mock_pwron.assert_called_once_with(self.apt, self.instance)
|
||||
|
||||
# Validate args on taskflow.task.Task instantiation
|
||||
with mock.patch('taskflow.task.Task.__init__') as tf:
|
||||
tf_vm.PowerOn(self.apt, self.instance)
|
||||
tf.assert_called_once_with(name='pwr_vm')
|
||||
|
||||
@mock.patch('nova.virt.powervm.vm.power_on')
|
||||
@mock.patch('nova.virt.powervm.vm.power_off')
|
||||
def test_power_on_revert(self, mock_pwroff, mock_pwron):
|
||||
|
@ -96,8 +106,18 @@ class TestVMTasks(test.NoDBTestCase):
|
|||
mock_pwroff.assert_called_once_with(self.apt, self.instance,
|
||||
force_immediate=True)
|
||||
|
||||
# Validate args on taskflow.task.Task instantiation
|
||||
with mock.patch('taskflow.task.Task.__init__') as tf:
|
||||
tf_vm.PowerOff(self.apt, self.instance)
|
||||
tf.assert_called_once_with(name='pwr_off_vm')
|
||||
|
||||
@mock.patch('nova.virt.powervm.vm.delete_lpar')
|
||||
def test_delete(self, mock_dlt):
|
||||
delete = tf_vm.Delete(self.apt, self.instance)
|
||||
delete.execute()
|
||||
mock_dlt.assert_called_once_with(self.apt, self.instance)
|
||||
|
||||
# Validate args on taskflow.task.Task instantiation
|
||||
with mock.patch('taskflow.task.Task.__init__') as tf:
|
||||
tf_vm.Delete(self.apt, self.instance)
|
||||
tf.assert_called_once_with(name='dlt_vm')
|
||||
|
|
|
@ -59,7 +59,7 @@ class PlugVifs(task.Task):
|
|||
self.cnas = None
|
||||
|
||||
super(PlugVifs, self).__init__(
|
||||
'plug_vifs', provides='vm_cnas', requires=['lpar_wrap'])
|
||||
name='plug_vifs', provides='vm_cnas', requires=['lpar_wrap'])
|
||||
|
||||
def _vif_exists(self, network_info):
|
||||
"""Does the instance have a CNA for a given net?
|
||||
|
@ -180,7 +180,7 @@ class UnplugVifs(task.Task):
|
|||
self.instance = instance
|
||||
self.network_infos = network_infos or []
|
||||
|
||||
super(UnplugVifs, self).__init__('unplug_vifs')
|
||||
super(UnplugVifs, self).__init__(name='unplug_vifs')
|
||||
|
||||
def execute(self):
|
||||
# If the LPAR is not in an OK state for deleting, then throw an
|
||||
|
@ -222,7 +222,7 @@ class PlugMgmtVif(task.Task):
|
|||
self.instance = instance
|
||||
|
||||
super(PlugMgmtVif, self).__init__(
|
||||
'plug_mgmt_vif', provides='mgmt_cna', requires=['vm_cnas'])
|
||||
name='plug_mgmt_vif', provides='mgmt_cna', requires=['vm_cnas'])
|
||||
|
||||
def execute(self, vm_cnas):
|
||||
LOG.info('Plugging the Management Network Interface to instance.',
|
||||
|
|
|
@ -39,7 +39,7 @@ class CreateDiskForImg(task.Task):
|
|||
The metadata of the image of the instance.
|
||||
"""
|
||||
super(CreateDiskForImg, self).__init__(
|
||||
'create_disk_from_img', provides='disk_dev_info')
|
||||
name='create_disk_from_img', provides='disk_dev_info')
|
||||
self.disk_dvr = disk_dvr
|
||||
self.instance = instance
|
||||
self.context = context
|
||||
|
@ -80,7 +80,7 @@ class AttachDisk(task.Task):
|
|||
:param stg_ftsk: FeedTask to defer storage connectivity operations.
|
||||
"""
|
||||
super(AttachDisk, self).__init__(
|
||||
'attach_disk', requires=['disk_dev_info'])
|
||||
name='attach_disk', requires=['disk_dev_info'])
|
||||
self.disk_dvr = disk_dvr
|
||||
self.instance = instance
|
||||
self.stg_ftsk = stg_ftsk
|
||||
|
@ -111,7 +111,7 @@ class DetachDisk(task.Task):
|
|||
:param instance: The nova instance.
|
||||
"""
|
||||
super(DetachDisk, self).__init__(
|
||||
'detach_disk', provides='stor_adpt_mappings')
|
||||
name='detach_disk', provides='stor_adpt_mappings')
|
||||
self.instance = instance
|
||||
self.disk_dvr = disk_dvr
|
||||
|
||||
|
@ -131,7 +131,7 @@ class DeleteDisk(task.Task):
|
|||
:param disk_dvr: The DiskAdapter for the VM.
|
||||
"""
|
||||
super(DeleteDisk, self).__init__(
|
||||
'delete_disk', requires=['stor_adpt_mappings'])
|
||||
name='delete_disk', requires=['stor_adpt_mappings'])
|
||||
self.disk_dvr = disk_dvr
|
||||
|
||||
def execute(self, stor_adpt_mappings):
|
||||
|
@ -158,7 +158,7 @@ class CreateAndConnectCfgDrive(task.Task):
|
|||
VM.
|
||||
"""
|
||||
super(CreateAndConnectCfgDrive, self).__init__(
|
||||
instance, 'cfg_drive', requires=['mgmt_cna'])
|
||||
name='cfg_drive', requires=['mgmt_cna'])
|
||||
self.adapter = adapter
|
||||
self.instance = instance
|
||||
self.injected_files = injected_files
|
||||
|
@ -197,7 +197,7 @@ class DeleteVOpt(task.Task):
|
|||
:param instance: The nova instance.
|
||||
:param stg_ftsk: FeedTask to defer storage connectivity operations.
|
||||
"""
|
||||
super(DeleteVOpt, self).__init__(instance, 'vopt_delete')
|
||||
super(DeleteVOpt, self).__init__(name='vopt_delete')
|
||||
self.adapter = adapter
|
||||
self.instance = instance
|
||||
self.stg_ftsk = stg_ftsk
|
||||
|
|
|
@ -48,7 +48,7 @@ class Create(task.Task):
|
|||
:param instance: The nova instance.
|
||||
:param stg_ftsk: FeedTask to defer storage connectivity operations.
|
||||
"""
|
||||
super(Create, self).__init__('crt_vm', provides='lpar_wrap')
|
||||
super(Create, self).__init__(name='crt_vm', provides='lpar_wrap')
|
||||
self.instance = instance
|
||||
self.adapter = adapter
|
||||
self.host_wrapper = host_wrapper
|
||||
|
@ -74,7 +74,7 @@ class PowerOn(task.Task):
|
|||
:param adapter: The pypowervm adapter.
|
||||
:param instance: The nova instance.
|
||||
"""
|
||||
super(PowerOn, self).__init__('pwr_vm')
|
||||
super(PowerOn, self).__init__(name='pwr_vm')
|
||||
self.adapter = adapter
|
||||
self.instance = instance
|
||||
|
||||
|
@ -107,7 +107,7 @@ class PowerOff(task.Task):
|
|||
:param instance: The nova instance.
|
||||
:param force_immediate: Boolean. Perform a VSP hard power off.
|
||||
"""
|
||||
super(PowerOff, self).__init__('pwr_off_vm')
|
||||
super(PowerOff, self).__init__(name='pwr_off_vm')
|
||||
self.instance = instance
|
||||
self.adapter = adapter
|
||||
self.force_immediate = force_immediate
|
||||
|
@ -126,7 +126,7 @@ class Delete(task.Task):
|
|||
:param adapter: The adapter for the pypowervm API.
|
||||
:param instance: The nova instance.
|
||||
"""
|
||||
super(Delete, self).__init__('dlt_vm')
|
||||
super(Delete, self).__init__(name='dlt_vm')
|
||||
self.adapter = adapter
|
||||
self.instance = instance
|
||||
|
||||
|
|
Loading…
Reference in New Issue