From d6782ad3c1e638748f37cf432c959ea318d4b6be Mon Sep 17 00:00:00 2001 From: Doug Hellmann Date: Tue, 5 Feb 2013 08:43:55 -0500 Subject: [PATCH] More robust mocking of nova conductor Update the nova notifier test to use the fake RPC implementation to avoid hangs more completely. Also update the test to mock out the entire conductor API object in the manager created by the test, instead of mocking individual methods. Change-Id: I741a609bd3ddfeb302d39b1c61a4b6896de2bf47 Signed-off-by: Doug Hellmann --- tests/compute/test_nova_notifier.py | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/tests/compute/test_nova_notifier.py b/tests/compute/test_nova_notifier.py index b96fb6dd0..f658a8344 100644 --- a/tests/compute/test_nova_notifier.py +++ b/tests/compute/test_nova_notifier.py @@ -91,6 +91,7 @@ class TestNovaNotifier(base.TestCase): super(TestNovaNotifier, self).setUp() nova_CONF.compute_driver = 'nova.virt.fake.FakeDriver' nova_CONF.notification_driver = [nova_notifier.__name__] + nova_CONF.rpc_backend = 'ceilometer.openstack.common.rpc.impl_fake' self.compute = importutils.import_object(nova_CONF.compute_manager) self.context = context.get_admin_context() fake_network.set_stub_network_methods(self.stubs) @@ -168,19 +169,13 @@ class TestNovaNotifier(base.TestCase): # the nova manager and the remote system since we can't # expect the message bus to be available, or the remote # controller to be there if the message bus is online. - @mock.patch.object(nova.conductor.api.API, - 'block_device_mapping_get_all_by_instance', - lambda obj, context, instance: {}) + @mock.patch.object(self.compute, 'conductor_api') + # The code that looks up the instance uses a global + # reference to the API, so we also have to patch that to + # return our fake data. @mock.patch.object(nova.conductor.api.API, 'instance_get_by_uuid', self.fake_db_instance_get) - @mock.patch('nova.conductor.api.API.instance_info_cache_delete') - @mock.patch('nova.conductor.api.API.instance_destroy') - @mock.patch('nova.conductor.api.API.block_device_mapping_destroy') - @mock.patch('nova.conductor.api.API.instance_update') - @mock.patch('nova.conductor.api.API.action_event_start') - @mock.patch('nova.conductor.api.API.action_event_finish') - @mock.patch('nova.compute.utils.add_instance_fault_from_exc') def run_test(*omit_args): self.compute.terminate_instance(self.context, instance=self.instance)