def test_verify_exist_marks_exist_failed_if_field_mismatch_exception(self):
        utils.mock_datetime_utcnow(self.mox, '2014-01-02 03:04:05')

        exist1 = self.mox.CreateMockAnything()
        exist2 = self.mox.CreateMockAnything()

        self.mox.StubOutWithMock(glance_verifier, '_verify_for_usage')
        self.mox.StubOutWithMock(glance_verifier, '_verify_for_delete')
        self.mox.StubOutWithMock(glance_verifier, '_verify_validity')
        entity_1 = {'name': 'exists', 'value': 'expected'}
        entity_2 = {'name': 'launches', 'value': 'actual'}
        field_mismatch_exc = FieldMismatch('field', entity_1, entity_2, 'uuid')
        glance_verifier._verify_for_usage(exist1).AndRaise(
            exception=field_mismatch_exc)
        exist1.mark_failed(
            reason="Failed at 2014-01-02 03:04:05 UTC for uuid: Data mismatch "
                   "for 'field' - 'exists' contains 'expected' but 'launches' "
                   "contains 'actual'")
        glance_verifier._verify_for_usage(exist2)
        glance_verifier._verify_for_delete(exist2)
        glance_verifier._verify_validity(exist2)
        exist2.mark_verified()
        self.mox.ReplayAll()

        verified, exist = glance_verifier._verify([exist1, exist2])
        self.mox.VerifyAll()
        self.assertFalse(verified)
    def test_verify_exist_marks_exist_failed_if_field_mismatch_exception(self):
        utils.mock_datetime_utcnow(self.mox, "2014-01-02 03:04:05")

        exist1 = self.mox.CreateMockAnything()
        exist2 = self.mox.CreateMockAnything()

        self.mox.StubOutWithMock(glance_verifier, "_verify_for_usage")
        self.mox.StubOutWithMock(glance_verifier, "_verify_for_delete")
        self.mox.StubOutWithMock(glance_verifier, "_verify_validity")
        entity_1 = {"name": "exists", "value": "expected"}
        entity_2 = {"name": "launches", "value": "actual"}
        field_mismatch_exc = FieldMismatch("field", entity_1, entity_2, "uuid")
        glance_verifier._verify_for_usage(exist1).AndRaise(exception=field_mismatch_exc)
        exist1.mark_failed(
            reason="Failed at 2014-01-02 03:04:05 UTC for uuid: Data mismatch "
            "for 'field' - 'exists' contains 'expected' but 'launches' "
            "contains 'actual'"
        )
        glance_verifier._verify_for_usage(exist2)
        glance_verifier._verify_for_delete(exist2)
        glance_verifier._verify_validity(exist2)
        exist2.mark_verified()
        self.mox.ReplayAll()

        verified, exist = glance_verifier._verify([exist1, exist2])
        self.mox.VerifyAll()
        self.assertFalse(verified)
    def test_null_field_exception(self):
        utils.mock_datetime_utcnow(self.mox, '2014-01-02 03:04:05')

        exception = NullFieldException('field_name', 'exist_id', 'uuid')

        self.assertEqual(exception.field_name, 'field_name')
        self.assertEqual(
            exception.reason,
            "Failed at 2014-01-02 03:04:05 UTC for uuid: field_name field was "
            "null for exist id exist_id")
Esempio n. 4
0
    def test_null_field_exception(self):
        utils.mock_datetime_utcnow(self.mox, '2014-01-02 03:04:05')

        exception = NullFieldException('field_name', 'exist_id', 'uuid')

        self.assertEqual(exception.field_name, 'field_name')
        self.assertEqual(
            exception.reason,
            "Failed at 2014-01-02 03:04:05 UTC for uuid: field_name field was "
            "null for exist id exist_id")
    def test_wrong_type_exception(self):
        utils.mock_datetime_utcnow(self.mox, '2014-01-02 03:04:05')

        exception = WrongTypeException(
            'field_name', 'value', 'exist_id', 'uuid')
        self.assertEqual(exception.field_name, 'field_name')
        self.assertEqual(exception.value, 'value')
        self.assertEqual(exception.exist_id, 'exist_id')
        self.assertEqual(exception.uuid, 'uuid')
        self.assertEqual(
            exception.reason,
            "Failed at 2014-01-02 03:04:05 UTC for uuid: {field_name: value} "
            "was of incorrect type for exist id exist_id")
