Fix database poison warnings, part 10
The following warning appears in the unit test logs a number of times. "UserWarning: This test uses methods that set internal oslo_db state, but it does not claim to use the database. This will conflict with the setup of tests that do use the database and cause failures later." This patch fixes all the warnings from: unit.compute.test_compute_mgr.py Note that this warning is only emitted once per unit test worker, so new offenders will show up in the logs each time you fix a test until they are all gone. Change-Id: I72da6b07a854a69c275258027afa73e7bfaeba17 Related-Bug: #1568414
This commit is contained in:
parent
eec3a2b9e8
commit
0d814ac437
|
@ -2485,11 +2485,12 @@ class ComputeManagerUnitTestCase(test.NoDBTestCase):
|
|||
mock.patch.object(compute_utils, 'notify_usage_exists'),
|
||||
mock.patch.object(self.compute, '_get_power_state',
|
||||
return_value=power_state.RUNNING),
|
||||
mock.patch.object(instance, 'save')
|
||||
mock.patch.object(instance, 'save'),
|
||||
mock.patch.object(compute_utils, 'EventReporter')
|
||||
) as (
|
||||
elevated_context, get_nw_info,
|
||||
get_rescue_image, notify_instance_usage, power_off_instance,
|
||||
driver_rescue, notify_usage_exists, get_power_state, instance_save
|
||||
elevated_context, get_nw_info, get_rescue_image,
|
||||
notify_instance_usage, power_off_instance, driver_rescue,
|
||||
notify_usage_exists, get_power_state, instance_save, event_reporter
|
||||
):
|
||||
self.compute.rescue_instance(
|
||||
self.context, instance, rescue_password='verybadpass',
|
||||
|
@ -2549,11 +2550,11 @@ class ComputeManagerUnitTestCase(test.NoDBTestCase):
|
|||
mock.patch.object(self.compute.driver, 'unrescue'),
|
||||
mock.patch.object(self.compute, '_get_power_state',
|
||||
return_value=power_state.RUNNING),
|
||||
mock.patch.object(instance, 'save')
|
||||
mock.patch.object(instance, 'save'),
|
||||
mock.patch.object(compute_utils, 'EventReporter')
|
||||
) as (
|
||||
elevated_context, get_nw_info,
|
||||
notify_instance_usage, driver_unrescue, get_power_state,
|
||||
instance_save
|
||||
elevated_context, get_nw_info, notify_instance_usage,
|
||||
driver_unrescue, get_power_state, instance_save, event_reporter
|
||||
):
|
||||
self.compute.unrescue_instance(self.context, instance)
|
||||
|
||||
|
@ -2582,7 +2583,8 @@ class ComputeManagerUnitTestCase(test.NoDBTestCase):
|
|||
return_value=power_state.RUNNING)
|
||||
@mock.patch.object(objects.Instance, 'save')
|
||||
@mock.patch('nova.utils.generate_password', return_value='fake-pass')
|
||||
def test_set_admin_password(self, gen_password_mock,
|
||||
@mock.patch.object(compute_utils, 'EventReporter')
|
||||
def test_set_admin_password(self, event_mock, gen_password_mock,
|
||||
instance_save_mock, power_state_mock):
|
||||
# Ensure instance can have its admin password set.
|
||||
instance = fake_instance.fake_instance_obj(
|
||||
|
@ -2611,9 +2613,9 @@ class ComputeManagerUnitTestCase(test.NoDBTestCase):
|
|||
@mock.patch('nova.compute.manager.ComputeManager._instance_update')
|
||||
@mock.patch.object(objects.Instance, 'save')
|
||||
@mock.patch.object(compute_utils, 'add_instance_fault_from_exc')
|
||||
def test_set_admin_password_bad_state(self, add_fault_mock,
|
||||
instance_save_mock,
|
||||
update_mock,
|
||||
@mock.patch.object(compute_utils, 'EventReporter')
|
||||
def test_set_admin_password_bad_state(self, event_mock, add_fault_mock,
|
||||
instance_save_mock, update_mock,
|
||||
power_state_mock):
|
||||
# Test setting password while instance is rebuilding.
|
||||
instance = fake_instance.fake_instance_obj(self.context)
|
||||
|
@ -2631,6 +2633,7 @@ class ComputeManagerUnitTestCase(test.NoDBTestCase):
|
|||
add_fault_mock.assert_called_once_with(
|
||||
self.context, instance, mock.ANY, mock.ANY)
|
||||
|
||||
@mock.patch.object(compute_utils, 'EventReporter')
|
||||
@mock.patch('nova.utils.generate_password', return_value='fake-pass')
|
||||
@mock.patch('nova.compute.manager.ComputeManager._get_power_state',
|
||||
return_value=power_state.RUNNING)
|
||||
|
@ -2645,7 +2648,8 @@ class ComputeManagerUnitTestCase(test.NoDBTestCase):
|
|||
instance_save_mock,
|
||||
update_mock,
|
||||
power_state_mock,
|
||||
gen_password_mock):
|
||||
gen_password_mock,
|
||||
event_mock):
|
||||
# Ensure expected exception is raised if set_admin_password fails.
|
||||
instance = fake_instance.fake_instance_obj(
|
||||
self.context,
|
||||
|
@ -2880,7 +2884,9 @@ class ComputeManagerUnitTestCase(test.NoDBTestCase):
|
|||
@mock.patch.object(self.compute, '_notify_about_instance_usage')
|
||||
@mock.patch.object(self.compute, '_power_off_instance')
|
||||
@mock.patch.object(instance, 'save')
|
||||
def do_test(save_mock, power_off_mock, notify_mock, get_state_mock):
|
||||
@mock.patch.object(compute_utils, 'EventReporter')
|
||||
def do_test(event_mock, save_mock, power_off_mock, notify_mock,
|
||||
get_state_mock):
|
||||
# run the code
|
||||
self.compute.stop_instance(self.context, instance, True)
|
||||
# assert the calls
|
||||
|
@ -2927,8 +2933,9 @@ class ComputeManagerUnitTestCase(test.NoDBTestCase):
|
|||
mock.patch.object(self.compute, '_do_rebuild_instance_with_claim',
|
||||
side_effect=ex),
|
||||
mock.patch.object(self.compute, '_set_migration_status'),
|
||||
mock.patch.object(self.compute, '_notify_about_instance_usage')
|
||||
) as (mock_get, mock_rebuild, mock_set, mock_notify):
|
||||
mock.patch.object(self.compute, '_notify_about_instance_usage'),
|
||||
mock.patch.object(compute_utils, 'EventReporter')
|
||||
) as (mock_get, mock_rebuild, mock_set, mock_notify, mock_event):
|
||||
self.compute.rebuild_instance(self.context, instance, None, None,
|
||||
None, None, None, None, None)
|
||||
mock_set.assert_called_once_with(None, 'failed')
|
||||
|
@ -3179,7 +3186,9 @@ class ComputeManagerUnitTestCase(test.NoDBTestCase):
|
|||
|
||||
@mock.patch('nova.objects.BlockDeviceMappingList.get_by_instance_uuid')
|
||||
@mock.patch('nova.compute.manager.ComputeManager._delete_instance')
|
||||
def test_terminate_instance_no_bdm_volume_id(self, mock_delete_instance,
|
||||
@mock.patch.object(compute_utils, 'EventReporter')
|
||||
def test_terminate_instance_no_bdm_volume_id(self, mock_event,
|
||||
mock_delete_instance,
|
||||
mock_bdm_get_by_inst):
|
||||
# Tests that we refresh the bdm list if a volume bdm does not have the
|
||||
# volume_id set.
|
||||
|
@ -3201,7 +3210,8 @@ class ComputeManagerUnitTestCase(test.NoDBTestCase):
|
|||
|
||||
@mock.patch.object(nova.compute.manager.ComputeManager,
|
||||
'_notify_about_instance_usage')
|
||||
def test_trigger_crash_dump(self, notify_mock):
|
||||
@mock.patch.object(compute_utils, 'EventReporter')
|
||||
def test_trigger_crash_dump(self, event_mock, notify_mock):
|
||||
instance = fake_instance.fake_instance_obj(
|
||||
self.context, vm_state=vm_states.ACTIVE)
|
||||
|
||||
|
@ -3222,8 +3232,11 @@ class ComputeManagerUnitTestCase(test.NoDBTestCase):
|
|||
'notify_about_instance_action'),
|
||||
mock.patch.object(self.compute, '_notify_about_instance_usage'),
|
||||
mock.patch.object(objects.Instance, 'save'),
|
||||
mock.patch.object(self.compute.driver, 'restore')
|
||||
) as (fake_notify, fake_notify_usage, fake_save, fake_restore):
|
||||
mock.patch.object(self.compute.driver, 'restore'),
|
||||
mock.patch.object(compute_utils, 'EventReporter')
|
||||
) as (
|
||||
fake_notify, fake_usage, fake_save, fake_restore, fake_event
|
||||
):
|
||||
self.compute.restore_instance(self.context, inst_obj)
|
||||
fake_notify.assert_has_calls([
|
||||
mock.call(self.context, inst_obj, 'fake-mini',
|
||||
|
@ -3339,10 +3352,11 @@ class ComputeManagerBuildInstanceTestCase(test.NoDBTestCase):
|
|||
|
||||
# This test when sending an icehouse compatible rpc call to juno compute
|
||||
# node, NetworkRequest object can load from three items tuple.
|
||||
@mock.patch.object(compute_utils, 'EventReporter')
|
||||
@mock.patch('nova.objects.Instance.save')
|
||||
@mock.patch('nova.compute.manager.ComputeManager._build_and_run_instance')
|
||||
def test_build_and_run_instance_with_icehouse_requested_network(
|
||||
self, mock_build_and_run, mock_save):
|
||||
self, mock_build_and_run, mock_save, mock_event):
|
||||
mock_save.return_value = self.instance
|
||||
self.compute.build_and_run_instance(self.context, self.instance,
|
||||
self.image, request_spec={},
|
||||
|
@ -4493,9 +4507,10 @@ class ComputeManagerMigrationTestCase(test.NoDBTestCase):
|
|||
mock.patch.object(self.instance, 'save'),
|
||||
mock.patch.object(self.migration, 'save'),
|
||||
mock.patch.object(self.migration, 'obj_as_admin',
|
||||
return_value=mock.MagicMock())
|
||||
return_value=mock.MagicMock()),
|
||||
mock.patch.object(compute_utils, 'EventReporter')
|
||||
) as (meth, fault_create, instance_update, instance_save,
|
||||
migration_save, migration_obj_as_admin):
|
||||
migration_save, migration_obj_as_admin, event_reporter):
|
||||
fault_create.return_value = (
|
||||
test_instance_fault.fake_faults['fake-uuid'][0])
|
||||
self.assertRaises(
|
||||
|
@ -4531,10 +4546,11 @@ class ComputeManagerMigrationTestCase(test.NoDBTestCase):
|
|||
return_value=None),
|
||||
mock.patch.object(objects.Flavor,
|
||||
'get_by_id',
|
||||
return_value=None)
|
||||
return_value=None),
|
||||
mock.patch.object(compute_utils, 'EventReporter')
|
||||
) as (meth, fault_create, instance_update,
|
||||
migration_save, migration_obj_as_admin, nw_info, save_inst,
|
||||
notify, vol_block_info, bdm, flavor):
|
||||
notify, vol_block_info, bdm, flavor, event_reporter):
|
||||
fault_create.return_value = (
|
||||
test_instance_fault.fake_faults['fake-uuid'][0])
|
||||
self.assertRaises(
|
||||
|
@ -4567,7 +4583,9 @@ class ComputeManagerMigrationTestCase(test.NoDBTestCase):
|
|||
@mock.patch.object(self.migration, 'save')
|
||||
@mock.patch.object(objects.BlockDeviceMappingList,
|
||||
'get_by_instance_uuid')
|
||||
def do_test(get_by_instance_uuid,
|
||||
@mock.patch.object(compute_utils, 'EventReporter')
|
||||
def do_test(event_reporter,
|
||||
get_by_instance_uuid,
|
||||
migration_save,
|
||||
notify_usage_exists,
|
||||
migrate_instance_start,
|
||||
|
@ -4625,7 +4643,8 @@ class ComputeManagerMigrationTestCase(test.NoDBTestCase):
|
|||
|
||||
@mock.patch('nova.compute.manager.ComputeManager.'
|
||||
'_do_live_migration')
|
||||
def _test_max_concurrent_live(self, mock_lm):
|
||||
@mock.patch.object(compute_utils, 'EventReporter')
|
||||
def _test_max_concurrent_live(self, mock_event, mock_lm):
|
||||
|
||||
@mock.patch('nova.objects.Migration.save')
|
||||
def _do_it(mock_mig_save):
|
||||
|
@ -4683,7 +4702,8 @@ class ComputeManagerMigrationTestCase(test.NoDBTestCase):
|
|||
@mock.patch.object(compute.driver, 'check_can_live_migrate_source')
|
||||
@mock.patch.object(compute, '_get_instance_block_device_info')
|
||||
@mock.patch.object(compute_utils, 'is_volume_backed_instance')
|
||||
def _test(mock_ivbi, mock_gibdi, mock_cclms):
|
||||
@mock.patch.object(compute_utils, 'EventReporter')
|
||||
def _test(mock_event, mock_ivbi, mock_gibdi, mock_cclms):
|
||||
mock_cclms.return_value = data
|
||||
self.assertIsInstance(
|
||||
compute.check_can_live_migrate_source(
|
||||
|
@ -4697,12 +4717,14 @@ class ComputeManagerMigrationTestCase(test.NoDBTestCase):
|
|||
def test_pre_live_migration_handles_dict(self):
|
||||
compute = manager.ComputeManager()
|
||||
|
||||
@mock.patch.object(compute_utils, 'EventReporter')
|
||||
@mock.patch.object(compute, '_notify_about_instance_usage')
|
||||
@mock.patch.object(compute, 'network_api')
|
||||
@mock.patch.object(compute.driver, 'pre_live_migration')
|
||||
@mock.patch.object(compute, '_get_instance_block_device_info')
|
||||
@mock.patch.object(compute_utils, 'is_volume_backed_instance')
|
||||
def _test(mock_ivbi, mock_gibdi, mock_plm, mock_nwapi, mock_notify):
|
||||
def _test(mock_ivbi, mock_gibdi, mock_plm, mock_nwapi, mock_notify,
|
||||
mock_event):
|
||||
migrate_data = migrate_data_obj.LiveMigrateData()
|
||||
mock_plm.return_value = migrate_data
|
||||
r = compute.pre_live_migration(self.context, {'uuid': 'foo'},
|
||||
|
@ -4756,6 +4778,7 @@ class ComputeManagerMigrationTestCase(test.NoDBTestCase):
|
|||
migration.status = 'running'
|
||||
migration.id = 0
|
||||
|
||||
@mock.patch.object(compute_utils.EventReporter, '__exit__')
|
||||
@mock.patch.object(compute_utils.EventReporter, '__enter__')
|
||||
@mock.patch.object(self.compute, '_notify_about_instance_usage')
|
||||
@mock.patch.object(objects.Migration, 'get_by_id',
|
||||
|
@ -4763,7 +4786,7 @@ class ComputeManagerMigrationTestCase(test.NoDBTestCase):
|
|||
@mock.patch.object(self.compute.driver,
|
||||
'live_migration_force_complete')
|
||||
def _do_test(force_complete, get_by_id, _notify_about_instance_usage,
|
||||
enter_event_reporter):
|
||||
enter_event_reporter, exit_event_reporter):
|
||||
self.compute.live_migration_force_complete(
|
||||
self.context, instance, migration.id)
|
||||
|
||||
|
@ -4783,6 +4806,7 @@ class ComputeManagerMigrationTestCase(test.NoDBTestCase):
|
|||
|
||||
def test_post_live_migration_at_destination_success(self):
|
||||
|
||||
@mock.patch.object(compute_utils, 'EventReporter')
|
||||
@mock.patch.object(self.instance, 'save')
|
||||
@mock.patch.object(self.compute.network_api, 'get_instance_nw_info',
|
||||
return_value='test_network')
|
||||
|
@ -4797,7 +4821,8 @@ class ComputeManagerMigrationTestCase(test.NoDBTestCase):
|
|||
def _do_test(post_live_migration_at_destination, _get_compute_info,
|
||||
_get_power_state, _get_instance_block_device_info,
|
||||
_notify_about_instance_usage, migrate_instance_finish,
|
||||
setup_networks_on_host, get_instance_nw_info, save):
|
||||
setup_networks_on_host, get_instance_nw_info, save,
|
||||
event_reporter):
|
||||
|
||||
cn = mock.Mock(spec_set=['hypervisor_hostname'])
|
||||
cn.hypervisor_hostname = 'test_host'
|
||||
|
@ -4851,6 +4876,7 @@ class ComputeManagerMigrationTestCase(test.NoDBTestCase):
|
|||
|
||||
def test_post_live_migration_at_destination_compute_not_found(self):
|
||||
|
||||
@mock.patch.object(compute_utils, 'EventReporter')
|
||||
@mock.patch.object(self.instance, 'save')
|
||||
@mock.patch.object(self.compute, 'network_api')
|
||||
@mock.patch.object(self.compute, '_notify_about_instance_usage')
|
||||
|
@ -4863,7 +4889,8 @@ class ComputeManagerMigrationTestCase(test.NoDBTestCase):
|
|||
'post_live_migration_at_destination')
|
||||
def _do_test(post_live_migration_at_destination, _get_compute_info,
|
||||
_get_power_state, _get_instance_block_device_info,
|
||||
_notify_about_instance_usage, network_api, save):
|
||||
_notify_about_instance_usage, network_api, save,
|
||||
event_reporter):
|
||||
cn = mock.Mock(spec_set=['hypervisor_hostname'])
|
||||
cn.hypervisor_hostname = 'test_host'
|
||||
_get_compute_info.return_value = cn
|
||||
|
@ -4876,6 +4903,7 @@ class ComputeManagerMigrationTestCase(test.NoDBTestCase):
|
|||
|
||||
def test_post_live_migration_at_destination_unexpected_exception(self):
|
||||
|
||||
@mock.patch.object(compute_utils, 'EventReporter')
|
||||
@mock.patch.object(compute_utils, 'add_instance_fault_from_exc')
|
||||
@mock.patch.object(self.instance, 'save')
|
||||
@mock.patch.object(self.compute, 'network_api')
|
||||
|
@ -4889,7 +4917,7 @@ class ComputeManagerMigrationTestCase(test.NoDBTestCase):
|
|||
def _do_test(post_live_migration_at_destination, _get_compute_info,
|
||||
_get_power_state, _get_instance_block_device_info,
|
||||
_notify_about_instance_usage, network_api, save,
|
||||
add_instance_fault_from_exc):
|
||||
add_instance_fault_from_exc, event_reporter):
|
||||
cn = mock.Mock(spec_set=['hypervisor_hostname'])
|
||||
cn.hypervisor_hostname = 'test_host'
|
||||
_get_compute_info.return_value = cn
|
||||
|
@ -4911,7 +4939,9 @@ class ComputeManagerMigrationTestCase(test.NoDBTestCase):
|
|||
@mock.patch.object(manager.ComputeManager, '_notify_about_instance_usage')
|
||||
@mock.patch.object(objects.Migration, 'get_by_id')
|
||||
@mock.patch.object(nova.virt.fake.SmallFakeDriver, 'live_migration_abort')
|
||||
@mock.patch.object(compute_utils, 'EventReporter')
|
||||
def test_live_migration_abort(self,
|
||||
mock_event,
|
||||
mock_driver,
|
||||
mock_get_migration,
|
||||
mock_notify):
|
||||
|
@ -4934,7 +4964,9 @@ class ComputeManagerMigrationTestCase(test.NoDBTestCase):
|
|||
@mock.patch.object(manager.ComputeManager, '_notify_about_instance_usage')
|
||||
@mock.patch.object(objects.Migration, 'get_by_id')
|
||||
@mock.patch.object(nova.virt.fake.SmallFakeDriver, 'live_migration_abort')
|
||||
@mock.patch.object(compute_utils, 'EventReporter')
|
||||
def test_live_migration_abort_not_supported(self,
|
||||
mock_event,
|
||||
mock_driver,
|
||||
mock_get_migration,
|
||||
mock_notify,
|
||||
|
@ -4951,7 +4983,9 @@ class ComputeManagerMigrationTestCase(test.NoDBTestCase):
|
|||
|
||||
@mock.patch.object(compute_utils, 'add_instance_fault_from_exc')
|
||||
@mock.patch.object(objects.Migration, 'get_by_id')
|
||||
@mock.patch.object(compute_utils, 'EventReporter')
|
||||
def test_live_migration_abort_wrong_migration_state(self,
|
||||
mock_event,
|
||||
mock_get_migration,
|
||||
mock_instance_fault):
|
||||
instance = objects.Instance(id=123, uuid=uuids.instance)
|
||||
|
|
Loading…
Reference in New Issue