Merge pull request #304 from manalilatkar/os_distro_optional
Making the type and null check for os_distro optional according to import image_type
This commit is contained in:
commit
29d878d706
@ -3,6 +3,7 @@ from operator import itemgetter
|
||||
|
||||
BASE_IMAGE = 0x1
|
||||
SNAPSHOT_IMAGE = 0x2
|
||||
IMPORT_IMAGE = 0x3
|
||||
|
||||
LINUX_IMAGE = 0x10
|
||||
WINDOWS_IMAGE = 0x20
|
||||
@ -48,7 +49,8 @@ def get_numeric_code(payload, default=0):
|
||||
num |= BASE_IMAGE
|
||||
if image_type == 'snapshot':
|
||||
num |= SNAPSHOT_IMAGE
|
||||
|
||||
if image_type == 'import':
|
||||
num |= IMPORT_IMAGE
|
||||
os_type = meta.get('os_type', payload.get('os_type', ''))
|
||||
if os_type == 'linux':
|
||||
num |= LINUX_IMAGE
|
||||
|
@ -338,6 +338,9 @@ class InstanceExists(models.Model):
|
||||
def update_status(self, new_status):
|
||||
self.status = new_status
|
||||
|
||||
def is_image_type_import(self):
|
||||
return (self.raw.image_type & 0xf) == 3
|
||||
|
||||
@staticmethod
|
||||
def mark_exists_as_sent_unverified(message_ids):
|
||||
absent_exists = []
|
||||
|
@ -1184,6 +1184,7 @@ class NovaVerifierValidityTestCase(StacktachBaseTestCase):
|
||||
|
||||
exist = self._create_mock_exist()
|
||||
exist.rax_options = 'a'
|
||||
exist.is_image_type_import().AndReturn(False)
|
||||
self.mox.ReplayAll()
|
||||
|
||||
with self.assertRaises(WrongTypeException) as wt:
|
||||
@ -1207,6 +1208,7 @@ class NovaVerifierValidityTestCase(StacktachBaseTestCase):
|
||||
|
||||
exist = self._create_mock_exist()
|
||||
exist.rax_options = ''
|
||||
exist.is_image_type_import().AndReturn(False)
|
||||
self.mox.ReplayAll()
|
||||
|
||||
with self.assertRaises(NullFieldException) as nf:
|
||||
@ -1230,6 +1232,7 @@ class NovaVerifierValidityTestCase(StacktachBaseTestCase):
|
||||
|
||||
exist = self._create_mock_exist()
|
||||
exist.os_architecture = 'x64,'
|
||||
exist.is_image_type_import().AndReturn(False)
|
||||
self.mox.ReplayAll()
|
||||
|
||||
with self.assertRaises(WrongTypeException) as wt:
|
||||
@ -1252,6 +1255,7 @@ class NovaVerifierValidityTestCase(StacktachBaseTestCase):
|
||||
|
||||
exist = self._create_mock_exist()
|
||||
exist.os_architecture = ''
|
||||
exist.is_image_type_import().AndReturn(False)
|
||||
self.mox.ReplayAll()
|
||||
|
||||
with self.assertRaises(NullFieldException) as nf:
|
||||
@ -1275,6 +1279,7 @@ class NovaVerifierValidityTestCase(StacktachBaseTestCase):
|
||||
|
||||
exist = self._create_mock_exist()
|
||||
exist.os_distro = 'com.microsoft.server,'
|
||||
exist.is_image_type_import().AndReturn(False)
|
||||
self.mox.ReplayAll()
|
||||
|
||||
with self.assertRaises(WrongTypeException) as wt:
|
||||
@ -1299,6 +1304,7 @@ class NovaVerifierValidityTestCase(StacktachBaseTestCase):
|
||||
|
||||
exist = self._create_mock_exist()
|
||||
exist.os_distro = ''
|
||||
exist.is_image_type_import().AndReturn(False)
|
||||
self.mox.ReplayAll()
|
||||
|
||||
with self.assertRaises(NullFieldException) as nf:
|
||||
@ -1322,6 +1328,7 @@ class NovaVerifierValidityTestCase(StacktachBaseTestCase):
|
||||
|
||||
exist = self._create_mock_exist()
|
||||
exist.os_version = '2008.2,'
|
||||
exist.is_image_type_import().AndReturn(False)
|
||||
self.mox.ReplayAll()
|
||||
|
||||
with self.assertRaises(WrongTypeException) as wt:
|
||||
@ -1345,6 +1352,7 @@ class NovaVerifierValidityTestCase(StacktachBaseTestCase):
|
||||
|
||||
exist = self._create_mock_exist()
|
||||
exist.os_version = ''
|
||||
exist.is_image_type_import().AndReturn(False)
|
||||
self.mox.ReplayAll()
|
||||
|
||||
with self.assertRaises(NullFieldException) as nf:
|
||||
@ -1363,6 +1371,7 @@ class NovaVerifierValidityTestCase(StacktachBaseTestCase):
|
||||
config.flavor_field_name().AndReturn('dummy_flavor_field_name')
|
||||
|
||||
exist = self._create_mock_exist()
|
||||
exist.is_image_type_import().AndReturn(False)
|
||||
self.mox.ReplayAll()
|
||||
|
||||
nova_verifier._verify_validity(exist, 'all')
|
||||
@ -1397,6 +1406,19 @@ class NovaVerifierValidityTestCase(StacktachBaseTestCase):
|
||||
|
||||
exist = self._create_mock_exist()
|
||||
exist.deleted_at = None
|
||||
exist.is_image_type_import().AndReturn(False)
|
||||
self.mox.ReplayAll()
|
||||
|
||||
nova_verifier._verify_validity(exist, 'all')
|
||||
self.mox.VerifyAll()
|
||||
|
||||
def test_should_verify_null_os_distro_if_image_type_is_import(self):
|
||||
self.mox.StubOutWithMock(config, 'flavor_field_name')
|
||||
config.flavor_field_name().AndReturn('dummy_flavor_field_name')
|
||||
|
||||
exist = self._create_mock_exist()
|
||||
exist.os_distro = ""
|
||||
exist.is_image_type_import().AndReturn(True)
|
||||
self.mox.ReplayAll()
|
||||
|
||||
nova_verifier._verify_validity(exist, 'all')
|
||||
|
@ -176,10 +176,12 @@ def _verify_basic_validity(exist):
|
||||
|
||||
|
||||
def _verify_optional_validity(exist):
|
||||
is_image_type_import = exist.is_image_type_import()
|
||||
fields = {exist.rax_options: 'rax_options',
|
||||
exist.os_architecture: 'os_architecture',
|
||||
exist.os_version: 'os_version',
|
||||
exist.os_distro: 'os_distro'}
|
||||
exist.os_version: 'os_version'}
|
||||
if not is_image_type_import:
|
||||
fields.update({exist.os_distro: 'os_distro'})
|
||||
for (field_value, field_name) in fields.items():
|
||||
if field_value == '':
|
||||
raise NullFieldException(field_name, exist.id, exist.instance)
|
||||
@ -187,8 +189,9 @@ def _verify_optional_validity(exist):
|
||||
'rax_options', exist.rax_options, exist.id, exist.instance)
|
||||
base_verifier._is_alphanumeric(
|
||||
'os_architecture', exist.os_architecture, exist.id, exist.instance)
|
||||
base_verifier._is_alphanumeric(
|
||||
'os_distro', exist.os_distro, exist.id, exist.instance)
|
||||
if not is_image_type_import:
|
||||
base_verifier._is_alphanumeric(
|
||||
'os_distro', exist.os_distro, exist.id, exist.instance)
|
||||
base_verifier._is_alphanumeric(
|
||||
'os_version', exist.os_version, exist.id, exist.instance)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user