def test_image_download(self): handler = notifications.ImageDownload() counters = handler.process_notification(NOTIFICATION_SEND) self.assertEqual(len(counters), 1) download = counters[0] self._verify_common_counter(download, 'image.download', 42) self.assertEqual(download.user_id, utils.fake_uuid('d')) self.assertEqual(download.project_id, utils.fake_uuid('b')) self.assertEqual(download.type, counter.TYPE_DELTA)
def test_image_serve(self): handler = notifications.ImageServe() counters = handler.process_notification(NOTIFICATION_SEND) self.assertEqual(len(counters), 1) serve = counters[0] self._verify_common_counter(serve, 'image.serve', 42) self.assertEqual(serve.project_id, utils.fake_uuid('e')) self.assertEquals(serve.resource_metadata.get('receiver_user_id'), utils.fake_uuid('d')) self.assertEquals(serve.resource_metadata.get('receiver_tenant_id'), utils.fake_uuid('b')) self.assertEqual(serve.type, counter.TYPE_DELTA)
def _verify_common_counter(self, c, name, volume): self.assertFalse(c is None) self.assertEqual(c.name, name) self.assertEqual(c.resource_id, utils.fake_uuid('c')) self.assertEqual(c.timestamp, NOW) self.assertEqual(c.volume, volume) metadata = c.resource_metadata self.assertEquals(metadata.get('host'), u'images.example.com')
# License for the specific language governing permissions and limitations # under the License. from datetime import datetime import unittest from ceilometer.image import notifications from ceilometer import counter from tests import utils NOW = datetime.isoformat(datetime.utcnow()) NOTIFICATION_SEND = { u'event_type': u'image.send', u'timestamp': NOW, u'message_id': utils.fake_uuid('a'), u'priority': u'INFO', u'publisher_id': u'images.example.com', u'payload': {u'receiver_tenant_id': utils.fake_uuid('b'), u'destination_ip': u'1.2.3.4', u'bytes_sent': 42, u'image_id': utils.fake_uuid('c'), u'receiver_user_id': utils.fake_uuid('d'), u'owner_id': utils.fake_uuid('e')} } IMAGE_META = {u'status': u'saving', u'name': u'fake image #3', u'deleted': False, u'container_format': u'ovf', u'created_at': u'2012-09-18T10:13:44.571370',