Fix nova test_notifier wrt new notifier API

The Oslo notifier api lost add_driver(), and nova copy of that code has
been updated recently, so that broke Ceilometer testing of that piece.
Fix it by using another mechanism to test.

Change-Id: I0169fcc9955501d490dfcdd7742205ea5c9ba15b
Closes-Bug: #1211532
This commit is contained in:
Julien Danjou 2013-08-13 11:15:03 +02:00
parent 90ad86c084
commit 486f723f43

View File

@ -43,7 +43,6 @@ from nova import context
from nova import db from nova import db
from nova.openstack.common import importutils from nova.openstack.common import importutils
from nova.openstack.common import log as logging from nova.openstack.common import log as logging
from nova.openstack.common.notifier import api as notifier_api
# This option is used in the nova_notifier module, so make # This option is used in the nova_notifier module, so make
# sure it is defined. # sure it is defined.
@ -89,7 +88,10 @@ class TestNovaNotifier(base.TestCase):
def setUp(self): def setUp(self):
super(TestNovaNotifier, self).setUp() super(TestNovaNotifier, self).setUp()
nova_CONF.compute_driver = 'nova.virt.fake.FakeDriver' nova_CONF.compute_driver = 'nova.virt.fake.FakeDriver'
nova_CONF.notification_driver = [nova_notifier.__name__] nova_CONF.notification_driver = [
nova_notifier.__name__,
'nova.openstack.common.notifier.rpc_notifier',
]
nova_CONF.rpc_backend = 'nova.openstack.common.rpc.impl_fake' nova_CONF.rpc_backend = 'nova.openstack.common.rpc.impl_fake'
nova_CONF.vnc_enabled = False nova_CONF.vnc_enabled = False
nova_CONF.spice.enabled = False nova_CONF.spice.enabled = False
@ -149,9 +151,6 @@ class TestNovaNotifier(base.TestCase):
# Set up to capture the notification messages generated by the # Set up to capture the notification messages generated by the
# plugin and to invoke our notifier plugin. # plugin and to invoke our notifier plugin.
self.notifications = [] self.notifications = []
notifier_api._reset_drivers()
notifier_api.add_driver(self)
notifier_api.add_driver(nova_notifier)
ext_mgr = test_manager.TestExtensionManager([ ext_mgr = test_manager.TestExtensionManager([
extension.Extension('test', extension.Extension('test',
@ -179,12 +178,13 @@ class TestNovaNotifier(base.TestCase):
mock.patch.object(nova_notifier.instance_info_source, mock.patch.object(nova_notifier.instance_info_source,
'instance_get_by_uuid', 'instance_get_by_uuid',
self.fake_instance_ref_get), self.fake_instance_ref_get),
mock.patch('nova.openstack.common.notifier.rpc_notifier.notify',
self.notify)
): ):
self.compute.terminate_instance(self.context, self.compute.terminate_instance(self.context,
instance=self.instance) instance=self.instance)
def tearDown(self): def tearDown(self):
notifier_api._reset_drivers()
self.Pollster.instances = [] self.Pollster.instances = []
super(TestNovaNotifier, self).tearDown() super(TestNovaNotifier, self).tearDown()
nova_notifier._gatherer = None nova_notifier._gatherer = None
@ -206,9 +206,7 @@ class TestNovaNotifier(base.TestCase):
self.notifications.append(message) self.notifications.append(message)
def test_pollster_called(self): def test_pollster_called(self):
# The notifier plugin sends another notification for the same self.assertEqual(len(self.Pollster.instances), 1)
# instance, so we expect to have 2 entries in the list.
self.assertEqual(len(self.Pollster.instances), 2)
def test_correct_instance(self): def test_correct_instance(self):
for i, (gatherer, inst) in enumerate(self.Pollster.instances): for i, (gatherer, inst) in enumerate(self.Pollster.instances):