Skip to content

Commit

Permalink
remove direct nova db access from ceilometer.
Browse files Browse the repository at this point in the history
fix bug #1034666

Change-Id: I0686e7bb5311a39bd574fd9d67769450c9896b43
  • Loading branch information
Yaguang Tang committed Dec 11, 2012
1 parent c6a0935 commit 23ff2f9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
13 changes: 10 additions & 3 deletions ceilometer/compute/nova_notifier.py
Expand Up @@ -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
6 changes: 4 additions & 2 deletions tests/compute/test_nova_notifier.py
Expand Up @@ -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',
Expand Down Expand Up @@ -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:
Expand All @@ -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)
Expand Down

0 comments on commit 23ff2f9

Please sign in to comment.