Exemplo n.º 1
0
    def test_save_image_exists(self):
        raw = self.mox.CreateMockAnything()
        notification = self.mox.CreateMockAnything()
        notification.save_exists(raw)
        self.mox.ReplayAll()

        views._process_glance_exists(raw, notification)
        self.mox.VerifyAll()
Exemplo n.º 2
0
    def test_save_image_exists(self):
        raw = self.mox.CreateMockAnything()
        notification = self.mox.CreateMockAnything()
        notification.save_exists(raw)
        self.mox.ReplayAll()

        views._process_glance_exists(raw, notification)
        self.mox.VerifyAll()
Exemplo n.º 3
0
    def test_save_image_exists_with_delete_not_none(self):
        raw = self.mox.CreateMockAnything()
        delete = self.mox.CreateMockAnything()
        audit_period_beginning = "2013-05-20 17:31:57.939614"
        audit_period_ending = "2013-06-20 17:31:57.939614"
        size = 123
        uuid = "2df2ccf6-bc1b-4853-aab0-25fda346b3bb"
        deleted_at = "2013-06-20 14:31:57.939614"
        body = {
            "event_type": "image.upload",
            "timestamp": "2013-06-20 18:31:57.939614",
            "publisher_id": "glance-api01-r2961.global.preprod-ord.ohthree.com",
            "payload": {
                "created_at": str(DUMMY_TIME),
                "status": "saving",
                "audit_period_beginning": audit_period_beginning,
                "audit_period_ending": audit_period_ending,
                "properties": {
                    "image_type": "snapshot",
                    "instance_uuid": INSTANCE_ID_1,
                    },
                "deleted_at": deleted_at,
                "size": size,
                "owner": TENANT_ID_1,
                "id": "2df2ccf6-bc1b-4853-aab0-25fda346b3bb",
                }
        }
        deployment = "1"
        routing_key = "glance_monitor.info"
        json = '{["routing_key", {%s}]}' % body

        self.mox.StubOutWithMock(db, 'create_image_exists')
        self.mox.StubOutWithMock(db, 'get_image_usage')
        self.mox.StubOutWithMock(db, 'get_image_delete')

        created_at_range = (DECIMAL_DUMMY_TIME, DECIMAL_DUMMY_TIME+1)
        db.get_image_usage(created_at__range=created_at_range,
                           uuid=uuid).AndReturn(None)
        db.get_image_delete(created_at__range=created_at_range,
                            uuid=uuid).AndReturn(delete)
        db.create_image_exists(
            created_at=utils.str_time_to_unix(str(DUMMY_TIME)),
            owner=TENANT_ID_1,
            raw=raw,
            audit_period_beginning=utils.str_time_to_unix(audit_period_beginning),
            audit_period_ending=utils.str_time_to_unix(audit_period_ending),
            size=size,
            uuid=uuid,
            usage=None,
            delete=delete,
            deleted_at=utils.str_time_to_unix(str(deleted_at))).AndReturn(raw)

        self.mox.ReplayAll()

        notification = GlanceNotification(body, deployment, routing_key,
                                          json)
        notification.save_exists(raw)
        self.mox.VerifyAll()
Exemplo n.º 4
0
    def test_save_image_exists_without_created_at(self):
        raw = self.mox.CreateMockAnything()
        raw.id = 1
        audit_period_beginning = "2013-05-20 17:31:57.939614"
        audit_period_ending = "2013-06-20 17:31:57.939614"
        size = 123
        uuid = "2df2ccf6-bc1b-4853-aab0-25fda346b3bb"
        body = {
            "event_type": "image.exists",
            "timestamp": "2013-06-20 18:31:57.939614",
            "publisher_id":
            "glance-api01-r2961.global.preprod-ord.ohthree.com",
            "payload": {
                "audit_period_beginning":
                audit_period_beginning,
                "audit_period_ending":
                audit_period_ending,
                "owner":
                TENANT_ID_1,
                "images": [{
                    "created_at": None,
                    "id": uuid,
                    "size": size,
                    "status": "saving",
                    "properties": {
                        "instance_uuid": INSTANCE_ID_1
                    },
                    "deleted_at": None,
                }, {
                    "created_at": None,
                    "id": uuid,
                    "size": size,
                    "status": "saving",
                    "properties": {
                        "instance_uuid": INSTANCE_ID_1
                    },
                    "deleted_at": None,
                }]
            }
        }
        deployment = "1"
        routing_key = "glance_monitor.info"
        json_body = json.dumps([routing_key, body])
        self.mox.StubOutWithMock(stacklog, 'warn')
        stacklog.warn("Ignoring exists without created_at. GlanceRawData(1)")
        stacklog.warn("Ignoring exists without created_at. GlanceRawData(1)")
        self.mox.ReplayAll()

        notification = GlanceNotification(body, deployment, routing_key,
                                          json_body)
        notification.save_exists(raw)
        self.mox.VerifyAll()