Esempio n. 6
0
    def test_wrong_type_exception(self):
        utils.mock_datetime_utcnow(self.mox, '2014-01-02 03:04:05')

        exception = WrongTypeException('field_name', 'value', 'exist_id',
                                       'uuid')
        self.assertEqual(exception.field_name, 'field_name')
        self.assertEqual(exception.value, 'value')
        self.assertEqual(exception.exist_id, 'exist_id')
        self.assertEqual(exception.uuid, 'uuid')
        self.assertEqual(
            exception.reason,
            "Failed at 2014-01-02 03:04:05 UTC for uuid: {field_name: value} "
            "was of incorrect type for exist id exist_id")
    def test_field_mismatch_exception(self):
        utils.mock_datetime_utcnow(self.mox, '2014-01-02 03:04:05')

        exception = FieldMismatch(
            'field_name',
            {'name': 'entity1', 'value': 'expected'},
            {'name': 'entity2', 'value': 'actual'},
            'uuid')

        self.assertEqual(
            exception.reason,
            "Failed at 2014-01-02 03:04:05 UTC for uuid: Data mismatch for "
            "'field_name' - 'entity1' contains 'expected' but 'entity2' "
            "contains 'actual'")
Esempio n. 8
0
    def test_field_mismatch_exception(self):
        utils.mock_datetime_utcnow(self.mox, '2014-01-02 03:04:05')

        exception = FieldMismatch('field_name', {
            'name': 'entity1',
            'value': 'expected'
        }, {
            'name': 'entity2',
            'value': 'actual'
        }, 'uuid')

        self.assertEqual(
            exception.reason,
            "Failed at 2014-01-02 03:04:05 UTC for uuid: Data mismatch for "
            "'field_name' - 'entity1' contains 'expected' but 'entity2' "
            "contains 'actual'")
    def test_verify_delete_deleted_at_mismatch(self):
        utils.mock_datetime_utcnow(self.mox, "2014-01-02 03:04:05")

        exist = self.mox.CreateMockAnything()
        exist.uuid = IMAGE_UUID_1
        exist.delete = self.mox.CreateMockAnything()
        exist.deleted_at = DELETED_AT_1
        exist.delete.deleted_at = DELETED_AT_2
        self.mox.ReplayAll()

        with self.assertRaises(FieldMismatch) as fm:
            glance_verifier._verify_for_delete(exist)
        exception = fm.exception
        entity_1 = {"name": "exists", "value": DELETED_AT_1}
        entity_2 = {"name": "deletes", "value": DELETED_AT_2}
        self.assertEqual(exception.field_name, "deleted_at")
        self.assertEqual(exception.entity_1, entity_1)
        self.assertEqual(exception.entity_2, entity_2)
        self.mox.VerifyAll()
    def test_should_verify_that_uuid_in_exist_is_not_null(self):
        utils.mock_datetime_utcnow(self.mox, '2014-01-01 01:02:03')

        exist = self.mox.CreateMockAnything()
        exist.id = 23
        exist.size = 'size'
        exist.created_at = decimal.Decimal('5.1')
        exist.uuid = None
        self.mox.ReplayAll()

        try:
            glance_verifier._verify_validity(exist)
            self.fail()
        except NullFieldException as nf:
            self.assertEqual(nf.field_name, 'uuid')
            self.assertEqual(
                nf.reason, "Failed at 2014-01-01 01:02:03 UTC for None: "
                           "uuid field was null for exist id 23")
        self.mox.VerifyAll()
    def test_should_verify_that_uuid_in_exist_is_not_null(self):
        utils.mock_datetime_utcnow(self.mox, "2014-01-01 01:02:03")

        exist = self.mox.CreateMockAnything()
        exist.id = 23
        exist.size = "size"
        exist.created_at = decimal.Decimal("5.1")
        exist.uuid = None
        self.mox.ReplayAll()

        try:
            glance_verifier._verify_validity(exist)
            self.fail()
        except NullFieldException as nf:
            self.assertEqual(nf.field_name, "uuid")
            self.assertEqual(
                nf.reason, "Failed at 2014-01-01 01:02:03 UTC for None: " "uuid field was null for exist id 23"
            )
        self.mox.VerifyAll()
    def test_verify_delete_deleted_at_mismatch(self):
        utils.mock_datetime_utcnow(self.mox, '2014-01-02 03:04:05')

        exist = self.mox.CreateMockAnything()
        exist.uuid = IMAGE_UUID_1
        exist.delete = self.mox.CreateMockAnything()
        exist.deleted_at = DELETED_AT_1
        exist.delete.deleted_at = DELETED_AT_2
        self.mox.ReplayAll()

        with self.assertRaises(FieldMismatch) as fm:
            glance_verifier._verify_for_delete(exist)
        exception = fm.exception
        entity_1 = {'name': 'exists', 'value': DELETED_AT_1}
        entity_2 = {'name': 'deletes', 'value': DELETED_AT_2}
        self.assertEqual(exception.field_name, 'deleted_at')
        self.assertEqual(exception.entity_1, entity_1)
        self.assertEqual(exception.entity_2, entity_2)
        self.mox.VerifyAll()
    def test_should_verify_that_created_at_in_exist_is_not_null(self):
        utils.mock_datetime_utcnow(self.mox, '2014-01-01 01:02:03')

        exist = self.mox.CreateMockAnything()
        exist.id = 23
        exist.size = 'size'
        exist.created_at = None
        exist.uuid = IMAGE_UUID_1
        self.mox.ReplayAll()

        with self.assertRaises(NullFieldException) as nfe:
            glance_verifier._verify_validity(exist)
        exception = nfe.exception

        self.assertEqual(exception.field_name, 'created_at')
        self.assertEqual(exception.reason,
                         "Failed at 2014-01-01 01:02:03 UTC for "
                         "%s: created_at "
                         "field was null for exist id 23" % IMAGE_UUID_1)
        self.mox.VerifyAll()
    def test_verify_usage_created_at_mismatch(self):
        utils.mock_datetime_utcnow(self.mox, "2014-01-01 01:02:03")

        exist = self.mox.CreateMockAnything()
        exist.uuid = IMAGE_UUID_1
        exist.usage = self.mox.CreateMockAnything()
        exist.created_at = CREATED_AT_1
        exist.usage.created_at = CREATED_AT_2
        self.mox.ReplayAll()

        with self.assertRaises(FieldMismatch) as cm:
            glance_verifier._verify_for_usage(exist)

        exception = cm.exception
        entity_1 = {"name": "exists", "value": CREATED_AT_1}
        entity_2 = {"name": "launches", "value": CREATED_AT_2}
        self.assertEqual(exception.field_name, "created_at")
        self.assertEqual(exception.entity_1, entity_1)
        self.assertEqual(exception.entity_2, entity_2)
        self.mox.VerifyAll()
    def test_verify_usage_created_at_mismatch(self):
        utils.mock_datetime_utcnow(self.mox, '2014-01-01 01:02:03')

        exist = self.mox.CreateMockAnything()
        exist.uuid = IMAGE_UUID_1
        exist.usage = self.mox.CreateMockAnything()
        exist.created_at = CREATED_AT_1
        exist.usage.created_at = CREATED_AT_2
        self.mox.ReplayAll()

        with self.assertRaises(FieldMismatch) as cm:
            glance_verifier._verify_for_usage(exist)

        exception = cm.exception
        entity_1 = {'name': 'exists', 'value': CREATED_AT_1}
        entity_2 = {'name': 'launches', 'value': CREATED_AT_2}
        self.assertEqual(exception.field_name, 'created_at')
        self.assertEqual(exception.entity_1, entity_1)
        self.assertEqual(exception.entity_2, entity_2)
        self.mox.VerifyAll()
