From 3228eac892473aa87b2f82f240a4336fa320ef24 Mon Sep 17 00:00:00 2001 From: Julien Danjou Date: Thu, 26 Jul 2012 13:13:49 +0200 Subject: [PATCH] Implements vcpus counter This is the same kind of counter of memory. Change-Id: If2e3a0e9c958f1c147ad1cbabcd25539d5b8b68f Signed-off-by: Julien Danjou --- ceilometer/compute/notifications.py | 12 +++++++++++- tests/compute/test_notifications.py | 11 ++++++++--- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/ceilometer/compute/notifications.py b/ceilometer/compute/notifications.py index aa26ac55..501d8ca9 100644 --- a/ceilometer/compute/notifications.py +++ b/ceilometer/compute/notifications.py @@ -54,7 +54,17 @@ class InstanceNotifications(plugin.NotificationBase): volume=message['payload']['memory_mb'], user_id=message['payload']['user_id'], project_id=message['payload']['tenant_id'], - resource_id=message['payload']['instance_id'], + resource_id=message['payload']['instance_id'], + timestamp=message['timestamp'], + duration=0, + resource_metadata={}), + counter.Counter(source='?', + name='vcpus', + type='absolute', + volume=message['payload']['vcpus'], + 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 7b0ce304..fdf0bcb4 100644 --- a/tests/compute/test_notifications.py +++ b/tests/compute/test_notifications.py @@ -191,7 +191,7 @@ class TestNotifications(unittest.TestCase): ic = notifications.InstanceNotifications() counters = ic.process_notification(INSTANCE_CREATE_END) - self.assertEqual(len(counters), 2) + self.assertEqual(len(counters), 3) self.assertEqual(counters[0].name, 'instance') self.assertEqual(counters[0].volume, 1) @@ -199,18 +199,23 @@ class TestNotifications(unittest.TestCase): 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']) + def test_instance_exists(self): ic = notifications.InstanceNotifications() counters = ic.process_notification(INSTANCE_EXISTS) - self.assertEqual(len(counters), 2) + self.assertEqual(len(counters), 3) self.assertEqual(counters[0].name, 'instance') self.assertEqual(counters[1].name, 'memory') + self.assertEqual(counters[2].name, 'vcpus') def test_instance_delete(self): ic = notifications.InstanceNotifications() counters = ic.process_notification(INSTANCE_DELETE_START) - self.assertEqual(len(counters), 2) + self.assertEqual(len(counters), 3) self.assertEqual(counters[0].name, 'instance') self.assertEqual(counters[1].name, 'memory') + self.assertEqual(counters[2].name, 'vcpus')