Split the existing notification handlers up
We want to be able to enable and disable the handlers for notification events individually. This change splits them up so they are registered with separate names to allow that. This change also adds python-glanceclient as a test dependency so we can import the test code from nova. Change-Id: Icc07baba3f00294d8ee505a2cc82f65c0c7f4fc9 Signed-off-by: Doug Hellmann <doug.hellmann@dreamhost.com>
This commit is contained in:
parent
25d9bdb6ab
commit
a8ff8fe0c3
@ -23,7 +23,7 @@ from ceilometer import plugin
|
||||
from ceilometer.compute import instance
|
||||
|
||||
|
||||
class InstanceNotifications(plugin.NotificationBase):
|
||||
class _Base(plugin.NotificationBase):
|
||||
"""Convert compute.instance.* notifications into Counters
|
||||
"""
|
||||
|
||||
@ -34,8 +34,12 @@ class InstanceNotifications(plugin.NotificationBase):
|
||||
'compute.instance.delete.start',
|
||||
]
|
||||
|
||||
|
||||
class Instance(_Base):
|
||||
|
||||
@staticmethod
|
||||
def process_notification(message):
|
||||
metadata = instance.get_metadata_from_event(message)
|
||||
return [
|
||||
counter.Counter(source='?',
|
||||
name='instance',
|
||||
@ -46,8 +50,16 @@ class InstanceNotifications(plugin.NotificationBase):
|
||||
resource_id=message['payload']['instance_id'],
|
||||
timestamp=message['timestamp'],
|
||||
duration=0,
|
||||
resource_metadata=instance.get_metadata_from_event(
|
||||
message)),
|
||||
resource_metadata=metadata,
|
||||
),
|
||||
]
|
||||
|
||||
|
||||
class Memory(_Base):
|
||||
|
||||
@staticmethod
|
||||
def process_notification(message):
|
||||
return [
|
||||
counter.Counter(source='?',
|
||||
name='memory',
|
||||
type='absolute',
|
||||
@ -58,6 +70,14 @@ class InstanceNotifications(plugin.NotificationBase):
|
||||
timestamp=message['timestamp'],
|
||||
duration=0,
|
||||
resource_metadata={}),
|
||||
]
|
||||
|
||||
|
||||
class VCpus(_Base):
|
||||
|
||||
@staticmethod
|
||||
def process_notification(message):
|
||||
return [
|
||||
counter.Counter(source='?',
|
||||
name='vcpus',
|
||||
type='absolute',
|
||||
@ -68,6 +88,14 @@ class InstanceNotifications(plugin.NotificationBase):
|
||||
timestamp=message['timestamp'],
|
||||
duration=0,
|
||||
resource_metadata={}),
|
||||
]
|
||||
|
||||
|
||||
class RootDiskSize(_Base):
|
||||
|
||||
@staticmethod
|
||||
def process_notification(message):
|
||||
return [
|
||||
counter.Counter(source='?',
|
||||
name='root_disk_size',
|
||||
type='absolute',
|
||||
@ -78,6 +106,14 @@ class InstanceNotifications(plugin.NotificationBase):
|
||||
timestamp=message['timestamp'],
|
||||
duration=0,
|
||||
resource_metadata={}),
|
||||
]
|
||||
|
||||
|
||||
class EphemeralDiskSize(_Base):
|
||||
|
||||
@staticmethod
|
||||
def process_notification(message):
|
||||
return [
|
||||
counter.Counter(source='?',
|
||||
name='ephemeral_disk_size',
|
||||
type='absolute',
|
||||
|
6
setup.py
6
setup.py
@ -37,7 +37,11 @@ setuptools.setup(
|
||||
py_modules=[],
|
||||
entry_points=textwrap.dedent("""
|
||||
[ceilometer.collector.compute]
|
||||
instance = ceilometer.compute.notifications:InstanceNotifications
|
||||
instance = ceilometer.compute.notifications:Instance
|
||||
memory = ceilometer.compute.notifications:Memory
|
||||
vcpus = ceilometer.compute.notifications:VCpus
|
||||
root_disk_size = ceilometer.compute.notifications:RootDiskSize
|
||||
ephemeral_disk_size = ceilometer.compute.notifications:EphemeralDiskSize
|
||||
|
||||
[ceilometer.poll.compute]
|
||||
libvirt_diskio = ceilometer.compute.libvirt:DiskIOPollster
|
||||
|
@ -25,7 +25,7 @@ from ceilometer.collector import dispatcher
|
||||
class StubDispatcher(dispatcher.NotificationDispatcher):
|
||||
def _load_plugins(self):
|
||||
self.handlers['compute.instance.create.end'] = [
|
||||
notifications.InstanceNotifications(),
|
||||
notifications.Instance(),
|
||||
]
|
||||
|
||||
|
||||
|
@ -167,7 +167,7 @@ INSTANCE_EXISTS = {
|
||||
|
||||
class TestNotifications(unittest.TestCase):
|
||||
def test_process_notification(self):
|
||||
info = notifications.InstanceNotifications.process_notification(INSTANCE_CREATE_END)[0]
|
||||
info = notifications.Instance.process_notification(INSTANCE_CREATE_END)[0]
|
||||
|
||||
for name, actual, expected in [
|
||||
('counter_name', info.name, 'instance'),
|
||||
@ -186,38 +186,53 @@ class TestNotifications(unittest.TestCase):
|
||||
]:
|
||||
yield compare, name, actual, expected
|
||||
|
||||
def _check_counters(self, counters):
|
||||
counter_names = [ counter.name for counter in counters ]
|
||||
self.assertEqual(len(counters), 5)
|
||||
self.assert_('instance' in counter_names)
|
||||
self.assert_('memory' in counter_names)
|
||||
self.assert_('vcpus' in counter_names)
|
||||
self.assert_('root_disk_size' in counter_names)
|
||||
self.assert_('ephemeral_disk_size' in counter_names)
|
||||
|
||||
@staticmethod
|
||||
def _find_counter(counters, name):
|
||||
return filter(lambda counter: counter.name == name, counters)[0]
|
||||
|
||||
def test_instance_create(self):
|
||||
ic = notifications.InstanceNotifications()
|
||||
def test_instance_create_instance(self):
|
||||
ic = notifications.Instance()
|
||||
counters = ic.process_notification(INSTANCE_CREATE_END)
|
||||
self._check_counters(counters)
|
||||
self.assertEqual(len(counters), 1)
|
||||
c = counters[0]
|
||||
self.assertEqual(c.volume, 1)
|
||||
|
||||
self.assertEqual(self._find_counter(counters, 'instance').volume, 1)
|
||||
self.assertEqual(self._find_counter(counters, 'memory').volume,
|
||||
INSTANCE_CREATE_END['payload']['memory_mb'])
|
||||
self.assertEqual(self._find_counter(counters, 'vcpus').volume,
|
||||
INSTANCE_CREATE_END['payload']['vcpus'])
|
||||
self.assertEqual(self._find_counter(counters, 'root_disk_size').volume,
|
||||
INSTANCE_CREATE_END['payload']['root_gb'])
|
||||
self.assertEqual(self._find_counter(counters, 'ephemeral_disk_size').volume,
|
||||
def test_instance_create_memory(self):
|
||||
ic = notifications.Memory()
|
||||
counters = ic.process_notification(INSTANCE_CREATE_END)
|
||||
self.assertEqual(len(counters), 1)
|
||||
c = counters[0]
|
||||
self.assertEqual(c.volume, INSTANCE_CREATE_END['payload']['memory_mb'])
|
||||
|
||||
def test_instance_create_vcpus(self):
|
||||
ic = notifications.VCpus()
|
||||
counters = ic.process_notification(INSTANCE_CREATE_END)
|
||||
self.assertEqual(len(counters), 1)
|
||||
c = counters[0]
|
||||
self.assertEqual(c.volume, INSTANCE_CREATE_END['payload']['vcpus'])
|
||||
|
||||
def test_instance_create_root_disk_size(self):
|
||||
ic = notifications.RootDiskSize()
|
||||
counters = ic.process_notification(INSTANCE_CREATE_END)
|
||||
self.assertEqual(len(counters), 1)
|
||||
c = counters[0]
|
||||
self.assertEqual(c.volume, INSTANCE_CREATE_END['payload']['root_gb'])
|
||||
|
||||
def test_instance_create_ephemiral_disk_size(self):
|
||||
ic = notifications.EphemeralDiskSize()
|
||||
counters = ic.process_notification(INSTANCE_CREATE_END)
|
||||
self.assertEqual(len(counters), 1)
|
||||
c = counters[0]
|
||||
self.assertEqual(c.volume,
|
||||
INSTANCE_CREATE_END['payload']['ephemeral_gb'])
|
||||
|
||||
def test_instance_exists(self):
|
||||
ic = notifications.InstanceNotifications()
|
||||
self._check_counters(ic.process_notification(INSTANCE_EXISTS))
|
||||
def test_instance_exists_instance(self):
|
||||
ic = notifications.Instance()
|
||||
counters = ic.process_notification(INSTANCE_EXISTS)
|
||||
self.assertEqual(len(counters), 1)
|
||||
|
||||
def test_instance_delete_instance(self):
|
||||
ic = notifications.Instance()
|
||||
counters = ic.process_notification(INSTANCE_DELETE_START)
|
||||
self.assertEqual(len(counters), 1)
|
||||
|
||||
def test_instance_delete(self):
|
||||
ic = notifications.InstanceNotifications()
|
||||
self._check_counters(ic.process_notification(INSTANCE_DELETE_START))
|
||||
|
@ -3,6 +3,7 @@ coverage
|
||||
pep8>=1.0
|
||||
mox
|
||||
glance>=2011.3.1
|
||||
python-glanceclient
|
||||
# NOTE(dhellmann): Ming is necessary to provide the Mongo-in-memory
|
||||
# implementation for of MongoDB. The original source for Ming is at
|
||||
# http://sourceforge.net/project/merciless but there does not seem to
|
||||
|
Loading…
x
Reference in New Issue
Block a user