Esempio n. 16
0
    def test_verify_usage_owner_mismatch(self):
        utils.mock_datetime_utcnow(self.mox, '2014-01-01 01:02:03')

        exist = self.mox.CreateMockAnything()
        exist.uuid = IMAGE_UUID_1
        exist.usage = self.mox.CreateMockAnything()
        exist.owner = IMAGE_OWNER_1
        exist.usage.owner = IMAGE_OWNER_2
        self.mox.ReplayAll()

        with self.assertRaises(FieldMismatch) as cm:
            glance_verifier._verify_for_usage(exist)

        exception = cm.exception
        entity_1 = {'name': 'exists', 'value': IMAGE_OWNER_1}
        entity_2 = {'name': 'launches', 'value': IMAGE_OWNER_2}
        self.assertEqual(exception.field_name, 'owner')
        self.assertEqual(exception.entity_1, entity_1)
        self.assertEqual(exception.entity_2, entity_2)
        self.mox.VerifyAll()
    def test_should_verify_that_image_size_in_exist_is_not_null(self):
        utils.mock_datetime_utcnow(self.mox, '2014-01-02 03:04:05')

        exist = self.mox.CreateMockAnything()
        exist.id = 23
        exist.size = None
        exist.created_at = decimal.Decimal('5.1')
        exist.uuid = IMAGE_UUID_1
        self.mox.ReplayAll()

        try:
            glance_verifier._verify_validity(exist)
            self.fail()
        except NullFieldException as nf:
            self.assertEqual(nf.field_name, 'image_size')
            self.assertEqual(
                nf.reason, "Failed at 2014-01-02 03:04:05 UTC for "
                "%s: image_size field was "
                "null for exist id 23" % IMAGE_UUID_1)
        self.mox.VerifyAll()
    def test_should_verify_that_owner_in_exist_is_not_null(self):
        utils.mock_datetime_utcnow(self.mox, '2014-01-01 01:02:03')

        exist = self.mox.CreateMockAnything()
        exist.id = 23
        exist.size = 1234
        exist.created_at = decimal.Decimal('5.1')
        exist.uuid = IMAGE_UUID_1
        exist.owner = None
        self.mox.ReplayAll()

        try:
            glance_verifier._verify_validity(exist)
            self.fail()
        except NullFieldException as nf:
            self.assertEqual(nf.field_name, 'owner')
            self.assertEqual(
                nf.reason, "Failed at 2014-01-01 01:02:03 UTC for "
                "12345678-6352-4dbc-8271-96cc54bf14cd: owner field was null "
                "for exist id 23")
        self.mox.VerifyAll()
