From a58a9eefaf66eb1f0cec198b33b5816fd92d3800 Mon Sep 17 00:00:00 2001 From: Julien Danjou Date: Tue, 9 Oct 2012 11:04:40 +0200 Subject: [PATCH] image: handle glance delete notifications This fixes bug #1056982 Change-Id: Ica181bf8ee6f2952cf5e8c761768a58325ce802d Signed-off-by: Julien Danjou --- ceilometer/image/notifications.py | 1 + doc/source/measurements.rst | 1 + tests/image/test_notifications.py | 33 +++++++++++++++++++++++++++++++ 3 files changed, 35 insertions(+) diff --git a/ceilometer/image/notifications.py b/ceilometer/image/notifications.py index 48dfb5da..c165d87f 100644 --- a/ceilometer/image/notifications.py +++ b/ceilometer/image/notifications.py @@ -78,6 +78,7 @@ class ImageCRUDBase(ImageBase): return [ 'image.update', 'image.upload', + 'image.delete', ] diff --git a/doc/source/measurements.rst b/doc/source/measurements.rst index 35b9cd96..a38b5239 100644 --- a/doc/source/measurements.rst +++ b/doc/source/measurements.rst @@ -85,6 +85,7 @@ image Gauge 1 image ID Image polling -> it (st image.size Gauge bytes image ID Uploaded image size image.update Delta reqs image ID Number of update on the image image.upload Delta reqs image ID Number of upload of the image +image.delete Delta reqs image ID Number of delete on the image image.download Delta bytes image ID Image is downloaded image.serve Delta bytes image ID Image is served out ======================== ========== ======= ======== ======================================================= diff --git a/tests/image/test_notifications.py b/tests/image/test_notifications.py index 28e597a9..e4ae8f11 100644 --- a/tests/image/test_notifications.py +++ b/tests/image/test_notifications.py @@ -77,6 +77,14 @@ NOTIFICATION_UPLOAD = {"message_id": "0c65cb9c-018c-11e2-bc91-5453ed1bbb5f", "timestamp": NOW} +NOTIFICATION_DELETE = {"message_id": "0c65cb9c-018c-11e2-bc91-5453ed1bbb5f", + "publisher_id": "images.example.com", + "event_type": "image.delete", + "priority": "info", + "payload": IMAGE_META, + "timestamp": NOW} + + class TestNotification(unittest.TestCase): def _verify_common_counter(self, c, name, volume): @@ -160,3 +168,28 @@ class TestNotification(unittest.TestCase): self._verify_common_counter(upload, 'image.size', IMAGE_META['size']) self.assertEqual(upload.type, counter.TYPE_GAUGE) + + def test_image_crud_on_delete(self): + handler = notifications.ImageCRUD() + counters = handler.process_notification(NOTIFICATION_DELETE) + self.assertEqual(len(counters), 1) + delete = counters[0] + self._verify_common_counter(delete, 'image.delete', 1) + self.assertEqual(delete.type, counter.TYPE_DELTA) + + def test_image_on_delete(self): + handler = notifications.Image() + counters = handler.process_notification(NOTIFICATION_DELETE) + self.assertEqual(len(counters), 1) + delete = counters[0] + self._verify_common_counter(delete, 'image', 1) + self.assertEqual(delete.type, counter.TYPE_GAUGE) + + def test_image_size_on_delete(self): + handler = notifications.ImageSize() + counters = handler.process_notification(NOTIFICATION_DELETE) + self.assertEqual(len(counters), 1) + delete = counters[0] + self._verify_common_counter(delete, 'image.size', + IMAGE_META['size']) + self.assertEqual(delete.type, counter.TYPE_GAUGE)