Exemplo n.º 1
0
    def test_verify_for_launch_late_ambiguous_usage(self):
        exist = self.mox.CreateMockAnything()
        exist.usage = None
        exist.instance = INSTANCE_ID_1
        exist.launched_at = decimal.Decimal('1.1')
        exist.instance_type_id = 2
        results = self.mox.CreateMockAnything()
        models.InstanceUsage.objects.filter(instance=INSTANCE_ID_1) \
            .AndReturn(results)
        results.count().AndReturn(1)
        filters = {
            'instance': INSTANCE_ID_1,
            'launched_at__gte': decimal.Decimal('1.0'),
            'launched_at__lte': decimal.Decimal('1.999999')
        }
        models.InstanceUsage.objects.filter(**filters).AndReturn(results)
        results.count().AndReturn(2)
        self.mox.ReplayAll()

        try:
            dbverifier._verify_for_launch(exist)
            self.fail()
        except AmbiguousResults, nf:
            self.assertEqual(nf.object_type, 'InstanceUsage')
            search_params = {'instance': INSTANCE_ID_1,
                             'launched_at': decimal.Decimal('1.1')}
            self.assertEqual(nf.search_params, search_params)
Exemplo n.º 2
0
    def test_verify_for_launch_late_usage(self):
        exist = self.mox.CreateMockAnything()
        exist.usage = None
        exist.instance = INSTANCE_ID_1
        exist.launched_at = decimal.Decimal('1.1')
        exist.instance_type_id = 2
        results = self.mox.CreateMockAnything()
        models.InstanceUsage.objects.filter(instance=INSTANCE_ID_1)\
                                    .AndReturn(results)
        results.count().AndReturn(1)
        filters = {
            'instance': INSTANCE_ID_1,
            'launched_at__gte': decimal.Decimal('1.0'),
            'launched_at__lte': decimal.Decimal('1.999999')
        }
        models.InstanceUsage.objects.filter(**filters).AndReturn(results)
        results.count().AndReturn(1)
        usage = self.mox.CreateMockAnything()
        results.__getitem__(0).AndReturn(usage)
        usage.launched_at = decimal.Decimal('1.1')
        usage.instance_type_id = 2
        self.mox.ReplayAll()

        dbverifier._verify_for_launch(exist)
        self.mox.VerifyAll()
Exemplo n.º 3
0
    def test_verify_for_launch_late_usage(self):
        exist = self.mox.CreateMockAnything()
        exist.usage = None
        exist.instance = INSTANCE_ID_1
        exist.launched_at = decimal.Decimal('1.1')
        exist.instance_type_id = 2
        results = self.mox.CreateMockAnything()
        models.InstanceUsage.objects.filter(instance=INSTANCE_ID_1)\
                                    .AndReturn(results)
        results.count().AndReturn(1)
        filters = {
            'instance': INSTANCE_ID_1,
            'launched_at__gte': decimal.Decimal('1.0'),
            'launched_at__lte': decimal.Decimal('1.999999')
        }
        models.InstanceUsage.objects.filter(**filters).AndReturn(results)
        results.count().AndReturn(1)
        usage = self.mox.CreateMockAnything()
        results.__getitem__(0).AndReturn(usage)
        usage.launched_at = decimal.Decimal('1.1')
        usage.instance_type_id = 2
        self.mox.ReplayAll()

        dbverifier._verify_for_launch(exist)
        self.mox.VerifyAll()
Exemplo n.º 4
0
    def test_verify_for_launch_late_ambiguous_usage(self):
        exist = self.mox.CreateMockAnything()
        exist.usage = None
        exist.instance = INSTANCE_ID_1
        exist.launched_at = decimal.Decimal('1.1')
        exist.instance_type_id = 2
        results = self.mox.CreateMockAnything()
        models.InstanceUsage.objects.filter(instance=INSTANCE_ID_1) \
            .AndReturn(results)
        results.count().AndReturn(1)
        filters = {
            'instance': INSTANCE_ID_1,
            'launched_at__gte': decimal.Decimal('1.0'),
            'launched_at__lte': decimal.Decimal('1.999999')
        }
        models.InstanceUsage.objects.filter(**filters).AndReturn(results)
        results.count().AndReturn(2)
        self.mox.ReplayAll()

        try:
            dbverifier._verify_for_launch(exist)
            self.fail()
        except AmbiguousResults, nf:
            self.assertEqual(nf.object_type, 'InstanceUsage')
            search_params = {'instance': INSTANCE_ID_1,
                             'launched_at': decimal.Decimal('1.1')}
            self.assertEqual(nf.search_params, search_params)
