From 8034b27272bc8101f926319dbe3a4f7c57e1d070 Mon Sep 17 00:00:00 2001 From: Julien Danjou Date: Thu, 26 Jul 2012 13:28:14 +0200 Subject: [PATCH] Add {root,ephemeral}_disk_size counters Change-Id: Ia4b9a9048df5cfca7cb868ee518297de86c78b71 Signed-off-by: Julien Danjou --- ceilometer/compute/notifications.py | 20 +++++++++++++ tests/compute/test_notifications.py | 46 +++++++++++++++-------------- 2 files changed, 44 insertions(+), 22 deletions(-) diff --git a/ceilometer/compute/notifications.py b/ceilometer/compute/notifications.py index 501d8ca9..e12e7239 100644 --- a/ceilometer/compute/notifications.py +++ b/ceilometer/compute/notifications.py @@ -68,4 +68,24 @@ class InstanceNotifications(plugin.NotificationBase): timestamp=message['timestamp'], duration=0, resource_metadata={}), + counter.Counter(source='?', + name='root_disk_size', + type='absolute', + volume=message['payload']['root_gb'], + user_id=message['payload']['user_id'], + project_id=message['payload']['tenant_id'], + resource_id=message['payload']['instance_id'], + timestamp=message['timestamp'], + duration=0, + resource_metadata={}), + counter.Counter(source='?', + name='ephemeral_disk_size', + type='absolute', + volume=message['payload']['ephemeral_gb'], + user_id=message['payload']['user_id'], + project_id=message['payload']['tenant_id'], + resource_id=message['payload']['instance_id'], + timestamp=message['timestamp'], + duration=0, + resource_metadata={}), ] diff --git a/tests/compute/test_notifications.py b/tests/compute/test_notifications.py index fdf0bcb4..9600965c 100644 --- a/tests/compute/test_notifications.py +++ b/tests/compute/test_notifications.py @@ -186,36 +186,38 @@ 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() counters = ic.process_notification(INSTANCE_CREATE_END) + self._check_counters(counters) - self.assertEqual(len(counters), 3) - - self.assertEqual(counters[0].name, 'instance') - self.assertEqual(counters[0].volume, 1) - - self.assertEqual(counters[1].name, 'memory') - self.assertEqual(counters[1].volume, INSTANCE_CREATE_END['payload']['memory_mb']) - - self.assertEqual(counters[2].name, 'vcpus') - self.assertEqual(counters[2].volume, INSTANCE_CREATE_END['payload']['vcpus']) - + 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, + INSTANCE_CREATE_END['payload']['ephemeral_gb']) def test_instance_exists(self): ic = notifications.InstanceNotifications() - counters = ic.process_notification(INSTANCE_EXISTS) - self.assertEqual(len(counters), 3) - self.assertEqual(counters[0].name, 'instance') - self.assertEqual(counters[1].name, 'memory') - self.assertEqual(counters[2].name, 'vcpus') - + self._check_counters(ic.process_notification(INSTANCE_EXISTS)) def test_instance_delete(self): ic = notifications.InstanceNotifications() - counters = ic.process_notification(INSTANCE_DELETE_START) - self.assertEqual(len(counters), 3) - self.assertEqual(counters[0].name, 'instance') - self.assertEqual(counters[1].name, 'memory') - self.assertEqual(counters[2].name, 'vcpus') + self._check_counters(ic.process_notification(INSTANCE_DELETE_START))