Exemplo n.º 5
0
    def test_save_image_exists_without_created_at(self):
        raw = self.mox.CreateMockAnything()
        raw.id = 1
        audit_period_beginning = "2013-05-20 17:31:57.939614"
        audit_period_ending = "2013-06-20 17:31:57.939614"
        size = 123
        uuid = "2df2ccf6-bc1b-4853-aab0-25fda346b3bb"
        body = {
            "event_type": "image.exists",
            "timestamp": "2013-06-20 18:31:57.939614",
            "publisher_id": "glance-api01-r2961.global.preprod-ord.ohthree.com",
            "payload": {
                "audit_period_beginning": audit_period_beginning,
                "audit_period_ending": audit_period_ending,
                "owner": TENANT_ID_1,
                "images":
                [
                    {
                        "created_at": None,
                        "id": uuid,
                        "size": size,
                        "status": "saving",
                        "properties": {"instance_uuid": INSTANCE_ID_1},
                        "deleted_at": None,
                    },
                    {
                        "created_at": None,
                        "id": uuid,
                        "size": size,
                        "status": "saving",
                        "properties": {"instance_uuid": INSTANCE_ID_1},
                        "deleted_at": None,
                    }
                ]
            }
        }
        deployment = "1"
        routing_key = "glance_monitor.info"
        json_body = json.dumps([routing_key, body])
        self.mox.StubOutWithMock(stacklog, 'warn')
        stacklog.warn("Ignoring exists without created_at. GlanceRawData(1)")
        stacklog.warn("Ignoring exists without created_at. GlanceRawData(1)")
        self.mox.ReplayAll()

        notification = GlanceNotification(body, deployment, routing_key,
                                          json_body)
        notification.save_exists(raw)
        self.mox.VerifyAll()
Exemplo n.º 6
0
    def test_save_exists_should_log_warning_when_payload_is_invalid(self):
        raw = self.mox.CreateMockAnything()
        raw.id = 1
        body = {
            "event_type": "image.exists",
            "publisher_id": "glance-api01-r2961.global.preprod-ord.ohthree.com",
            "payload": []
        }
        deployment = "1"
        routing_key = "glance_monitor.info"
        json_body = json.dumps([routing_key, body])
        self.mox.StubOutWithMock(stacklog, 'warn')
        stacklog.warn("Received exists with invalid payload GlanceRawData(1)")
        self.mox.ReplayAll()

        notification = GlanceNotification(body, deployment, routing_key,
                                          json_body)
        notification.save_exists(raw)
        self.mox.VerifyAll()
Exemplo n.º 7
0
    def test_save_exists_should_log_warning_when_payload_is_invalid(self):
        raw = self.mox.CreateMockAnything()
        raw.id = 1
        body = {
            "event_type": "image.exists",
            "publisher_id": "glance-api01-r2961.global.preprod-ord.ohthree.com",
            "payload": []
        }
        deployment = "1"
        routing_key = "glance_monitor.info"
        json_body = json.dumps([routing_key, body])
        self.mox.StubOutWithMock(stacklog, 'warn')
        stacklog.warn("Received exists with invalid payload GlanceRawData(1)")
        self.mox.ReplayAll()

        notification = GlanceNotification(body, deployment, routing_key,
                                          json_body)
        notification.save_exists(raw)
        self.mox.VerifyAll()
Exemplo n.º 8
0
def _process_glance_exists(raw, notification):
    notification.save_exists(raw)
Exemplo n.º 9
0
def _process_glance_exists(raw, notification):
    notification.save_exists(raw)