Exemplo n.º 5
0
    def test_verify_for_launch(self):
        exist = self.mox.CreateMockAnything()
        exist.usage = self.mox.CreateMockAnything()
        exist.launched_at = decimal.Decimal('1.1')
        exist.instance_type_id = 2
        exist.usage.launched_at = decimal.Decimal('1.1')
        exist.usage.instance_type_id = 2
        self.mox.ReplayAll()

        dbverifier._verify_for_launch(exist)
        self.mox.VerifyAll()
Exemplo n.º 6
0
 def test_verify_exception_during_launch(self):
     exist = self.mox.CreateMockAnything()
     exist.launched_at = decimal.Decimal('1.1')
     self.mox.StubOutWithMock(dbverifier, '_verify_for_launch')
     self.mox.StubOutWithMock(dbverifier, '_verify_for_delete')
     self.mox.StubOutWithMock(dbverifier, '_mark_exist_failed')
     self.mox.StubOutWithMock(dbverifier, '_mark_exist_verified')
     dbverifier._verify_for_launch(exist).AndRaise(Exception())
     dbverifier._mark_exist_failed(exist, reason='Exception')
     self.mox.ReplayAll()
     dbverifier._verify(exist)
     self.mox.VerifyAll()
Exemplo n.º 7
0
 def test_verify_exception_during_launch(self):
     exist = self.mox.CreateMockAnything()
     exist.launched_at = decimal.Decimal('1.1')
     self.mox.StubOutWithMock(dbverifier, '_verify_for_launch')
     self.mox.StubOutWithMock(dbverifier, '_verify_for_delete')
     self.mox.StubOutWithMock(dbverifier, '_mark_exist_failed')
     self.mox.StubOutWithMock(dbverifier, '_mark_exist_verified')
     dbverifier._verify_for_launch(exist).AndRaise(Exception())
     dbverifier._mark_exist_failed(exist, reason='Exception')
     self.mox.ReplayAll()
     dbverifier._verify(exist)
     self.mox.VerifyAll()
Exemplo n.º 8
0
 def test_verify_pass(self):
     exist = self.mox.CreateMockAnything()
     exist.launched_at = decimal.Decimal('1.1')
     self.mox.StubOutWithMock(dbverifier, '_verify_for_launch')
     self.mox.StubOutWithMock(dbverifier, '_verify_for_delete')
     self.mox.StubOutWithMock(dbverifier, '_mark_exist_failed')
     self.mox.StubOutWithMock(dbverifier, '_mark_exist_verified')
     dbverifier._verify_for_launch(exist)
     dbverifier._verify_for_delete(exist)
     dbverifier._mark_exist_verified(exist)
     self.mox.ReplayAll()
     dbverifier._verify(exist)
     self.mox.VerifyAll()
Exemplo n.º 9
0
 def test_verify_launch_fail(self):
     exist = self.mox.CreateMockAnything()
     exist.launched_at = decimal.Decimal('1.1')
     self.mox.StubOutWithMock(dbverifier, '_verify_for_launch')
     self.mox.StubOutWithMock(dbverifier, '_verify_for_delete')
     self.mox.StubOutWithMock(dbverifier, '_mark_exists_failed')
     self.mox.StubOutWithMock(dbverifier, '_mark_exist_verified')
     verify_exception = VerificationException('test')
     dbverifier._verify_for_launch(exist).AndRaise(verify_exception)
     dbverifier._mark_exists_failed(exist)
     self.mox.ReplayAll()
     dbverifier._verify(exist)
     self.mox.VerifyAll()
Exemplo n.º 10
0
 def test_verify_pass(self):
     exist = self.mox.CreateMockAnything()
     exist.launched_at = decimal.Decimal('1.1')
     self.mox.StubOutWithMock(dbverifier, '_verify_for_launch')
     self.mox.StubOutWithMock(dbverifier, '_verify_for_delete')
     self.mox.StubOutWithMock(dbverifier, '_mark_exist_failed')
     self.mox.StubOutWithMock(dbverifier, '_mark_exist_verified')
     dbverifier._verify_for_launch(exist)
     dbverifier._verify_for_delete(exist)
     dbverifier._mark_exist_verified(exist)
     self.mox.ReplayAll()
     dbverifier._verify(exist)
     self.mox.VerifyAll()
Exemplo n.º 11
0
    def test_verify_for_launch(self):
        exist = self.mox.CreateMockAnything()
        exist.launched_at = decimal.Decimal('1.1')
        exist.instance_type_id = INSTANCE_TYPE_ID_1
        exist.tenant = TENANT_ID_1

        exist.usage = self.mox.CreateMockAnything()
        exist.usage.launched_at = decimal.Decimal('1.1')
        exist.usage.instance_type_id = INSTANCE_TYPE_ID_1
        exist.usage.tenant = TENANT_ID_1
        self.mox.ReplayAll()

        dbverifier._verify_for_launch(exist)

        self.mox.VerifyAll()