Esempio n. 19
0
    def test_should_verify_that_owner_in_exist_is_not_null(self):
        utils.mock_datetime_utcnow(self.mox, '2014-01-01 01:02:03')

        exist = self.mox.CreateMockAnything()
        exist.id = 23
        exist.size = 1234
        exist.created_at = decimal.Decimal('5.1')
        exist.uuid = IMAGE_UUID_1
        exist.owner = None
        self.mox.ReplayAll()

        try:
            glance_verifier._verify_validity(exist)
            self.fail()
        except NullFieldException as nf:
            self.assertEqual(nf.field_name, 'owner')
            self.assertEqual(
                nf.reason,
                "Failed at 2014-01-01 01:02:03 UTC for "
                "%s: owner field was null "
                "for exist id 23" % IMAGE_UUID_1)
        self.mox.VerifyAll()
    def test_should_verify_that_image_size_in_exist_is_not_null(self):
        utils.mock_datetime_utcnow(self.mox, "2014-01-02 03:04:05")

        exist = self.mox.CreateMockAnything()
        exist.id = 23
        exist.size = None
        exist.created_at = decimal.Decimal("5.1")
        exist.uuid = IMAGE_UUID_1
        self.mox.ReplayAll()

        try:
            glance_verifier._verify_validity(exist)
            self.fail()
        except NullFieldException as nf:
            self.assertEqual(nf.field_name, "image_size")
            self.assertEqual(
                nf.reason,
                "Failed at 2014-01-02 03:04:05 UTC for "
                "12345678-6352-4dbc-8271-96cc54bf14cd: image_size field was "
                "null for exist id 23",
            )
        self.mox.VerifyAll()
    def test_should_verify_owner_is_of_type_hex(self):
        utils.mock_datetime_utcnow(self.mox, '2014-01-02 03:04:05')

        exist = self.mox.CreateMockAnything()
        exist.id = 23
        exist.size = 1234L
        exist.created_at = decimal.Decimal('5.1')
        exist.uuid = "58fb036d-5ef8-47a8-b503-7571276c400a"
        exist.owner = "3762854cd6f6435998188d5120e4c271,kl"
        self.mox.ReplayAll()

        try:
            glance_verifier._verify_validity(exist)
            self.fail()
        except WrongTypeException as wt:
            self.assertEqual(wt.field_name, 'owner')
            self.assertEqual(
                wt.reason, "Failed at 2014-01-02 03:04:05 UTC for "
                "58fb036d-5ef8-47a8-b503-7571276c400a: "
                "{owner: 3762854cd6f6435998188d5120e4c271,kl} was of "
                "incorrect type for exist id 23")
        self.mox.VerifyAll()
    def test_should_verify_that_created_at_in_exist_is_not_null(self):
        utils.mock_datetime_utcnow(self.mox, "2014-01-01 01:02:03")

        exist = self.mox.CreateMockAnything()
        exist.id = 23
        exist.size = "size"
        exist.created_at = None
        exist.uuid = IMAGE_UUID_1
        self.mox.ReplayAll()

        with self.assertRaises(NullFieldException) as nfe:
            glance_verifier._verify_validity(exist)
        exception = nfe.exception

        self.assertEqual(exception.field_name, "created_at")
        self.assertEqual(
            exception.reason,
            "Failed at 2014-01-01 01:02:03 UTC for "
            "12345678-6352-4dbc-8271-96cc54bf14cd: created_at "
            "field was null for exist id 23",
        )
        self.mox.VerifyAll()
Esempio n. 23
0
    def test_should_verify_owner_is_of_type_hex(self):
        utils.mock_datetime_utcnow(self.mox, '2014-01-02 03:04:05')

        exist = self.mox.CreateMockAnything()
        exist.id = 23
        exist.size = 1234L
        exist.created_at = decimal.Decimal('5.1')
        exist.uuid = "58fb036d-5ef8-47a8-b503-7571276c400a"
        exist.owner = "3762854cd6f6435998188d5120e4c271,kl"
        self.mox.ReplayAll()

        try:
            glance_verifier._verify_validity(exist)
            self.fail()
        except WrongTypeException as wt:
            self.assertEqual(wt.field_name, 'owner')
            self.assertEqual(
                wt.reason,
                "Failed at 2014-01-02 03:04:05 UTC for "
                "58fb036d-5ef8-47a8-b503-7571276c400a: "
                "{owner: 3762854cd6f6435998188d5120e4c271,kl} was of "
                "incorrect type for exist id 23")
        self.mox.VerifyAll()