Autospeccing: powervm
This adds autospeccing throughout the base powervm files. It only covers a subset of mock.patch decorators, but is progress towards the eventual goal of autospeccing throughout the project. Change-Id: I479e24a56ca7370432dc6a117b2b82953d188767
This commit is contained in:
parent
6f195f9451
commit
5f1c2c9277
|
@ -107,9 +107,10 @@ class TestPowerVMDriverInit(test.NoDBTestCase):
|
|||
self.assertFalse(test_driver.capabilities['has_imagecache'])
|
||||
self.assertEqual(9, len(test_driver.capabilities))
|
||||
|
||||
@mock.patch('nova_powervm.virt.powervm.event.PowerVMNovaEventHandler')
|
||||
@mock.patch('pypowervm.adapter.Adapter')
|
||||
@mock.patch('pypowervm.adapter.Session')
|
||||
@mock.patch('nova_powervm.virt.powervm.event.PowerVMNovaEventHandler',
|
||||
autospec=True)
|
||||
@mock.patch('pypowervm.adapter.Adapter', autospec=True)
|
||||
@mock.patch('pypowervm.adapter.Session', autospec=True)
|
||||
def test_get_adapter(self, mock_session, mock_adapter, mock_evt_handler):
|
||||
# Set up the mocks.
|
||||
mock_evt_listener = (mock_session.return_value.get_event_listener.
|
||||
|
@ -205,7 +206,8 @@ class TestPowerVMDriver(test.NoDBTestCase):
|
|||
self.assertTrue(
|
||||
self.drv.session.get_event_listener.return_value.shutdown.called)
|
||||
|
||||
@mock.patch('nova_powervm.virt.powervm.volume.get_iscsi_initiator')
|
||||
@mock.patch('nova_powervm.virt.powervm.volume.get_iscsi_initiator',
|
||||
autospec=True)
|
||||
def test_get_volume_connector(self, mock_initiator):
|
||||
"""Tests that a volume connector can be built."""
|
||||
mock_initiator.return_value = 'iscsi_initiator'
|
||||
|
@ -228,9 +230,10 @@ class TestPowerVMDriver(test.NoDBTestCase):
|
|||
# The local disk driver has been mocked, so we just compare the name
|
||||
self.assertIn('LocalStorage()', str(self.drv.disk_dvr))
|
||||
|
||||
@mock.patch('nova_powervm.virt.powervm.nvram.manager.NvramManager')
|
||||
@mock.patch('oslo_utils.importutils.import_object')
|
||||
@mock.patch('nova.utils.spawn')
|
||||
@mock.patch('nova_powervm.virt.powervm.nvram.manager.NvramManager',
|
||||
autospec=True)
|
||||
@mock.patch('oslo_utils.importutils.import_object', autospec=True)
|
||||
@mock.patch('nova.utils.spawn', autospec=True)
|
||||
def test_setup_rebuild_store(self, mock_spawn, mock_import, mock_mgr):
|
||||
self.flags(nvram_store='NoNe', group='powervm')
|
||||
self.drv._setup_rebuild_store()
|
||||
|
@ -245,8 +248,8 @@ class TestPowerVMDriver(test.NoDBTestCase):
|
|||
self.assertTrue(mock_spawn.called)
|
||||
self.assertIsNotNone(self.drv.store_api)
|
||||
|
||||
@mock.patch.object(vm, 'get_lpars')
|
||||
@mock.patch.object(vm, 'get_instance')
|
||||
@mock.patch.object(vm, 'get_lpars', autospec=True)
|
||||
@mock.patch.object(vm, 'get_instance', autospec=True)
|
||||
def test_nvram_host_startup(self, mock_get_inst, mock_get_lpars):
|
||||
|
||||
mock_lpar_wrapper = mock.Mock()
|
||||
|
@ -263,9 +266,10 @@ class TestPowerVMDriver(test.NoDBTestCase):
|
|||
self.drv.nvram_mgr.store.assert_has_calls(
|
||||
[mock.call(powervm.TEST_INST1), mock.call(powervm.TEST_INST2)])
|
||||
|
||||
@mock.patch('nova_powervm.virt.powervm.vm.get_pvm_uuid')
|
||||
@mock.patch('nova_powervm.virt.powervm.vm.get_vm_qp')
|
||||
@mock.patch('nova_powervm.virt.powervm.vm._translate_vm_state')
|
||||
@mock.patch('nova_powervm.virt.powervm.vm.get_pvm_uuid', autospec=True)
|
||||
@mock.patch('nova_powervm.virt.powervm.vm.get_vm_qp', autospec=True)
|
||||
@mock.patch('nova_powervm.virt.powervm.vm._translate_vm_state',
|
||||
autospec=True)
|
||||
def test_get_info(self, mock_tx_state, mock_qp, mock_uuid):
|
||||
mock_tx_state.return_value = 'fake-state'
|
||||
self.assertEqual(hardware.InstanceInfo('fake-state'),
|
||||
|
@ -850,8 +854,9 @@ class TestPowerVMDriver(test.NoDBTestCase):
|
|||
# (but maybe failed on another).
|
||||
self.assertTrue(self.vol_drv.disconnect_volume.called)
|
||||
|
||||
@mock.patch('nova.block_device.get_root_bdm')
|
||||
@mock.patch('nova.virt.driver.block_device_info_get_mapping')
|
||||
@mock.patch('nova.block_device.get_root_bdm', autospec=True)
|
||||
@mock.patch('nova.virt.driver.block_device_info_get_mapping',
|
||||
autospec=True)
|
||||
def test_is_booted_from_volume(self, mock_get_mapping, mock_get_root_bdm):
|
||||
block_device_info = self._fake_bdms()
|
||||
ret = self.drv._is_booted_from_volume(block_device_info)
|
||||
|
@ -908,8 +913,10 @@ class TestPowerVMDriver(test.NoDBTestCase):
|
|||
pvm_const.XAG.VIO_SMAP,
|
||||
pvm_const.XAG.VIO_FMAP}, set(xag))
|
||||
|
||||
@mock.patch('nova_powervm.virt.powervm.tasks.storage.ConnectVolume')
|
||||
@mock.patch('nova_powervm.virt.powervm.tasks.storage.SaveBDM')
|
||||
@mock.patch('nova_powervm.virt.powervm.tasks.storage.ConnectVolume',
|
||||
autospec=True)
|
||||
@mock.patch('nova_powervm.virt.powervm.tasks.storage.SaveBDM',
|
||||
autospec=True)
|
||||
def test_add_vol_conn_task(self, mock_save_bdm, mock_conn_vol):
|
||||
bdm1, bdm2, vol_drv1, vol_drv2 = [mock.Mock()] * 4
|
||||
flow = mock.Mock()
|
||||
|
@ -930,7 +937,8 @@ class TestPowerVMDriver(test.NoDBTestCase):
|
|||
mock.call('conn_vol1'), mock.call('save_bdm1'),
|
||||
mock.call('conn_vol2'), mock.call('save_bdm2')])
|
||||
|
||||
@mock.patch('nova_powervm.virt.powervm.tasks.storage.DisconnectVolume')
|
||||
@mock.patch('nova_powervm.virt.powervm.tasks.storage.DisconnectVolume',
|
||||
autospec=True)
|
||||
def test_add_vol_disconn_task(self, mock_disconn_vol):
|
||||
vol_drv1, vol_drv2 = [mock.Mock()] * 2
|
||||
flow = mock.Mock()
|
||||
|
@ -1151,8 +1159,8 @@ class TestPowerVMDriver(test.NoDBTestCase):
|
|||
self.assertFalse(self.drv.nvram_mgr.remove.called)
|
||||
self.assertFalse(mock_bld_slot_mgr.return_value.delete.called)
|
||||
|
||||
@mock.patch('nova_powervm.virt.powervm.vm.get_pvm_uuid')
|
||||
@mock.patch('nova_powervm.virt.powervm.vm.get_vm_qp')
|
||||
@mock.patch('nova_powervm.virt.powervm.vm.get_pvm_uuid', autospec=True)
|
||||
@mock.patch('nova_powervm.virt.powervm.vm.get_vm_qp', autospec=True)
|
||||
def test_destroy(self, mock_getqp, mock_getuuid):
|
||||
"""Validates the basic PowerVM destroy."""
|
||||
# BDMs
|
||||
|
@ -1190,7 +1198,7 @@ class TestPowerVMDriver(test.NoDBTestCase):
|
|||
'context', self.inst, block_device_info=mock_bdms,
|
||||
destroy_disks=True, shutdown=True, network_info=[])
|
||||
|
||||
@mock.patch('nova_powervm.virt.powervm.slot.build_slot_mgr')
|
||||
@mock.patch('nova_powervm.virt.powervm.slot.build_slot_mgr', autospec=True)
|
||||
def test_attach_volume(self, mock_bld_slot_mgr):
|
||||
"""Validates the basic PowerVM attach volume."""
|
||||
# BDMs
|
||||
|
@ -1209,8 +1217,8 @@ class TestPowerVMDriver(test.NoDBTestCase):
|
|||
mock_bld_slot_mgr.return_value.save.assert_called_once_with()
|
||||
self.assertTrue(mock_save.called)
|
||||
|
||||
@mock.patch('nova_powervm.virt.powervm.vm.instance_exists')
|
||||
@mock.patch('nova_powervm.virt.powervm.slot.build_slot_mgr')
|
||||
@mock.patch('nova_powervm.virt.powervm.vm.instance_exists', autospec=True)
|
||||
@mock.patch('nova_powervm.virt.powervm.slot.build_slot_mgr', autospec=True)
|
||||
def test_detach_volume(self, mock_bld_slot_mgr, mock_inst_exists):
|
||||
"""Validates the basic PowerVM detach volume."""
|
||||
# Mock that the instance exists for the first test, then not.
|
||||
|
@ -1291,7 +1299,7 @@ class TestPowerVMDriver(test.NoDBTestCase):
|
|||
# Validate the rollbacks were called.
|
||||
self.assertEqual(2, self.vol_drv.connect_volume.call_count)
|
||||
|
||||
@mock.patch('nova_powervm.virt.powervm.slot.build_slot_mgr')
|
||||
@mock.patch('nova_powervm.virt.powervm.slot.build_slot_mgr', autospec=True)
|
||||
def test_migrate_disk_and_power_off(self, mock_bld_slot_mgr):
|
||||
"""Validates the PowerVM driver migrate / resize operation."""
|
||||
# Set up the mocks to the migrate / resize operation.
|
||||
|
@ -1342,7 +1350,7 @@ class TestPowerVMDriver(test.NoDBTestCase):
|
|||
taskflow_fix.tasks_added[4].slot_mgr)
|
||||
self.san_lpar_name.assert_called_with('migrate_' + self.inst.name)
|
||||
|
||||
@mock.patch('nova_powervm.virt.powervm.slot.build_slot_mgr')
|
||||
@mock.patch('nova_powervm.virt.powervm.slot.build_slot_mgr', autospec=True)
|
||||
def test_finish_migration(self, mock_bld_slot_mgr):
|
||||
mock_bdms = self._fake_bdms()
|
||||
mig = objects.Migration(**powervm.TEST_MIGRATION)
|
||||
|
@ -1430,9 +1438,9 @@ class TestPowerVMDriver(test.NoDBTestCase):
|
|||
mock_bld_slot_mgr.assert_not_called()
|
||||
self.san_lpar_name.assert_called_with('resize_' + self.inst.name)
|
||||
|
||||
@mock.patch('nova_powervm.virt.powervm.vm.power_on')
|
||||
@mock.patch('nova_powervm.virt.powervm.vm.update')
|
||||
@mock.patch('nova_powervm.virt.powervm.vm.power_off')
|
||||
@mock.patch('nova_powervm.virt.powervm.vm.power_on', autospec=True)
|
||||
@mock.patch('nova_powervm.virt.powervm.vm.update', autospec=True)
|
||||
@mock.patch('nova_powervm.virt.powervm.vm.power_off', autospec=True)
|
||||
def test_finish_revert_migration(self, mock_off, mock_update, mock_on):
|
||||
"""Validates that the finish revert migration works."""
|
||||
mock_instance = mock.Mock()
|
||||
|
@ -1446,9 +1454,9 @@ class TestPowerVMDriver(test.NoDBTestCase):
|
|||
self.apt, self.drv.host_wrapper, mock_instance)
|
||||
mock_on.assert_called_once_with(self.apt, mock_instance)
|
||||
|
||||
@mock.patch('nova_powervm.virt.powervm.vm.power_on')
|
||||
@mock.patch('nova_powervm.virt.powervm.vm.update')
|
||||
@mock.patch('nova_powervm.virt.powervm.vm.power_off')
|
||||
@mock.patch('nova_powervm.virt.powervm.vm.power_on', autospec=True)
|
||||
@mock.patch('nova_powervm.virt.powervm.vm.update', autospec=True)
|
||||
@mock.patch('nova_powervm.virt.powervm.vm.power_off', autospec=True)
|
||||
def test_finish_revert_migration_no_power_on(self, mock_off, mock_update,
|
||||
mock_on):
|
||||
"""Validates that the finish revert migration works, no power_on."""
|
||||
|
@ -1462,10 +1470,10 @@ class TestPowerVMDriver(test.NoDBTestCase):
|
|||
mock_off.assert_called_once_with(self.apt, mock_instance)
|
||||
mock_update.assert_called_once_with(
|
||||
self.apt, self.drv.host_wrapper, mock_instance)
|
||||
mock_on.assert_not_called()
|
||||
self.assertEqual(0, mock_on.call_count)
|
||||
|
||||
@mock.patch('nova_powervm.virt.powervm.vm.power_off')
|
||||
@mock.patch('nova_powervm.virt.powervm.vm.power_on')
|
||||
@mock.patch('nova_powervm.virt.powervm.vm.power_off', autospec=True)
|
||||
@mock.patch('nova_powervm.virt.powervm.vm.power_on', autospec=True)
|
||||
def test_rescue(self, mock_pwron, mock_pwroff):
|
||||
"""Validates the PowerVM driver rescue operation."""
|
||||
with mock.patch.object(self.drv, 'disk_dvr') as mock_disk_dvr:
|
||||
|
@ -1481,8 +1489,8 @@ class TestPowerVMDriver(test.NoDBTestCase):
|
|||
self.assertEqual('PowerOn(bootmode=sms)',
|
||||
str(mock_pwron.call_args[1]['opts']))
|
||||
|
||||
@mock.patch('nova_powervm.virt.powervm.vm.power_off')
|
||||
@mock.patch('nova_powervm.virt.powervm.vm.power_on')
|
||||
@mock.patch('nova_powervm.virt.powervm.vm.power_off', autospec=True)
|
||||
@mock.patch('nova_powervm.virt.powervm.vm.power_on', autospec=True)
|
||||
def test_unrescue(self, mock_pwron, mock_pwroff):
|
||||
"""Validates the PowerVM driver rescue operation."""
|
||||
with mock.patch.object(self.drv, 'disk_dvr') as mock_disk_dvr:
|
||||
|
@ -1495,7 +1503,7 @@ class TestPowerVMDriver(test.NoDBTestCase):
|
|||
self.assertTrue(mock_disk_dvr.delete_disks.called)
|
||||
mock_pwron.assert_called_once_with(self.apt, self.inst, opts=None)
|
||||
|
||||
@mock.patch('nova_powervm.virt.powervm.driver.LOG')
|
||||
@mock.patch('nova_powervm.virt.powervm.driver.LOG', autospec=True)
|
||||
def test_log_op(self, mock_log):
|
||||
"""Validates the log_operations."""
|
||||
self.drv._log_operation('fake_op', self.inst)
|
||||
|
@ -1567,7 +1575,7 @@ class TestPowerVMDriver(test.NoDBTestCase):
|
|||
mock_bld_slot_mgr.return_value.save.assert_called_once_with()
|
||||
self.assertEqual(0, mock_plug_rmc_vif.call_count)
|
||||
|
||||
@mock.patch('nova_powervm.virt.powervm.tasks.vm.Get')
|
||||
@mock.patch('nova_powervm.virt.powervm.tasks.vm.Get', autospec=True)
|
||||
def test_plug_vif_failures(self, mock_vm):
|
||||
# Test instance not found handling
|
||||
mock_vm.execute.side_effect = exc.InstanceNotFound(
|
||||
|
@ -1584,10 +1592,11 @@ class TestPowerVMDriver(test.NoDBTestCase):
|
|||
self.assertRaises(exc.VirtualInterfacePlugException,
|
||||
self.drv.plug_vifs, self.inst, {})
|
||||
|
||||
@mock.patch('nova_powervm.virt.powervm.vif.unplug')
|
||||
@mock.patch('nova_powervm.virt.powervm.vm.get_cnas')
|
||||
@mock.patch('nova_powervm.virt.powervm.vm.get_instance_wrapper')
|
||||
@mock.patch('nova_powervm.virt.powervm.slot.build_slot_mgr')
|
||||
@mock.patch('nova_powervm.virt.powervm.vif.unplug', autospec=True)
|
||||
@mock.patch('nova_powervm.virt.powervm.vm.get_cnas', autospec=True)
|
||||
@mock.patch('nova_powervm.virt.powervm.vm.get_instance_wrapper',
|
||||
autospec=True)
|
||||
@mock.patch('nova_powervm.virt.powervm.slot.build_slot_mgr', autospec=True)
|
||||
def test_unplug_vifs(self, mock_bld_slot_mgr, mock_wrap, mock_vm_get,
|
||||
mock_unplug_vif):
|
||||
# Mock up the CNA response
|
||||
|
@ -1623,7 +1632,8 @@ class TestPowerVMDriver(test.NoDBTestCase):
|
|||
cna_w_list=cnas) for net_inf in net_info])
|
||||
mock_bld_slot_mgr.return_value.save.assert_called_once_with()
|
||||
|
||||
@mock.patch('nova_powervm.virt.powervm.tasks.vm.Get.execute')
|
||||
@mock.patch('nova_powervm.virt.powervm.tasks.vm.Get.execute',
|
||||
autospec=True)
|
||||
def test_unplug_vif_failures(self, mock_vm):
|
||||
# Test instance not found handling
|
||||
mock_vm.side_effect = exc.InstanceNotFound(
|
||||
|
@ -1633,7 +1643,8 @@ class TestPowerVMDriver(test.NoDBTestCase):
|
|||
self.drv.unplug_vifs(self.inst, {})
|
||||
self.assertEqual(1, mock_vm.call_count)
|
||||
|
||||
@mock.patch('nova_powervm.virt.powervm.vm.get_instance_wrapper')
|
||||
@mock.patch('nova_powervm.virt.powervm.vm.get_instance_wrapper',
|
||||
autospec=True)
|
||||
def test_unplug_vif_failures_httperror(self, mock_wrap):
|
||||
# Test instance not found handling
|
||||
mock_wrap.side_effect = exc.InstanceNotFound(
|
||||
|
@ -1655,8 +1666,8 @@ class TestPowerVMDriver(test.NoDBTestCase):
|
|||
def test_get_host_ip_addr(self):
|
||||
self.assertEqual(self.drv.get_host_ip_addr(), '127.0.0.1')
|
||||
|
||||
@mock.patch('nova.virt.powervm_ext.driver.LOG.warning')
|
||||
@mock.patch('nova.compute.utils.get_machine_ips')
|
||||
@mock.patch('nova.virt.powervm_ext.driver.LOG.warning', autospec=True)
|
||||
@mock.patch('nova.compute.utils.get_machine_ips', autospec=True)
|
||||
def test_get_host_ip_addr_failure(self, mock_ips, mock_log):
|
||||
mock_ips.return_value = ['1.1.1.1']
|
||||
self.drv.get_host_ip_addr()
|
||||
|
@ -1679,7 +1690,7 @@ class TestPowerVMDriver(test.NoDBTestCase):
|
|||
self.assertTrue(
|
||||
self.drv.disk_dvr.check_instance_shared_storage_cleanup.called)
|
||||
|
||||
@mock.patch('nova_powervm.virt.powervm.vm.reboot')
|
||||
@mock.patch('nova_powervm.virt.powervm.vm.reboot', autospec=True)
|
||||
def test_reboot(self, mock_reboot):
|
||||
inst = mock.Mock()
|
||||
self.drv.reboot('context', inst, 'network_info', 'SOFT')
|
||||
|
@ -1758,7 +1769,8 @@ class TestPowerVMDriver(test.NoDBTestCase):
|
|||
self.drv.snapshot, 'context', self.inst, 'image_id',
|
||||
'update_task_state')
|
||||
|
||||
@mock.patch('nova_powervm.virt.powervm.live_migration.LiveMigrationDest')
|
||||
@mock.patch('nova_powervm.virt.powervm.live_migration.LiveMigrationDest',
|
||||
autospec=True)
|
||||
def test_can_migrate_dest(self, mock_lpm):
|
||||
mock_lpm.return_value.check_destination.return_value = 'dest_data'
|
||||
dest_data = self.drv.check_can_live_migrate_destination(
|
||||
|
@ -1769,7 +1781,8 @@ class TestPowerVMDriver(test.NoDBTestCase):
|
|||
self.drv.cleanup_live_migration_destination_check(
|
||||
'context', 'dest_data')
|
||||
|
||||
@mock.patch('nova_powervm.virt.powervm.live_migration.LiveMigrationSrc')
|
||||
@mock.patch('nova_powervm.virt.powervm.live_migration.LiveMigrationSrc',
|
||||
autospec=True)
|
||||
def test_can_live_mig_src(self, mock_lpm):
|
||||
mock_lpm.return_value.check_source.return_value = (
|
||||
'src_data')
|
||||
|
@ -1863,7 +1876,7 @@ class TestPowerVMDriver(test.NoDBTestCase):
|
|||
self.lpm.post_live_migration_at_source.assert_called_once_with(
|
||||
'network_info')
|
||||
|
||||
@mock.patch('nova_powervm.virt.powervm.vm.power_off')
|
||||
@mock.patch('nova_powervm.virt.powervm.vm.power_off', autospec=True)
|
||||
def test_power_off(self, mock_power_off):
|
||||
self.drv.power_off(self.inst)
|
||||
mock_power_off.assert_called_once_with(
|
||||
|
@ -1884,7 +1897,7 @@ class TestPowerVMDriver(test.NoDBTestCase):
|
|||
'context', self.lpm_inst, block_device_info=None,
|
||||
destroy_disks=False, shutdown=False)
|
||||
|
||||
@mock.patch('nova_powervm.virt.powervm.vm.rename')
|
||||
@mock.patch('nova_powervm.virt.powervm.vm.rename', autospec=True)
|
||||
def test_confirm_migration_same_host(self, mock_rename):
|
||||
mock_mig = mock.Mock(source_compute='host1', dest_compute='host1')
|
||||
self.drv.confirm_migration('context', mock_mig, self.lpm_inst,
|
||||
|
@ -1898,7 +1911,8 @@ class TestPowerVMDriver(test.NoDBTestCase):
|
|||
self.lpm.post_live_migration_at_destination.assert_called_once_with(
|
||||
'network_info', [])
|
||||
|
||||
@mock.patch('pypowervm.tasks.memory.calculate_memory_overhead_on_host')
|
||||
@mock.patch('pypowervm.tasks.memory.calculate_memory_overhead_on_host',
|
||||
autospec=True)
|
||||
def test_estimate_instance_overhead(self, mock_calc_over):
|
||||
mock_calc_over.return_value = ('2048', '96')
|
||||
|
||||
|
@ -1911,7 +1925,7 @@ class TestPowerVMDriver(test.NoDBTestCase):
|
|||
mock_calc_over.reset_mock()
|
||||
overhead = self.drv.estimate_instance_overhead(inst_info)
|
||||
self.assertEqual({'memory_mb': '2048'}, overhead)
|
||||
mock_calc_over.assert_not_called()
|
||||
self.assertEqual(0, mock_calc_over.call_count)
|
||||
|
||||
# Reset the cache every time from now on
|
||||
self.drv._inst_overhead_cache = {}
|
||||
|
@ -1988,7 +2002,7 @@ class TestPowerVMDriver(test.NoDBTestCase):
|
|||
candeallocate = self.drv.deallocate_networks_on_reschedule(mock.Mock())
|
||||
self.assertTrue(candeallocate)
|
||||
|
||||
@mock.patch('pypowervm.tasks.cna.find_orphaned_trunks')
|
||||
@mock.patch('pypowervm.tasks.cna.find_orphaned_trunks', autospec=True)
|
||||
def test_cleanup_orphan_adapters(self, mock_find_orphans):
|
||||
mock_orphan = mock.MagicMock()
|
||||
mock_find_orphans.return_value = [mock_orphan]
|
||||
|
|
|
@ -25,16 +25,16 @@ from nova_powervm.virt.powervm import event
|
|||
|
||||
|
||||
class TestGetInstance(test.NoDBTestCase):
|
||||
@mock.patch('nova.context.get_admin_context')
|
||||
@mock.patch('nova_powervm.virt.powervm.vm.get_instance')
|
||||
@mock.patch('nova.context.get_admin_context', autospec=True)
|
||||
@mock.patch('nova_powervm.virt.powervm.vm.get_instance', autospec=True)
|
||||
def test_get_instance(self, mock_get_inst, mock_get_context):
|
||||
# If instance provided, vm.get_instance not called
|
||||
self.assertEqual('inst', event._get_instance('inst', 'uuid'))
|
||||
mock_get_inst.assert_not_called()
|
||||
self.assertEqual(0, mock_get_inst.call_count)
|
||||
# Note that we can only guarantee get_admin_context wasn't called
|
||||
# because _get_instance is mocked everywhere else in this suite.
|
||||
# Otherwise it could run from another test case executing in parallel.
|
||||
mock_get_context.assert_not_called()
|
||||
self.assertEqual(0, mock_get_context.call_count)
|
||||
|
||||
# If instance not provided, vm.get_instance is called
|
||||
mock_get_inst.return_value = 'inst2'
|
||||
|
@ -59,7 +59,7 @@ class TestPowerVMNovaEventHandler(test.NoDBTestCase):
|
|||
self.mock_driver = mock.Mock()
|
||||
self.handler = event.PowerVMNovaEventHandler(self.mock_driver)
|
||||
|
||||
@mock.patch('nova_powervm.virt.powervm.event._get_instance')
|
||||
@mock.patch('nova_powervm.virt.powervm.event._get_instance', autospec=True)
|
||||
def test_get_inst_uuid(self, mock_get_instance):
|
||||
fake_inst1 = mock.Mock(uuid='uuid1')
|
||||
fake_inst2 = mock.Mock(uuid='uuid2')
|
||||
|
@ -86,14 +86,14 @@ class TestPowerVMNovaEventHandler(test.NoDBTestCase):
|
|||
[mock.call(fake_inst1, 'fake_pvm_uuid1'),
|
||||
mock.call(fake_inst2, 'fake_pvm_uuid2')])
|
||||
|
||||
@mock.patch('nova_powervm.virt.powervm.event._get_instance')
|
||||
@mock.patch('nova_powervm.virt.powervm.event._get_instance', autospec=True)
|
||||
def test_handle_inst_event(self, mock_get_instance):
|
||||
# If no event we care about, or NVRAM but no nvram_mgr, nothing happens
|
||||
self.mock_driver.nvram_mgr = None
|
||||
for dets in ([], ['foo', 'bar', 'baz'], ['NVRAM']):
|
||||
self.assertEqual('inst', self.handler._handle_inst_event(
|
||||
'inst', 'uuid', dets))
|
||||
mock_get_instance.assert_not_called()
|
||||
self.assertEqual(0, mock_get_instance.call_count)
|
||||
self.mock_lceh_process.assert_not_called()
|
||||
|
||||
self.mock_driver.nvram_mgr = mock.Mock()
|
||||
|
@ -101,7 +101,7 @@ class TestPowerVMNovaEventHandler(test.NoDBTestCase):
|
|||
# PartitionState only: no NVRAM handling, and inst is passed through.
|
||||
self.assertEqual('inst', self.handler._handle_inst_event(
|
||||
'inst', 'uuid', ['foo', 'PartitionState', 'bar']))
|
||||
mock_get_instance.assert_not_called()
|
||||
self.assertEqual(0, mock_get_instance.call_count)
|
||||
self.mock_driver.nvram_mgr.store.assert_not_called()
|
||||
self.mock_lceh_process.assert_called_once_with('inst', 'uuid')
|
||||
|
||||
|
@ -218,7 +218,7 @@ class TestPowerVMNovaEventHandler(test.NoDBTestCase):
|
|||
# inst1 pulled from the cache based on uuid1
|
||||
mock.call('inst1', 'uuid1', ['blah', 'PartitionState'])])
|
||||
|
||||
@mock.patch('nova_powervm.virt.powervm.event._get_instance')
|
||||
@mock.patch('nova_powervm.virt.powervm.event._get_instance', autospec=True)
|
||||
@mock.patch('pypowervm.util.get_req_path_uuid', autospec=True)
|
||||
def test_uuid_cache(self, mock_get_rpu, mock_get_instance):
|
||||
deluri = pvm_evt.EventType.DELETE_URI
|
||||
|
@ -268,7 +268,7 @@ class TestPowerVMNovaEventHandler(test.NoDBTestCase):
|
|||
|
||||
# Make sure a delete to a non-cached UUID doesn't blow up
|
||||
self.handler.process([events[7]])
|
||||
mock_get_instance.assert_not_called()
|
||||
self.assertEqual(0, mock_get_instance.call_count)
|
||||
|
||||
mock_get_rpu.reset_mock()
|
||||
mock_get_instance.reset_mock()
|
||||
|
@ -279,7 +279,7 @@ class TestPowerVMNovaEventHandler(test.NoDBTestCase):
|
|||
self.handler.process(clear_events)
|
||||
self.assertEqual(dict(), self.handler._uuid_cache)
|
||||
self.assertEqual(0, mock_get_rpu.call_count)
|
||||
mock_get_instance.assert_not_called()
|
||||
self.assertEqual(0, mock_get_instance.call_count)
|
||||
|
||||
|
||||
class TestPowerVMLifecycleEventHandler(test.NoDBTestCase):
|
||||
|
@ -288,10 +288,10 @@ class TestPowerVMLifecycleEventHandler(test.NoDBTestCase):
|
|||
self.mock_driver = mock.MagicMock()
|
||||
self.handler = event.PowerVMLifecycleEventHandler(self.mock_driver)
|
||||
|
||||
@mock.patch('nova_powervm.virt.powervm.vm.get_vm_qp')
|
||||
@mock.patch('nova_powervm.virt.powervm.event._get_instance')
|
||||
@mock.patch('nova_powervm.virt.powervm.vm.translate_event')
|
||||
@mock.patch('nova.virt.event.LifecycleEvent')
|
||||
@mock.patch('nova_powervm.virt.powervm.vm.get_vm_qp', autospec=True)
|
||||
@mock.patch('nova_powervm.virt.powervm.event._get_instance', autospec=True)
|
||||
@mock.patch('nova_powervm.virt.powervm.vm.translate_event', autospec=True)
|
||||
@mock.patch('nova.virt.event.LifecycleEvent', autospec=True)
|
||||
def test_emit_event(self, mock_lce, mock_tx_evt, mock_get_inst, mock_qp):
|
||||
def assert_qp():
|
||||
mock_qp.assert_called_once_with(
|
||||
|
@ -306,9 +306,9 @@ class TestPowerVMLifecycleEventHandler(test.NoDBTestCase):
|
|||
mock_qp.side_effect = exception.InstanceNotFound(instance_id='uuid')
|
||||
self.handler._emit_event('uuid', None)
|
||||
assert_qp()
|
||||
mock_get_inst.assert_not_called()
|
||||
mock_tx_evt.assert_not_called()
|
||||
mock_lce.assert_not_called()
|
||||
self.assertEqual(0, mock_get_inst.call_count)
|
||||
self.assertEqual(0, mock_tx_evt.call_count)
|
||||
self.assertEqual(0, mock_lce.call_count)
|
||||
self.mock_driver.emit_event.assert_not_called()
|
||||
|
||||
# Let get_vm_qp return its usual mock from now on
|
||||
|
@ -319,8 +319,8 @@ class TestPowerVMLifecycleEventHandler(test.NoDBTestCase):
|
|||
self.handler._emit_event('uuid', 'inst')
|
||||
assert_qp()
|
||||
assert_get_inst()
|
||||
mock_tx_evt.assert_not_called()
|
||||
mock_lce.assert_not_called()
|
||||
self.assertEqual(0, mock_tx_evt.call_count)
|
||||
self.assertEqual(0, mock_lce.call_count)
|
||||
self.mock_driver.emit_event.assert_not_called()
|
||||
|
||||
# Ignore if task_state isn't one we care about
|
||||
|
@ -329,8 +329,8 @@ class TestPowerVMLifecycleEventHandler(test.NoDBTestCase):
|
|||
self.handler._emit_event('uuid', 'inst')
|
||||
assert_qp()
|
||||
assert_get_inst()
|
||||
mock_tx_evt.assert_not_called()
|
||||
mock_lce.assert_not_called()
|
||||
self.assertEqual(0, mock_tx_evt.call_count)
|
||||
self.assertEqual(0, mock_lce.call_count)
|
||||
self.mock_driver.emit_event.assert_not_called()
|
||||
|
||||
# Task state we care about from now on
|
||||
|
@ -366,7 +366,7 @@ class TestPowerVMLifecycleEventHandler(test.NoDBTestCase):
|
|||
self.assertEqual({'uuid2': 'thread2'},
|
||||
self.handler._delayed_event_threads)
|
||||
|
||||
@mock.patch('eventlet.greenthread.spawn_after')
|
||||
@mock.patch('eventlet.greenthread.spawn_after', autospec=True)
|
||||
def test_process(self, mock_spawn):
|
||||
thread1 = mock.Mock()
|
||||
thread2 = mock.Mock()
|
||||
|
|
|
@ -29,9 +29,9 @@ else:
|
|||
|
||||
class TestImage(test.NoDBTestCase):
|
||||
|
||||
@mock.patch('nova.utils.temporary_chown')
|
||||
@mock.patch(_BUILTIN + '.open')
|
||||
@mock.patch('nova.image.api.API')
|
||||
@mock.patch('nova.utils.temporary_chown', autospec=True)
|
||||
@mock.patch(_BUILTIN + '.open', autospec=True)
|
||||
@mock.patch('nova.image.api.API', autospec=True)
|
||||
def test_stream_blockdev_to_glance(self, mock_api, mock_open, mock_chown):
|
||||
mock_open.return_value.__enter__.return_value = 'mock_stream'
|
||||
image.stream_blockdev_to_glance('context', mock_api, 'image_id',
|
||||
|
@ -41,7 +41,7 @@ class TestImage(test.NoDBTestCase):
|
|||
mock_api.update.assert_called_with('context', 'image_id', 'metadata',
|
||||
'mock_stream')
|
||||
|
||||
@mock.patch('nova.image.api.API')
|
||||
@mock.patch('nova.image.api.API', autospec=True)
|
||||
def test_snapshot_metadata(self, mock_api):
|
||||
mock_api.get.return_value = {'name': 'image_name'}
|
||||
mock_instance = mock.Mock()
|
||||
|
|
|
@ -68,10 +68,13 @@ class TestLPM(test.NoDBTestCase):
|
|||
# Short path to the host's migration_data
|
||||
self.host_mig_data = self.drv.host_wrapper.migration_data
|
||||
|
||||
@mock.patch('pypowervm.tasks.storage.ScrubOrphanStorageForLpar')
|
||||
@mock.patch('nova_powervm.virt.powervm.media.ConfigDrivePowerVM')
|
||||
@mock.patch('nova_powervm.virt.powervm.vm.get_instance_wrapper')
|
||||
@mock.patch('pypowervm.tasks.vterm.close_vterm')
|
||||
@mock.patch('pypowervm.tasks.storage.ScrubOrphanStorageForLpar',
|
||||
autospec=True)
|
||||
@mock.patch('nova_powervm.virt.powervm.media.ConfigDrivePowerVM',
|
||||
autospec=True)
|
||||
@mock.patch('nova_powervm.virt.powervm.vm.get_instance_wrapper',
|
||||
autospec=True)
|
||||
@mock.patch('pypowervm.tasks.vterm.close_vterm', autospec=True)
|
||||
def test_lpm_source(self, mock_vterm_close, mock_get_wrap,
|
||||
mock_cd, mock_scrub):
|
||||
self.host_mig_data['active_migrations_supported'] = 4
|
||||
|
@ -152,9 +155,9 @@ class TestLPM(test.NoDBTestCase):
|
|||
self.lpmdst.check_destination, 'context',
|
||||
src_compute_info, dst_compute_info)
|
||||
|
||||
@mock.patch('pypowervm.tasks.storage.ComprehensiveScrub')
|
||||
@mock.patch('pypowervm.tasks.storage.ComprehensiveScrub', autospec=True)
|
||||
@mock.patch('nova_powervm.virt.powervm.vif.'
|
||||
'pre_live_migrate_at_destination')
|
||||
'pre_live_migrate_at_destination', autospec=True)
|
||||
def test_pre_live_mig(self, mock_vif_pre, mock_scrub):
|
||||
vol_drv = mock.MagicMock()
|
||||
network_infos = [{'type': 'pvm_sea'}]
|
||||
|
@ -210,10 +213,11 @@ class TestLPM(test.NoDBTestCase):
|
|||
# Ensure the volume driver was called to clean up the volume.
|
||||
vol_drv.cleanup_volume_at_destination.assert_called_once()
|
||||
|
||||
@mock.patch('pypowervm.tasks.migration.migrate_lpar')
|
||||
@mock.patch('pypowervm.tasks.migration.migrate_lpar', autospec=True)
|
||||
@mock.patch('nova_powervm.virt.powervm.live_migration.LiveMigrationSrc.'
|
||||
'_convert_nl_io_mappings')
|
||||
@mock.patch('nova_powervm.virt.powervm.vif.pre_live_migrate_at_source')
|
||||
'_convert_nl_io_mappings', autospec=True)
|
||||
@mock.patch('nova_powervm.virt.powervm.vif.pre_live_migrate_at_source',
|
||||
autospec=True)
|
||||
def test_live_migration(self, mock_vif_pre_lpm, mock_convert_mappings,
|
||||
mock_migr):
|
||||
mock_trunk = mock.MagicMock()
|
||||
|
@ -254,7 +258,7 @@ class TestLPM(test.NoDBTestCase):
|
|||
set(expected),
|
||||
set(self.lpmsrc._convert_nl_io_mappings(test_mappings)))
|
||||
|
||||
@mock.patch('pypowervm.tasks.migration.migrate_recover')
|
||||
@mock.patch('pypowervm.tasks.migration.migrate_recover', autospec=True)
|
||||
def test_rollback(self, mock_migr):
|
||||
self.lpmsrc.lpar_w = mock.Mock()
|
||||
|
||||
|
@ -289,19 +293,21 @@ class TestLPM(test.NoDBTestCase):
|
|||
self.assertRaises(exception.MigrationPreCheckError,
|
||||
self.lpmsrc._check_migration_ready, lpar_w, host_w)
|
||||
|
||||
@mock.patch('pypowervm.tasks.migration.migrate_abort')
|
||||
@mock.patch('pypowervm.tasks.migration.migrate_abort', autospec=True)
|
||||
def test_migration_abort(self, mock_mig_abort):
|
||||
self.lpmsrc.lpar_w = mock.Mock()
|
||||
self.lpmsrc.migration_abort()
|
||||
mock_mig_abort.called_once_with(self.lpmsrc.lpar_w)
|
||||
mock_mig_abort.assert_called_once_with(self.lpmsrc.lpar_w)
|
||||
|
||||
@mock.patch('pypowervm.tasks.migration.migrate_recover')
|
||||
@mock.patch('pypowervm.tasks.migration.migrate_recover', autospec=True)
|
||||
def test_migration_recover(self, mock_mig_recover):
|
||||
self.lpmsrc.lpar_w = mock.Mock()
|
||||
self.lpmsrc.migration_recover()
|
||||
mock_mig_recover.called_once_with(self.lpmsrc.lpar_w, force=True)
|
||||
mock_mig_recover.assert_called_once_with(
|
||||
self.lpmsrc.lpar_w, force=True)
|
||||
|
||||
@mock.patch('nova_powervm.virt.powervm.vif.post_live_migrate_at_source')
|
||||
@mock.patch('nova_powervm.virt.powervm.vif.post_live_migrate_at_source',
|
||||
autospec=True)
|
||||
def test_post_live_migration_at_source(self, mock_vif_post_lpm_at_source):
|
||||
network_infos = [{'devname': 'tap-dev1', 'address': 'mac-addr1',
|
||||
'network': {'bridge': 'br-int'}, 'id': 'vif_id_1'},
|
||||
|
|
|
@ -39,8 +39,9 @@ class TestConfigDrivePowerVM(test.NoDBTestCase):
|
|||
'pypowervm.tasks.vopt.validate_vopt_repo_exists')).mock
|
||||
self.validate_vopt.return_value = None, None
|
||||
|
||||
@mock.patch('nova.api.metadata.base.InstanceMetadata')
|
||||
@mock.patch('nova.virt.configdrive.ConfigDriveBuilder.make_drive')
|
||||
@mock.patch('nova.api.metadata.base.InstanceMetadata', autospec=True)
|
||||
@mock.patch('nova.virt.configdrive.ConfigDriveBuilder.make_drive',
|
||||
autospec=True)
|
||||
def test_crt_cfg_dr_iso(self, mock_mkdrv, mock_meta):
|
||||
"""Validates that the image creation method works."""
|
||||
cfg_dr_builder = m.ConfigDrivePowerVM(self.apt)
|
||||
|
@ -77,11 +78,11 @@ class TestConfigDrivePowerVM(test.NoDBTestCase):
|
|||
self.assertEqual(mock_mkdrv.call_count, 2)
|
||||
|
||||
@mock.patch('nova_powervm.virt.powervm.media.ConfigDrivePowerVM.'
|
||||
'_create_cfg_dr_iso')
|
||||
@mock.patch('os.path.getsize')
|
||||
@mock.patch('os.remove')
|
||||
'_create_cfg_dr_iso', autospec=True)
|
||||
@mock.patch('os.path.getsize', autospec=True)
|
||||
@mock.patch('os.remove', autospec=True)
|
||||
@mock.patch('nova_powervm.virt.powervm.media.ConfigDrivePowerVM.'
|
||||
'_upload_vopt')
|
||||
'_upload_vopt', autospec=True)
|
||||
@mock.patch('nova_powervm.virt.powervm.media.ConfigDrivePowerVM.'
|
||||
'_attach_vopt')
|
||||
def test_crt_cfg_drv_vopt(self, mock_attach, mock_upld, mock_rm, mock_size,
|
||||
|
@ -100,9 +101,10 @@ class TestConfigDrivePowerVM(test.NoDBTestCase):
|
|||
mock_attach.assert_called_with(mock.ANY, 'fake_lpar', mock.ANY, None)
|
||||
self.assertTrue(self.validate_vopt.called)
|
||||
|
||||
@mock.patch('pypowervm.tasks.scsi_mapper.add_map')
|
||||
@mock.patch('pypowervm.tasks.scsi_mapper.build_vscsi_mapping')
|
||||
@mock.patch('pypowervm.utils.transaction.WrapperTask')
|
||||
@mock.patch('pypowervm.tasks.scsi_mapper.add_map', autospec=True)
|
||||
@mock.patch('pypowervm.tasks.scsi_mapper.build_vscsi_mapping',
|
||||
autospec=True)
|
||||
@mock.patch('pypowervm.utils.transaction.WrapperTask', autospec=True)
|
||||
def test_attach_vopt(self, mock_class_wrapper_task, mock_build_map,
|
||||
mock_add_map):
|
||||
# Create objects to test with
|
||||
|
@ -208,17 +210,18 @@ class TestConfigDrivePowerVM(test.NoDBTestCase):
|
|||
mock_add_dlt_vopt_tasks.assert_not_called()
|
||||
self.assertTrue(mock_feed_task.execute.called)
|
||||
|
||||
@mock.patch('nova_powervm.virt.powervm.vm.get_vm_id',
|
||||
new=mock.MagicMock(return_value='2'))
|
||||
@mock.patch('pypowervm.tasks.scsi_mapper.gen_match_func')
|
||||
@mock.patch('pypowervm.tasks.scsi_mapper.find_maps')
|
||||
def test_add_dlt_vopt_tasks(self, mock_find_maps, mock_gen_match_func):
|
||||
@mock.patch('nova_powervm.virt.powervm.vm.get_vm_id', autospec=True)
|
||||
@mock.patch('pypowervm.tasks.scsi_mapper.gen_match_func', autospec=True)
|
||||
@mock.patch('pypowervm.tasks.scsi_mapper.find_maps', autospec=True)
|
||||
def test_add_dlt_vopt_tasks(self, mock_find_maps, mock_gen_match_func,
|
||||
mock_vm_id):
|
||||
# Init objects to test with
|
||||
cfg_dr = m.ConfigDrivePowerVM(self.apt)
|
||||
stg_ftsk = mock.MagicMock()
|
||||
cfg_dr.vios_uuid = 'vios_uuid'
|
||||
lpar_uuid = 'lpar_uuid'
|
||||
mock_find_maps.return_value = [mock.Mock(backing_storage='stor')]
|
||||
mock_vm_id.return_value = '2'
|
||||
|
||||
# Run
|
||||
cfg_dr.add_dlt_vopt_tasks(lpar_uuid, stg_ftsk)
|
||||
|
|
|
@ -39,7 +39,7 @@ class TestMgmt(test.NoDBTestCase):
|
|||
|
||||
self.resp = lpar_http.response
|
||||
|
||||
@mock.patch('pypowervm.tasks.partition.get_this_partition')
|
||||
@mock.patch('pypowervm.tasks.partition.get_this_partition', autospec=True)
|
||||
def test_mgmt_uuid(self, mock_get_partition):
|
||||
mock_get_partition.return_value = mock.Mock(uuid='mock_mgmt')
|
||||
adpt = mock.Mock()
|
||||
|
@ -51,11 +51,11 @@ class TestMgmt(test.NoDBTestCase):
|
|||
# But a subsequent call should effectively no-op
|
||||
mock_get_partition.reset_mock()
|
||||
self.assertEqual('mock_mgmt', mgmt.mgmt_uuid(adpt))
|
||||
mock_get_partition.assert_not_called()
|
||||
self.assertEqual(0, mock_get_partition.call_count)
|
||||
|
||||
@mock.patch('glob.glob')
|
||||
@mock.patch('nova.privsep.path.writefile')
|
||||
@mock.patch('os.path.realpath')
|
||||
@mock.patch('glob.glob', autospec=True)
|
||||
@mock.patch('nova.privsep.path.writefile', autospec=True)
|
||||
@mock.patch('os.path.realpath', autospec=True)
|
||||
def test_discover_vscsi_disk(self, mock_realpath, mock_dacw, mock_glob):
|
||||
scanpath = '/sys/bus/vio/devices/30000005/host*/scsi_host/host*/scan'
|
||||
udid = ('275b5d5f88fa5611e48be9000098be9400'
|
||||
|
@ -73,10 +73,11 @@ class TestMgmt(test.NoDBTestCase):
|
|||
mock_dacw.assert_called_with(scanpath, 'a', '- - -')
|
||||
mock_realpath.assert_called_with(devlink)
|
||||
|
||||
@mock.patch('retrying.retry')
|
||||
@mock.patch('glob.glob')
|
||||
@mock.patch('nova.privsep.path.writefile', new=mock.Mock())
|
||||
def test_discover_vscsi_disk_not_one_result(self, mock_glob, mock_retry):
|
||||
@mock.patch('retrying.retry', autospec=True)
|
||||
@mock.patch('glob.glob', autospec=True)
|
||||
@mock.patch('nova.privsep.path.writefile', autospec=True)
|
||||
def test_discover_vscsi_disk_not_one_result(self, mock_write, mock_glob,
|
||||
mock_retry):
|
||||
"""Zero or more than one disk is found by discover_vscsi_disk."""
|
||||
def validate_retry(kwargs):
|
||||
self.assertIn('retry_on_result', kwargs)
|
||||
|
@ -116,10 +117,10 @@ class TestMgmt(test.NoDBTestCase):
|
|||
self.assertRaises(npvmex.UniqueDiskDiscoveryException,
|
||||
mgmt.discover_vscsi_disk, mapping)
|
||||
|
||||
@mock.patch('time.sleep')
|
||||
@mock.patch('os.path.realpath')
|
||||
@mock.patch('os.stat')
|
||||
@mock.patch('nova.privsep.path.writefile')
|
||||
@mock.patch('time.sleep', autospec=True)
|
||||
@mock.patch('os.path.realpath', autospec=True)
|
||||
@mock.patch('os.stat', autospec=True)
|
||||
@mock.patch('nova.privsep.path.writefile', autospec=True)
|
||||
def test_remove_block_dev(self, mock_dacw, mock_stat, mock_realpath,
|
||||
mock_sleep):
|
||||
link = '/dev/link/foo'
|
||||
|
|
|
@ -100,8 +100,8 @@ class TestSwiftSlotManager(test.NoDBTestCase):
|
|||
self.store_api.delete_slot_map.assert_called_once_with(
|
||||
self.inst.uuid + '_slot_map')
|
||||
|
||||
@mock.patch('pypowervm.tasks.slot_map.RebuildSlotMap')
|
||||
@mock.patch('pypowervm.tasks.storage.ComprehensiveScrub')
|
||||
@mock.patch('pypowervm.tasks.slot_map.RebuildSlotMap', autospec=True)
|
||||
@mock.patch('pypowervm.tasks.storage.ComprehensiveScrub', autospec=True)
|
||||
def test_init_recreate_map(self, mock_ftsk, mock_rebuild_slot):
|
||||
vios1, vios2 = mock.Mock(uuid='uuid1'), mock.Mock(uuid='uuid2')
|
||||
mock_ftsk.return_value.feed = [vios1, vios2]
|
||||
|
@ -111,8 +111,8 @@ class TestSwiftSlotManager(test.NoDBTestCase):
|
|||
self.slot_mgr, mock.ANY, {'udid': ['uuid2'], 'iscsi': ['uuid1']},
|
||||
['a', 'b'])
|
||||
|
||||
@mock.patch('pypowervm.tasks.slot_map.RebuildSlotMap')
|
||||
@mock.patch('pypowervm.tasks.storage.ComprehensiveScrub')
|
||||
@mock.patch('pypowervm.tasks.slot_map.RebuildSlotMap', autospec=True)
|
||||
@mock.patch('pypowervm.tasks.storage.ComprehensiveScrub', autospec=True)
|
||||
def test_init_recreate_map_fails(self, mock_ftsk, mock_rebuild_slot):
|
||||
vios1, vios2 = mock.Mock(uuid='uuid1'), mock.Mock(uuid='uuid2')
|
||||
mock_ftsk.return_value.feed = [vios1, vios2]
|
||||
|
@ -122,8 +122,8 @@ class TestSwiftSlotManager(test.NoDBTestCase):
|
|||
p_exc.InvalidRebuild, self.slot_mgr.init_recreate_map, mock.Mock(),
|
||||
self._vol_drv_iter())
|
||||
|
||||
@mock.patch('pypowervm.tasks.slot_map.RebuildSlotMap')
|
||||
@mock.patch('pypowervm.tasks.storage.ComprehensiveScrub')
|
||||
@mock.patch('pypowervm.tasks.slot_map.RebuildSlotMap', autospec=True)
|
||||
@mock.patch('pypowervm.tasks.storage.ComprehensiveScrub', autospec=True)
|
||||
def test_init_recreate_map_fileio(self, mock_ftsk, mock_rebuild_slot):
|
||||
vios1, vios2 = mock.Mock(uuid='uuid1'), mock.Mock(uuid='uuid2')
|
||||
mock_ftsk.return_value.feed = [vios1, vios2]
|
||||
|
|
|
@ -59,8 +59,8 @@ class TestVifFunctions(test.NoDBTestCase):
|
|||
traits=pvm_fx.LocalPVMTraits)).adpt
|
||||
self.slot_mgr = mock.Mock()
|
||||
|
||||
@mock.patch('oslo_serialization.jsonutils.dumps')
|
||||
@mock.patch('pypowervm.wrappers.event.Event')
|
||||
@mock.patch('oslo_serialization.jsonutils.dumps', autospec=True)
|
||||
@mock.patch('pypowervm.wrappers.event.Event', autospec=True)
|
||||
def test_push_vif_event(self, mock_event, mock_dumps):
|
||||
mock_vif = mock.Mock(mac='MAC', href='HREF')
|
||||
vif._push_vif_event(self.adpt, 'action', mock_vif, mock.Mock(),
|
||||
|
@ -87,8 +87,9 @@ class TestVifFunctions(test.NoDBTestCase):
|
|||
mock_dumps.return_value)
|
||||
mock_event.bld.return_value.create.assert_called_once_with()
|
||||
|
||||
@mock.patch('nova_powervm.virt.powervm.vif._build_vif_driver')
|
||||
@mock.patch('nova_powervm.virt.powervm.vif._push_vif_event')
|
||||
@mock.patch('nova_powervm.virt.powervm.vif._build_vif_driver',
|
||||
autospec=True)
|
||||
@mock.patch('nova_powervm.virt.powervm.vif._push_vif_event', autospec=True)
|
||||
def test_plug(self, mock_event, mock_bld_drv):
|
||||
"""Test the top-level plug method."""
|
||||
mock_vif = {'address': 'MAC', 'type': 'pvm_sea'}
|
||||
|
@ -129,11 +130,12 @@ class TestVifFunctions(test.NoDBTestCase):
|
|||
mock_bld_drv.return_value.plug.assert_called_once_with(mock_vif, 123,
|
||||
new_vif=False)
|
||||
slot_mgr.register_vnet.assert_not_called()
|
||||
mock_event.assert_not_called()
|
||||
self.assertEqual(0, mock_event.call_count)
|
||||
self.assertIsNone(vnet)
|
||||
|
||||
@mock.patch('nova_powervm.virt.powervm.vif._build_vif_driver')
|
||||
@mock.patch('nova_powervm.virt.powervm.vif._push_vif_event')
|
||||
@mock.patch('nova_powervm.virt.powervm.vif._build_vif_driver',
|
||||
autospec=True)
|
||||
@mock.patch('nova_powervm.virt.powervm.vif._push_vif_event', autospec=True)
|
||||
def test_unplug(self, mock_event, mock_bld_drv):
|
||||
"""Test the top-level unplug method."""
|
||||
mock_vif = {'address': 'MAC', 'type': 'pvm_sea'}
|
||||
|
@ -166,9 +168,10 @@ class TestVifFunctions(test.NoDBTestCase):
|
|||
mock_vif, cna_w_list='cnalist')
|
||||
slot_mgr.drop_vnet.assert_not_called()
|
||||
# When unplug doesn't find a vif, we don't push an event
|
||||
mock_event.assert_not_called()
|
||||
self.assertEqual(0, mock_event.call_count)
|
||||
|
||||
@mock.patch('nova_powervm.virt.powervm.vif._build_vif_driver')
|
||||
@mock.patch('nova_powervm.virt.powervm.vif._build_vif_driver',
|
||||
autospec=True)
|
||||
def test_plug_raises(self, mock_vif_drv):
|
||||
"""HttpError is converted to VirtualInterfacePlugException."""
|
||||
vif_drv = mock.Mock(plug=mock.Mock(side_effect=pvm_ex.HttpError(
|
||||
|
@ -205,8 +208,8 @@ class TestVifFunctions(test.NoDBTestCase):
|
|||
self.adpt, parent_type=pvm_ms.System.schema_type,
|
||||
parent_uuid='host_uuid', name=vif.SECURE_RMC_VSWITCH)
|
||||
|
||||
@mock.patch('pypowervm.tasks.cna.crt_cna')
|
||||
@mock.patch('nova_powervm.virt.powervm.vm.get_pvm_uuid')
|
||||
@mock.patch('pypowervm.tasks.cna.crt_cna', autospec=True)
|
||||
@mock.patch('nova_powervm.virt.powervm.vm.get_pvm_uuid', autospec=True)
|
||||
def test_plug_secure_rmc_vif(self, mock_pvm_uuid, mock_crt):
|
||||
# Mock up the data
|
||||
mock_pvm_uuid.return_value = 'lpar_uuid'
|
||||
|
@ -226,8 +229,8 @@ class TestVifFunctions(test.NoDBTestCase):
|
|||
self.slot_mgr.register_cna.assert_called_once_with(
|
||||
mock_crt.return_value)
|
||||
|
||||
@mock.patch('pypowervm.tasks.cna.crt_cna')
|
||||
@mock.patch('nova_powervm.virt.powervm.vm.get_pvm_uuid')
|
||||
@mock.patch('pypowervm.tasks.cna.crt_cna', autospec=True)
|
||||
@mock.patch('nova_powervm.virt.powervm.vm.get_pvm_uuid', autospec=True)
|
||||
def test_plug_secure_rmc_vif_with_slot(self, mock_pvm_uuid, mock_crt):
|
||||
# Mock up the data
|
||||
mock_pvm_uuid.return_value = 'lpar_uuid'
|
||||
|
@ -246,8 +249,8 @@ class TestVifFunctions(test.NoDBTestCase):
|
|||
crt_vswitch=True, slot_num=5, mac_addr='mac_addr')
|
||||
self.assertFalse(self.slot_mgr.called)
|
||||
|
||||
@mock.patch('pypowervm.tasks.cna.crt_cna')
|
||||
@mock.patch('nova_powervm.virt.powervm.vm.get_pvm_uuid')
|
||||
@mock.patch('pypowervm.tasks.cna.crt_cna', autospec=True)
|
||||
@mock.patch('nova_powervm.virt.powervm.vm.get_pvm_uuid', autospec=True)
|
||||
def test_plug_secure_rmc_vif_for_rebuild(self, mock_pvm_uuid, mock_crt):
|
||||
# Mock up the data
|
||||
mock_pvm_uuid.return_value = 'lpar_uuid'
|
||||
|
@ -301,7 +304,8 @@ class TestVifFunctions(test.NoDBTestCase):
|
|||
vif._build_vif_driver, self.adpt, 'host_uuid',
|
||||
mock_inst, {'type': 'bad'})
|
||||
|
||||
@mock.patch('nova_powervm.virt.powervm.vif._build_vif_driver')
|
||||
@mock.patch('nova_powervm.virt.powervm.vif._build_vif_driver',
|
||||
autospec=True)
|
||||
def test_pre_live_migrate_at_source(self, mock_build_vif_drv):
|
||||
mock_drv = mock.MagicMock()
|
||||
mock_build_vif_drv.return_value = mock_drv
|
||||
|
@ -312,7 +316,8 @@ class TestVifFunctions(test.NoDBTestCase):
|
|||
|
||||
mock_drv.pre_live_migrate_at_source.assert_called_once_with(mock_vif)
|
||||
|
||||
@mock.patch('nova_powervm.virt.powervm.vif._build_vif_driver')
|
||||
@mock.patch('nova_powervm.virt.powervm.vif._build_vif_driver',
|
||||
autospec=True)
|
||||
def test_rollback_live_migration_at_destination(self, mock_build_vif_drv):
|
||||
mock_build_vif_drv.return_value = mock_drv = mock.MagicMock()
|
||||
mock_vif, mappings = mock.MagicMock(), {}
|
||||
|
@ -324,7 +329,8 @@ class TestVifFunctions(test.NoDBTestCase):
|
|||
rb = mock_drv.rollback_live_migration_at_destination
|
||||
rb.assert_called_once_with(mock_vif, mappings)
|
||||
|
||||
@mock.patch('nova_powervm.virt.powervm.vif._build_vif_driver')
|
||||
@mock.patch('nova_powervm.virt.powervm.vif._build_vif_driver',
|
||||
autospec=True)
|
||||
def test_pre_live_migrate_at_destination(self, mock_build_vif_drv):
|
||||
mock_drv = mock.MagicMock()
|
||||
mock_build_vif_drv.return_value = mock_drv
|
||||
|
@ -336,7 +342,8 @@ class TestVifFunctions(test.NoDBTestCase):
|
|||
mock_drv.pre_live_migrate_at_destination.assert_called_once_with(
|
||||
mock_vif, {})
|
||||
|
||||
@mock.patch('nova_powervm.virt.powervm.vif._build_vif_driver')
|
||||
@mock.patch('nova_powervm.virt.powervm.vif._build_vif_driver',
|
||||
autospec=True)
|
||||
def test_post_live_migrate_at_source(self, mock_build_vif_drv):
|
||||
mock_drv = mock.MagicMock()
|
||||
mock_build_vif_drv.return_value = mock_drv
|
||||
|
@ -383,8 +390,8 @@ class TestVifSriovDriver(test.NoDBTestCase):
|
|||
self.drv.plug, FakeDirectVif('net2'), 1)
|
||||
|
||||
@mock.patch('pypowervm.wrappers.iocard.VNIC.bld')
|
||||
@mock.patch('nova_powervm.virt.powervm.vm.get_pvm_uuid')
|
||||
@mock.patch('pypowervm.tasks.sriov.set_vnic_back_devs')
|
||||
@mock.patch('nova_powervm.virt.powervm.vm.get_pvm_uuid', autospec=True)
|
||||
@mock.patch('pypowervm.tasks.sriov.set_vnic_back_devs', autospec=True)
|
||||
@mock.patch('pypowervm.wrappers.managed_system.System.get')
|
||||
def test_plug_no_physnet(self, mock_sysget, mock_back_devs, mock_pvm_uuid,
|
||||
mock_vnic_bld):
|
||||
|
@ -408,8 +415,8 @@ class TestVifSriovDriver(test.NoDBTestCase):
|
|||
sys_w=sys)
|
||||
|
||||
@mock.patch('pypowervm.wrappers.iocard.VNIC.bld')
|
||||
@mock.patch('nova_powervm.virt.powervm.vm.get_pvm_uuid')
|
||||
@mock.patch('pypowervm.tasks.sriov.set_vnic_back_devs')
|
||||
@mock.patch('nova_powervm.virt.powervm.vm.get_pvm_uuid', autospec=True)
|
||||
@mock.patch('pypowervm.tasks.sriov.set_vnic_back_devs', autospec=True)
|
||||
@mock.patch('pypowervm.wrappers.managed_system.System.get')
|
||||
def test_plug_no_matching_pports(self, mock_sysget, mock_back_devs,
|
||||
mock_pvm_uuid, mock_vnic_bld):
|
||||
|
@ -431,8 +438,8 @@ class TestVifSriovDriver(test.NoDBTestCase):
|
|||
FakeDirectVif('default'), slot)
|
||||
|
||||
@mock.patch('pypowervm.wrappers.iocard.VNIC.bld')
|
||||
@mock.patch('nova_powervm.virt.powervm.vm.get_pvm_uuid')
|
||||
@mock.patch('pypowervm.tasks.sriov.set_vnic_back_devs')
|
||||
@mock.patch('nova_powervm.virt.powervm.vm.get_pvm_uuid', autospec=True)
|
||||
@mock.patch('pypowervm.tasks.sriov.set_vnic_back_devs', autospec=True)
|
||||
@mock.patch('pypowervm.wrappers.managed_system.System.get')
|
||||
def test_plug_bad_pports(self, mock_sysget, mock_back_devs, mock_pvm_uuid,
|
||||
mock_vnic_bld):
|
||||
|
@ -456,10 +463,10 @@ class TestVifSriovDriver(test.NoDBTestCase):
|
|||
sys_w=sys)
|
||||
|
||||
@mock.patch('pypowervm.wrappers.managed_system.System.get')
|
||||
@mock.patch('pypowervm.util.sanitize_mac_for_api')
|
||||
@mock.patch('pypowervm.util.sanitize_mac_for_api', autospec=True)
|
||||
@mock.patch('pypowervm.wrappers.iocard.VNIC.bld')
|
||||
@mock.patch('pypowervm.tasks.sriov.set_vnic_back_devs')
|
||||
@mock.patch('nova_powervm.virt.powervm.vm.get_pvm_uuid')
|
||||
@mock.patch('pypowervm.tasks.sriov.set_vnic_back_devs', autospec=True)
|
||||
@mock.patch('nova_powervm.virt.powervm.vm.get_pvm_uuid', autospec=True)
|
||||
def test_plug(self, mock_pvm_uuid, mock_back_devs, mock_vnic_bld,
|
||||
mock_san_mac, mock_sysget):
|
||||
slot = 10
|
||||
|
@ -514,10 +521,10 @@ class TestVifSriovDriver(test.NoDBTestCase):
|
|||
mock_pvm_uuid.reset_mock()
|
||||
self.assertIsNone(self.drv.plug(
|
||||
FakeDirectVif('default'), slot, new_vif=False))
|
||||
mock_san_mac.assert_not_called()
|
||||
mock_vnic_bld.assert_not_called()
|
||||
mock_back_devs.assert_not_called()
|
||||
mock_pvm_uuid.assert_not_called()
|
||||
self.assertEqual(0, mock_san_mac.call_count)
|
||||
self.assertEqual(0, mock_vnic_bld.call_count)
|
||||
self.assertEqual(0, mock_back_devs.call_count)
|
||||
self.assertEqual(0, mock_pvm_uuid.call_count)
|
||||
|
||||
@mock.patch('pypowervm.wrappers.iocard.VNIC.bld')
|
||||
@mock.patch('nova_powervm.virt.powervm.vm.get_pvm_uuid')
|
||||
|
@ -584,8 +591,8 @@ class TestVifSriovDriver(test.NoDBTestCase):
|
|||
cap=0.5, maxcap=0.4), 1)
|
||||
|
||||
@mock.patch('pypowervm.wrappers.iocard.VNIC.search')
|
||||
@mock.patch('nova_powervm.virt.powervm.vm.get_pvm_uuid')
|
||||
@mock.patch('pypowervm.util.sanitize_mac_for_api')
|
||||
@mock.patch('nova_powervm.virt.powervm.vm.get_pvm_uuid', autospec=True)
|
||||
@mock.patch('pypowervm.util.sanitize_mac_for_api', autospec=True)
|
||||
def test_unplug(self, mock_san_mac, mock_pvm_uuid, mock_find):
|
||||
fvif = FakeDirectVif('default')
|
||||
self.assertEqual(mock_find.return_value, self.drv.unplug(fvif))
|
||||
|
@ -650,8 +657,8 @@ class TestVifSeaDriver(test.NoDBTestCase):
|
|||
self.inst = mock.MagicMock()
|
||||
self.drv = vif.PvmSeaVifDriver(self.adpt, 'host_uuid', self.inst)
|
||||
|
||||
@mock.patch('nova_powervm.virt.powervm.vm.get_pvm_uuid')
|
||||
@mock.patch('pypowervm.tasks.cna.crt_cna')
|
||||
@mock.patch('nova_powervm.virt.powervm.vm.get_pvm_uuid', autospec=True)
|
||||
@mock.patch('pypowervm.tasks.cna.crt_cna', autospec=True)
|
||||
def test_plug(self, mock_crt_cna, mock_pvm_uuid):
|
||||
"""Tests that a VIF can be created."""
|
||||
|
||||
|
@ -678,8 +685,8 @@ class TestVifSeaDriver(test.NoDBTestCase):
|
|||
self.assertIsNotNone(resp)
|
||||
self.assertIsInstance(resp, pvm_net.CNA)
|
||||
|
||||
@mock.patch('nova_powervm.virt.powervm.vm.get_pvm_uuid')
|
||||
@mock.patch('pypowervm.tasks.cna.crt_cna')
|
||||
@mock.patch('nova_powervm.virt.powervm.vm.get_pvm_uuid', autospec=True)
|
||||
@mock.patch('pypowervm.tasks.cna.crt_cna', autospec=True)
|
||||
def test_plug_from_neutron(self, mock_crt_cna, mock_pvm_uuid):
|
||||
"""Tests that a VIF can be created. Mocks Neutron net"""
|
||||
|
||||
|
@ -719,7 +726,7 @@ class TestVifSeaDriver(test.NoDBTestCase):
|
|||
|
||||
self.assertIsNone(resp)
|
||||
|
||||
@mock.patch('nova_powervm.virt.powervm.vm.get_cnas')
|
||||
@mock.patch('nova_powervm.virt.powervm.vm.get_cnas', autospec=True)
|
||||
def test_unplug_vifs(self, mock_vm_get):
|
||||
"""Tests that a delete of the vif can be done."""
|
||||
# Mock up the CNA response. Two should already exist, the other
|
||||
|
@ -751,10 +758,11 @@ class TestVifOvsDriver(test.NoDBTestCase):
|
|||
self.inst = mock.MagicMock(uuid='inst_uuid')
|
||||
self.drv = vif.PvmOvsVifDriver(self.adpt, 'host_uuid', self.inst)
|
||||
|
||||
@mock.patch('nova_powervm.virt.powervm.vif._get_trunk_dev_name')
|
||||
@mock.patch('nova_powervm.virt.powervm.vif._get_trunk_dev_name',
|
||||
autospec=True)
|
||||
@mock.patch('pypowervm.tasks.cna.crt_p2p_cna', autospec=True)
|
||||
@mock.patch('pypowervm.tasks.partition.get_mgmt_partition', autospec=True)
|
||||
@mock.patch('nova_powervm.virt.powervm.vm.get_pvm_uuid')
|
||||
@mock.patch('nova_powervm.virt.powervm.vm.get_pvm_uuid', autospec=True)
|
||||
def test_plug(self, mock_pvm_uuid, mock_mgmt_lpar, mock_p2p_cna,
|
||||
mock_trunk_dev_name):
|
||||
# Mock the data
|
||||
|
@ -852,7 +860,7 @@ class TestVifOvsDriver(test.NoDBTestCase):
|
|||
@mock.patch('pypowervm.tasks.cna.find_trunks', autospec=True)
|
||||
@mock.patch('pypowervm.wrappers.network.CNA', autospec=True)
|
||||
@mock.patch('pypowervm.util.sanitize_mac_for_api', autospec=True)
|
||||
@mock.patch('nova_powervm.virt.powervm.vm.get_pvm_uuid')
|
||||
@mock.patch('nova_powervm.virt.powervm.vm.get_pvm_uuid', autospec=True)
|
||||
def test_pre_live_migrate_at_source(self, mock_pvm_uuid, mock_sanitize,
|
||||
mock_cna, mock_trunk_find):
|
||||
# Set up the mocks
|
||||
|
|
|
@ -383,8 +383,8 @@ class TestVM(test.NoDBTestCase):
|
|||
self.assertEqual(lpar_list[0], 'z3-9-5-126-208-000001f0')
|
||||
self.assertEqual(len(lpar_list), 20)
|
||||
|
||||
@mock.patch('nova_powervm.virt.powervm.vm.get_pvm_uuid')
|
||||
@mock.patch('pypowervm.tasks.vterm.close_vterm')
|
||||
@mock.patch('nova_powervm.virt.powervm.vm.get_pvm_uuid', autospec=True)
|
||||
@mock.patch('pypowervm.tasks.vterm.close_vterm', autospec=True)
|
||||
def test_dlt_lpar(self, mock_vterm, mock_pvm_uuid):
|
||||
"""Performs a delete LPAR test."""
|
||||
mock_pvm_uuid.return_value = 'pvm_uuid'
|
||||
|
@ -463,10 +463,14 @@ class TestVM(test.NoDBTestCase):
|
|||
mock_vterm.assert_called_once_with(self.apt, 'pvm_uuid')
|
||||
self.apt.delete.assert_not_called()
|
||||
|
||||
@mock.patch('nova_powervm.virt.powervm.vm.VMBuilder._add_IBMi_attrs')
|
||||
@mock.patch('pypowervm.utils.lpar_builder.DefaultStandardize')
|
||||
@mock.patch('pypowervm.utils.lpar_builder.LPARBuilder.build')
|
||||
@mock.patch('pypowervm.utils.validation.LPARWrapperValidator.validate_all')
|
||||
@mock.patch('nova_powervm.virt.powervm.vm.VMBuilder._add_IBMi_attrs',
|
||||
autospec=True)
|
||||
@mock.patch('pypowervm.utils.lpar_builder.DefaultStandardize',
|
||||
autospec=True)
|
||||
@mock.patch('pypowervm.utils.lpar_builder.LPARBuilder.build',
|
||||
autospec=True)
|
||||
@mock.patch('pypowervm.utils.validation.LPARWrapperValidator.validate_all',
|
||||
autospec=True)
|
||||
def test_crt_lpar(self, mock_vld_all, mock_bld, mock_stdz, mock_ibmi):
|
||||
instance = objects.Instance(**powervm.TEST_INSTANCE)
|
||||
flavor = instance.get_flavor()
|
||||
|
@ -532,8 +536,9 @@ class TestVM(test.NoDBTestCase):
|
|||
self.assertRaises(exception.InstanceNotFound, vm.get_instance_wrapper,
|
||||
self.apt, instance, 'lpar_uuid')
|
||||
|
||||
@mock.patch('nova_powervm.virt.powervm.vm.get_instance_wrapper')
|
||||
@mock.patch('nova_powervm.virt.powervm.vm.VMBuilder')
|
||||
@mock.patch('nova_powervm.virt.powervm.vm.get_instance_wrapper',
|
||||
autospec=True)
|
||||
@mock.patch('nova_powervm.virt.powervm.vm.VMBuilder', autospec=True)
|
||||
def test_update(self, mock_vmb, mock_get_inst):
|
||||
instance = objects.Instance(**powervm.TEST_INSTANCE)
|
||||
entry = mock.Mock()
|
||||
|
@ -550,8 +555,9 @@ class TestVM(test.NoDBTestCase):
|
|||
self.assertEqual('NewEntry', new_entry)
|
||||
self.san_lpar_name.assert_called_with(name)
|
||||
|
||||
@mock.patch('pypowervm.utils.transaction.entry_transaction')
|
||||
@mock.patch('nova_powervm.virt.powervm.vm.get_instance_wrapper')
|
||||
@mock.patch('pypowervm.utils.transaction.entry_transaction', autospec=True)
|
||||
@mock.patch('nova_powervm.virt.powervm.vm.get_instance_wrapper',
|
||||
autospec=True)
|
||||
def test_rename(self, mock_get_inst, mock_entry_transaction):
|
||||
instance = objects.Instance(**powervm.TEST_INSTANCE)
|
||||
|
||||
|
@ -595,9 +601,10 @@ class TestVM(test.NoDBTestCase):
|
|||
bldr._add_IBMi_attrs(inst, attrs)
|
||||
self.assertDictEqual(attrs, {'env': 'OS400'})
|
||||
|
||||
@mock.patch('pypowervm.tasks.power.power_on')
|
||||
@mock.patch('oslo_concurrency.lockutils.lock')
|
||||
@mock.patch('nova_powervm.virt.powervm.vm.get_instance_wrapper')
|
||||
@mock.patch('pypowervm.tasks.power.power_on', autospec=True)
|
||||
@mock.patch('oslo_concurrency.lockutils.lock', autospec=True)
|
||||
@mock.patch('nova_powervm.virt.powervm.vm.get_instance_wrapper',
|
||||
autospec=True)
|
||||
def test_power_on(self, mock_wrap, mock_lock, mock_power_on):
|
||||
instance = objects.Instance(**powervm.TEST_INSTANCE)
|
||||
entry = mock.Mock(state=pvm_bp.LPARState.NOT_ACTIVATED)
|
||||
|
@ -619,14 +626,15 @@ class TestVM(test.NoDBTestCase):
|
|||
for stop_state in stop_states:
|
||||
entry.state = stop_state
|
||||
self.assertFalse(vm.power_on(None, instance))
|
||||
mock_power_on.assert_not_called()
|
||||
self.assertEqual(0, mock_power_on.call_count)
|
||||
mock_lock.assert_called_once_with('power_%s' % instance.uuid)
|
||||
mock_lock.reset_mock()
|
||||
|
||||
@mock.patch('pypowervm.tasks.power.PowerOp', autospec=True)
|
||||
@mock.patch('pypowervm.tasks.power.power_off_progressive', autospec=True)
|
||||
@mock.patch('oslo_concurrency.lockutils.lock')
|
||||
@mock.patch('nova_powervm.virt.powervm.vm.get_instance_wrapper')
|
||||
@mock.patch('oslo_concurrency.lockutils.lock', autospec=True)
|
||||
@mock.patch('nova_powervm.virt.powervm.vm.get_instance_wrapper',
|
||||
autospec=True)
|
||||
def test_power_off(self, mock_wrap, mock_lock, mock_power_off, mock_pop):
|
||||
instance = objects.Instance(**powervm.TEST_INSTANCE)
|
||||
entry = mock.Mock(state=pvm_bp.LPARState.NOT_ACTIVATED)
|
||||
|
@ -663,7 +671,8 @@ class TestVM(test.NoDBTestCase):
|
|||
mock_lock.assert_called_once_with('power_%s' % instance.uuid)
|
||||
|
||||
@mock.patch('pypowervm.tasks.power.power_off_progressive', autospec=True)
|
||||
@mock.patch('nova_powervm.virt.powervm.vm.get_instance_wrapper')
|
||||
@mock.patch('nova_powervm.virt.powervm.vm.get_instance_wrapper',
|
||||
autospec=True)
|
||||
def test_power_off_negative(self, mock_wrap, mock_power_off):
|
||||
"""Negative tests."""
|
||||
instance = objects.Instance(**powervm.TEST_INSTANCE)
|
||||
|
@ -676,8 +685,9 @@ class TestVM(test.NoDBTestCase):
|
|||
self.assertRaises(exception.InstancePowerOffFailure,
|
||||
vm.power_off, None, instance)
|
||||
|
||||
@mock.patch('oslo_concurrency.lockutils.lock')
|
||||
@mock.patch('nova_powervm.virt.powervm.vm.get_instance_wrapper')
|
||||
@mock.patch('oslo_concurrency.lockutils.lock', autospec=True)
|
||||
@mock.patch('nova_powervm.virt.powervm.vm.get_instance_wrapper',
|
||||
autospec=True)
|
||||
@mock.patch('pypowervm.tasks.power.power_on', autospec=True)
|
||||
@mock.patch('pypowervm.tasks.power.power_off_progressive', autospec=True)
|
||||
@mock.patch('pypowervm.tasks.power.PowerOp', autospec=True)
|
||||
|
@ -743,8 +753,8 @@ class TestVM(test.NoDBTestCase):
|
|||
self.assertEqual('5BBB48F1-2406-4019-98AF-1C16D3DF0204',
|
||||
vm.get_pvm_uuid(mock_inst))
|
||||
|
||||
@mock.patch('nova_powervm.virt.powervm.vm.get_pvm_uuid')
|
||||
@mock.patch('nova_powervm.virt.powervm.vm.get_vm_qp')
|
||||
@mock.patch('nova_powervm.virt.powervm.vm.get_pvm_uuid', autospec=True)
|
||||
@mock.patch('nova_powervm.virt.powervm.vm.get_vm_qp', autospec=True)
|
||||
def test_instance_exists(self, mock_getvmqp, mock_getuuid):
|
||||
# Try the good case where it exists
|
||||
mock_getvmqp.side_effect = 'fake_state'
|
||||
|
@ -836,8 +846,9 @@ class TestVM(test.NoDBTestCase):
|
|||
self.assertEqual(EXPECTED, vm.norm_mac("12:34:56:78:90:AB"))
|
||||
self.assertEqual(EXPECTED, vm.norm_mac("1234567890AB"))
|
||||
|
||||
@mock.patch('pypowervm.tasks.ibmi.update_ibmi_settings')
|
||||
@mock.patch('nova_powervm.virt.powervm.vm.get_instance_wrapper')
|
||||
@mock.patch('pypowervm.tasks.ibmi.update_ibmi_settings', autospec=True)
|
||||
@mock.patch('nova_powervm.virt.powervm.vm.get_instance_wrapper',
|
||||
autospec=True)
|
||||
def test_update_ibmi_settings(self, mock_lparw, mock_ibmi):
|
||||
instance = mock.MagicMock()
|
||||
|
||||
|
|
Loading…
Reference in New Issue