Exemplo n.º 12
0
    def test_verify_for_launch(self):
        exist = self.mox.CreateMockAnything()
        exist.launched_at = decimal.Decimal('1.1')
        exist.instance_type_id = INSTANCE_TYPE_ID_1
        exist.tenant = TENANT_ID_1

        exist.usage = self.mox.CreateMockAnything()
        exist.usage.launched_at = decimal.Decimal('1.1')
        exist.usage.instance_type_id = INSTANCE_TYPE_ID_1
        exist.usage.tenant = TENANT_ID_1
        self.mox.ReplayAll()

        dbverifier._verify_for_launch(exist)

        self.mox.VerifyAll()
Exemplo n.º 13
0
 def test_verify_fail_reconcile_success(self):
     exist = self.mox.CreateMockAnything()
     exist.launched_at = decimal.Decimal('1.1')
     self.mox.StubOutWithMock(dbverifier, '_verify_for_launch')
     self.mox.StubOutWithMock(dbverifier, '_verify_for_delete')
     self.mox.StubOutWithMock(dbverifier, '_mark_exist_failed')
     self.mox.StubOutWithMock(dbverifier, '_mark_exist_verified')
     verify_exception = VerificationException('test')
     dbverifier._verify_for_launch(exist).AndRaise(verify_exception)
     self.mox.StubOutWithMock(dbverifier, '_verify_with_reconciled_data')
     dbverifier._verify_with_reconciled_data(exist, verify_exception)
     dbverifier._mark_exist_verified(exist)
     self.mox.ReplayAll()
     result, exists = dbverifier._verify(exist)
     self.assertTrue(result)
     self.mox.VerifyAll()
Exemplo n.º 14
0
    def test_verify_for_launch_instance_type_id_missmatch(self):
        exist = self.mox.CreateMockAnything()
        exist.usage = self.mox.CreateMockAnything()
        exist.launched_at = decimal.Decimal('1.1')
        exist.instance_type_id = 2
        exist.usage.launched_at = decimal.Decimal('1.1')
        exist.usage.instance_type_id = 3
        self.mox.ReplayAll()

        try:
            dbverifier._verify_for_launch(exist)
            self.fail()
        except FieldMismatch, fm:
            self.assertEqual(fm.field_name, 'instance_type_id')
            self.assertEqual(fm.expected, 2)
            self.assertEqual(fm.actual, 3)
Exemplo n.º 15
0
    def test_verify_for_launch_instance_type_id_missmatch(self):
        exist = self.mox.CreateMockAnything()
        exist.usage = self.mox.CreateMockAnything()
        exist.launched_at = decimal.Decimal('1.1')
        exist.instance_type_id = 2
        exist.usage.launched_at = decimal.Decimal('1.1')
        exist.usage.instance_type_id = 3
        self.mox.ReplayAll()

        try:
            dbverifier._verify_for_launch(exist)
            self.fail()
        except FieldMismatch, fm:
            self.assertEqual(fm.field_name, 'instance_type_id')
            self.assertEqual(fm.expected, 2)
            self.assertEqual(fm.actual, 3)
Exemplo n.º 16
0
 def test_verify_launch_fail(self):
     exist = self.mox.CreateMockAnything()
     exist.launched_at = decimal.Decimal('1.1')
     self.mox.StubOutWithMock(dbverifier, '_verify_for_launch')
     self.mox.StubOutWithMock(dbverifier, '_verify_for_delete')
     self.mox.StubOutWithMock(dbverifier, '_mark_exist_failed')
     self.mox.StubOutWithMock(dbverifier, '_mark_exist_verified')
     verify_exception = VerificationException('test')
     dbverifier._verify_for_launch(exist).AndRaise(verify_exception)
     self.mox.StubOutWithMock(dbverifier, '_verify_with_reconciled_data')
     dbverifier._verify_with_reconciled_data(exist, verify_exception)\
               .AndRaise(NotFound('InstanceReconcile', {}))
     dbverifier._mark_exist_failed(exist, reason='test')
     self.mox.ReplayAll()
     result, exists = dbverifier._verify(exist)
     self.assertFalse(result)
     self.mox.VerifyAll()
Exemplo n.º 17
0
    def test_verify_for_launch_tenant_id_mismatch(self):
        exist = self.mox.CreateMockAnything()
        exist.tenant = TENANT_ID_1

        exist.usage = self.mox.CreateMockAnything()
        exist.usage.tenant = TENANT_ID_2
        self.mox.ReplayAll()

        with self.assertRaises(FieldMismatch) as cm:
            dbverifier._verify_for_launch(exist)
        exception = cm.exception

        self.assertEqual(exception.field_name, 'tenant')
        self.assertEqual(exception.expected, TENANT_ID_1)
        self.assertEqual(exception.actual, TENANT_ID_2)

        self.mox.VerifyAll()
