Fixed type check for instance_type_id and rax_options for instanceexists and size for glanceexists

changed the order of the validity check
added validation level as flag
Added empty check for nova image properties
This commit is contained in:
Manali Latkar 2013-08-26 12:09:55 +05:30
parent 065a2d76f2
commit e294145f66
8 changed files with 277 additions and 133 deletions

View File

@ -4,6 +4,7 @@
"settle_units": "minutes", "settle_units": "minutes",
"pool_size": 2, "pool_size": 2,
"enable_notifications": true, "enable_notifications": true,
"validation_level": "all",
"rabbit": { "rabbit": {
"durable_queue": false, "durable_queue": false,
"host": "10.0.0.1", "host": "10.0.0.1",

View File

@ -379,7 +379,7 @@ class GlanceVerifierTestCase(StacktachBaseTestCase):
def test_should_verify_owner_is_of_type_hex(self): def test_should_verify_owner_is_of_type_hex(self):
exist = self.mox.CreateMockAnything() exist = self.mox.CreateMockAnything()
exist.id = 23 exist.id = 23
exist.size = 1234 exist.size = 1234L
exist.created_at = decimal.Decimal('5.1') exist.created_at = decimal.Decimal('5.1')
exist.uuid = "58fb036d-5ef8-47a8-b503-7571276c400a" exist.uuid = "58fb036d-5ef8-47a8-b503-7571276c400a"
exist.owner = "3762854cd6f6435998188d5120e4c271,kl" exist.owner = "3762854cd6f6435998188d5120e4c271,kl"
@ -396,7 +396,7 @@ class GlanceVerifierTestCase(StacktachBaseTestCase):
def test_should_verify_correctly_for_all_non_null_and_valid_types(self): def test_should_verify_correctly_for_all_non_null_and_valid_types(self):
exist = self.mox.CreateMockAnything() exist = self.mox.CreateMockAnything()
exist.id = 23 exist.id = 23
exist.size = 983040 exist.size = 983040L
exist.created_at = decimal.Decimal('5.1') exist.created_at = decimal.Decimal('5.1')
exist.uuid = "58fb036d-5ef8-47a8-b503-7571276c400a" exist.uuid = "58fb036d-5ef8-47a8-b503-7571276c400a"
exist.owner = "3762854cd6f6435998188d5120e4c271" exist.owner = "3762854cd6f6435998188d5120e4c271"

View File

@ -290,12 +290,11 @@ class NovaVerifierTestCase(StacktachBaseTestCase):
results.count().AndReturn(0) results.count().AndReturn(0)
self.mox.ReplayAll() self.mox.ReplayAll()
try: with self.assertRaises(NotFound) as nf:
nova_verifier._verify_for_launch(exist) nova_verifier._verify_for_launch(exist)
self.fail() exception = nf.exception
except NotFound, nf: self.assertEqual(exception.object_type, 'InstanceUsage')
self.assertEqual(nf.object_type, 'InstanceUsage') self.assertEqual(exception.search_params, {'instance': INSTANCE_ID_1})
self.assertEqual(nf.search_params, {'instance': INSTANCE_ID_1})
self.mox.VerifyAll() self.mox.VerifyAll()
@ -315,14 +314,13 @@ class NovaVerifierTestCase(StacktachBaseTestCase):
results.count().AndReturn(2) results.count().AndReturn(2)
self.mox.ReplayAll() self.mox.ReplayAll()
try: with self.assertRaises(AmbiguousResults) as ar:
nova_verifier._verify_for_launch(exist) nova_verifier._verify_for_launch(exist)
self.fail() exception = ar.exception
except AmbiguousResults, nf: self.assertEqual(exception.object_type, 'InstanceUsage')
self.assertEqual(nf.object_type, 'InstanceUsage') search_params = {'instance': INSTANCE_ID_1,
search_params = {'instance': INSTANCE_ID_1, 'launched_at': decimal.Decimal('1.1')}
'launched_at': decimal.Decimal('1.1')} self.assertEqual(exception.search_params, search_params)
self.assertEqual(nf.search_params, search_params)
self.mox.VerifyAll() self.mox.VerifyAll()
@ -332,12 +330,12 @@ class NovaVerifierTestCase(StacktachBaseTestCase):
exist.id = 23 exist.id = 23
self.mox.ReplayAll() self.mox.ReplayAll()
try: with self.assertRaises(NullFieldException) as nf:
nova_verifier._verify_validity(exist) nova_verifier._verify_validity(exist, 'all')
self.fail() exception = nf.exception
except NullFieldException as nf: self.assertEqual(exception.field_name, 'tenant')
self.assertEqual(nf.field_name, 'tenant') self.assertEqual(exception.reason,
self.assertEqual(nf.reason, "tenant field was null for exist id 23") "tenant field was null for exist id 23")
self.mox.VerifyAll() self.mox.VerifyAll()
def test_should_verify_that_launched_at_in_exist_is_not_null(self): def test_should_verify_that_launched_at_in_exist_is_not_null(self):
@ -347,12 +345,12 @@ class NovaVerifierTestCase(StacktachBaseTestCase):
exist.launched_at = None exist.launched_at = None
self.mox.ReplayAll() self.mox.ReplayAll()
try: with self.assertRaises(NullFieldException) as nf:
nova_verifier._verify_validity(exist) nova_verifier._verify_validity(exist, 'all')
self.fail() exception = nf.exception
except NullFieldException as nf: self.assertEqual(exception.field_name, 'launched_at')
self.assertEqual(nf.field_name, 'launched_at') self.assertEqual(exception.reason,
self.assertEqual(nf.reason, "launched_at field was null for exist id 23") "launched_at field was null for exist id 23")
self.mox.VerifyAll() self.mox.VerifyAll()
def test_should_verify_that_instance_type_id_in_exist_is_not_null(self): def test_should_verify_that_instance_type_id_in_exist_is_not_null(self):
@ -363,12 +361,12 @@ class NovaVerifierTestCase(StacktachBaseTestCase):
exist.instance_type_id = None exist.instance_type_id = None
self.mox.ReplayAll() self.mox.ReplayAll()
try: with self.assertRaises(NullFieldException) as nf:
nova_verifier._verify_validity(exist) nova_verifier._verify_validity(exist, 'all')
self.fail() exception = nf.exception
except NullFieldException as nf: self.assertEqual(exception.field_name, 'instance_type_id')
self.assertEqual(nf.field_name, 'instance_type_id') self.assertEqual(exception.reason,
self.assertEqual(nf.reason, "instance_type_id field was null for exist id 23") "instance_type_id field was null for exist id 23")
self.mox.VerifyAll() self.mox.VerifyAll()
def test_should_verify_tenant_id_is_of_type_hex(self): def test_should_verify_tenant_id_is_of_type_hex(self):
@ -379,12 +377,13 @@ class NovaVerifierTestCase(StacktachBaseTestCase):
exist.instance_type_id = 2 exist.instance_type_id = 2
self.mox.ReplayAll() self.mox.ReplayAll()
try: with self.assertRaises(WrongTypeException) as wt:
nova_verifier._verify_validity(exist) nova_verifier._verify_validity(exist, 'all')
self.fail() exception = wt.exception
except WrongTypeException as wt: self.assertEqual(exception.field_name, 'tenant')
self.assertEqual(wt.field_name, 'tenant') self.assertEqual(
self.assertEqual(wt.reason, "{ tenant : tenant } of incorrect type for exist id 23") exception.reason,
"{ tenant : tenant } of incorrect type for exist id 23")
self.mox.VerifyAll() self.mox.VerifyAll()
def test_should_verify_flavor_is_of_type_integer(self): def test_should_verify_flavor_is_of_type_integer(self):
@ -395,12 +394,13 @@ class NovaVerifierTestCase(StacktachBaseTestCase):
exist.instance_type_id = 'flavor' exist.instance_type_id = 'flavor'
self.mox.ReplayAll() self.mox.ReplayAll()
try: with self.assertRaises(WrongTypeException) as wt:
nova_verifier._verify_validity(exist) nova_verifier._verify_validity(exist, 'all')
self.fail() exception = wt.exception
except WrongTypeException as wt: self.assertEqual(exception.field_name, 'instance_type_id')
self.assertEqual(wt.field_name, 'instance_type_id') self.assertEqual(
self.assertEqual(wt.reason, "{ instance_type_id : flavor } of incorrect type for exist id 23") exception.reason,
"{ instance_type_id : flavor } of incorrect type for exist id 23")
self.mox.VerifyAll() self.mox.VerifyAll()
def test_should_verify_launched_at_is_of_type_decimal(self): def test_should_verify_launched_at_is_of_type_decimal(self):
@ -411,12 +411,13 @@ class NovaVerifierTestCase(StacktachBaseTestCase):
exist.instance_type_id = 4 exist.instance_type_id = 4
self.mox.ReplayAll() self.mox.ReplayAll()
try: with self.assertRaises(WrongTypeException) as wt:
nova_verifier._verify_validity(exist) nova_verifier._verify_validity(exist, 'all')
self.fail() exception = wt.exception
except WrongTypeException as wt: self.assertEqual(exception.field_name, 'launched_at')
self.assertEqual(wt.field_name, 'launched_at') self.assertEqual(
self.assertEqual(wt.reason, "{ launched_at : 111 } of incorrect type for exist id 23") exception.reason,
"{ launched_at : 111 } of incorrect type for exist id 23")
self.mox.VerifyAll() self.mox.VerifyAll()
def test_should_verify_deleted_at_is_of_decimal_type_if_present(self): def test_should_verify_deleted_at_is_of_decimal_type_if_present(self):
@ -428,12 +429,13 @@ class NovaVerifierTestCase(StacktachBaseTestCase):
exist.deleted_at = 20 exist.deleted_at = 20
self.mox.ReplayAll() self.mox.ReplayAll()
try: with self.assertRaises(WrongTypeException) as wt:
nova_verifier._verify_validity(exist) nova_verifier._verify_validity(exist, 'all')
self.fail() exception = wt.exception
except WrongTypeException as wt: self.assertEqual(exception.field_name, 'deleted_at')
self.assertEqual(wt.field_name, 'deleted_at') self.assertEqual(
self.assertEqual(wt.reason, "{ deleted_at : 20 } of incorrect type for exist id 23") exception.reason,
"{ deleted_at : 20 } of incorrect type for exist id 23")
self.mox.VerifyAll() self.mox.VerifyAll()
@ -447,12 +449,30 @@ class NovaVerifierTestCase(StacktachBaseTestCase):
exist.rax_options = 'a' exist.rax_options = 'a'
self.mox.ReplayAll() self.mox.ReplayAll()
try: with self.assertRaises(WrongTypeException) as wt:
nova_verifier._verify_validity(exist) nova_verifier._verify_validity(exist, 'all')
self.fail() exception = wt.exception
except WrongTypeException as wt: self.assertEqual(exception.field_name, 'rax_options')
self.assertEqual(wt.field_name, 'rax_options') self.assertEqual(
self.assertEqual(wt.reason, "{ rax_options : a } of incorrect type for exist id 23") exception.reason,
"{ rax_options : a } of incorrect type for exist id 23")
self.mox.VerifyAll()
def test_should_verify_rax_options_should_not_be_empty(self):
exist = self.mox.CreateMockAnything()
exist.tenant = '3762854cd6f6435998188d5120e4c271'
exist.id = 23
exist.launched_at = decimal.Decimal('1.1')
exist.deleted_at = decimal.Decimal('5.1')
exist.instance_type_id = 4
exist.rax_options = ''
self.mox.ReplayAll()
with self.assertRaises(NullFieldException) as nf:
nova_verifier._verify_validity(exist, 'all')
exception = nf.exception
self.assertEqual(exception.field_name, 'rax_options')
self.assertEqual(exception.reason, "rax_options field was null for exist id 23")
self.mox.VerifyAll() self.mox.VerifyAll()
def test_should_verify_os_arch_should_be_alphanumeric(self): def test_should_verify_os_arch_should_be_alphanumeric(self):
@ -464,15 +484,37 @@ class NovaVerifierTestCase(StacktachBaseTestCase):
exist.instance_type_id = 4 exist.instance_type_id = 4
exist.rax_options = 12 exist.rax_options = 12
exist.os_arch = 'x64,' exist.os_architecture = 'x64,'
self.mox.ReplayAll() self.mox.ReplayAll()
try: with self.assertRaises(WrongTypeException) as wt:
nova_verifier._verify_validity(exist) nova_verifier._verify_validity(exist, 'all')
self.fail() exception = wt.exception
except WrongTypeException as wt: self.assertEqual(exception.field_name, 'os_architecture')
self.assertEqual(wt.field_name, 'os_arch') self.assertEqual(
self.assertEqual(wt.reason, "{ os_arch : x64, } of incorrect type for exist id 23") exception.reason,
"{ os_architecture : x64, } of incorrect type for exist id 23")
self.mox.VerifyAll()
def test_should_verify_os_arch_should_not_be_empty(self):
exist = self.mox.CreateMockAnything()
exist.tenant = '3762854cd6f6435998188d5120e4c271'
exist.id = 23
exist.launched_at = decimal.Decimal('1.1')
exist.deleted_at = decimal.Decimal('5.1')
exist.instance_type_id = 4
exist.rax_options = 12
exist.os_architecture = ''
self.mox.ReplayAll()
with self.assertRaises(NullFieldException) as nf:
nova_verifier._verify_validity(exist, 'all')
exception = nf.exception
self.assertEqual(exception.field_name, 'os_architecture')
self.assertEqual(
exception.reason,
"os_architecture field was null for exist id 23")
self.mox.VerifyAll() self.mox.VerifyAll()
def test_should_verify_os_distro_should_be_alphanumeric(self): def test_should_verify_os_distro_should_be_alphanumeric(self):
@ -483,16 +525,38 @@ class NovaVerifierTestCase(StacktachBaseTestCase):
exist.deleted_at = decimal.Decimal('5.1') exist.deleted_at = decimal.Decimal('5.1')
exist.instance_type_id = 4 exist.instance_type_id = 4
exist.rax_options = 12 exist.rax_options = 12
exist.os_arch = 'x64' exist.os_architecture = 'x64'
exist.os_distro = 'com.microsoft.server,' exist.os_distro = 'com.microsoft.server,'
self.mox.ReplayAll() self.mox.ReplayAll()
try: with self.assertRaises(WrongTypeException) as wt:
nova_verifier._verify_validity(exist) nova_verifier._verify_validity(exist, 'all')
self.fail() exception = wt.exception
except WrongTypeException as wt: self.assertEqual(exception.field_name, 'os_distro')
self.assertEqual(wt.field_name, 'os_distro') self.assertEqual(
self.assertEqual(wt.reason, "{ os_distro : com.microsoft.server, } of incorrect type for exist id 23") exception.reason,
"{ os_distro : com.microsoft.server, } of incorrect type for exist id 23")
self.mox.VerifyAll()
def test_should_verify_os_distro_should_not_be_empty(self):
exist = self.mox.CreateMockAnything()
exist.tenant = '3762854cd6f6435998188d5120e4c271'
exist.id = 23
exist.launched_at = decimal.Decimal('1.1')
exist.deleted_at = decimal.Decimal('5.1')
exist.instance_type_id = 4
exist.rax_options = 12
exist.os_architecture = 'x64'
exist.os_distro = ''
self.mox.ReplayAll()
with self.assertRaises(NullFieldException) as nf:
nova_verifier._verify_validity(exist, 'all')
exception = nf.exception
self.assertEqual(exception.field_name, 'os_distro')
self.assertEqual(
exception.reason,
"os_distro field was null for exist id 23")
self.mox.VerifyAll() self.mox.VerifyAll()
def test_should_verify_os_version_should_be_alphanumeric(self): def test_should_verify_os_version_should_be_alphanumeric(self):
@ -503,20 +567,21 @@ class NovaVerifierTestCase(StacktachBaseTestCase):
exist.deleted_at = decimal.Decimal('5.1') exist.deleted_at = decimal.Decimal('5.1')
exist.instance_type_id = 4 exist.instance_type_id = 4
exist.rax_options = 12 exist.rax_options = 12
exist.os_arch = 'x64' exist.os_architecture = 'x64'
exist.os_distro = 'com.microsoft.server' exist.os_distro = 'com.microsoft.server'
exist.os_version = '2008.2,' exist.os_version = '2008.2,'
self.mox.ReplayAll() self.mox.ReplayAll()
try: with self.assertRaises(WrongTypeException) as wt:
nova_verifier._verify_validity(exist) nova_verifier._verify_validity(exist, 'all')
self.fail() exception = wt.exception
except WrongTypeException as wt: self.assertEqual(exception.field_name, 'os_version')
self.assertEqual(wt.field_name, 'os_version') self.assertEqual(
self.assertEqual(wt.reason, "{ os_version : 2008.2, } of incorrect type for exist id 23") exception.reason,
"{ os_version : 2008.2, } of incorrect type for exist id 23")
self.mox.VerifyAll() self.mox.VerifyAll()
def test_should_verify_exist_fields_correctly(self): def test_should_verify_os_version_should_not_be_empty(self):
exist = self.mox.CreateMockAnything() exist = self.mox.CreateMockAnything()
exist.tenant = '3762854cd6f6435998188d5120e4c271' exist.tenant = '3762854cd6f6435998188d5120e4c271'
exist.id = 23 exist.id = 23
@ -524,15 +589,56 @@ class NovaVerifierTestCase(StacktachBaseTestCase):
exist.deleted_at = decimal.Decimal('5.1') exist.deleted_at = decimal.Decimal('5.1')
exist.instance_type_id = 4 exist.instance_type_id = 4
exist.rax_options = 12 exist.rax_options = 12
exist.os_arch = 'x64' exist.os_architecture = 'x64'
exist.os_distro = 'com.microsoft.server'
exist.os_version = ''
self.mox.ReplayAll()
with self.assertRaises(NullFieldException) as nf:
nova_verifier._verify_validity(exist, 'all')
exception = nf.exception
self.assertEqual(exception.field_name, 'os_version')
self.assertEqual(
exception.reason, "os_version field was null for exist id 23")
self.mox.VerifyAll()
def test_should_verify_all_exist_fields_when_validity_check_value_is_all(self):
exist = self.mox.CreateMockAnything()
exist.tenant = '3762854cd6f6435998188d5120e4c271'
exist.id = 23
exist.launched_at = decimal.Decimal('1.1')
exist.deleted_at = decimal.Decimal('5.1')
exist.instance_type_id = '4'
exist.rax_options = '12'
exist.os_architecture = 'x64'
exist.os_distro = 'com.microsoft.server' exist.os_distro = 'com.microsoft.server'
exist.os_version = '2008.2' exist.os_version = '2008.2'
self.mox.ReplayAll() self.mox.ReplayAll()
nova_verifier._verify_validity(exist) nova_verifier._verify_validity(exist, 'all')
self.mox.VerifyAll() self.mox.VerifyAll()
def test_should_verify_exist_fields_correctly_and_deleted_at_can_be_none(self): def test_should_verify_only_basic_exist_fields_when_validity_check_value_is_basic(self):
exist = self.mox.CreateMockAnything()
exist.tenant = '3762854cd6f6435998188d5120e4c271'
exist.id = 23
exist.launched_at = decimal.Decimal('1.1')
exist.deleted_at = decimal.Decimal('5.1')
exist.instance_type_id = '4'
self.mox.ReplayAll()
nova_verifier._verify_validity(exist, 'basic')
self.mox.VerifyAll()
def test_should_not_verify_any_fields_if_validity_check_value_is_none(self):
exist = self.mox.CreateMockAnything()
exist.id = 23
self.mox.ReplayAll()
nova_verifier._verify_validity(exist, 'none')
self.mox.VerifyAll()
def test_should_verify_exist_fields_even_if_deleted_at_is_none(self):
exist = self.mox.CreateMockAnything() exist = self.mox.CreateMockAnything()
exist.tenant = '3762854cd6f6435998188d5120e4c271' exist.tenant = '3762854cd6f6435998188d5120e4c271'
exist.id = 23 exist.id = 23
@ -540,12 +646,12 @@ class NovaVerifierTestCase(StacktachBaseTestCase):
exist.deleted_at = None exist.deleted_at = None
exist.instance_type_id = 4 exist.instance_type_id = 4
exist.rax_options = 12 exist.rax_options = 12
exist.os_arch = 'x64' exist.os_architecture = 'x64'
exist.os_distro = 'com.microsoft.server' exist.os_distro = 'com.microsoft.server'
exist.os_version = '2008.2' exist.os_version = '2008.2'
self.mox.ReplayAll() self.mox.ReplayAll()
nova_verifier._verify_validity(exist) nova_verifier._verify_validity(exist, 'all')
self.mox.VerifyAll() self.mox.VerifyAll()
def test_verify_for_delete(self): def test_verify_for_delete(self):
@ -618,12 +724,11 @@ class NovaVerifierTestCase(StacktachBaseTestCase):
self.mox.ReplayAll() self.mox.ReplayAll()
try: with self.assertRaises(VerificationException) as ve:
nova_verifier._verify_for_delete(exist) nova_verifier._verify_for_delete(exist)
self.fail() exception = ve.exception
except VerificationException, ve: msg = 'Found InstanceDeletes for non-delete exist'
msg = 'Found InstanceDeletes for non-delete exist' self.assertEqual(exception.reason, msg)
self.assertEqual(ve.reason, msg)
self.mox.VerifyAll() self.mox.VerifyAll()
@ -636,13 +741,12 @@ class NovaVerifierTestCase(StacktachBaseTestCase):
exist.delete.deleted_at = decimal.Decimal('5.1') exist.delete.deleted_at = decimal.Decimal('5.1')
self.mox.ReplayAll() self.mox.ReplayAll()
try: with self.assertRaises(FieldMismatch) as fm:
nova_verifier._verify_for_delete(exist) nova_verifier._verify_for_delete(exist)
self.fail() exception = fm.exception
except FieldMismatch, fm: self.assertEqual(exception.field_name, 'launched_at')
self.assertEqual(fm.field_name, 'launched_at') self.assertEqual(exception.expected, decimal.Decimal('1.1'))
self.assertEqual(fm.expected, decimal.Decimal('1.1')) self.assertEqual(exception.actual, decimal.Decimal('2.1'))
self.assertEqual(fm.actual, decimal.Decimal('2.1'))
self.mox.VerifyAll() self.mox.VerifyAll()
def test_verify_for_delete_deleted_at_mismatch(self): def test_verify_for_delete_deleted_at_mismatch(self):
@ -654,13 +758,12 @@ class NovaVerifierTestCase(StacktachBaseTestCase):
exist.delete.deleted_at = decimal.Decimal('6.1') exist.delete.deleted_at = decimal.Decimal('6.1')
self.mox.ReplayAll() self.mox.ReplayAll()
try: with self.assertRaises(FieldMismatch) as fm:
nova_verifier._verify_for_delete(exist) nova_verifier._verify_for_delete(exist)
self.fail() exception = fm.exception
except FieldMismatch, fm: self.assertEqual(exception.field_name, 'deleted_at')
self.assertEqual(fm.field_name, 'deleted_at') self.assertEqual(exception.expected, decimal.Decimal('5.1'))
self.assertEqual(fm.expected, decimal.Decimal('5.1')) self.assertEqual(exception.actual, decimal.Decimal('6.1'))
self.assertEqual(fm.actual, decimal.Decimal('6.1'))
self.mox.VerifyAll() self.mox.VerifyAll()
def test_verify_with_reconciled_data(self): def test_verify_with_reconciled_data(self):
@ -799,10 +902,10 @@ class NovaVerifierTestCase(StacktachBaseTestCase):
self.mox.StubOutWithMock(exist, 'mark_verified') self.mox.StubOutWithMock(exist, 'mark_verified')
nova_verifier._verify_for_launch(exist) nova_verifier._verify_for_launch(exist)
nova_verifier._verify_for_delete(exist) nova_verifier._verify_for_delete(exist)
nova_verifier._verify_validity(exist) nova_verifier._verify_validity(exist, 'all')
exist.mark_verified() exist.mark_verified()
self.mox.ReplayAll() self.mox.ReplayAll()
result, exists = nova_verifier._verify(exist) result, exists = nova_verifier._verify(exist, 'all')
self.assertTrue(result) self.assertTrue(result)
self.mox.VerifyAll() self.mox.VerifyAll()
@ -817,7 +920,7 @@ class NovaVerifierTestCase(StacktachBaseTestCase):
nova_verifier._verify_with_reconciled_data(exist)\ nova_verifier._verify_with_reconciled_data(exist)\
.AndRaise(NotFound('InstanceReconcile', {})) .AndRaise(NotFound('InstanceReconcile', {}))
self.mox.ReplayAll() self.mox.ReplayAll()
result, exists = nova_verifier._verify(exist) result, exists = nova_verifier._verify(exist, 'all')
self.assertFalse(result) self.assertFalse(result)
self.mox.VerifyAll() self.mox.VerifyAll()
@ -833,7 +936,7 @@ class NovaVerifierTestCase(StacktachBaseTestCase):
.AndRaise(VerificationException('test2')) .AndRaise(VerificationException('test2'))
exist.mark_failed(reason='test2') exist.mark_failed(reason='test2')
self.mox.ReplayAll() self.mox.ReplayAll()
result, exists = nova_verifier._verify(exist) result, exists = nova_verifier._verify(exist, 'none')
self.assertFalse(result) self.assertFalse(result)
self.mox.VerifyAll() self.mox.VerifyAll()
@ -850,7 +953,7 @@ class NovaVerifierTestCase(StacktachBaseTestCase):
.AndRaise(NotFound('InstanceReconcile', {})) .AndRaise(NotFound('InstanceReconcile', {}))
exist.mark_failed(reason='test') exist.mark_failed(reason='test')
self.mox.ReplayAll() self.mox.ReplayAll()
result, exists = nova_verifier._verify(exist) result, exists = nova_verifier._verify(exist, 'none')
self.assertFalse(result) self.assertFalse(result)
self.mox.VerifyAll() self.mox.VerifyAll()
@ -866,7 +969,7 @@ class NovaVerifierTestCase(StacktachBaseTestCase):
nova_verifier._verify_with_reconciled_data(exist) nova_verifier._verify_with_reconciled_data(exist)
exist.mark_verified(reconciled=True) exist.mark_verified(reconciled=True)
self.mox.ReplayAll() self.mox.ReplayAll()
result, exists = nova_verifier._verify(exist) result, exists = nova_verifier._verify(exist, 'none')
self.assertTrue(result) self.assertTrue(result)
self.mox.VerifyAll() self.mox.VerifyAll()
@ -883,7 +986,7 @@ class NovaVerifierTestCase(StacktachBaseTestCase):
.AndRaise(Exception()) .AndRaise(Exception())
exist.mark_failed(reason='Exception') exist.mark_failed(reason='Exception')
self.mox.ReplayAll() self.mox.ReplayAll()
result, exists = nova_verifier._verify(exist) result, exists = nova_verifier._verify(exist, 'none')
self.assertFalse(result) self.assertFalse(result)
self.mox.VerifyAll() self.mox.VerifyAll()
@ -901,7 +1004,7 @@ class NovaVerifierTestCase(StacktachBaseTestCase):
.AndRaise(NotFound('InstanceReconcile', {})) .AndRaise(NotFound('InstanceReconcile', {}))
exist.mark_failed(reason='test') exist.mark_failed(reason='test')
self.mox.ReplayAll() self.mox.ReplayAll()
result, exists = nova_verifier._verify(exist) result, exists = nova_verifier._verify(exist, 'none')
self.assertFalse(result) self.assertFalse(result)
self.mox.VerifyAll() self.mox.VerifyAll()
@ -914,7 +1017,7 @@ class NovaVerifierTestCase(StacktachBaseTestCase):
nova_verifier._verify_for_launch(exist).AndRaise(Exception()) nova_verifier._verify_for_launch(exist).AndRaise(Exception())
exist.mark_failed(reason='Exception') exist.mark_failed(reason='Exception')
self.mox.ReplayAll() self.mox.ReplayAll()
result, exists = nova_verifier._verify(exist) result, exists = nova_verifier._verify(exist, 'none')
self.assertFalse(result) self.assertFalse(result)
self.mox.VerifyAll() self.mox.VerifyAll()
@ -928,7 +1031,7 @@ class NovaVerifierTestCase(StacktachBaseTestCase):
nova_verifier._verify_for_delete(exist).AndRaise(Exception()) nova_verifier._verify_for_delete(exist).AndRaise(Exception())
exist.mark_failed(reason='Exception') exist.mark_failed(reason='Exception')
self.mox.ReplayAll() self.mox.ReplayAll()
result, exists = nova_verifier._verify(exist) result, exists = nova_verifier._verify(exist, 'none')
self.assertFalse(result) self.assertFalse(result)
self.mox.VerifyAll() self.mox.VerifyAll()
@ -948,9 +1051,9 @@ class NovaVerifierTestCase(StacktachBaseTestCase):
exist2.update_status('verifying') exist2.update_status('verifying')
exist1.save() exist1.save()
exist2.save() exist2.save()
self.pool.apply_async(nova_verifier._verify, args=(exist1,), self.pool.apply_async(nova_verifier._verify, args=(exist1, 'all'),
callback=None) callback=None)
self.pool.apply_async(nova_verifier._verify, args=(exist2,), self.pool.apply_async(nova_verifier._verify, args=(exist2, 'all'),
callback=None) callback=None)
self.mox.ReplayAll() self.mox.ReplayAll()
self.verifier.verify_for_range(when_max) self.verifier.verify_for_range(when_max)
@ -973,9 +1076,9 @@ class NovaVerifierTestCase(StacktachBaseTestCase):
exist2.update_status('verifying') exist2.update_status('verifying')
exist1.save() exist1.save()
exist2.save() exist2.save()
self.pool.apply_async(nova_verifier._verify, args=(exist1,), self.pool.apply_async(nova_verifier._verify, args=(exist1, 'all'),
callback=callback) callback=callback)
self.pool.apply_async(nova_verifier._verify, args=(exist2,), self.pool.apply_async(nova_verifier._verify, args=(exist2, 'all'),
callback=callback) callback=callback)
self.mox.ReplayAll() self.mox.ReplayAll()
self.verifier.verify_for_range(when_max, callback=callback) self.verifier.verify_for_range(when_max, callback=callback)

View File

@ -163,6 +163,7 @@ class FakeVerifierConfig(object):
self.durable_queue = lambda: durable_queue self.durable_queue = lambda: durable_queue
self.topics = lambda: topics self.topics = lambda: topics
self.enable_notifications = lambda: notifs self.enable_notifications = lambda: notifs
self.validation_level = lambda: 'all'
def make_verifier_config(notifs): def make_verifier_config(notifs):

View File

@ -80,8 +80,15 @@ def _is_like_date(attr_name, attr_value, exist_id):
raise WrongTypeException(attr_name, attr_value, exist_id) raise WrongTypeException(attr_name, attr_value, exist_id)
def _is_int(attr_name, attr_value, exist_id): def _is_long(attr_name, attr_value, exist_id):
if not isinstance(attr_value, int): if not isinstance(attr_value, long):
raise WrongTypeException(attr_name, attr_value, exist_id)
def _is_int_in_char(attr_name, attr_value, exist_id):
try:
int(attr_value)
except ValueError:
raise WrongTypeException(attr_name, attr_value, exist_id) raise WrongTypeException(attr_name, attr_value, exist_id)
@ -89,6 +96,7 @@ def _is_hex_owner_id(attr_name, attr_value, exist_id):
if not re.match("[0-9a-f]{32}$", attr_value): if not re.match("[0-9a-f]{32}$", attr_value):
raise WrongTypeException(attr_name, attr_value, exist_id) raise WrongTypeException(attr_name, attr_value, exist_id)
def _is_alphanumeric(attr_name, attr_value, exist_id): def _is_alphanumeric(attr_name, attr_value, exist_id):
if not re.match("[a-zA-Z0-9.]+$", attr_value): if not re.match("[a-zA-Z0-9.]+$", attr_value):
raise WrongTypeException(attr_name, attr_value, exist_id) raise WrongTypeException(attr_name, attr_value, exist_id)

View File

@ -87,3 +87,7 @@ def password():
def virtual_host(): def virtual_host():
return config['rabbit']['virtual_host'] return config['rabbit']['virtual_host']
def validation_level():
return config['validation_level']

View File

@ -65,11 +65,10 @@ def _verify_validity(exist):
raise NullFieldException(field_name, exist.id) raise NullFieldException(field_name, exist.id)
base_verifier._is_like_uuid('uuid', exist.uuid, exist.id) base_verifier._is_like_uuid('uuid', exist.uuid, exist.id)
base_verifier._is_like_date('created_at', exist.created_at, exist.id) base_verifier._is_like_date('created_at', exist.created_at, exist.id)
base_verifier._is_int('size', exist.size, exist.id) base_verifier._is_long('size', exist.size, exist.id)
base_verifier._is_hex_owner_id('owner', exist.owner, exist.id) base_verifier._is_hex_owner_id('owner', exist.owner, exist.id)
def _verify_for_usage(exist, usage=None): def _verify_for_usage(exist, usage=None):
usage_type = "ImageUsage" usage_type = "ImageUsage"
if not usage and exist.usage: if not usage and exist.usage:

View File

@ -18,7 +18,6 @@
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
# IN THE SOFTWARE. # IN THE SOFTWARE.
import argparse
import datetime import datetime
import json import json
import os import os
@ -146,22 +145,50 @@ def _verify_for_delete(exist, delete=None,
'deleted_at', exist.deleted_at, delete.deleted_at) 'deleted_at', exist.deleted_at, delete.deleted_at)
def _verify_validity(exist): def _verify_basic_validity(exist):
fields = {exist.tenant: 'tenant', exist.launched_at: 'launched_at', fields = {exist.tenant: 'tenant',
exist.launched_at: 'launched_at',
exist.instance_type_id: 'instance_type_id'} exist.instance_type_id: 'instance_type_id'}
for (field_value, field_name) in fields.items(): for (field_value, field_name) in fields.items():
if field_value is None: if field_value is None:
raise NullFieldException(field_name, exist.id) raise NullFieldException(field_name, exist.id)
base_verifier._is_hex_owner_id('tenant', exist.tenant, exist.id) base_verifier._is_hex_owner_id('tenant', exist.tenant, exist.id)
base_verifier._is_int('instance_type_id', exist.instance_type_id, exist.id) base_verifier._is_int_in_char('instance_type_id', exist.instance_type_id,
exist.id)
base_verifier._is_like_date('launched_at', exist.launched_at, exist.id) base_verifier._is_like_date('launched_at', exist.launched_at, exist.id)
if exist.deleted_at is not None: if exist.deleted_at is not None:
base_verifier._is_like_date('deleted_at', exist.deleted_at, exist.id) base_verifier._is_like_date('deleted_at', exist.deleted_at, exist.id)
base_verifier._is_int('rax_options', exist.rax_options, exist.id)
base_verifier._is_alphanumeric('os_arch', exist.os_arch, exist.id)
def _verify_optional_validity(exist):
fields = {exist.rax_options: 'rax_options',
exist.os_architecture: 'os_architecture',
exist.os_version: 'os_version',
exist.os_distro: 'os_distro'}
for (field_value, field_name) in fields.items():
if field_value == '':
raise NullFieldException(field_name, exist.id)
base_verifier._is_int_in_char('rax_options', exist.rax_options, exist.id)
base_verifier._is_alphanumeric('os_architecture', exist.os_architecture, exist.id)
base_verifier._is_alphanumeric('os_distro', exist.os_distro, exist.id) base_verifier._is_alphanumeric('os_distro', exist.os_distro, exist.id)
base_verifier._is_alphanumeric('os_version', exist.os_version, exist.id) base_verifier._is_alphanumeric('os_version', exist.os_version, exist.id)
def verify_fields_not_null(exist_id, null_value, fields):
for (field_value, field_name) in fields.items():
print "value: %s, name = %s" % (field_value, field_name)
if field_value == null_value:
raise NullFieldException(field_name, exist_id)
def _verify_validity(exist, validation_level):
if validation_level == 'none':
return
if validation_level == 'basic':
_verify_basic_validity(exist)
if validation_level == 'all':
_verify_basic_validity(exist)
_verify_optional_validity(exist)
def _verify_with_reconciled_data(exist): def _verify_with_reconciled_data(exist):
@ -212,15 +239,15 @@ def _attempt_reconciled_verify(exist, orig_e):
return verified return verified
def _verify(exist): def _verify(exist, validation_level):
verified = False verified = False
try: try:
if not exist.launched_at: if not exist.launched_at:
raise VerificationException("Exists without a launched_at") raise VerificationException("Exists without a launched_at")
_verify_validity(exist, validation_level)
_verify_for_launch(exist) _verify_for_launch(exist)
_verify_for_delete(exist) _verify_for_delete(exist)
_verify_validity(exist)
verified = True verified = True
exist.mark_verified() exist.mark_verified()
@ -267,8 +294,9 @@ class NovaVerifier(base_verifier.Verifier):
for exist in exists[0:1000]: for exist in exists[0:1000]:
exist.update_status(models.InstanceExists.VERIFYING) exist.update_status(models.InstanceExists.VERIFYING)
exist.save() exist.save()
validation_level = self.config.validation_level()
result = self.pool.apply_async( result = self.pool.apply_async(
_verify, args=(exist,), _verify, args=(exist, validation_level),
callback=callback) callback=callback)
self.results.append(result) self.results.append(result)
added += 1 added += 1