Exemplo n.º 10
0
    def test_save_image_exists_with_created_at_and_deleted_at(self):
        raw = self.mox.CreateMockAnything()
        delete = self.mox.CreateMockAnything()
        audit_period_beginning = "2013-05-20 17:31:57.939614"
        audit_period_ending = "2013-06-20 17:31:57.939614"
        created_at = "2013-05-20 19:31:57.939614"
        deleted_at = "2013-05-20 21:31:57.939614"
        size = 123
        uuid = "2df2ccf6-bc1b-4853-aab0-25fda346b3bb"
        body = {
            "event_type": "image.exists",
            "timestamp": "2013-06-20 18:31:57.939614",
            "publisher_id":
            "glance-api01-r2961.global.preprod-ord.ohthree.com",
            "message_id": "d14cfa51-6a0e-4cf8-9130-804738be96d2",
            "payload": {
                "audit_period_beginning":
                audit_period_beginning,
                "audit_period_ending":
                audit_period_ending,
                "owner":
                TENANT_ID_1,
                "images": [{
                    "created_at": created_at,
                    "id": uuid,
                    "size": size,
                    "status": "saving",
                    "properties": {
                        "instance_uuid": INSTANCE_ID_1
                    },
                    "deleted_at": deleted_at,
                }, {
                    "created_at": created_at,
                    "id": uuid,
                    "size": size,
                    "status": "saving",
                    "properties": {
                        "instance_uuid": INSTANCE_ID_1
                    },
                    "deleted_at": deleted_at,
                }]
            }
        }
        deployment = "1"
        routing_key = "glance_monitor.info"
        json_body = json.dumps([routing_key, body])
        self.mox.StubOutWithMock(db, 'create_image_exists')
        self.mox.StubOutWithMock(db, 'get_image_usage')
        self.mox.StubOutWithMock(db, 'get_image_delete')

        for i in range(0, 2):
            db.get_image_usage(uuid=uuid).AndReturn(None)
            db.get_image_delete(uuid=uuid).AndReturn(delete)
            db.create_image_exists(
                created_at=utils.str_time_to_unix(created_at),
                owner=TENANT_ID_1,
                raw=raw,
                audit_period_beginning=utils.str_time_to_unix(
                    audit_period_beginning),
                audit_period_ending=utils.str_time_to_unix(
                    audit_period_ending),
                size=size,
                uuid=uuid,
                usage=None,
                delete=delete,
                deleted_at=utils.str_time_to_unix(deleted_at),
                message_id="d14cfa51-6a0e-4cf8-9130-804738be96d2").AndReturn(
                    raw)

        self.mox.ReplayAll()

        notification = GlanceNotification(body, deployment, routing_key,
                                          json_body)
        notification.save_exists(raw)
        self.mox.VerifyAll()
Exemplo n.º 11
0
    def test_save_image_exists_with_created_at_and_deleted_at(self):
        raw = self.mox.CreateMockAnything()
        delete = self.mox.CreateMockAnything()
        audit_period_beginning = "2013-05-20 17:31:57.939614"
        audit_period_ending = "2013-06-20 17:31:57.939614"
        created_at = "2013-05-20 19:31:57.939614"
        deleted_at = "2013-05-20 21:31:57.939614"
        size = 123
        uuid = "2df2ccf6-bc1b-4853-aab0-25fda346b3bb"
        body = {
            "event_type": "image.exists",
            "timestamp": "2013-06-20 18:31:57.939614",
            "publisher_id": "glance-api01-r2961.global.preprod-ord.ohthree.com",
            "message_id": "d14cfa51-6a0e-4cf8-9130-804738be96d2",
            "payload": {
                "audit_period_beginning": audit_period_beginning,
                "audit_period_ending": audit_period_ending,
                "owner": TENANT_ID_1,
                "images":
                [
                    {
                        "created_at": created_at,
                        "id": uuid,
                        "size": size,
                        "status": "saving",
                        "properties": {"instance_uuid": INSTANCE_ID_1},
                        "deleted_at": deleted_at,
                    },
                    {
                        "created_at": created_at,
                        "id": uuid,
                        "size": size,
                        "status": "saving",
                        "properties": {"instance_uuid": INSTANCE_ID_1},
                        "deleted_at": deleted_at,
                    }
                ]
            }
        }
        deployment = "1"
        routing_key = "glance_monitor.info"
        json_body = json.dumps([routing_key, body])
        self.mox.StubOutWithMock(db, 'create_image_exists')
        self.mox.StubOutWithMock(db, 'get_image_usage')
        self.mox.StubOutWithMock(db, 'get_image_delete')

        for i in range(0, 2):
            db.get_image_usage(uuid=uuid).AndReturn(None)
            db.get_image_delete(uuid=uuid).AndReturn(delete)
            db.create_image_exists(
                created_at=utils.str_time_to_unix(created_at),
                owner=TENANT_ID_1,
                raw=raw,
                audit_period_beginning=utils.str_time_to_unix(audit_period_beginning),
                audit_period_ending=utils.str_time_to_unix(audit_period_ending),
                size=size,
                uuid=uuid,
                usage=None,
                delete=delete,
                deleted_at=utils.str_time_to_unix(deleted_at),
                message_id="d14cfa51-6a0e-4cf8-9130-804738be96d2").AndReturn(raw)

        self.mox.ReplayAll()

        notification = GlanceNotification(body, deployment, routing_key,
                                          json_body)
        notification.save_exists(raw)
        self.mox.VerifyAll()