예제 #1
0
 def glance_cuf(self, deployment_info, payload):
     args = dict(region=deployment_info['REGION'],
                 data_center=deployment_info['DATACENTER'],
                 event_type='image.exists.verified.cuf')
     glance_notification = GlanceNotification(payload, **args)
     entity = glance_notification.to_entity()
     payload_body = yagi.serializer.cuf.dump_item(entity, service_title="Glance")
     return self.unescape_strings(payload_body)
예제 #2
0
 def glance_cuf(self, deployment_info, payload):
     args = dict(region=deployment_info['REGION'],
                 data_center=deployment_info['DATACENTER'],
                 event_type='image.exists.verified.cuf')
     glance_notification = GlanceNotification(payload, **args)
     entity = glance_notification.to_entity()
     payload_body = yagi.serializer.cuf.dump_item(entity,
                                                  service_title="Glance")
     return self.unescape_strings(payload_body)
예제 #3
0
    def glance_cuf(self, deployment_info, payload):
        glance_notification = GlanceNotification(payload)
        cuf = glance_notification.convert_to_verified_message_in_cuf_format(
            {'region': deployment_info['DATACENTER'],
             'data_center': deployment_info['REGION']})

        entity = dict(content=cuf,
                      id=str(uuid.uuid4()),
                      event_type='image.exists.verified.cuf',
                      original_message_id=glance_notification.get_original_message_id())
        payload_body = yagi.serializer.cuf.dump_item(entity, service_title="Glance")
        return self.unescape_strings(payload_body)
예제 #4
0
    def glance_cuf(self, deployment_info, payload):

        cuf = GlanceNotification(payload). \
            convert_to_verified_message_in_cuf_format(
            {'region': deployment_info['DATACENTER'],
             'data_center': deployment_info['REGION']})

        entity = dict(content=cuf,
                      id=str(uuid.uuid4()),
                      event_type='image.exists.verified.cuf')
        payload_body = yagi.serializer.cuf.dump_item(entity,
                                                     service_title="Glance")
        return payload_body
예제 #5
0
    def test_convert_to_cuf_format(self):
        self.maxDiff = None
        event_type = 'image.exists.verified.cuf'
        exists_message = {
            "event_type": "image.exists",
            "timestamp": "2013-09-02 16:09:16.247932",
            "message_id": "18b59543-2e99-4208-ba53-22726c02bd67",
            "priority": "INFO",
            "publisher_id": "ubuntu",
            "payload": {
                "images": [{
                    "status": "active",
                    "name": "image1",
                    "created_at": "2013-09-02 16:08:10",
                    "properties": {
                        "image_type": "snapshot",
                        "instance_uuid": "inst_uuid1"
                    },
                    "deleted_at": None,
                    "id": "image1",
                    "size": 12345
                }, {
                    "status": "deleted",
                    "name": "image2",
                    "created_at": "2013-09-02 16:05:17",
                    "properties": {
                        "image_type": "snapshot",
                        "instance_uuid": "inst_uuid2"
                    },
                    "deleted_at": "2013-09-02 16:08:46",
                    "id": "image2",
                    "size": 67890
                }],
                "owner":
                "owner1",
                "audit_period_ending":
                "2013-09-02 23:59:59.999999",
                "audit_period_beginning":
                "2013-09-02 00:00:00"
            }
        }
        self.mox.StubOutWithMock(uuid, 'uuid4')
        uuid.uuid4().AndReturn('uuid1')
        uuid.uuid4().AndReturn('uuid2')
        self.mox.StubOutWithMock(notification_payload, 'start_time')
        self.mox.StubOutWithMock(notification_payload, 'end_time')
        notification_payload.start_time('2013-09-02 16:08:10',
                                        '2013-09-02 00:00:00').AndReturn(
                                            datetime.datetime(2013, 9, 2))
        notification_payload.end_time(None,
                                      '2013-09-02 23:59:59.999999').AndReturn(
                                          datetime.datetime(
                                              2013, 9, 2, 23, 59, 59, 999999))
        notification_payload.start_time('2013-09-02 16:05:17',
                                        '2013-09-02 00:00:00').AndReturn(
                                            datetime.datetime(
                                                2013, 9, 2, 16, 5, 17))
        notification_payload.end_time('2013-09-02 16:08:46',
                                      '2013-09-02 23:59:59.999999').AndReturn(
                                          datetime.datetime(
                                              2013, 9, 2, 23, 59, 59, 999999))
        self.mox.ReplayAll()
        expected_cuf_xml = {
            'payload':
            ("""<events><event endTime="2013-09-02T23:59:59Z" """
             """startTime="2013-09-02T00:00:00Z" region="DFW" dataCenter="DFW1" """
             """type="USAGE" id="uuid1" resourceId="image1" tenantId="owner1" """
             """version="1"> <glance:product storage="12345" serverId="inst_uuid1" """
             """serviceCode="Glance" serverName="" resourceType="snapshot" """
             """version="1"/></event><event endTime="2013-09-02T23:59:59Z" """
             """startTime="2013-09-02T16:05:17Z" region="DFW" dataCenter="DFW1" """
             """type="USAGE" id="uuid2" resourceId="image2" tenantId="owner1" """
             """version="1"> <glance:product storage="67890" serverId="inst_uuid2" """
             """serviceCode="Glance" serverName="" resourceType="snapshot" """
             """version="1"/></event></events>""")
        }
        notification = GlanceNotification(exists_message,
                                          event_type=event_type,
                                          region='DFW',
                                          data_center='DFW1')
        verified_message = notification.\
            convert_to_verified_message_in_cuf_format()

        self.assertEquals(verified_message, expected_cuf_xml)
        self.mox.VerifyAll()