Added instance/image id and verified_at to error messages
This commit is contained in:
parent
1c2042c8bf
commit
259fe6edd0
@ -17,11 +17,9 @@
|
||||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
# IN THE SOFTWARE.
|
||||
from datetime import datetime
|
||||
|
||||
import datetime
|
||||
import decimal
|
||||
import json
|
||||
import logging
|
||||
import uuid
|
||||
import kombu
|
||||
|
||||
@ -31,7 +29,7 @@ from stacktach import datetime_to_decimal as dt
|
||||
from stacktach import stacklog
|
||||
from stacktach import models
|
||||
from tests.unit import StacktachBaseTestCase
|
||||
from utils import IMAGE_UUID_1
|
||||
from utils import IMAGE_UUID_1, SIZE_1, SIZE_2, CREATED_AT_1, CREATED_AT_2
|
||||
from utils import GLANCE_VERIFIER_EVENT_TYPE
|
||||
from utils import make_verifier_config
|
||||
from verifier import glance_verifier
|
||||
@ -87,8 +85,8 @@ class GlanceVerifierTestCase(StacktachBaseTestCase):
|
||||
def test_verify_usage_created_at_mismatch(self):
|
||||
exist = self.mox.CreateMockAnything()
|
||||
exist.usage = self.mox.CreateMockAnything()
|
||||
exist.created_at = decimal.Decimal('1.1')
|
||||
exist.usage.created_at = decimal.Decimal('2.1')
|
||||
exist.created_at = CREATED_AT_1
|
||||
exist.usage.created_at = CREATED_AT_2
|
||||
self.mox.ReplayAll()
|
||||
|
||||
with self.assertRaises(FieldMismatch) as cm:
|
||||
@ -96,8 +94,8 @@ class GlanceVerifierTestCase(StacktachBaseTestCase):
|
||||
|
||||
exception = cm.exception
|
||||
self.assertEqual(exception.field_name, 'created_at')
|
||||
self.assertEqual(exception.expected, decimal.Decimal('1.1'))
|
||||
self.assertEqual(exception.actual, decimal.Decimal('2.1'))
|
||||
self.assertEqual(exception.expected, CREATED_AT_1)
|
||||
self.assertEqual(exception.actual, CREATED_AT_2)
|
||||
|
||||
self.mox.VerifyAll()
|
||||
|
||||
@ -119,10 +117,10 @@ class GlanceVerifierTestCase(StacktachBaseTestCase):
|
||||
|
||||
def test_verify_usage_size_mismatch(self):
|
||||
exist = self.mox.CreateMockAnything()
|
||||
exist.size = 1234
|
||||
exist.size = SIZE_1
|
||||
|
||||
exist.usage = self.mox.CreateMockAnything()
|
||||
exist.usage.size = 5678
|
||||
exist.usage.size = SIZE_2
|
||||
self.mox.ReplayAll()
|
||||
|
||||
with self.assertRaises(FieldMismatch) as cm:
|
||||
@ -130,8 +128,8 @@ class GlanceVerifierTestCase(StacktachBaseTestCase):
|
||||
exception = cm.exception
|
||||
|
||||
self.assertEqual(exception.field_name, 'size')
|
||||
self.assertEqual(exception.expected, 1234)
|
||||
self.assertEqual(exception.actual, 5678)
|
||||
self.assertEqual(exception.expected, SIZE_1)
|
||||
self.assertEqual(exception.actual, SIZE_2)
|
||||
|
||||
self.mox.VerifyAll()
|
||||
|
||||
@ -255,30 +253,16 @@ class GlanceVerifierTestCase(StacktachBaseTestCase):
|
||||
self.assertEqual(exception.actual, decimal.Decimal('4.1'))
|
||||
self.mox.VerifyAll()
|
||||
|
||||
def test_verify_for_delete_size_mismatch(self):
|
||||
exist = self.mox.CreateMockAnything()
|
||||
exist.delete = self.mox.CreateMockAnything()
|
||||
exist.launched_at = decimal.Decimal('1.1')
|
||||
exist.deleted_at = decimal.Decimal('5.1')
|
||||
exist.delete.launched_at = decimal.Decimal('1.1')
|
||||
exist.delete.deleted_at = decimal.Decimal('6.1')
|
||||
def test_should_verify_that_image_size_in_exist_is_not_null(self):
|
||||
self.mox.StubOutWithMock(datetime, 'datetime')
|
||||
datetime.datetime.utcnow().AndReturn('2014-01-02 03:04:05')
|
||||
self.mox.ReplayAll()
|
||||
|
||||
try:
|
||||
glance_verifier._verify_for_delete(exist)
|
||||
self.fail()
|
||||
except FieldMismatch, fm:
|
||||
self.assertEqual(fm.field_name, 'deleted_at')
|
||||
self.assertEqual(fm.expected, decimal.Decimal('5.1'))
|
||||
self.assertEqual(fm.actual, decimal.Decimal('6.1'))
|
||||
self.mox.VerifyAll()
|
||||
|
||||
def test_should_verify_that_image_size_in_exist_is_not_null(self):
|
||||
exist = self.mox.CreateMockAnything()
|
||||
exist.id = 23
|
||||
exist.size = None
|
||||
exist.created_at = decimal.Decimal('5.1')
|
||||
exist.uuid = 'abcd1234'
|
||||
exist.uuid = '1234-5678-9012-3456'
|
||||
self.mox.ReplayAll()
|
||||
|
||||
try:
|
||||
@ -286,26 +270,40 @@ class GlanceVerifierTestCase(StacktachBaseTestCase):
|
||||
self.fail()
|
||||
except NullFieldException as nf:
|
||||
self.assertEqual(nf.field_name, 'image_size')
|
||||
self.assertEqual(nf.reason, "image_size field was null for exist id 23")
|
||||
self.assertEqual(
|
||||
nf.reason, "Failed at 2014-01-02 03:04:05 UTC for "
|
||||
"1234-5678-9012-3456: image_size field was null for "
|
||||
"exist id 23")
|
||||
self.mox.VerifyAll()
|
||||
|
||||
def test_should_verify_that_created_at_in_exist_is_not_null(self):
|
||||
self.mox.StubOutWithMock(datetime, 'datetime')
|
||||
datetime.datetime.utcnow().AndReturn('2014-01-01 01:02:03')
|
||||
self.mox.ReplayAll()
|
||||
|
||||
exist = self.mox.CreateMockAnything()
|
||||
exist.id = 23
|
||||
exist.size = 'size'
|
||||
exist.created_at = None
|
||||
exist.uuid = 'abcd1234'
|
||||
exist.uuid = '1234-5678-9012-3456'
|
||||
self.mox.ReplayAll()
|
||||
|
||||
try:
|
||||
with self.assertRaises(NullFieldException) as nfe:
|
||||
glance_verifier._verify_validity(exist)
|
||||
self.fail()
|
||||
except NullFieldException as nf:
|
||||
self.assertEqual(nf.field_name, 'created_at')
|
||||
self.assertEqual(nf.reason, "created_at field was null for exist id 23")
|
||||
exception = nfe.exception
|
||||
|
||||
self.assertEqual(exception.field_name, 'created_at')
|
||||
self.assertEqual(exception.reason,
|
||||
"Failed at 2014-01-01 01:02:03 UTC for "
|
||||
"1234-5678-9012-3456: created_at field was "
|
||||
"null for exist id 23")
|
||||
self.mox.VerifyAll()
|
||||
|
||||
def test_should_verify_that_uuid_in_exist_is_not_null(self):
|
||||
self.mox.StubOutWithMock(datetime, 'datetime')
|
||||
datetime.datetime.utcnow().AndReturn('2014-01-01 01:02:03')
|
||||
self.mox.ReplayAll()
|
||||
|
||||
exist = self.mox.CreateMockAnything()
|
||||
exist.id = 23
|
||||
exist.size = 'size'
|
||||
@ -318,15 +316,21 @@ class GlanceVerifierTestCase(StacktachBaseTestCase):
|
||||
self.fail()
|
||||
except NullFieldException as nf:
|
||||
self.assertEqual(nf.field_name, 'uuid')
|
||||
self.assertEqual(nf.reason, "uuid field was null for exist id 23")
|
||||
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_owner_in_exist_is_not_null(self):
|
||||
self.mox.StubOutWithMock(datetime, 'datetime')
|
||||
datetime.datetime.utcnow().AndReturn('2014-01-02 03:04:05')
|
||||
self.mox.ReplayAll()
|
||||
|
||||
exist = self.mox.CreateMockAnything()
|
||||
exist.id = 23
|
||||
exist.size = 1234
|
||||
exist.created_at = decimal.Decimal('5.1')
|
||||
exist.uuid = 'abcd1234'
|
||||
exist.uuid = '1234-5678-9012-3456'
|
||||
exist.owner = None
|
||||
self.mox.ReplayAll()
|
||||
|
||||
@ -335,10 +339,16 @@ class GlanceVerifierTestCase(StacktachBaseTestCase):
|
||||
self.fail()
|
||||
except NullFieldException as nf:
|
||||
self.assertEqual(nf.field_name, 'owner')
|
||||
self.assertEqual(nf.reason, "owner field was null for exist id 23")
|
||||
self.assertEqual(
|
||||
nf.reason, "Failed at 2014-01-02 03:04:05 UTC for "
|
||||
"1234-5678-9012-3456: owner field was null for exist id 23")
|
||||
self.mox.VerifyAll()
|
||||
|
||||
def test_should_verify_that_uuid_value_is_uuid_like(self):
|
||||
self.mox.StubOutWithMock(datetime, 'datetime')
|
||||
datetime.datetime.utcnow().AndReturn('2014-01-02 03:04:05')
|
||||
self.mox.ReplayAll()
|
||||
|
||||
exist = self.mox.CreateMockAnything()
|
||||
exist.id = 23
|
||||
exist.size = 'size'
|
||||
@ -351,10 +361,17 @@ class GlanceVerifierTestCase(StacktachBaseTestCase):
|
||||
self.fail()
|
||||
except WrongTypeException as wt:
|
||||
self.assertEqual(wt.field_name, 'uuid')
|
||||
self.assertEqual(wt.reason, "{ uuid : asdfe-fgh } of incorrect type for exist id 23")
|
||||
self.assertEqual(
|
||||
wt.reason,
|
||||
"Failed at 2014-01-02 03:04:05 UTC for None: "
|
||||
"{uuid: asdfe-fgh} was of incorrect type for exist id 23")
|
||||
self.mox.VerifyAll()
|
||||
|
||||
def test_should_verify_created_at_is_decimal(self):
|
||||
self.mox.StubOutWithMock(datetime, 'datetime')
|
||||
datetime.datetime.utcnow().AndReturn('2014-01-02 03:04:05')
|
||||
self.mox.ReplayAll()
|
||||
|
||||
exist = self.mox.CreateMockAnything()
|
||||
exist.id = 23
|
||||
exist.size = 'size'
|
||||
@ -367,13 +384,21 @@ class GlanceVerifierTestCase(StacktachBaseTestCase):
|
||||
self.fail()
|
||||
except WrongTypeException as wt:
|
||||
self.assertEqual(wt.field_name, 'created_at')
|
||||
self.assertEqual(wt.reason, "{ created_at : 123.a } of incorrect type for exist id 23")
|
||||
self.assertEqual(
|
||||
wt.reason,
|
||||
"Failed at 2014-01-02 03:04:05 UTC for "
|
||||
"58fb036d-5ef8-47a8-b503-7571276c400a: {created_at: 123.a} was "
|
||||
"of incorrect type for exist id 23")
|
||||
self.mox.VerifyAll()
|
||||
|
||||
def test_should_verify_image_size_is_of_type_decimal(self):
|
||||
self.mox.StubOutWithMock(datetime, 'datetime')
|
||||
datetime.datetime.utcnow().AndReturn('2014-01-02 03:04:05')
|
||||
self.mox.ReplayAll()
|
||||
|
||||
exist = self.mox.CreateMockAnything()
|
||||
exist.id = 23
|
||||
exist.size = 'size'
|
||||
exist.size = 'random'
|
||||
exist.created_at = decimal.Decimal('5.1')
|
||||
exist.uuid = "58fb036d-5ef8-47a8-b503-7571276c400a"
|
||||
self.mox.ReplayAll()
|
||||
@ -383,10 +408,18 @@ class GlanceVerifierTestCase(StacktachBaseTestCase):
|
||||
self.fail()
|
||||
except WrongTypeException as wt:
|
||||
self.assertEqual(wt.field_name, 'size')
|
||||
self.assertEqual(wt.reason, "{ size : size } of incorrect type for exist id 23")
|
||||
self.assertEqual(
|
||||
wt.reason,
|
||||
"Failed at 2014-01-02 03:04:05 UTC for "
|
||||
"58fb036d-5ef8-47a8-b503-7571276c400a: {size: random} was "
|
||||
"of incorrect type for exist id 23")
|
||||
self.mox.VerifyAll()
|
||||
|
||||
def test_should_verify_owner_is_of_type_hex(self):
|
||||
self.mox.StubOutWithMock(datetime, 'datetime')
|
||||
datetime.datetime.utcnow().AndReturn('2014-01-02 03:04:05')
|
||||
self.mox.ReplayAll()
|
||||
|
||||
exist = self.mox.CreateMockAnything()
|
||||
exist.id = 23
|
||||
exist.size = 1234L
|
||||
@ -400,7 +433,12 @@ class GlanceVerifierTestCase(StacktachBaseTestCase):
|
||||
self.fail()
|
||||
except WrongTypeException as wt:
|
||||
self.assertEqual(wt.field_name, 'owner')
|
||||
self.assertEqual(wt.reason, "{ owner : 3762854cd6f6435998188d5120e4c271,kl } of incorrect type for exist id 23")
|
||||
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_correctly_for_all_non_null_and_valid_types(self):
|
||||
@ -435,6 +473,9 @@ class GlanceVerifierTestCase(StacktachBaseTestCase):
|
||||
self.assertTrue(verified)
|
||||
|
||||
def test_verify_exist_marks_exist_failed_if_field_mismatch_exception(self):
|
||||
self.mox.StubOutWithMock(datetime, 'datetime')
|
||||
datetime.datetime.utcnow().AndReturn('2014-01-01 01:01:01')
|
||||
self.mox.ReplayAll()
|
||||
|
||||
exist1 = self.mox.CreateMockAnything()
|
||||
exist2 = self.mox.CreateMockAnything()
|
||||
@ -442,11 +483,13 @@ class GlanceVerifierTestCase(StacktachBaseTestCase):
|
||||
self.mox.StubOutWithMock(glance_verifier, '_verify_for_usage')
|
||||
self.mox.StubOutWithMock(glance_verifier, '_verify_for_delete')
|
||||
self.mox.StubOutWithMock(glance_verifier, '_verify_validity')
|
||||
|
||||
field_mismatch_exc = FieldMismatch('field', 'expected', 'actual')
|
||||
field_mismatch_exc = FieldMismatch('field', 'expected',
|
||||
'actual', 'uuid')
|
||||
glance_verifier._verify_for_usage(exist1).AndRaise(
|
||||
exception=field_mismatch_exc)
|
||||
exist1.mark_failed(reason="Expected field to be 'expected' got 'actual'")
|
||||
exist1.mark_failed(
|
||||
reason="Failed at 2014-01-01 01:01:01 UTC for uuid: Expected "
|
||||
"field to be 'expected' got 'actual'")
|
||||
|
||||
glance_verifier._verify_for_usage(exist2)
|
||||
glance_verifier._verify_for_delete(exist2)
|
||||
@ -465,7 +508,7 @@ class GlanceVerifierTestCase(StacktachBaseTestCase):
|
||||
stacklog.get_logger('verifier', is_parent=False).AndReturn(mock_logger)
|
||||
mock_logger.info('glance: Adding 2 per-owner exists to queue.')
|
||||
mock_logger.info('glance: Adding 2 per-owner exists to queue.')
|
||||
when_max = datetime.utcnow()
|
||||
when_max = datetime.datetime.utcnow()
|
||||
models.ImageExists.VERIFYING = 'verifying'
|
||||
models.ImageExists.PENDING = 'pending'
|
||||
models.ImageExists.SENT_VERIFYING = 'sent_verifying'
|
||||
@ -514,7 +557,7 @@ class GlanceVerifierTestCase(StacktachBaseTestCase):
|
||||
mock_logger.info('glance: Adding 0 per-owner exists to queue.')
|
||||
mock_logger.info('glance: Adding 2 per-owner exists to queue.')
|
||||
callback = self.mox.CreateMockAnything()
|
||||
when_max = datetime.utcnow()
|
||||
when_max = datetime.datetime.utcnow()
|
||||
models.ImageExists.SENT_VERIFYING = 'sent_verifying'
|
||||
models.ImageExists.SENT_UNVERIFIED = 'sent_unverified'
|
||||
models.ImageExists.PENDING = 'pending'
|
||||
@ -559,8 +602,8 @@ class GlanceVerifierTestCase(StacktachBaseTestCase):
|
||||
]
|
||||
exist_str = json.dumps(exist_dict)
|
||||
exist.raw.json = exist_str
|
||||
exist.audit_period_beginning = datetime(2013, 10, 10)
|
||||
exist.audit_period_ending = datetime(2013, 10, 10, 23, 59, 59)
|
||||
exist.audit_period_beginning = datetime.datetime(2013, 10, 10)
|
||||
exist.audit_period_ending = datetime.datetime(2013, 10, 10, 23, 59, 59)
|
||||
exist.owner = "1"
|
||||
self.mox.StubOutWithMock(uuid, 'uuid4')
|
||||
uuid.uuid4().AndReturn('some_other_uuid')
|
||||
@ -601,8 +644,8 @@ class GlanceVerifierTestCase(StacktachBaseTestCase):
|
||||
]
|
||||
exist_str = json.dumps(exist_dict)
|
||||
exist.raw.json = exist_str
|
||||
exist.audit_period_beginning = datetime(2013, 10, 10)
|
||||
exist.audit_period_ending = datetime(2013, 10, 10, 23, 59, 59)
|
||||
exist.audit_period_beginning = datetime.datetime(2013, 10, 10)
|
||||
exist.audit_period_ending = datetime.datetime(2013, 10, 10, 23, 59, 59)
|
||||
exist.owner = "1"
|
||||
self.mox.StubOutWithMock(kombu.pools, 'producers')
|
||||
self.mox.StubOutWithMock(kombu.common, 'maybe_declare')
|
||||
|
@ -32,7 +32,7 @@ from stacktach import datetime_to_decimal as dt
|
||||
from stacktach import stacklog
|
||||
from stacktach import models
|
||||
from tests.unit import StacktachBaseTestCase
|
||||
from utils import make_verifier_config
|
||||
from utils import make_verifier_config, LAUNCHED_AT_1, INSTANCE_FLAVOR_ID_1, INSTANCE_FLAVOR_ID_2, FLAVOR_FIELD_NAME, DELETED_AT_1, LAUNCHED_AT_2, DELETED_AT_2
|
||||
from utils import INSTANCE_ID_1
|
||||
from utils import RAX_OPTIONS_1
|
||||
from utils import RAX_OPTIONS_2
|
||||
@ -54,12 +54,14 @@ from verifier import FieldMismatch
|
||||
from verifier import NotFound
|
||||
from verifier import VerificationException
|
||||
|
||||
|
||||
class NovaVerifierVerifyForLaunchTestCase(StacktachBaseTestCase):
|
||||
def setUp(self):
|
||||
self.mox = mox.Mox()
|
||||
self.mox.StubOutWithMock(models, 'InstanceUsage',
|
||||
use_mock_anything=True)
|
||||
models.InstanceUsage.objects = self.mox.CreateMockAnything()
|
||||
|
||||
self._setup_verifier()
|
||||
|
||||
def _setup_verifier(self):
|
||||
@ -132,28 +134,36 @@ class NovaVerifierVerifyForLaunchTestCase(StacktachBaseTestCase):
|
||||
self.mox.VerifyAll()
|
||||
|
||||
def test_verify_for_launch_flavor_id_missmatch(self):
|
||||
self.mox.StubOutWithMock(config, 'flavor_field_name')
|
||||
config.flavor_field_name().AndReturn('dummy_flavor_field_name')
|
||||
exist = self.mox.CreateMockAnything()
|
||||
exist.usage = self.mox.CreateMockAnything()
|
||||
exist.launched_at = decimal.Decimal('1.1')
|
||||
exist.dummy_flavor_field_name = 'dummy_flavor_1'
|
||||
exist.usage.launched_at = decimal.Decimal('1.1')
|
||||
exist.usage.dummy_flavor_field_name = 'dummy_flavor_2'
|
||||
self.mox.StubOutWithMock(datetime, 'datetime')
|
||||
datetime.datetime.utcnow().AndReturn('2014-01-02 03:04:05')
|
||||
self.mox.ReplayAll()
|
||||
|
||||
self.mox.StubOutWithMock(config, 'flavor_field_name')
|
||||
config.flavor_field_name().AndReturn(FLAVOR_FIELD_NAME)
|
||||
exist = self.mox.CreateMockAnything()
|
||||
exist.instance = INSTANCE_ID_1
|
||||
exist.usage = self.mox.CreateMockAnything()
|
||||
exist.launched_at = decimal.Decimal(LAUNCHED_AT_1)
|
||||
exist.flavor_field_name = INSTANCE_FLAVOR_ID_1
|
||||
exist.usage.launched_at = decimal.Decimal(LAUNCHED_AT_1)
|
||||
exist.usage.flavor_field_name = INSTANCE_FLAVOR_ID_2
|
||||
self.mox.ReplayAll()
|
||||
with self.assertRaises(FieldMismatch) as fm:
|
||||
nova_verifier._verify_for_launch(exist)
|
||||
exception = fm.exception
|
||||
self.assertEqual(exception.field_name, 'dummy_flavor_field_name')
|
||||
self.assertEqual(exception.expected, 'dummy_flavor_1')
|
||||
self.assertEqual(exception.actual, 'dummy_flavor_2')
|
||||
|
||||
self.assertEqual(exception.field_name, FLAVOR_FIELD_NAME)
|
||||
self.assertEqual(exception.expected, INSTANCE_FLAVOR_ID_1)
|
||||
self.assertEqual(exception.actual, INSTANCE_FLAVOR_ID_2)
|
||||
self.assertEqual(
|
||||
exception.reason,
|
||||
"Failed at 2014-01-02 03:04:05 UTC for "
|
||||
"08f685d9-6352-4dbc-8271-96cc54bf14cd: Expected flavor_field_name "
|
||||
"to be '1' got 'performance2-120'")
|
||||
self.mox.VerifyAll()
|
||||
|
||||
def test_verify_for_launch_tenant_id_mismatch(self):
|
||||
self.mox.StubOutWithMock(config, 'flavor_field_name')
|
||||
config.flavor_field_name().AndReturn("flavor_field_name")
|
||||
config.flavor_field_name().AndReturn(FLAVOR_FIELD_NAME)
|
||||
|
||||
exist = self.mox.CreateMockAnything()
|
||||
exist.tenant = TENANT_ID_1
|
||||
@ -425,35 +435,35 @@ class NovaVerifierVerifyForDeleteTestCase(StacktachBaseTestCase):
|
||||
def test_verify_for_delete_launched_at_mismatch(self):
|
||||
exist = self.mox.CreateMockAnything()
|
||||
exist.delete = self.mox.CreateMockAnything()
|
||||
exist.launched_at = decimal.Decimal('1.1')
|
||||
exist.deleted_at = decimal.Decimal('5.1')
|
||||
exist.delete.launched_at = decimal.Decimal('2.1')
|
||||
exist.delete.deleted_at = decimal.Decimal('5.1')
|
||||
exist.launched_at = LAUNCHED_AT_1
|
||||
exist.deleted_at = DELETED_AT_1
|
||||
exist.delete.launched_at = LAUNCHED_AT_2
|
||||
exist.delete.deleted_at = DELETED_AT_1
|
||||
self.mox.ReplayAll()
|
||||
|
||||
with self.assertRaises(FieldMismatch) as fm:
|
||||
nova_verifier._verify_for_delete(exist)
|
||||
exception = fm.exception
|
||||
self.assertEqual(exception.field_name, 'launched_at')
|
||||
self.assertEqual(exception.expected, decimal.Decimal('1.1'))
|
||||
self.assertEqual(exception.actual, decimal.Decimal('2.1'))
|
||||
self.assertEqual(exception.expected, LAUNCHED_AT_1)
|
||||
self.assertEqual(exception.actual, LAUNCHED_AT_2)
|
||||
self.mox.VerifyAll()
|
||||
|
||||
def test_verify_for_delete_deleted_at_mismatch(self):
|
||||
exist = self.mox.CreateMockAnything()
|
||||
exist.delete = self.mox.CreateMockAnything()
|
||||
exist.launched_at = decimal.Decimal('1.1')
|
||||
exist.deleted_at = decimal.Decimal('5.1')
|
||||
exist.delete.launched_at = decimal.Decimal('1.1')
|
||||
exist.delete.deleted_at = decimal.Decimal('6.1')
|
||||
exist.launched_at = LAUNCHED_AT_1
|
||||
exist.deleted_at = DELETED_AT_1
|
||||
exist.delete.launched_at = LAUNCHED_AT_1
|
||||
exist.delete.deleted_at = DELETED_AT_2
|
||||
self.mox.ReplayAll()
|
||||
|
||||
with self.assertRaises(FieldMismatch) as fm:
|
||||
nova_verifier._verify_for_delete(exist)
|
||||
exception = fm.exception
|
||||
self.assertEqual(exception.field_name, 'deleted_at')
|
||||
self.assertEqual(exception.expected, decimal.Decimal('5.1'))
|
||||
self.assertEqual(exception.actual, decimal.Decimal('6.1'))
|
||||
self.assertEqual(exception.expected, DELETED_AT_1)
|
||||
self.assertEqual(exception.actual, DELETED_AT_2)
|
||||
self.mox.VerifyAll()
|
||||
|
||||
|
||||
@ -1012,28 +1022,52 @@ class NovaVerifierValidityTestCase(StacktachBaseTestCase):
|
||||
def tearDown(self):
|
||||
self.mox.UnsetStubs()
|
||||
|
||||
def _create_mock_exist(self):
|
||||
exist = self.mox.CreateMockAnything()
|
||||
exist.instance = '58fb036d-5ef8-47a8-b503-7571276c400a'
|
||||
exist.tenant = '3762854cd6f6435998188d5120e4c271'
|
||||
exist.id = 23
|
||||
exist.launched_at = decimal.Decimal('1.1')
|
||||
exist.deleted_at = decimal.Decimal('5.1')
|
||||
exist.dummy_flavor_field_name = 'dummy_flavor'
|
||||
exist.rax_options = '1'
|
||||
exist.os_architecture = 'x64'
|
||||
exist.os_distro = 'com.microsoft.server'
|
||||
exist.os_version = '2008.2'
|
||||
|
||||
return exist
|
||||
|
||||
def test_should_verify_that_tenant_in_exist_is_not_null(self):
|
||||
self.mox.StubOutWithMock(datetime, 'datetime')
|
||||
datetime.datetime.utcnow().AndReturn('2014-01-02 03:04:05')
|
||||
self.mox.ReplayAll()
|
||||
|
||||
self.mox.StubOutWithMock(config, 'flavor_field_name')
|
||||
config.flavor_field_name().AndReturn('dummy_flavor_field_name')
|
||||
exist = self.mox.CreateMockAnything()
|
||||
|
||||
exist = self._create_mock_exist()
|
||||
exist.tenant = None
|
||||
exist.id = 23
|
||||
self.mox.ReplayAll()
|
||||
|
||||
with self.assertRaises(NullFieldException) as nf:
|
||||
nova_verifier._verify_validity(exist, 'all')
|
||||
exception = nf.exception
|
||||
self.assertEqual(exception.field_name, 'tenant')
|
||||
self.assertEqual(exception.reason,
|
||||
"tenant field was null for exist id 23")
|
||||
self.assertEqual(
|
||||
exception.reason, "Failed at 2014-01-02 03:04:05 UTC for "
|
||||
"58fb036d-5ef8-47a8-b503-7571276c400a: tenant field was null for "
|
||||
"exist id 23")
|
||||
self.mox.VerifyAll()
|
||||
|
||||
def test_should_verify_that_launched_at_in_exist_is_not_null(self):
|
||||
self.mox.StubOutWithMock(datetime, 'datetime')
|
||||
datetime.datetime.utcnow().AndReturn('2014-01-02 03:04:05')
|
||||
self.mox.ReplayAll()
|
||||
|
||||
self.mox.StubOutWithMock(config, 'flavor_field_name')
|
||||
config.flavor_field_name().AndReturn('dummy_flavor_field_name')
|
||||
exist = self.mox.CreateMockAnything()
|
||||
exist.tenant = 'tenant'
|
||||
exist.id = 23
|
||||
|
||||
exist = self._create_mock_exist()
|
||||
exist.launched_at = None
|
||||
self.mox.ReplayAll()
|
||||
|
||||
@ -1041,17 +1075,21 @@ class NovaVerifierValidityTestCase(StacktachBaseTestCase):
|
||||
nova_verifier._verify_validity(exist, 'all')
|
||||
exception = nf.exception
|
||||
self.assertEqual(exception.field_name, 'launched_at')
|
||||
self.assertEqual(exception.reason,
|
||||
"launched_at field was null for exist id 23")
|
||||
self.assertEqual(
|
||||
exception.reason, "Failed at 2014-01-02 03:04:05 UTC for "
|
||||
"58fb036d-5ef8-47a8-b503-7571276c400a: launched_at field was null "
|
||||
"for exist id 23")
|
||||
self.mox.VerifyAll()
|
||||
|
||||
def test_should_verify_that_instance_flavor_id_in_exist_is_not_null(self):
|
||||
self.mox.StubOutWithMock(datetime, 'datetime')
|
||||
datetime.datetime.utcnow().AndReturn('2014-01-02 03:04:05')
|
||||
self.mox.ReplayAll()
|
||||
|
||||
self.mox.StubOutWithMock(config, 'flavor_field_name')
|
||||
config.flavor_field_name().AndReturn('dummy_flavor_field_name')
|
||||
exist = self.mox.CreateMockAnything()
|
||||
exist.tenant = '3762854cd6f6435998188d5120e4c271'
|
||||
exist.id = 23
|
||||
exist.launched_at = decimal.Decimal('1.1')
|
||||
|
||||
exist = self._create_mock_exist()
|
||||
exist.dummy_flavor_field_name = None
|
||||
self.mox.ReplayAll()
|
||||
|
||||
@ -1061,17 +1099,21 @@ class NovaVerifierValidityTestCase(StacktachBaseTestCase):
|
||||
self.assertEqual(exception.field_name, 'dummy_flavor_field_name')
|
||||
self.assertEqual(
|
||||
exception.reason,
|
||||
"dummy_flavor_field_name field was null for exist id 23")
|
||||
"Failed at 2014-01-02 03:04:05 UTC for "
|
||||
"58fb036d-5ef8-47a8-b503-7571276c400a: dummy_flavor_field_name "
|
||||
"field was null for exist id 23")
|
||||
self.mox.VerifyAll()
|
||||
|
||||
def test_should_verify_tenant_id_is_of_type_hex(self):
|
||||
self.mox.StubOutWithMock(datetime, 'datetime')
|
||||
datetime.datetime.utcnow().AndReturn('2014-01-02 03:04:05')
|
||||
self.mox.ReplayAll()
|
||||
|
||||
self.mox.StubOutWithMock(config, 'flavor_field_name')
|
||||
config.flavor_field_name().AndReturn('dummy_flavor_field_name')
|
||||
exist = self.mox.CreateMockAnything()
|
||||
exist.tenant = 'tenant'
|
||||
exist.id = 23
|
||||
exist.launched_at = decimal.Decimal('1.1')
|
||||
exist.dummy_flavor_field_name = 'dummy_flavor'
|
||||
|
||||
exist = self._create_mock_exist()
|
||||
exist.tenant = 'invalid_tenant'
|
||||
self.mox.ReplayAll()
|
||||
|
||||
with self.assertRaises(WrongTypeException) as wt:
|
||||
@ -1080,17 +1122,21 @@ class NovaVerifierValidityTestCase(StacktachBaseTestCase):
|
||||
self.assertEqual(exception.field_name, 'tenant')
|
||||
self.assertEqual(
|
||||
exception.reason,
|
||||
"{ tenant : tenant } of incorrect type for exist id 23")
|
||||
"Failed at 2014-01-02 03:04:05 UTC for "
|
||||
"58fb036d-5ef8-47a8-b503-7571276c400a: {tenant: invalid_tenant} "
|
||||
"was of incorrect type for exist id 23")
|
||||
self.mox.VerifyAll()
|
||||
|
||||
def test_should_verify_launched_at_is_of_type_decimal(self):
|
||||
self.mox.StubOutWithMock(datetime, 'datetime')
|
||||
datetime.datetime.utcnow().AndReturn('2014-01-02 03:04:05')
|
||||
self.mox.ReplayAll()
|
||||
|
||||
self.mox.StubOutWithMock(config, 'flavor_field_name')
|
||||
config.flavor_field_name().AndReturn('dummy_flavor_field_name')
|
||||
exist = self.mox.CreateMockAnything()
|
||||
exist.tenant = '3762854cd6f6435998188d5120e4c271'
|
||||
exist.id = 23
|
||||
|
||||
exist = self._create_mock_exist()
|
||||
exist.launched_at = 111
|
||||
exist.dummy_flavor_field_name = 'dummy_flavor'
|
||||
|
||||
self.mox.ReplayAll()
|
||||
|
||||
@ -1100,17 +1146,20 @@ class NovaVerifierValidityTestCase(StacktachBaseTestCase):
|
||||
self.assertEqual(exception.field_name, 'launched_at')
|
||||
self.assertEqual(
|
||||
exception.reason,
|
||||
"{ launched_at : 111 } of incorrect type for exist id 23")
|
||||
'Failed at 2014-01-02 03:04:05 UTC for '
|
||||
'58fb036d-5ef8-47a8-b503-7571276c400a: {launched_at: 111} was of '
|
||||
'incorrect type for exist id 23')
|
||||
self.mox.VerifyAll()
|
||||
|
||||
def test_should_verify_deleted_at_is_of_decimal_type_if_present(self):
|
||||
self.mox.StubOutWithMock(datetime, 'datetime')
|
||||
datetime.datetime.utcnow().AndReturn('2014-01-02 03:04:05')
|
||||
self.mox.ReplayAll()
|
||||
|
||||
self.mox.StubOutWithMock(config, 'flavor_field_name')
|
||||
config.flavor_field_name().AndReturn('dummy_flavor_field_name')
|
||||
exist = self.mox.CreateMockAnything()
|
||||
exist.tenant = '3762854cd6f6435998188d5120e4c271'
|
||||
exist.id = 23
|
||||
exist.launched_at = decimal.Decimal('1.1')
|
||||
exist.dummy_flavor_field_name = 'dummy_flavor'
|
||||
|
||||
exist = self._create_mock_exist()
|
||||
exist.deleted_at = 20
|
||||
self.mox.ReplayAll()
|
||||
|
||||
@ -1120,19 +1169,20 @@ class NovaVerifierValidityTestCase(StacktachBaseTestCase):
|
||||
self.assertEqual(exception.field_name, 'deleted_at')
|
||||
self.assertEqual(
|
||||
exception.reason,
|
||||
"{ deleted_at : 20 } of incorrect type for exist id 23")
|
||||
'Failed at 2014-01-02 03:04:05 UTC for '
|
||||
'58fb036d-5ef8-47a8-b503-7571276c400a: {deleted_at: 20} was of '
|
||||
'incorrect type for exist id 23')
|
||||
self.mox.VerifyAll()
|
||||
|
||||
|
||||
def test_should_verify_rax_options_should_be_of_integer_type(self):
|
||||
self.mox.StubOutWithMock(datetime, 'datetime')
|
||||
datetime.datetime.utcnow().AndReturn('2014-01-02 03:04:05')
|
||||
self.mox.ReplayAll()
|
||||
|
||||
self.mox.StubOutWithMock(config, 'flavor_field_name')
|
||||
config.flavor_field_name().AndReturn('dummy_flavor_field_name')
|
||||
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.dummy_flavor_field_name = 'dummy_flavor'
|
||||
|
||||
exist = self._create_mock_exist()
|
||||
exist.rax_options = 'a'
|
||||
self.mox.ReplayAll()
|
||||
|
||||
@ -1142,18 +1192,20 @@ class NovaVerifierValidityTestCase(StacktachBaseTestCase):
|
||||
self.assertEqual(exception.field_name, 'rax_options')
|
||||
self.assertEqual(
|
||||
exception.reason,
|
||||
"{ rax_options : a } of incorrect type for exist id 23")
|
||||
'Failed at 2014-01-02 03:04:05 UTC for '
|
||||
'58fb036d-5ef8-47a8-b503-7571276c400a: {rax_options: a} was of '
|
||||
'incorrect type for exist id 23')
|
||||
self.mox.VerifyAll()
|
||||
|
||||
def test_should_verify_rax_options_should_not_be_empty(self):
|
||||
self.mox.StubOutWithMock(datetime, 'datetime')
|
||||
datetime.datetime.utcnow().AndReturn('2014-01-02 03:04:05')
|
||||
self.mox.ReplayAll()
|
||||
|
||||
self.mox.StubOutWithMock(config, 'flavor_field_name')
|
||||
config.flavor_field_name().AndReturn('dummy_flavor_field_name')
|
||||
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.dummy_flavor_field_name = 'dummy_flavor'
|
||||
|
||||
exist = self._create_mock_exist()
|
||||
exist.rax_options = ''
|
||||
self.mox.ReplayAll()
|
||||
|
||||
@ -1161,20 +1213,22 @@ class NovaVerifierValidityTestCase(StacktachBaseTestCase):
|
||||
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.assertEqual(
|
||||
exception.reason,
|
||||
"Failed at 2014-01-02 03:04:05 UTC for "
|
||||
"58fb036d-5ef8-47a8-b503-7571276c400a: rax_options field was null "
|
||||
"for exist id 23")
|
||||
self.mox.VerifyAll()
|
||||
|
||||
def test_should_verify_os_arch_should_be_alphanumeric(self):
|
||||
self.mox.StubOutWithMock(datetime, 'datetime')
|
||||
datetime.datetime.utcnow().AndReturn('2014-01-02 03:04:05')
|
||||
self.mox.ReplayAll()
|
||||
|
||||
self.mox.StubOutWithMock(config, 'flavor_field_name')
|
||||
config.flavor_field_name().AndReturn('dummy_flavor_field_name')
|
||||
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.dummy_flavor_field_name = 'dummy_flavor'
|
||||
exist.rax_options = 12
|
||||
|
||||
exist = self._create_mock_exist()
|
||||
exist.os_architecture = 'x64,'
|
||||
self.mox.ReplayAll()
|
||||
|
||||
@ -1184,19 +1238,19 @@ class NovaVerifierValidityTestCase(StacktachBaseTestCase):
|
||||
self.assertEqual(exception.field_name, 'os_architecture')
|
||||
self.assertEqual(
|
||||
exception.reason,
|
||||
"{ os_architecture : x64, } of incorrect type for exist id 23")
|
||||
'Failed at 2014-01-02 03:04:05 UTC for '
|
||||
'58fb036d-5ef8-47a8-b503-7571276c400a: {os_architecture: x64,} '
|
||||
'was of incorrect type for exist id 23')
|
||||
self.mox.VerifyAll()
|
||||
|
||||
def test_should_verify_os_arch_should_not_be_empty(self):
|
||||
self.mox.StubOutWithMock(datetime, 'datetime')
|
||||
datetime.datetime.utcnow().AndReturn('2014-01-02 03:04:05')
|
||||
self.mox.ReplayAll()
|
||||
self.mox.StubOutWithMock(config, 'flavor_field_name')
|
||||
config.flavor_field_name().AndReturn('dummy_flavor_field_name')
|
||||
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.dummy_flavor_field_name = 'dummy_flavor'
|
||||
exist.rax_options = 12
|
||||
|
||||
exist = self._create_mock_exist()
|
||||
exist.os_architecture = ''
|
||||
self.mox.ReplayAll()
|
||||
|
||||
@ -1206,20 +1260,20 @@ class NovaVerifierValidityTestCase(StacktachBaseTestCase):
|
||||
self.assertEqual(exception.field_name, 'os_architecture')
|
||||
self.assertEqual(
|
||||
exception.reason,
|
||||
"os_architecture field was null for exist id 23")
|
||||
"Failed at 2014-01-02 03:04:05 UTC for "
|
||||
"58fb036d-5ef8-47a8-b503-7571276c400a: os_architecture field was "
|
||||
"null for exist id 23")
|
||||
self.mox.VerifyAll()
|
||||
|
||||
def test_should_verify_os_distro_should_be_alphanumeric(self):
|
||||
self.mox.StubOutWithMock(datetime, 'datetime')
|
||||
datetime.datetime.utcnow().AndReturn('2014-01-02 03:04:05')
|
||||
self.mox.ReplayAll()
|
||||
|
||||
self.mox.StubOutWithMock(config, 'flavor_field_name')
|
||||
config.flavor_field_name().AndReturn('dummy_flavor_field_name')
|
||||
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.dummy_flavor_field_name = 'dummy_flavor'
|
||||
exist.rax_options = 12
|
||||
exist.os_architecture = 'x64'
|
||||
|
||||
exist = self._create_mock_exist()
|
||||
exist.os_distro = 'com.microsoft.server,'
|
||||
self.mox.ReplayAll()
|
||||
|
||||
@ -1229,21 +1283,21 @@ class NovaVerifierValidityTestCase(StacktachBaseTestCase):
|
||||
self.assertEqual(exception.field_name, 'os_distro')
|
||||
self.assertEqual(
|
||||
exception.reason,
|
||||
"{ os_distro : com.microsoft.server, } "
|
||||
"of incorrect type for exist id 23")
|
||||
"Failed at 2014-01-02 03:04:05 UTC for "
|
||||
"58fb036d-5ef8-47a8-b503-7571276c400a: "
|
||||
"{os_distro: com.microsoft.server,} was of incorrect type for "
|
||||
"exist id 23")
|
||||
self.mox.VerifyAll()
|
||||
|
||||
def test_should_verify_os_distro_should_not_be_empty(self):
|
||||
self.mox.StubOutWithMock(datetime, 'datetime')
|
||||
datetime.datetime.utcnow().AndReturn('2014-01-02 03:04:05')
|
||||
self.mox.ReplayAll()
|
||||
|
||||
self.mox.StubOutWithMock(config, 'flavor_field_name')
|
||||
config.flavor_field_name().AndReturn('dummy_flavor_field_name')
|
||||
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.dummy_flavor_field_name = 'dummy_flavor'
|
||||
exist.rax_options = 12
|
||||
exist.os_architecture = 'x64'
|
||||
|
||||
exist = self._create_mock_exist()
|
||||
exist.os_distro = ''
|
||||
self.mox.ReplayAll()
|
||||
|
||||
@ -1253,21 +1307,20 @@ class NovaVerifierValidityTestCase(StacktachBaseTestCase):
|
||||
self.assertEqual(exception.field_name, 'os_distro')
|
||||
self.assertEqual(
|
||||
exception.reason,
|
||||
"os_distro field was null for exist id 23")
|
||||
"Failed at 2014-01-02 03:04:05 UTC for "
|
||||
"58fb036d-5ef8-47a8-b503-7571276c400a: os_distro field was null "
|
||||
"for exist id 23")
|
||||
self.mox.VerifyAll()
|
||||
|
||||
def test_should_verify_os_version_should_be_alphanumeric(self):
|
||||
self.mox.StubOutWithMock(datetime, 'datetime')
|
||||
datetime.datetime.utcnow().AndReturn('2014-01-02 03:04:05')
|
||||
self.mox.ReplayAll()
|
||||
|
||||
self.mox.StubOutWithMock(config, 'flavor_field_name')
|
||||
config.flavor_field_name().AndReturn('dummy_flavor_field_name')
|
||||
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.dummy_flavor_field_name = 'dummy_flavor'
|
||||
exist.rax_options = 12
|
||||
exist.os_architecture = 'x64'
|
||||
exist.os_distro = 'com.microsoft.server'
|
||||
|
||||
exist = self._create_mock_exist()
|
||||
exist.os_version = '2008.2,'
|
||||
self.mox.ReplayAll()
|
||||
|
||||
@ -1277,21 +1330,20 @@ class NovaVerifierValidityTestCase(StacktachBaseTestCase):
|
||||
self.assertEqual(exception.field_name, 'os_version')
|
||||
self.assertEqual(
|
||||
exception.reason,
|
||||
"{ os_version : 2008.2, } of incorrect type for exist id 23")
|
||||
'Failed at 2014-01-02 03:04:05 UTC for '
|
||||
'58fb036d-5ef8-47a8-b503-7571276c400a: {os_version: 2008.2,} was '
|
||||
'of incorrect type for exist id 23')
|
||||
self.mox.VerifyAll()
|
||||
|
||||
def test_should_verify_os_version_should_not_be_empty(self):
|
||||
self.mox.StubOutWithMock(datetime, 'datetime')
|
||||
datetime.datetime.utcnow().AndReturn('2014-01-02 03:04:05')
|
||||
self.mox.ReplayAll()
|
||||
|
||||
self.mox.StubOutWithMock(config, 'flavor_field_name')
|
||||
config.flavor_field_name().AndReturn('dummy_flavor_field_name')
|
||||
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.dummy_flavor_field_name = 'dummy_flavor'
|
||||
exist.rax_options = 12
|
||||
exist.os_architecture = 'x64'
|
||||
exist.os_distro = 'com.microsoft.server'
|
||||
|
||||
exist = self._create_mock_exist()
|
||||
exist.os_version = ''
|
||||
self.mox.ReplayAll()
|
||||
|
||||
@ -1300,30 +1352,26 @@ class NovaVerifierValidityTestCase(StacktachBaseTestCase):
|
||||
exception = nf.exception
|
||||
self.assertEqual(exception.field_name, 'os_version')
|
||||
self.assertEqual(
|
||||
exception.reason, "os_version field was null for exist id 23")
|
||||
exception.reason,
|
||||
"Failed at 2014-01-02 03:04:05 UTC for "
|
||||
"58fb036d-5ef8-47a8-b503-7571276c400a: 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):
|
||||
def test_should_verify_all_exist_fields_when_validity_check_value_all(self):
|
||||
self.mox.StubOutWithMock(config, 'flavor_field_name')
|
||||
config.flavor_field_name().AndReturn('dummy_flavor_field_name')
|
||||
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.dummy_flavor_field_name = 'dummy_flavor'
|
||||
exist.rax_options = '12'
|
||||
exist.os_architecture = 'x64'
|
||||
exist.os_distro = 'com.microsoft.server'
|
||||
exist.os_version = '2008.2'
|
||||
|
||||
exist = self._create_mock_exist()
|
||||
self.mox.ReplayAll()
|
||||
|
||||
nova_verifier._verify_validity(exist, 'all')
|
||||
self.mox.VerifyAll()
|
||||
|
||||
def test_should_verify_only_basic_exist_fields_when_validity_check_value_is_basic(self):
|
||||
def test_should_verify_only_basic_fields_when_validity_check_basic(self):
|
||||
self.mox.StubOutWithMock(config, 'flavor_field_name')
|
||||
config.flavor_field_name().AndReturn('dummy_flavor_field_name')
|
||||
|
||||
exist = self.mox.CreateMockAnything()
|
||||
exist.tenant = '3762854cd6f6435998188d5120e4c271'
|
||||
exist.id = 23
|
||||
@ -1346,16 +1394,9 @@ class NovaVerifierValidityTestCase(StacktachBaseTestCase):
|
||||
def test_should_verify_exist_fields_even_if_deleted_at_is_none(self):
|
||||
self.mox.StubOutWithMock(config, 'flavor_field_name')
|
||||
config.flavor_field_name().AndReturn('dummy_flavor_field_name')
|
||||
exist = self.mox.CreateMockAnything()
|
||||
exist.tenant = '3762854cd6f6435998188d5120e4c271'
|
||||
exist.id = 23
|
||||
exist.launched_at = decimal.Decimal('1.1')
|
||||
|
||||
exist = self._create_mock_exist()
|
||||
exist.deleted_at = None
|
||||
exist.dummy_flavor_field_name = 'dummy_flavor'
|
||||
exist.rax_options = 12
|
||||
exist.os_architecture = 'x64'
|
||||
exist.os_distro = 'com.microsoft.server'
|
||||
exist.os_version = '2008.2'
|
||||
self.mox.ReplayAll()
|
||||
|
||||
nova_verifier._verify_validity(exist, 'all')
|
||||
|
@ -19,6 +19,7 @@
|
||||
# IN THE SOFTWARE.
|
||||
|
||||
import datetime
|
||||
import decimal
|
||||
|
||||
TENANT_ID_1 = 'testtenantid1'
|
||||
TENANT_ID_2 = 'testtenantid2'
|
||||
@ -30,7 +31,7 @@ IMAGE_UUID_1 = "12345678-6352-4dbc-8271-96cc54bf14cd"
|
||||
INSTANCE_ID_1 = "08f685d9-6352-4dbc-8271-96cc54bf14cd"
|
||||
INSTANCE_ID_2 = "515adf96-41d3-b86d-5467-e584edc61dab"
|
||||
|
||||
INSTANCE_FLAVOR_ID_1 = "performance1-120"
|
||||
INSTANCE_FLAVOR_ID_1 = "1"
|
||||
INSTANCE_FLAVOR_ID_2 = "performance2-120"
|
||||
|
||||
INSTANCE_TYPE_ID_1 = "12345"
|
||||
@ -61,6 +62,18 @@ OS_ARCH_2 = "x64"
|
||||
OS_VERSION_1 = "1"
|
||||
OS_VERSION_2 = "2"
|
||||
|
||||
LAUNCHED_AT_1 = decimal.Decimal("1.1")
|
||||
LAUNCHED_AT_2 = decimal.Decimal("2.1")
|
||||
|
||||
DELETED_AT_1 = decimal.Decimal("3.1")
|
||||
DELETED_AT_2 = decimal.Decimal("4.1")
|
||||
|
||||
SIZE_1 = 1234
|
||||
SIZE_2 = 4567
|
||||
|
||||
CREATED_AT_1 = decimal.Decimal("10.1")
|
||||
CREATED_AT_2 = decimal.Decimal("11.1")
|
||||
|
||||
TIMESTAMP_1 = "2013-06-20 17:31:57.939614"
|
||||
SETTLE_TIME = 5
|
||||
SETTLE_UNITS = "minutes"
|
||||
|
@ -17,6 +17,8 @@
|
||||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
# IN THE SOFTWARE.
|
||||
import datetime
|
||||
|
||||
|
||||
class VerificationException(Exception):
|
||||
def __init__(self, reason):
|
||||
@ -44,22 +46,35 @@ class AmbiguousResults(VerificationException):
|
||||
|
||||
|
||||
class FieldMismatch(VerificationException):
|
||||
def __init__(self, field_name, expected, actual):
|
||||
def __init__(self, field_name, expected, actual, uuid):
|
||||
self.field_name = field_name
|
||||
self.expected = expected
|
||||
self.actual = actual
|
||||
self.reason = "Expected %s to be '%s' got '%s'" % (self.field_name,
|
||||
self.expected,
|
||||
self.actual)
|
||||
self.reason = \
|
||||
"Failed at {failed_at} UTC for {uuid}: Expected {field_name} " \
|
||||
"to be '{expected}' got '{actual}'".\
|
||||
format(failed_at=datetime.datetime.utcnow(), uuid=uuid,
|
||||
field_name=field_name, expected=expected,
|
||||
actual=actual)
|
||||
|
||||
|
||||
class NullFieldException(VerificationException):
|
||||
def __init__(self, field_name, exist_id):
|
||||
def __init__(self, field_name, exist_id, uuid):
|
||||
self.field_name = field_name
|
||||
self.reason = "%s field was null for exist id %s" %(field_name, exist_id)
|
||||
self.reason = \
|
||||
"Failed at {failed_at} UTC for {uuid}: {field_name} field " \
|
||||
"was null for exist id {exist_id}".format(
|
||||
failed_at=datetime.datetime.utcnow(), uuid=uuid,
|
||||
field_name=field_name, exist_id=exist_id)
|
||||
|
||||
|
||||
class WrongTypeException(VerificationException):
|
||||
def __init__(self, field_name, value, exist_id):
|
||||
def __init__(self, field_name, value, exist_id, uuid):
|
||||
self.field_name = field_name
|
||||
self.reason = "{ %s : %s } of incorrect type for exist id %s"\
|
||||
%(field_name, value, exist_id)
|
||||
self.reason = \
|
||||
"Failed at {failed_at} UTC for {uuid}: " \
|
||||
"{{{field_name}: {value}}} was of incorrect type for " \
|
||||
"exist id {exist_id}".format(
|
||||
failed_at=datetime.datetime.utcnow(), uuid=uuid,
|
||||
field_name=field_name, value=value, exist_id=exist_id)
|
||||
|
||||
|
@ -81,34 +81,34 @@ def _verify_date_field(d1, d2, same_second=False):
|
||||
def _is_like_uuid(attr_name, attr_value, exist_id):
|
||||
if not re.match("[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}$",
|
||||
attr_value):
|
||||
raise WrongTypeException(attr_name, attr_value, exist_id)
|
||||
raise WrongTypeException(attr_name, attr_value, exist_id, None)
|
||||
|
||||
|
||||
def _is_like_date(attr_name, attr_value, exist_id):
|
||||
def _is_like_date(attr_name, attr_value, exist_id, instance_uuid):
|
||||
if not isinstance(attr_value, decimal.Decimal):
|
||||
raise WrongTypeException(attr_name, attr_value, exist_id)
|
||||
raise WrongTypeException(attr_name, attr_value, exist_id, instance_uuid)
|
||||
|
||||
|
||||
def _is_long(attr_name, attr_value, exist_id):
|
||||
def _is_long(attr_name, attr_value, exist_id, instance_uuid):
|
||||
if not isinstance(attr_value, long):
|
||||
raise WrongTypeException(attr_name, attr_value, exist_id)
|
||||
raise WrongTypeException(attr_name, attr_value, exist_id, instance_uuid)
|
||||
|
||||
|
||||
def _is_int_in_char(attr_name, attr_value, exist_id):
|
||||
def _is_int_in_char(attr_name, attr_value, exist_id, instance_uuid):
|
||||
try:
|
||||
int(attr_value)
|
||||
except ValueError:
|
||||
raise WrongTypeException(attr_name, attr_value, exist_id)
|
||||
raise WrongTypeException(attr_name, attr_value, exist_id, instance_uuid)
|
||||
|
||||
|
||||
def _is_hex_owner_id(attr_name, attr_value, exist_id):
|
||||
def _is_hex_owner_id(attr_name, attr_value, exist_id, instance_uuid):
|
||||
if not re.match("^[0-9a-fA-F]+$", attr_value):
|
||||
raise WrongTypeException(attr_name, attr_value, exist_id)
|
||||
raise WrongTypeException(attr_name, attr_value, exist_id, instance_uuid)
|
||||
|
||||
|
||||
def _is_alphanumeric(attr_name, attr_value, exist_id):
|
||||
def _is_alphanumeric(attr_name, attr_value, exist_id, instance_uuid):
|
||||
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, instance_uuid)
|
||||
|
||||
|
||||
class Verifier(object):
|
||||
|
@ -51,16 +51,14 @@ def _get_child_logger():
|
||||
def _verify_field_mismatch(exists, usage):
|
||||
if not base_verifier._verify_date_field(
|
||||
usage.created_at, exists.created_at, same_second=True):
|
||||
raise FieldMismatch('created_at', exists.created_at,
|
||||
usage.created_at)
|
||||
raise FieldMismatch('created_at', exists.created_at, usage.created_at,
|
||||
exists.uuid)
|
||||
|
||||
if usage.owner != exists.owner:
|
||||
raise FieldMismatch('owner', exists.owner,
|
||||
usage.owner)
|
||||
raise FieldMismatch('owner', exists.owner, usage.owner, exists.uuid)
|
||||
|
||||
if usage.size != exists.size:
|
||||
raise FieldMismatch('size', exists.size,
|
||||
usage.size)
|
||||
raise FieldMismatch('size', exists.size, usage.size, exists.uuid)
|
||||
|
||||
|
||||
def _verify_validity(exist):
|
||||
@ -68,11 +66,12 @@ def _verify_validity(exist):
|
||||
exist.uuid: 'uuid', exist.owner: 'owner'}
|
||||
for (field_value, field_name) in fields.items():
|
||||
if field_value is None:
|
||||
raise NullFieldException(field_name, exist.id)
|
||||
raise NullFieldException(field_name, exist.id, exist.uuid)
|
||||
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_long('size', exist.size, exist.id)
|
||||
base_verifier._is_hex_owner_id('owner', exist.owner, exist.id)
|
||||
base_verifier._is_like_date('created_at', exist.created_at, exist.id,
|
||||
exist.uuid)
|
||||
base_verifier._is_long('size', exist.size, exist.id, exist.uuid)
|
||||
base_verifier._is_hex_owner_id('owner', exist.owner, exist.id, exist.uuid)
|
||||
|
||||
|
||||
def _verify_for_usage(exist, usage=None):
|
||||
@ -124,7 +123,7 @@ def _verify_for_delete(exist, delete=None):
|
||||
if not base_verifier._verify_date_field(
|
||||
delete.deleted_at, exist.deleted_at, same_second=True):
|
||||
raise FieldMismatch('deleted_at', exist.deleted_at,
|
||||
delete.deleted_at)
|
||||
delete.deleted_at, exist.uuid)
|
||||
|
||||
|
||||
def _verify(exists):
|
||||
|
@ -54,33 +54,34 @@ def _verify_field_mismatch(exists, launch):
|
||||
if not base_verifier._verify_date_field(
|
||||
launch.launched_at, exists.launched_at, same_second=True):
|
||||
raise FieldMismatch('launched_at', exists.launched_at,
|
||||
launch.launched_at)
|
||||
launch.launched_at, exists.instance)
|
||||
|
||||
if getattr(launch, flavor_field_name) != \
|
||||
getattr(exists, flavor_field_name):
|
||||
raise FieldMismatch(flavor_field_name,
|
||||
getattr(exists, flavor_field_name),
|
||||
getattr(launch, flavor_field_name))
|
||||
getattr(launch, flavor_field_name),
|
||||
exists.instance)
|
||||
|
||||
if launch.tenant != exists.tenant:
|
||||
raise FieldMismatch('tenant', exists.tenant,
|
||||
launch.tenant)
|
||||
raise FieldMismatch('tenant', exists.tenant, launch.tenant,
|
||||
exists.instance)
|
||||
|
||||
if launch.rax_options != exists.rax_options:
|
||||
raise FieldMismatch('rax_options', exists.rax_options,
|
||||
launch.rax_options)
|
||||
launch.rax_options, exists.instance)
|
||||
|
||||
if launch.os_architecture != exists.os_architecture:
|
||||
raise FieldMismatch('os_architecture', exists.os_architecture,
|
||||
launch.os_architecture)
|
||||
launch.os_architecture, exists.instance)
|
||||
|
||||
if launch.os_version != exists.os_version:
|
||||
raise FieldMismatch('os_version', exists.os_version,
|
||||
launch.os_version)
|
||||
launch.os_version, exists.instance)
|
||||
|
||||
if launch.os_distro != exists.os_distro:
|
||||
raise FieldMismatch('os_distro', exists.os_distro,
|
||||
launch.os_distro)
|
||||
launch.os_distro, exists.instance)
|
||||
|
||||
|
||||
def _verify_for_launch(exist, launch=None,
|
||||
@ -147,12 +148,12 @@ def _verify_for_delete(exist, delete=None,
|
||||
if not base_verifier._verify_date_field(
|
||||
delete.launched_at, exist.launched_at, same_second=True):
|
||||
raise FieldMismatch('launched_at', exist.launched_at,
|
||||
delete.launched_at)
|
||||
delete.launched_at, exist.instance)
|
||||
|
||||
if not base_verifier._verify_date_field(
|
||||
delete.deleted_at, exist.deleted_at, same_second=True):
|
||||
raise FieldMismatch(
|
||||
'deleted_at', exist.deleted_at, delete.deleted_at)
|
||||
raise FieldMismatch('deleted_at', exist.deleted_at,
|
||||
delete.deleted_at, exist.instance)
|
||||
|
||||
|
||||
def _verify_basic_validity(exist):
|
||||
@ -164,11 +165,14 @@ def _verify_basic_validity(exist):
|
||||
}
|
||||
for (field_name, field_value) in fields.items():
|
||||
if field_value is None:
|
||||
raise NullFieldException(field_name, exist.id)
|
||||
base_verifier._is_hex_owner_id('tenant', exist.tenant, exist.id)
|
||||
base_verifier._is_like_date('launched_at', exist.launched_at, exist.id)
|
||||
raise NullFieldException(field_name, exist.id, exist.instance)
|
||||
base_verifier._is_hex_owner_id(
|
||||
'tenant', exist.tenant, exist.id, exist.instance)
|
||||
base_verifier._is_like_date(
|
||||
'launched_at', exist.launched_at, exist.id, exist.instance)
|
||||
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, exist.instance)
|
||||
|
||||
|
||||
def _verify_optional_validity(exist):
|
||||
@ -178,11 +182,15 @@ def _verify_optional_validity(exist):
|
||||
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_version', exist.os_version, exist.id)
|
||||
raise NullFieldException(field_name, exist.id, exist.instance)
|
||||
base_verifier._is_int_in_char(
|
||||
'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)
|
||||
base_verifier._is_alphanumeric(
|
||||
'os_version', exist.os_version, exist.id, exist.instance)
|
||||
|
||||
|
||||
def _verify_validity(exist, validation_level):
|
||||
|
Loading…
x
Reference in New Issue
Block a user