Exemplo n.º 18
0
    def test_verify_for_launch_os_version_mismatch(self):
        exist = self.mox.CreateMockAnything()
        exist.os_version = OS_VERSION_1

        exist.usage = self.mox.CreateMockAnything()
        exist.usage.os_version = OS_VERSION_2
        self.mox.ReplayAll()

        with self.assertRaises(FieldMismatch) as cm:
            dbverifier._verify_for_launch(exist)
        exception = cm.exception

        self.assertEqual(exception.field_name, 'os_version')
        self.assertEqual(exception.expected, OS_VERSION_1)
        self.assertEqual(exception.actual, OS_VERSION_2)

        self.mox.VerifyAll()
Exemplo n.º 19
0
    def test_verify_for_launch_rax_options_mismatch(self):
        exist = self.mox.CreateMockAnything()
        exist.rax_options = RAX_OPTIONS_1

        exist.usage = self.mox.CreateMockAnything()
        exist.usage.rax_options = RAX_OPTIONS_2
        self.mox.ReplayAll()

        with self.assertRaises(FieldMismatch) as cm:
            dbverifier._verify_for_launch(exist)
        exception = cm.exception

        self.assertEqual(exception.field_name, 'rax_options')
        self.assertEqual(exception.expected, RAX_OPTIONS_1)
        self.assertEqual(exception.actual, RAX_OPTIONS_2)

        self.mox.VerifyAll()
Exemplo n.º 20
0
    def test_verify_for_launch_tenant_id_mismatch(self):
        exist = self.mox.CreateMockAnything()
        exist.tenant = TENANT_ID_1

        exist.usage = self.mox.CreateMockAnything()
        exist.usage.tenant = TENANT_ID_2
        self.mox.ReplayAll()

        with self.assertRaises(FieldMismatch) as cm:
            dbverifier._verify_for_launch(exist)
        exception = cm.exception

        self.assertEqual(exception.field_name, 'tenant')
        self.assertEqual(exception.expected, TENANT_ID_1)
        self.assertEqual(exception.actual, TENANT_ID_2)

        self.mox.VerifyAll()
Exemplo n.º 21
0
    def test_verify_for_launch_no_usage(self):
        exist = self.mox.CreateMockAnything()
        exist.usage = None
        exist.instance = INSTANCE_ID_1
        exist.launched_at = decimal.Decimal('1.1')
        exist.instance_type_id = 2
        results = self.mox.CreateMockAnything()
        models.InstanceUsage.objects.filter(instance=INSTANCE_ID_1) \
            .AndReturn(results)
        results.count().AndReturn(0)
        self.mox.ReplayAll()

        try:
            dbverifier._verify_for_launch(exist)
            self.fail()
        except NotFound, nf:
            self.assertEqual(nf.object_type, 'InstanceUsage')
            self.assertEqual(nf.search_params, {'instance': INSTANCE_ID_1})
Exemplo n.º 22
0
    def test_verify_for_launch_no_usage(self):
        exist = self.mox.CreateMockAnything()
        exist.usage = None
        exist.instance = INSTANCE_ID_1
        exist.launched_at = decimal.Decimal('1.1')
        exist.instance_type_id = 2
        results = self.mox.CreateMockAnything()
        models.InstanceUsage.objects.filter(instance=INSTANCE_ID_1) \
            .AndReturn(results)
        results.count().AndReturn(0)
        self.mox.ReplayAll()

        try:
            dbverifier._verify_for_launch(exist)
            self.fail()
        except NotFound, nf:
            self.assertEqual(nf.object_type, 'InstanceUsage')
            self.assertEqual(nf.search_params, {'instance': INSTANCE_ID_1})
Exemplo n.º 23
0
    def test_verify_for_launch_launched_at_in_range(self):
        exist = self.mox.CreateMockAnything()
        exist.usage = self.mox.CreateMockAnything()
        exist.launched_at = decimal.Decimal('1.0')
        exist.instance_type_id = 2
        exist.usage.launched_at = decimal.Decimal('1.4')
        exist.usage.instance_type_id = 2
        self.mox.ReplayAll()

        result = dbverifier._verify_for_launch(exist)
        self.assertIsNone(result)

        self.mox.VerifyAll()
Exemplo n.º 24
0
    def test_verify_for_launch_launched_at_in_range(self):
        exist = self.mox.CreateMockAnything()
        exist.usage = self.mox.CreateMockAnything()
        exist.launched_at = decimal.Decimal('1.0')
        exist.instance_type_id = 2
        exist.usage.launched_at = decimal.Decimal('1.4')
        exist.usage.instance_type_id = 2
        self.mox.ReplayAll()

        result = dbverifier._verify_for_launch(exist)
        self.assertIsNone(result)

        self.mox.VerifyAll()