py34: test_hot and test_validate
* use hashlib.algorithms_available in PY3 and hashlib.algorithms in PY2 * use e.args[0] instead of six.text_type(e) which will otherwise result in the unicode literal being flattened. * add stubs to prevent actual API calls in tests. * constraint the test template to help in more accurate testing which otherwise results in iterating through other unnecessary items. partial blueprint heat-python34-support Change-Id: I7480555330161cf6f197c83f3245685511284307
This commit is contained in:
parent
12d535f3ba
commit
800f38aac4
@ -122,7 +122,7 @@ class HeatException(Exception):
|
|||||||
raise_(exc_info[0], exc_info[1], exc_info[2])
|
raise_(exc_info[0], exc_info[1], exc_info[2])
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return six.text_type(self.message)
|
return self.message
|
||||||
|
|
||||||
def __deepcopy__(self, memo):
|
def __deepcopy__(self, memo):
|
||||||
return self.__class__(**self.kwargs)
|
return self.__class__(**self.kwargs)
|
||||||
|
@ -408,13 +408,18 @@ class Digest(function.Function):
|
|||||||
msg = _('Function "%s" usage: ["<algorithm>", "<value>"]')
|
msg = _('Function "%s" usage: ["<algorithm>", "<value>"]')
|
||||||
raise ValueError(msg % self.fn_name)
|
raise ValueError(msg % self.fn_name)
|
||||||
|
|
||||||
if args[0].lower() not in hashlib.algorithms:
|
if six.PY3:
|
||||||
|
algorithms = hashlib.algorithms_available
|
||||||
|
else:
|
||||||
|
algorithms = hashlib.algorithms
|
||||||
|
|
||||||
|
if args[0].lower() not in algorithms:
|
||||||
msg = _('Algorithm must be one of %s')
|
msg = _('Algorithm must be one of %s')
|
||||||
raise ValueError(msg % six.text_type(hashlib.algorithms))
|
raise ValueError(msg % six.text_type(algorithms))
|
||||||
|
|
||||||
def digest(self, algorithm, value):
|
def digest(self, algorithm, value):
|
||||||
_hash = hashlib.new(algorithm)
|
_hash = hashlib.new(algorithm)
|
||||||
_hash.update(value)
|
_hash.update(six.b(value))
|
||||||
|
|
||||||
return _hash.hexdigest()
|
return _hash.hexdigest()
|
||||||
|
|
||||||
|
@ -136,7 +136,7 @@ class HOTemplate20130523(template.Template):
|
|||||||
obj_name = section[:-1]
|
obj_name = section[:-1]
|
||||||
err_msg = _('"%%s" is not a valid keyword inside a %s '
|
err_msg = _('"%%s" is not a valid keyword inside a %s '
|
||||||
'definition') % obj_name
|
'definition') % obj_name
|
||||||
for name, attrs in six.iteritems(data):
|
for name, attrs in sorted(data.items()):
|
||||||
cfn_object = {}
|
cfn_object = {}
|
||||||
|
|
||||||
if not attrs:
|
if not attrs:
|
||||||
@ -159,7 +159,7 @@ class HOTemplate20130523(template.Template):
|
|||||||
raise exception.StackValidationFailed(message=message)
|
raise exception.StackValidationFailed(message=message)
|
||||||
except KeyError as e:
|
except KeyError as e:
|
||||||
# an invalid keyword was found
|
# an invalid keyword was found
|
||||||
raise exception.StackValidationFailed(message=six.text_type(e))
|
raise exception.StackValidationFailed(message=e.args[0])
|
||||||
|
|
||||||
return cfn_objects
|
return cfn_objects
|
||||||
|
|
||||||
|
@ -2852,12 +2852,8 @@ class StackServiceTest(common.HeatTestCase):
|
|||||||
self.eng._validate_new_stack,
|
self.eng._validate_new_stack,
|
||||||
self.ctx, 'test_existing_stack',
|
self.ctx, 'test_existing_stack',
|
||||||
parsed_template)
|
parsed_template)
|
||||||
msg = (u'u\'"Type" is not a valid keyword '
|
msg = (u'"Type" is not a valid keyword '
|
||||||
'inside a resource definition\'')
|
'inside a resource definition')
|
||||||
|
|
||||||
if six.PY3:
|
|
||||||
msg = ('\'"Type" is not a valid keyword inside a '
|
|
||||||
'resource definition\'')
|
|
||||||
|
|
||||||
self.assertEqual(msg, six.text_type(ex))
|
self.assertEqual(msg, six.text_type(ex))
|
||||||
|
|
||||||
|
@ -203,8 +203,8 @@ class HOTemplateTest(common.HeatTestCase):
|
|||||||
tmpl = template.Template(hot_tpl)
|
tmpl = template.Template(hot_tpl)
|
||||||
err = self.assertRaises(exception.StackValidationFailed,
|
err = self.assertRaises(exception.StackValidationFailed,
|
||||||
tmpl.__getitem__, tmpl.RESOURCES)
|
tmpl.__getitem__, tmpl.RESOURCES)
|
||||||
self.assertEqual('u\'"Type" is not a valid keyword '
|
self.assertEqual('"Type" is not a valid keyword '
|
||||||
'inside a resource definition\'',
|
'inside a resource definition',
|
||||||
six.text_type(err))
|
six.text_type(err))
|
||||||
|
|
||||||
def test_translate_resources_bad_properties(self):
|
def test_translate_resources_bad_properties(self):
|
||||||
@ -228,8 +228,8 @@ class HOTemplateTest(common.HeatTestCase):
|
|||||||
tmpl = template.Template(hot_tpl)
|
tmpl = template.Template(hot_tpl)
|
||||||
err = self.assertRaises(exception.StackValidationFailed,
|
err = self.assertRaises(exception.StackValidationFailed,
|
||||||
tmpl.__getitem__, tmpl.RESOURCES)
|
tmpl.__getitem__, tmpl.RESOURCES)
|
||||||
self.assertEqual('u\'"Properties" is not a valid keyword '
|
self.assertEqual('"Properties" is not a valid keyword '
|
||||||
'inside a resource definition\'',
|
'inside a resource definition',
|
||||||
six.text_type(err))
|
six.text_type(err))
|
||||||
|
|
||||||
def test_translate_resources_resources_without_name(self):
|
def test_translate_resources_resources_without_name(self):
|
||||||
@ -272,8 +272,9 @@ class HOTemplateTest(common.HeatTestCase):
|
|||||||
tmpl = template.Template(hot_tpl)
|
tmpl = template.Template(hot_tpl)
|
||||||
err = self.assertRaises(exception.StackValidationFailed,
|
err = self.assertRaises(exception.StackValidationFailed,
|
||||||
tmpl.__getitem__, tmpl.RESOURCES)
|
tmpl.__getitem__, tmpl.RESOURCES)
|
||||||
self.assertEqual('u\'"Metadata" is not a valid keyword '
|
|
||||||
'inside a resource definition\'',
|
self.assertEqual('"Metadata" is not a valid keyword '
|
||||||
|
'inside a resource definition',
|
||||||
six.text_type(err))
|
six.text_type(err))
|
||||||
|
|
||||||
def test_translate_resources_bad_depends_on(self):
|
def test_translate_resources_bad_depends_on(self):
|
||||||
@ -297,8 +298,8 @@ class HOTemplateTest(common.HeatTestCase):
|
|||||||
tmpl = template.Template(hot_tpl)
|
tmpl = template.Template(hot_tpl)
|
||||||
err = self.assertRaises(exception.StackValidationFailed,
|
err = self.assertRaises(exception.StackValidationFailed,
|
||||||
tmpl.__getitem__, tmpl.RESOURCES)
|
tmpl.__getitem__, tmpl.RESOURCES)
|
||||||
self.assertEqual('u\'"DependsOn" is not a valid keyword '
|
self.assertEqual('"DependsOn" is not a valid keyword '
|
||||||
'inside a resource definition\'',
|
'inside a resource definition',
|
||||||
six.text_type(err))
|
six.text_type(err))
|
||||||
|
|
||||||
def test_translate_resources_bad_deletion_policy(self):
|
def test_translate_resources_bad_deletion_policy(self):
|
||||||
@ -322,8 +323,8 @@ class HOTemplateTest(common.HeatTestCase):
|
|||||||
tmpl = template.Template(hot_tpl)
|
tmpl = template.Template(hot_tpl)
|
||||||
err = self.assertRaises(exception.StackValidationFailed,
|
err = self.assertRaises(exception.StackValidationFailed,
|
||||||
tmpl.__getitem__, tmpl.RESOURCES)
|
tmpl.__getitem__, tmpl.RESOURCES)
|
||||||
self.assertEqual('u\'"DeletionPolicy" is not a valid keyword '
|
self.assertEqual('"DeletionPolicy" is not a valid keyword '
|
||||||
'inside a resource definition\'',
|
'inside a resource definition',
|
||||||
six.text_type(err))
|
six.text_type(err))
|
||||||
|
|
||||||
def test_translate_resources_bad_update_policy(self):
|
def test_translate_resources_bad_update_policy(self):
|
||||||
@ -347,8 +348,8 @@ class HOTemplateTest(common.HeatTestCase):
|
|||||||
tmpl = template.Template(hot_tpl)
|
tmpl = template.Template(hot_tpl)
|
||||||
err = self.assertRaises(exception.StackValidationFailed,
|
err = self.assertRaises(exception.StackValidationFailed,
|
||||||
tmpl.__getitem__, tmpl.RESOURCES)
|
tmpl.__getitem__, tmpl.RESOURCES)
|
||||||
self.assertEqual('u\'"UpdatePolicy" is not a valid keyword '
|
self.assertEqual('"UpdatePolicy" is not a valid keyword '
|
||||||
'inside a resource definition\'',
|
'inside a resource definition',
|
||||||
six.text_type(err))
|
six.text_type(err))
|
||||||
|
|
||||||
def test_translate_outputs_good(self):
|
def test_translate_outputs_good(self):
|
||||||
|
@ -218,13 +218,7 @@ test_template_invalid_resources = '''
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"Resources" : {
|
"Resources" : {
|
||||||
"Type" : "AWS::EC2::Instance",
|
"Type" : "AWS::EC2::Instance"
|
||||||
"Metadata" : {
|
|
||||||
},
|
|
||||||
"Properties" : {
|
|
||||||
"ImageId" : { "Ref" : "centos-6.4-20130701-0" },
|
|
||||||
"InstanceType" : { "Ref" : "InstanceType" }
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
'''
|
'''
|
||||||
@ -1226,8 +1220,8 @@ class ValidateTest(common.HeatTestCase):
|
|||||||
|
|
||||||
engine = service.EngineService('a', 't')
|
engine = service.EngineService('a', 't')
|
||||||
res = dict(engine.validate_template(None, hot_tpl, {}))
|
res = dict(engine.validate_template(None, hot_tpl, {}))
|
||||||
self.assertEqual({'Error': 'u\'"Type" is not a valid keyword '
|
self.assertEqual({'Error': '"Type" is not a valid keyword '
|
||||||
'inside a resource definition\''}, res)
|
'inside a resource definition'}, res)
|
||||||
|
|
||||||
def test_validate_template_with_invalid_resource_properties(self):
|
def test_validate_template_with_invalid_resource_properties(self):
|
||||||
hot_tpl = template_format.parse('''
|
hot_tpl = template_format.parse('''
|
||||||
@ -1247,8 +1241,8 @@ class ValidateTest(common.HeatTestCase):
|
|||||||
|
|
||||||
engine = service.EngineService('a', 't')
|
engine = service.EngineService('a', 't')
|
||||||
res = dict(engine.validate_template(None, hot_tpl, {}))
|
res = dict(engine.validate_template(None, hot_tpl, {}))
|
||||||
self.assertEqual({'Error': 'u\'"Properties" is not a valid keyword '
|
self.assertEqual({'Error': '"Properties" is not a valid keyword '
|
||||||
'inside a resource definition\''}, res)
|
'inside a resource definition'}, res)
|
||||||
|
|
||||||
def test_validate_template_with_invalid_resource_matadata(self):
|
def test_validate_template_with_invalid_resource_matadata(self):
|
||||||
hot_tpl = template_format.parse('''
|
hot_tpl = template_format.parse('''
|
||||||
@ -1268,8 +1262,8 @@ class ValidateTest(common.HeatTestCase):
|
|||||||
|
|
||||||
engine = service.EngineService('a', 't')
|
engine = service.EngineService('a', 't')
|
||||||
res = dict(engine.validate_template(None, hot_tpl, {}))
|
res = dict(engine.validate_template(None, hot_tpl, {}))
|
||||||
self.assertEqual({'Error': 'u\'"Metadata" is not a valid keyword '
|
self.assertEqual({'Error': '"Metadata" is not a valid keyword '
|
||||||
'inside a resource definition\''}, res)
|
'inside a resource definition'}, res)
|
||||||
|
|
||||||
def test_validate_template_with_invalid_resource_depends_on(self):
|
def test_validate_template_with_invalid_resource_depends_on(self):
|
||||||
hot_tpl = template_format.parse('''
|
hot_tpl = template_format.parse('''
|
||||||
@ -1289,8 +1283,8 @@ class ValidateTest(common.HeatTestCase):
|
|||||||
|
|
||||||
engine = service.EngineService('a', 't')
|
engine = service.EngineService('a', 't')
|
||||||
res = dict(engine.validate_template(None, hot_tpl, {}))
|
res = dict(engine.validate_template(None, hot_tpl, {}))
|
||||||
self.assertEqual({'Error': 'u\'"DependsOn" is not a valid keyword '
|
self.assertEqual({'Error': '"DependsOn" is not a valid keyword '
|
||||||
'inside a resource definition\''}, res)
|
'inside a resource definition'}, res)
|
||||||
|
|
||||||
def test_validate_template_with_invalid_resource_deletion_policy(self):
|
def test_validate_template_with_invalid_resource_deletion_policy(self):
|
||||||
hot_tpl = template_format.parse('''
|
hot_tpl = template_format.parse('''
|
||||||
@ -1310,8 +1304,8 @@ class ValidateTest(common.HeatTestCase):
|
|||||||
|
|
||||||
engine = service.EngineService('a', 't')
|
engine = service.EngineService('a', 't')
|
||||||
res = dict(engine.validate_template(None, hot_tpl, {}))
|
res = dict(engine.validate_template(None, hot_tpl, {}))
|
||||||
self.assertEqual({'Error': 'u\'"DeletionPolicy" is not a valid '
|
self.assertEqual({'Error': '"DeletionPolicy" is not a valid '
|
||||||
'keyword inside a resource definition\''},
|
'keyword inside a resource definition'},
|
||||||
res)
|
res)
|
||||||
|
|
||||||
def test_validate_template_with_invalid_resource_update_policy(self):
|
def test_validate_template_with_invalid_resource_update_policy(self):
|
||||||
@ -1332,8 +1326,8 @@ class ValidateTest(common.HeatTestCase):
|
|||||||
|
|
||||||
engine = service.EngineService('a', 't')
|
engine = service.EngineService('a', 't')
|
||||||
res = dict(engine.validate_template(None, hot_tpl, {}))
|
res = dict(engine.validate_template(None, hot_tpl, {}))
|
||||||
self.assertEqual({'Error': 'u\'"UpdatePolicy" is not a valid '
|
self.assertEqual({'Error': '"UpdatePolicy" is not a valid '
|
||||||
'keyword inside a resource definition\''},
|
'keyword inside a resource definition'},
|
||||||
res)
|
res)
|
||||||
|
|
||||||
def test_unregistered_key(self):
|
def test_unregistered_key(self):
|
||||||
@ -1342,7 +1336,8 @@ class ValidateTest(common.HeatTestCase):
|
|||||||
template = tmpl.Template(t, env=environment.Environment(params))
|
template = tmpl.Template(t, env=environment.Environment(params))
|
||||||
stack = parser.Stack(self.ctx, 'test_stack', template)
|
stack = parser.Stack(self.ctx, 'test_stack', template)
|
||||||
|
|
||||||
self._mock_get_image_id_success('image_name', 'image_id')
|
self.stub_FlavorConstraint_validate()
|
||||||
|
self.stub_ImageConstraint_validate()
|
||||||
self.m.ReplayAll()
|
self.m.ReplayAll()
|
||||||
|
|
||||||
resource = stack['Instance']
|
resource = stack['Instance']
|
||||||
@ -1361,6 +1356,8 @@ class ValidateTest(common.HeatTestCase):
|
|||||||
exception.EntityNotFound(
|
exception.EntityNotFound(
|
||||||
entity='Image',
|
entity='Image',
|
||||||
name='image_name'))
|
name='image_name'))
|
||||||
|
self.stub_KeypairConstraint_validate()
|
||||||
|
self.stub_FlavorConstraint_validate()
|
||||||
self.m.ReplayAll()
|
self.m.ReplayAll()
|
||||||
|
|
||||||
resource = stack['Instance']
|
resource = stack['Instance']
|
||||||
@ -1380,6 +1377,8 @@ class ValidateTest(common.HeatTestCase):
|
|||||||
exception.PhysicalResourceNameAmbiguity(
|
exception.PhysicalResourceNameAmbiguity(
|
||||||
name='image_name'))
|
name='image_name'))
|
||||||
|
|
||||||
|
self.stub_KeypairConstraint_validate()
|
||||||
|
self.stub_FlavorConstraint_validate()
|
||||||
self.m.ReplayAll()
|
self.m.ReplayAll()
|
||||||
|
|
||||||
resource = stack['Instance']
|
resource = stack['Instance']
|
||||||
@ -1433,6 +1432,7 @@ class ValidateTest(common.HeatTestCase):
|
|||||||
glance_exceptions.ClientException(500))
|
glance_exceptions.ClientException(500))
|
||||||
self.m.StubOutWithMock(glance.GlanceClientPlugin, '_create')
|
self.m.StubOutWithMock(glance.GlanceClientPlugin, '_create')
|
||||||
glance.GlanceClientPlugin._create().AndReturn(self.gc)
|
glance.GlanceClientPlugin._create().AndReturn(self.gc)
|
||||||
|
self.stub_FlavorConstraint_validate()
|
||||||
self.m.ReplayAll()
|
self.m.ReplayAll()
|
||||||
|
|
||||||
self.assertRaises(exception.StackValidationFailed, stack.validate)
|
self.assertRaises(exception.StackValidationFailed, stack.validate)
|
||||||
|
@ -107,6 +107,7 @@ heat.tests.test_exception
|
|||||||
heat.tests.test_function
|
heat.tests.test_function
|
||||||
heat.tests.test_glance_image
|
heat.tests.test_glance_image
|
||||||
heat.tests.test_grouputils
|
heat.tests.test_grouputils
|
||||||
|
heat.tests.test_hot
|
||||||
heat.tests.test_identifier
|
heat.tests.test_identifier
|
||||||
heat.tests.test_instance_group
|
heat.tests.test_instance_group
|
||||||
heat.tests.test_instance_group_update_policy
|
heat.tests.test_instance_group_update_policy
|
||||||
@ -156,6 +157,7 @@ heat.tests.test_template_format
|
|||||||
heat.tests.test_timeutils
|
heat.tests.test_timeutils
|
||||||
heat.tests.test_trove_cluster
|
heat.tests.test_trove_cluster
|
||||||
heat.tests.test_urlfetch
|
heat.tests.test_urlfetch
|
||||||
|
heat.tests.test_validate
|
||||||
heat.tests.test_version
|
heat.tests.test_version
|
||||||
heat.tests.test_vpc
|
heat.tests.test_vpc
|
||||||
heat.tests.test_watch
|
heat.tests.test_watch
|
||||||
|
Loading…
Reference in New Issue
Block a user