diff --git a/ceilometer/compute/nova_notifier.py b/ceilometer/compute/nova_notifier.py index 543c500c6d..65cb8b3657 100644 --- a/ceilometer/compute/nova_notifier.py +++ b/ceilometer/compute/nova_notifier.py @@ -59,7 +59,14 @@ def notify(context, message): if message['event_type'] == 'compute.instance.delete.start': instance_id = message['payload']['instance_id'] LOG.debug('polling final stats for %r', instance_id) - _agent_manager.poll_instance( - context, - db.instance_get_by_uuid(context, instance_id)) + try: + from nova.conductor import api + except ImportError: + # Keep compatibility with folsom. + _agent_manager.poll_instance(context, + db.instance_get_by_uuid(context, instance_id)) + else: + conductor_api = api.API() + _agent_manager.poll_instance(context, + conductor_api.instance_get_by_uuid(context, instance_id)) return diff --git a/tests/compute/test_nova_notifier.py b/tests/compute/test_nova_notifier.py index dcfd035137..d3323ee00d 100644 --- a/tests/compute/test_nova_notifier.py +++ b/tests/compute/test_nova_notifier.py @@ -119,8 +119,6 @@ def setUp(self): "access_ip_v6": "someip", "metadata": {}, "uuid": "144e08f4-00cb-11e2-888e-5453ed1bbb5f"} - - self.stubs.Set(db, 'instance_get_by_uuid', self.fake_db_instance_get) self.stubs.Set(db, 'instance_info_cache_delete', self.do_nothing) self.stubs.Set(db, 'instance_destroy', self.do_nothing) self.stubs.Set(db, 'instance_system_metadata_get', @@ -155,6 +153,8 @@ def test_notifications(self): # Folsom does not have nova.conductor, and it is safe to # call this method directly, but not safe to mock it # because mock.patch() fails to find the original. + self.stubs.Set(db, 'instance_get_by_uuid', + self.fake_db_instance_get) self.compute.terminate_instance(self.context, instance=self.instance) else: @@ -164,6 +164,8 @@ def test_notifications(self): # 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. + self.stubs.Set(nova.conductor.api.API, 'instance_get_by_uuid', + self.fake_db_instance_get) with mock.patch('nova.conductor.api.API.instance_update'): self.compute.terminate_instance(self.context, instance=self.instance)