image: handle glance upload notifications

This fixes bug #1056983

Change-Id: I7af63a92c1181a371788d73bc0d3d79c1c9cadeb
Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
Julien Danjou 2012-10-09 11:03:19 +02:00
parent 7873fd8bfd
commit fb870c3a7b
3 changed files with 35 additions and 0 deletions

View File

@ -77,6 +77,7 @@ class ImageCRUDBase(ImageBase):
def get_event_types():
return [
'image.update',
'image.upload',
]

View File

@ -84,6 +84,7 @@ Name Type Volume Resource Note
image Gauge 1 image ID Image polling -> it (still) exists
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.download Delta bytes image ID Image is downloaded
image.serve Delta bytes image ID Image is served out
======================== ========== ======= ======== =======================================================

View File

@ -69,6 +69,14 @@ NOTIFICATION_UPDATE = {"message_id": "0c65cb9c-018c-11e2-bc91-5453ed1bbb5f",
"timestamp": NOW}
NOTIFICATION_UPLOAD = {"message_id": "0c65cb9c-018c-11e2-bc91-5453ed1bbb5f",
"publisher_id": "images.example.com",
"event_type": "image.upload",
"priority": "info",
"payload": IMAGE_META,
"timestamp": NOW}
class TestNotification(unittest.TestCase):
def _verify_common_counter(self, c, name, volume):
@ -127,3 +135,28 @@ class TestNotification(unittest.TestCase):
self._verify_common_counter(update, 'image.size',
IMAGE_META['size'])
self.assertEqual(update.type, counter.TYPE_GAUGE)
def test_image_crud_on_upload(self):
handler = notifications.ImageCRUD()
counters = handler.process_notification(NOTIFICATION_UPLOAD)
self.assertEqual(len(counters), 1)
upload = counters[0]
self._verify_common_counter(upload, 'image.upload', 1)
self.assertEqual(upload.type, counter.TYPE_DELTA)
def test_image_on_upload(self):
handler = notifications.Image()
counters = handler.process_notification(NOTIFICATION_UPLOAD)
self.assertEqual(len(counters), 1)
upload = counters[0]
self._verify_common_counter(upload, 'image', 1)
self.assertEqual(upload.type, counter.TYPE_GAUGE)
def test_image_size_on_upload(self):
handler = notifications.ImageSize()
counters = handler.process_notification(NOTIFICATION_UPLOAD)
self.assertEqual(len(counters), 1)
upload = counters[0]
self._verify_common_counter(upload, 'image.size',
IMAGE_META['size'])
self.assertEqual(upload.type, counter.TYPE_GAUGE)