Merge "Removing default version for templates"

This commit is contained in:
Jenkins 2014-05-13 18:24:34 +00:00 committed by Gerrit Code Review
commit 322f61f5c7
21 changed files with 319 additions and 191 deletions

View File

@ -301,7 +301,8 @@ class InstanceGroup(stack_resource.StackResource):
old_resources = self._get_instance_templates() old_resources = self._get_instance_templates()
templates = template.resource_templates( templates = template.resource_templates(
old_resources, instance_definition, num_instances, num_replace) old_resources, instance_definition, num_instances, num_replace)
return {"Resources": dict(templates)} return {"HeatTemplateFormatVersion": "2012-12-12",
"Resources": dict(templates)}
def _try_rolling_update(self, prop_diff): def _try_rolling_update(self, prop_diff):
if (self.update_policy[self.ROLLING_UPDATE] and if (self.update_policy[self.ROLLING_UPDATE] and
@ -958,6 +959,7 @@ class AutoScalingResourceGroup(AutoScalingGroup):
"""Use a HOT format for the template in the nested stack.""" """Use a HOT format for the template in the nested stack."""
tpl = super(AutoScalingResourceGroup, self)._create_template( tpl = super(AutoScalingResourceGroup, self)._create_template(
*args, **kwargs) *args, **kwargs)
tpl.pop('HeatTemplateFormatVersion', None)
tpl['heat_template_version'] = '2013-05-23' tpl['heat_template_version'] = '2013-05-23'
tpl['resources'] = tpl.pop('Resources') tpl['resources'] = tpl.pop('Resources')
return tpl return tpl

View File

@ -86,7 +86,8 @@ class TemplateResource(stack_resource.StackResource):
tmpl = template.Template(self.child_template()) tmpl = template.Template(self.child_template())
except ValueError as download_error: except ValueError as download_error:
self.validation_exception = download_error self.validation_exception = download_error
tmpl = template.Template({}) tmpl = template.Template(
{"HeatTemplateFormatVersion": "2012-12-12"})
# re-generate the properties and attributes from the template. # re-generate the properties and attributes from the template.
self.properties_schema = (properties.Properties self.properties_schema = (properties.Properties

View File

@ -25,8 +25,6 @@ logger = logging.getLogger(__name__)
__all__ = ['Template'] __all__ = ['Template']
DEFAULT_VERSION = ('HeatTemplateFormatVersion', '2012-12-12')
_template_classes = None _template_classes = None
@ -61,14 +59,15 @@ def get_version(template_data, available_versions):
isinstance(v, basestring)) isinstance(v, basestring))
keys_present = version_keys & candidate_keys keys_present = version_keys & candidate_keys
if not keys_present:
return DEFAULT_VERSION
if len(keys_present) > 1: if len(keys_present) > 1:
explanation = _('Ambiguous versions (%s)') % ', '.join(keys_present) explanation = _('Ambiguous versions (%s)') % ', '.join(keys_present)
raise exception.InvalidTemplateVersion(explanation=explanation) raise exception.InvalidTemplateVersion(explanation=explanation)
try:
version_key = keys_present.pop() version_key = keys_present.pop()
except KeyError:
explanation = _('Template version was not provided')
raise exception.InvalidTemplateVersion(explanation=explanation)
return version_key, template_data[version_key] return version_key, template_data[version_key]

View File

@ -33,6 +33,7 @@ class CloudConfigTest(HeatTestCase):
self.stack = parser.Stack( self.stack = parser.Stack(
self.ctx, 'software_config_test_stack', self.ctx, 'software_config_test_stack',
template.Template({ template.Template({
'HeatTemplateFormatVersion': '2012-12-12',
'Resources': { 'Resources': {
'config_mysql': { 'config_mysql': {
'Type': 'OS::Heat::CloudConfig', 'Type': 'OS::Heat::CloudConfig',

View File

@ -34,6 +34,7 @@ class FormatTest(HeatTestCase):
super(FormatTest, self).setUp() super(FormatTest, self).setUp()
template = parser.Template({ template = parser.Template({
'HeatTemplateFormatVersion': '2012-12-12',
'Resources': { 'Resources': {
'generic1': {'Type': 'GenericResourceType'}, 'generic1': {'Type': 'GenericResourceType'},
'generic2': { 'generic2': {

View File

@ -494,7 +494,7 @@ class StackServiceCreateUpdateDeleteTest(HeatTestCase):
self.assertRaises(ValueError, self.assertRaises(ValueError,
self.man.create_stack, self.man.create_stack,
self.ctx, stack_name, stack.t, {}, None, {}) self.ctx, stack_name, stack.t.t, {}, None, {})
def test_stack_create_invalid_resource_name(self): def test_stack_create_invalid_resource_name(self):
stack_name = 'service_create_test_stack_invalid_res' stack_name = 'service_create_test_stack_invalid_res'
@ -506,7 +506,7 @@ class StackServiceCreateUpdateDeleteTest(HeatTestCase):
self.assertRaises(ValueError, self.assertRaises(ValueError,
self.man.create_stack, self.man.create_stack,
self.ctx, stack_name, self.ctx, stack_name,
stack.t, {}, None, {}) stack.t.t, {}, None, {})
def test_stack_create_no_credentials(self): def test_stack_create_no_credentials(self):
stack_name = 'test_stack_create_no_credentials' stack_name = 'test_stack_create_no_credentials'
@ -557,7 +557,8 @@ class StackServiceCreateUpdateDeleteTest(HeatTestCase):
params = {} params = {}
res._register_class('GenericResourceType', res._register_class('GenericResourceType',
generic_rsrc.GenericResource) generic_rsrc.GenericResource)
tpl = {'Resources': { tpl = {'HeatTemplateFormatVersion': '2012-12-12',
'Resources': {
'A': {'Type': 'GenericResourceType'}, 'A': {'Type': 'GenericResourceType'},
'B': {'Type': 'GenericResourceType'}, 'B': {'Type': 'GenericResourceType'},
'C': {'Type': 'GenericResourceType'}}} 'C': {'Type': 'GenericResourceType'}}}
@ -593,15 +594,15 @@ class StackServiceCreateUpdateDeleteTest(HeatTestCase):
params = {} params = {}
res._register_class('GenericResourceType', res._register_class('GenericResourceType',
generic_rsrc.GenericResource) generic_rsrc.GenericResource)
tpl = {'Resources': { tpl = {'HeatTemplateFormatVersion': '2012-12-12',
'Resources': {
'A': {'Type': 'GenericResourceType'}, 'A': {'Type': 'GenericResourceType'},
'B': {'Type': 'GenericResourceType'}, 'B': {'Type': 'GenericResourceType'},
'C': {'Type': 'GenericResourceType'}}} 'C': {'Type': 'GenericResourceType'}}}
template = parser.Template(tpl)
cfg.CONF.set_override('max_resources_per_stack', 2) cfg.CONF.set_override('max_resources_per_stack', 2)
ex = self.assertRaises(rpc_common.ClientException, ex = self.assertRaises(rpc_common.ClientException,
self.man.create_stack, self.ctx, stack_name, self.man.create_stack, self.ctx, stack_name,
template, params, None, {}) tpl, params, None, {})
self.assertEqual(ex._exc_info[0], exception.RequestLimitExceeded) self.assertEqual(ex._exc_info[0], exception.RequestLimitExceeded)
self.assertIn(exception.StackResourceLimitExceeded.msg_fmt, self.assertIn(exception.StackResourceLimitExceeded.msg_fmt,
str(ex._exc_info[1])) str(ex._exc_info[1]))
@ -862,7 +863,8 @@ class StackServiceCreateUpdateDeleteTest(HeatTestCase):
params = {} params = {}
res._register_class('GenericResourceType', res._register_class('GenericResourceType',
generic_rsrc.GenericResource) generic_rsrc.GenericResource)
tpl = {'Resources': { tpl = {'HeatTemplateFormatVersion': '2012-12-12',
'Resources': {
'A': {'Type': 'GenericResourceType'}, 'A': {'Type': 'GenericResourceType'},
'B': {'Type': 'GenericResourceType'}, 'B': {'Type': 'GenericResourceType'},
'C': {'Type': 'GenericResourceType'}}} 'C': {'Type': 'GenericResourceType'}}}
@ -1046,13 +1048,13 @@ class StackServiceCreateUpdateDeleteTest(HeatTestCase):
params = {} params = {}
res._register_class('GenericResourceType', res._register_class('GenericResourceType',
generic_rsrc.GenericResource) generic_rsrc.GenericResource)
tpl = {'Resources': { tpl = {'HeatTemplateFormatVersion': '2012-12-12',
'Resources': {
'A': {'Type': 'GenericResourceType'}, 'A': {'Type': 'GenericResourceType'},
'B': {'Type': 'GenericResourceType'}, 'B': {'Type': 'GenericResourceType'},
'C': {'Type': 'GenericResourceType'}}} 'C': {'Type': 'GenericResourceType'}}}
template = parser.Template(tpl) template = parser.Template(tpl)
old_stack = parser.Stack(self.ctx, stack_name, template) old_stack = parser.Stack(self.ctx, stack_name, template)
sid = old_stack.store() sid = old_stack.store()
self.assertIsNotNone(sid) self.assertIsNotNone(sid)
@ -1061,7 +1063,7 @@ class StackServiceCreateUpdateDeleteTest(HeatTestCase):
ex = self.assertRaises(rpc_common.ClientException, ex = self.assertRaises(rpc_common.ClientException,
self.man.update_stack, self.ctx, self.man.update_stack, self.ctx,
old_stack.identifier(), template, params, old_stack.identifier(), tpl, params,
None, {}) None, {})
self.assertEqual(ex._exc_info[0], exception.RequestLimitExceeded) self.assertEqual(ex._exc_info[0], exception.RequestLimitExceeded)
self.assertIn(exception.StackResourceLimitExceeded.msg_fmt, self.assertIn(exception.StackResourceLimitExceeded.msg_fmt,
@ -1507,7 +1509,7 @@ class StackServiceTest(HeatTestCase):
def test_stack_create_existing(self): def test_stack_create_existing(self):
ex = self.assertRaises(rpc_common.ClientException, ex = self.assertRaises(rpc_common.ClientException,
self.eng.create_stack, self.ctx, self.eng.create_stack, self.ctx,
self.stack.name, self.stack.t, {}, None, {}) self.stack.name, self.stack.t.t, {}, None, {})
self.assertEqual(ex._exc_info[0], exception.StackExists) self.assertEqual(ex._exc_info[0], exception.StackExists)
@stack_context('service_name_tenants_test_stack', False) @stack_context('service_name_tenants_test_stack', False)
@ -1581,7 +1583,8 @@ class StackServiceTest(HeatTestCase):
return thread return thread
self.eng.thread_group_mgr.start = run self.eng.thread_group_mgr.start = run
new_tmpl = {'Resources': {'AResource': {'Type': new_tmpl = {'HeatTemplateFormatVersion': '2012-12-12',
'Resources': {'AResource': {'Type':
'GenericResourceType'}}} 'GenericResourceType'}}}
self.m.StubOutWithMock(instances.Instance, 'handle_delete') self.m.StubOutWithMock(instances.Instance, 'handle_delete')
@ -2570,6 +2573,7 @@ class StackServiceTest(HeatTestCase):
generic_rsrc.GenericResource) generic_rsrc.GenericResource)
lazy_load_template = { lazy_load_template = {
'HeatTemplateFormatVersion': '2012-12-12',
'Resources': { 'Resources': {
'foo': {'Type': 'GenericResourceType'}, 'foo': {'Type': 'GenericResourceType'},
'bar': { 'bar': {
@ -2607,13 +2611,11 @@ class StackServiceTest(HeatTestCase):
params = {} params = {}
files = None files = None
stack_name = 'SampleStack' stack_name = 'SampleStack'
tpl = { tpl = {'HeatTemplateFormatVersion': '2012-12-12',
'Description': 'Lorem ipsum.', 'Description': 'Lorem ipsum.',
'Resources': { 'Resources': {
'SampleResource1': {'Type': 'GenericResource1'}, 'SampleResource1': {'Type': 'GenericResource1'},
'SampleResource2': {'Type': 'GenericResource2'}, 'SampleResource2': {'Type': 'GenericResource2'}}}
}
}
return self.eng.preview_stack(self.ctx, stack_name, tpl, return self.eng.preview_stack(self.ctx, stack_name, tpl,
params, files, args) params, files, args)
@ -2669,14 +2671,16 @@ class StackServiceTest(HeatTestCase):
def test_validate_new_stack_checks_stack_limit(self, mock_db_count): def test_validate_new_stack_checks_stack_limit(self, mock_db_count):
cfg.CONF.set_override('max_stacks_per_tenant', 99) cfg.CONF.set_override('max_stacks_per_tenant', 99)
mock_db_count.return_value = 99 mock_db_count.return_value = 99
template = service.parser.Template({}) template = service.parser.Template(
{'HeatTemplateFormatVersion': '2012-12-12'})
self.assertRaises(exception.RequestLimitExceeded, self.assertRaises(exception.RequestLimitExceeded,
self.eng._validate_new_stack, self.eng._validate_new_stack,
self.ctx, 'test_existing_stack', template) self.ctx, 'test_existing_stack', template)
def test_validate_new_stack_checks_resource_limit(self): def test_validate_new_stack_checks_resource_limit(self):
cfg.CONF.set_override('max_resources_per_stack', 5) cfg.CONF.set_override('max_resources_per_stack', 5)
template = {'Resources': [1, 2, 3, 4, 5, 6]} template = {'HeatTemplateFormatVersion': '2012-12-12',
'Resources': [1, 2, 3, 4, 5, 6]}
parsed_template = service.parser.Template(template) parsed_template = service.parser.Template(template)
self.assertRaises(exception.RequestLimitExceeded, self.assertRaises(exception.RequestLimitExceeded,
self.eng._validate_new_stack, self.eng._validate_new_stack,

View File

@ -26,6 +26,7 @@ cfg.CONF.import_opt('event_purge_batch_size', 'heat.common.config')
cfg.CONF.import_opt('max_events_per_stack', 'heat.common.config') cfg.CONF.import_opt('max_events_per_stack', 'heat.common.config')
tmpl = { tmpl = {
'HeatTemplateFormatVersion': '2012-12-12',
'Resources': { 'Resources': {
'EventTestResource': { 'EventTestResource': {
'Type': 'ResourceWithRequiredProps', 'Type': 'ResourceWithRequiredProps',
@ -144,7 +145,8 @@ class EventTest(HeatTestCase):
self.assertIsNone(e.identifier()) self.assertIsNone(e.identifier())
def test_badprop(self): def test_badprop(self):
tmpl = {'Type': 'ResourceWithRequiredProps', tmpl = {'HeatTemplateFormatVersion': '2012-12-12',
'Type': 'ResourceWithRequiredProps',
'Properties': {'Foo': False}} 'Properties': {'Foo': False}}
rname = 'bad_resource' rname = 'bad_resource'
res = generic_rsrc.ResourceWithRequiredProps(rname, tmpl, self.stack) res = generic_rsrc.ResourceWithRequiredProps(rname, tmpl, self.stack)

View File

@ -561,7 +561,7 @@ class HOTemplateTest(HeatTestCase):
'UpdatePolicy': {"blarg": "wibble"}} 'UpdatePolicy': {"blarg": "wibble"}}
parent_resource.stack = parser.Stack(utils.dummy_context(), parent_resource.stack = parser.Stack(utils.dummy_context(),
'toplevel_stack', 'toplevel_stack',
parser.Template({})) parser.Template(hot_tpl_empty))
stack = parser.Stack(utils.dummy_context(), 'test_stack', stack = parser.Stack(utils.dummy_context(), 'test_stack',
parser.Template(hot_tpl_empty), parser.Template(hot_tpl_empty),
parent_resource=parent_resource) parent_resource=parent_resource)
@ -579,7 +579,7 @@ class HOTemplateTest(HeatTestCase):
parent_resource.metadata_set({"foo": "bar"}) parent_resource.metadata_set({"foo": "bar"})
parent_resource.stack = parser.Stack(utils.dummy_context(), parent_resource.stack = parser.Stack(utils.dummy_context(),
'toplevel_stack', 'toplevel_stack',
parser.Template({})) parser.Template(hot_tpl_empty))
parent_snippet = {'DeletionPolicy': {'Fn::Join': ['eta', parent_snippet = {'DeletionPolicy': {'Fn::Join': ['eta',
['R', 'in']]}} ['R', 'in']]}}
parent_tmpl = parent_resource.stack.t.parse(parent_resource.stack, parent_tmpl = parent_resource.stack.t.parse(parent_resource.stack,
@ -610,7 +610,7 @@ class HOTemplateTest(HeatTestCase):
parent_resource.t = {} parent_resource.t = {}
parent_resource.stack = parser.Stack(utils.dummy_context(), parent_resource.stack = parser.Stack(utils.dummy_context(),
'toplevel_stack', 'toplevel_stack',
parser.Template({})) parser.Template(hot_tpl_empty))
stack = parser.Stack(utils.dummy_context(), 'test_stack', stack = parser.Stack(utils.dummy_context(), 'test_stack',
parser.Template(hot_tpl_empty), parser.Template(hot_tpl_empty),
parent_resource=parent_resource) parent_resource=parent_resource)

View File

@ -35,6 +35,7 @@ class MultipartMimeTest(HeatTestCase):
stack = parser.Stack( stack = parser.Stack(
self.ctx, 'software_config_test_stack', self.ctx, 'software_config_test_stack',
template.Template({ template.Template({
'HeatTemplateFormatVersion': '2012-12-12',
'Resources': { 'Resources': {
'config_mysql': { 'config_mysql': {
'Type': 'OS::Heat::MultipartMime', 'Type': 'OS::Heat::MultipartMime',

View File

@ -53,7 +53,8 @@ class NotificationTest(common.HeatTestCase):
generic_resource.ResourceWithProps) generic_resource.ResourceWithProps)
def create_test_stack(self): def create_test_stack(self):
test_template = {'Parameters': {'Foo': {'Type': 'String'}, test_template = {'HeatTemplateFormatVersion': '2012-12-12',
'Parameters': {'Foo': {'Type': 'String'},
'Pass': {'Type': 'String', 'Pass': {'Type': 'String',
'NoEcho': True}}, 'NoEcho': True}},
'Resources': 'Resources':

View File

@ -26,7 +26,8 @@ class ParameterTest(testtools.TestCase):
def new_parameter(self, name, schema, value=None, def new_parameter(self, name, schema, value=None,
validate_value=True): validate_value=True):
tmpl = template.Template({'Parameters': {name: schema}}) tmpl = template.Template({'HeatTemplateFormatVersion': '2012-12-12',
'Parameters': {name: schema}})
schema = tmpl.param_schemata()[name] schema = tmpl.param_schemata()[name]
return parameters.Parameter(name, schema, value, return parameters.Parameter(name, schema, value,
validate_value) validate_value)
@ -310,6 +311,7 @@ params_schema = json.loads('''{
class ParametersTest(testtools.TestCase): class ParametersTest(testtools.TestCase):
def new_parameters(self, stack_name, tmpl, user_params={}, stack_id=None, def new_parameters(self, stack_name, tmpl, user_params={}, stack_id=None,
validate_value=True): validate_value=True):
tmpl.update({'HeatTemplateFormatVersion': '2012-12-12'})
tmpl = template.Template(tmpl) tmpl = template.Template(tmpl)
return tmpl.parameters( return tmpl.parameters(
identifier.HeatIdentifier('', stack_name, stack_id), identifier.HeatIdentifier('', stack_name, stack_id),

File diff suppressed because it is too large Load Diff

View File

@ -31,6 +31,9 @@ from heat.tests import generic_resource as generic_rsrc
from heat.tests import utils from heat.tests import utils
empty_template = {"HeatTemplateFormatVersion": "2012-12-12"}
class MyCloudResource(generic_rsrc.GenericResource): class MyCloudResource(generic_rsrc.GenericResource):
pass pass
@ -115,7 +118,8 @@ class ProviderTemplateTest(HeatTestCase):
env.load({'resource_registry': env.load({'resource_registry':
{'DummyResource': 'test_resource.template'}}) {'DummyResource': 'test_resource.template'}})
stack = parser.Stack(utils.dummy_context(), 'test_stack', stack = parser.Stack(utils.dummy_context(), 'test_stack',
parser.Template({}, files=files), env=env, parser.Template(empty_template, files=files),
env=env,
stack_id=str(uuid.uuid4())) stack_id=str(uuid.uuid4()))
map_prop_val = { map_prop_val = {
@ -174,7 +178,8 @@ class ProviderTemplateTest(HeatTestCase):
env.load({'resource_registry': env.load({'resource_registry':
{'DummyResource': 'test_resource.template'}}) {'DummyResource': 'test_resource.template'}})
stack = parser.Stack(utils.dummy_context(), 'test_stack', stack = parser.Stack(utils.dummy_context(), 'test_stack',
parser.Template({}, files=files), env=env, parser.Template(empty_template, files=files),
env=env,
stack_id=str(uuid.uuid4())) stack_id=str(uuid.uuid4()))
json_snippet = { json_snippet = {
@ -187,6 +192,7 @@ class ProviderTemplateTest(HeatTestCase):
def test_attributes_missing(self): def test_attributes_missing(self):
provider = { provider = {
'HeatTemplateFormatVersion': '2012-12-12',
'Outputs': { 'Outputs': {
'Blarg': {'Value': 'wibble'}, 'Blarg': {'Value': 'wibble'},
}, },
@ -206,7 +212,8 @@ class ProviderTemplateTest(HeatTestCase):
env.load({'resource_registry': env.load({'resource_registry':
{'DummyResource': 'test_resource.template'}}) {'DummyResource': 'test_resource.template'}})
stack = parser.Stack(utils.dummy_context(), 'test_stack', stack = parser.Stack(utils.dummy_context(), 'test_stack',
parser.Template({}, files=files), env=env, parser.Template(empty_template, files=files),
env=env,
stack_id=str(uuid.uuid4())) stack_id=str(uuid.uuid4()))
temp_res = template_resource.TemplateResource('test_t_res', temp_res = template_resource.TemplateResource('test_t_res',
@ -242,7 +249,8 @@ class ProviderTemplateTest(HeatTestCase):
env.load({'resource_registry': env.load({'resource_registry':
{'DummyResource': 'test_resource.template'}}) {'DummyResource': 'test_resource.template'}})
stack = parser.Stack(utils.dummy_context(), 'test_stack', stack = parser.Stack(utils.dummy_context(), 'test_stack',
parser.Template({}, files=files), env=env, parser.Template(empty_template, files=files),
env=env,
stack_id=str(uuid.uuid4())) stack_id=str(uuid.uuid4()))
temp_res = template_resource.TemplateResource('test_t_res', temp_res = template_resource.TemplateResource('test_t_res',
@ -251,6 +259,7 @@ class ProviderTemplateTest(HeatTestCase):
def test_properties_missing(self): def test_properties_missing(self):
provider = { provider = {
'HeatTemplateFormatVersion': '2012-12-12',
'Parameters': { 'Parameters': {
'Blarg': {'Type': 'String', 'Default': 'wibble'}, 'Blarg': {'Type': 'String', 'Default': 'wibble'},
}, },
@ -272,7 +281,8 @@ class ProviderTemplateTest(HeatTestCase):
env.load({'resource_registry': env.load({'resource_registry':
{'DummyResource': 'test_resource.template'}}) {'DummyResource': 'test_resource.template'}})
stack = parser.Stack(utils.dummy_context(), 'test_stack', stack = parser.Stack(utils.dummy_context(), 'test_stack',
parser.Template({}, files=files), env=env, parser.Template(empty_template, files=files),
env=env,
stack_id=str(uuid.uuid4())) stack_id=str(uuid.uuid4()))
temp_res = template_resource.TemplateResource('test_t_res', temp_res = template_resource.TemplateResource('test_t_res',
@ -282,6 +292,7 @@ class ProviderTemplateTest(HeatTestCase):
def test_properties_extra_required(self): def test_properties_extra_required(self):
provider = { provider = {
'HeatTemplateFormatVersion': '2012-12-12',
'Parameters': { 'Parameters': {
'Blarg': {'Type': 'String'}, 'Blarg': {'Type': 'String'},
}, },
@ -304,7 +315,8 @@ class ProviderTemplateTest(HeatTestCase):
env.load({'resource_registry': env.load({'resource_registry':
{'DummyResource': 'test_resource.template'}}) {'DummyResource': 'test_resource.template'}})
stack = parser.Stack(utils.dummy_context(), 'test_stack', stack = parser.Stack(utils.dummy_context(), 'test_stack',
parser.Template({}, files=files), env=env, parser.Template(empty_template, files=files),
env=env,
stack_id=str(uuid.uuid4())) stack_id=str(uuid.uuid4()))
temp_res = template_resource.TemplateResource('test_t_res', temp_res = template_resource.TemplateResource('test_t_res',
@ -337,7 +349,9 @@ class ProviderTemplateTest(HeatTestCase):
env.load({'resource_registry': env.load({'resource_registry':
{'DummyResource': 'test_resource.template'}}) {'DummyResource': 'test_resource.template'}})
stack = parser.Stack(utils.dummy_context(), 'test_stack', stack = parser.Stack(utils.dummy_context(), 'test_stack',
parser.Template({}, files=files), env=env, parser.Template(
{'HeatTemplateFormatVersion': '2012-12-12'},
files=files), env=env,
stack_id=str(uuid.uuid4())) stack_id=str(uuid.uuid4()))
temp_res = template_resource.TemplateResource('test_t_res', temp_res = template_resource.TemplateResource('test_t_res',
@ -411,7 +425,8 @@ class ProviderTemplateTest(HeatTestCase):
} }
} }
stack = parser.Stack(utils.dummy_context(), 'test_stack', stack = parser.Stack(utils.dummy_context(), 'test_stack',
parser.Template({}), stack_id=str(uuid.uuid4())) parser.Template(empty_template),
stack_id=str(uuid.uuid4()))
templ_resource = resource.Resource("test_templ_resource", json_snippet, templ_resource = resource.Resource("test_templ_resource", json_snippet,
stack) stack)
self.m.VerifyAll() self.m.VerifyAll()
@ -449,7 +464,7 @@ class ProviderTemplateTest(HeatTestCase):
g_env.load({'resource_registry': g_env.load({'resource_registry':
{'Test::Frodo': test_templ_name}}) {'Test::Frodo': test_templ_name}})
stack = parser.Stack(utils.dummy_context(), 'test_stack', stack = parser.Stack(utils.dummy_context(), 'test_stack',
parser.Template({}), parser.Template(empty_template),
stack_id=str(uuid.uuid4())) stack_id=str(uuid.uuid4()))
minimal_temp = json.dumps({'HeatTemplateFormatVersion': '2012-12-12', minimal_temp = json.dumps({'HeatTemplateFormatVersion': '2012-12-12',
@ -475,7 +490,7 @@ class ProviderTemplateTest(HeatTestCase):
env.load({'resource_registry': env.load({'resource_registry':
{'Test::Flippy': test_templ_name}}) {'Test::Flippy': test_templ_name}})
stack = parser.Stack(utils.dummy_context(), 'test_stack', stack = parser.Stack(utils.dummy_context(), 'test_stack',
parser.Template({}), env=env, parser.Template(empty_template), env=env,
stack_id=str(uuid.uuid4())) stack_id=str(uuid.uuid4()))
temp_res = template_resource.TemplateResource('test_t_res', temp_res = template_resource.TemplateResource('test_t_res',
@ -495,7 +510,7 @@ class ProviderTemplateTest(HeatTestCase):
g_env.load({'resource_registry': g_env.load({'resource_registry':
{'Test::Frodo': test_templ_name}}) {'Test::Frodo': test_templ_name}})
stack = parser.Stack(utils.dummy_context(), 'test_stack', stack = parser.Stack(utils.dummy_context(), 'test_stack',
parser.Template({}), parser.Template(empty_template),
stack_id=str(uuid.uuid4())) stack_id=str(uuid.uuid4()))
self.m.StubOutWithMock(urlfetch, "get") self.m.StubOutWithMock(urlfetch, "get")
@ -522,7 +537,7 @@ class ProviderTemplateTest(HeatTestCase):
env.load({'resource_registry': env.load({'resource_registry':
{'Test::Flippy': test_templ_name}}) {'Test::Flippy': test_templ_name}})
stack = parser.Stack(utils.dummy_context(), 'test_stack', stack = parser.Stack(utils.dummy_context(), 'test_stack',
parser.Template({}), env=env, parser.Template(empty_template), env=env,
stack_id=str(uuid.uuid4())) stack_id=str(uuid.uuid4()))
self.m.StubOutWithMock(urlfetch, "get") self.m.StubOutWithMock(urlfetch, "get")
@ -548,7 +563,7 @@ class ProviderTemplateTest(HeatTestCase):
env.load({'resource_registry': env.load({'resource_registry':
{'Test::Flippy': test_templ_name}}) {'Test::Flippy': test_templ_name}})
stack = parser.Stack(utils.dummy_context(), 'test_stack', stack = parser.Stack(utils.dummy_context(), 'test_stack',
parser.Template({}), env=env, parser.Template(empty_template), env=env,
stack_id=str(uuid.uuid4())) stack_id=str(uuid.uuid4()))
self.m.ReplayAll() self.m.ReplayAll()

View File

@ -32,6 +32,9 @@ from heat.tests import generic_resource as generic_rsrc
from heat.tests import utils from heat.tests import utils
empty_template = {"HeatTemplateFormatVersion": "2012-12-12"}
class ResourceTest(HeatTestCase): class ResourceTest(HeatTestCase):
def setUp(self): def setUp(self):
super(ResourceTest, self).setUp() super(ResourceTest, self).setUp()
@ -44,7 +47,7 @@ class ResourceTest(HeatTestCase):
{u'OS::Test::GenericResource': u'GenericResourceType'}}) {u'OS::Test::GenericResource': u'GenericResourceType'}})
self.stack = parser.Stack(utils.dummy_context(), 'test_stack', self.stack = parser.Stack(utils.dummy_context(), 'test_stack',
parser.Template({}), env=env, parser.Template(empty_template), env=env,
stack_id=str(uuid.uuid4())) stack_id=str(uuid.uuid4()))
def test_get_class_ok(self): def test_get_class_ok(self):
@ -295,7 +298,7 @@ class ResourceTest(HeatTestCase):
tmpl2 = {'Type': 'Foo'} tmpl2 = {'Type': 'Foo'}
tmpl3 = {'Type': 'Bar'} tmpl3 = {'Type': 'Bar'}
stack2 = parser.Stack(utils.dummy_context(), 'test_stack', stack2 = parser.Stack(utils.dummy_context(), 'test_stack',
parser.Template({}), stack_id=-1) parser.Template(empty_template), stack_id=-1)
res1 = generic_rsrc.GenericResource('test_resource', tmpl1, self.stack) res1 = generic_rsrc.GenericResource('test_resource', tmpl1, self.stack)
res2 = generic_rsrc.GenericResource('test_resource', tmpl2, stack2) res2 = generic_rsrc.GenericResource('test_resource', tmpl2, stack2)
res3 = generic_rsrc.GenericResource('test_resource2', tmpl3, stack2) res3 = generic_rsrc.GenericResource('test_resource2', tmpl3, stack2)
@ -747,6 +750,7 @@ class ResourceAdoptTest(HeatTestCase):
def test_adopt_resource_success(self): def test_adopt_resource_success(self):
adopt_data = '{}' adopt_data = '{}'
tmpl = template.Template({ tmpl = template.Template({
'HeatTemplateFormatVersion': '2012-12-12',
'Resources': { 'Resources': {
'foo': {'Type': 'GenericResourceType'}, 'foo': {'Type': 'GenericResourceType'},
} }
@ -773,6 +777,7 @@ class ResourceAdoptTest(HeatTestCase):
def test_adopt_with_resource_data_and_metadata(self): def test_adopt_with_resource_data_and_metadata(self):
adopt_data = '{}' adopt_data = '{}'
tmpl = template.Template({ tmpl = template.Template({
'HeatTemplateFormatVersion': '2012-12-12',
'Resources': { 'Resources': {
'foo': {'Type': 'GenericResourceType'}, 'foo': {'Type': 'GenericResourceType'},
} }
@ -806,6 +811,7 @@ class ResourceAdoptTest(HeatTestCase):
"resources": {} "resources": {}
}''' }'''
tmpl = template.Template({ tmpl = template.Template({
'HeatTemplateFormatVersion': '2012-12-12',
'Resources': { 'Resources': {
'foo': {'Type': 'GenericResourceType'}, 'foo': {'Type': 'GenericResourceType'},
} }
@ -834,6 +840,7 @@ class ResourceDependenciesTest(HeatTestCase):
def test_no_deps(self): def test_no_deps(self):
tmpl = template.Template({ tmpl = template.Template({
'HeatTemplateFormatVersion': '2012-12-12',
'Resources': { 'Resources': {
'foo': {'Type': 'GenericResourceType'}, 'foo': {'Type': 'GenericResourceType'},
} }
@ -848,6 +855,7 @@ class ResourceDependenciesTest(HeatTestCase):
def test_ref(self): def test_ref(self):
tmpl = template.Template({ tmpl = template.Template({
'HeatTemplateFormatVersion': '2012-12-12',
'Resources': { 'Resources': {
'foo': {'Type': 'GenericResourceType'}, 'foo': {'Type': 'GenericResourceType'},
'bar': { 'bar': {
@ -892,6 +900,7 @@ class ResourceDependenciesTest(HeatTestCase):
def test_ref_nested_dict(self): def test_ref_nested_dict(self):
tmpl = template.Template({ tmpl = template.Template({
'HeatTemplateFormatVersion': '2012-12-12',
'Resources': { 'Resources': {
'foo': {'Type': 'GenericResourceType'}, 'foo': {'Type': 'GenericResourceType'},
'bar': { 'bar': {
@ -935,6 +944,7 @@ class ResourceDependenciesTest(HeatTestCase):
def test_ref_nested_deep(self): def test_ref_nested_deep(self):
tmpl = template.Template({ tmpl = template.Template({
'HeatTemplateFormatVersion': '2012-12-12',
'Resources': { 'Resources': {
'foo': {'Type': 'GenericResourceType'}, 'foo': {'Type': 'GenericResourceType'},
'bar': { 'bar': {
@ -982,6 +992,7 @@ class ResourceDependenciesTest(HeatTestCase):
def test_ref_fail(self): def test_ref_fail(self):
tmpl = template.Template({ tmpl = template.Template({
'HeatTemplateFormatVersion': '2012-12-12',
'Resources': { 'Resources': {
'foo': {'Type': 'GenericResourceType'}, 'foo': {'Type': 'GenericResourceType'},
'bar': { 'bar': {
@ -1017,6 +1028,7 @@ class ResourceDependenciesTest(HeatTestCase):
def test_getatt(self): def test_getatt(self):
tmpl = template.Template({ tmpl = template.Template({
'HeatTemplateFormatVersion': '2012-12-12',
'Resources': { 'Resources': {
'foo': {'Type': 'GenericResourceType'}, 'foo': {'Type': 'GenericResourceType'},
'bar': { 'bar': {
@ -1060,6 +1072,7 @@ class ResourceDependenciesTest(HeatTestCase):
def test_getatt_nested_dict(self): def test_getatt_nested_dict(self):
tmpl = template.Template({ tmpl = template.Template({
'HeatTemplateFormatVersion': '2012-12-12',
'Resources': { 'Resources': {
'foo': {'Type': 'GenericResourceType'}, 'foo': {'Type': 'GenericResourceType'},
'bar': { 'bar': {
@ -1103,6 +1116,7 @@ class ResourceDependenciesTest(HeatTestCase):
def test_getatt_nested_deep(self): def test_getatt_nested_deep(self):
tmpl = template.Template({ tmpl = template.Template({
'HeatTemplateFormatVersion': '2012-12-12',
'Resources': { 'Resources': {
'foo': {'Type': 'GenericResourceType'}, 'foo': {'Type': 'GenericResourceType'},
'bar': { 'bar': {
@ -1152,6 +1166,7 @@ class ResourceDependenciesTest(HeatTestCase):
def test_getatt_fail(self): def test_getatt_fail(self):
tmpl = template.Template({ tmpl = template.Template({
'HeatTemplateFormatVersion': '2012-12-12',
'Resources': { 'Resources': {
'foo': {'Type': 'GenericResourceType'}, 'foo': {'Type': 'GenericResourceType'},
'bar': { 'bar': {
@ -1187,6 +1202,7 @@ class ResourceDependenciesTest(HeatTestCase):
def test_getatt_fail_nested_deep(self): def test_getatt_fail_nested_deep(self):
tmpl = template.Template({ tmpl = template.Template({
'HeatTemplateFormatVersion': '2012-12-12',
'Resources': { 'Resources': {
'foo': {'Type': 'GenericResourceType'}, 'foo': {'Type': 'GenericResourceType'},
'bar': { 'bar': {
@ -1232,6 +1248,7 @@ class ResourceDependenciesTest(HeatTestCase):
def test_dependson(self): def test_dependson(self):
tmpl = template.Template({ tmpl = template.Template({
'HeatTemplateFormatVersion': '2012-12-12',
'Resources': { 'Resources': {
'foo': {'Type': 'GenericResourceType'}, 'foo': {'Type': 'GenericResourceType'},
'bar': { 'bar': {
@ -1271,6 +1288,7 @@ class ResourceDependenciesTest(HeatTestCase):
def test_dependson_fail(self): def test_dependson_fail(self):
tmpl = template.Template({ tmpl = template.Template({
'HeatTemplateFormatVersion': '2012-12-12',
'Resources': { 'Resources': {
'foo': { 'foo': {
'Type': 'GenericResourceType', 'Type': 'GenericResourceType',
@ -1292,7 +1310,8 @@ class MetadataTest(HeatTestCase):
'Metadata': {'Test': 'Initial metadata'} 'Metadata': {'Test': 'Initial metadata'}
} }
self.stack = parser.Stack(utils.dummy_context(), self.stack = parser.Stack(utils.dummy_context(),
'test_stack', parser.Template({})) 'test_stack',
parser.Template(empty_template))
self.stack.store() self.stack.store()
self.res = generic_rsrc.GenericResource('metadata_resource', self.res = generic_rsrc.GenericResource('metadata_resource',
tmpl, self.stack) tmpl, self.stack)

View File

@ -39,6 +39,7 @@ class SoftwareConfigTest(HeatTestCase):
self.stack = parser.Stack( self.stack = parser.Stack(
self.ctx, 'software_config_test_stack', self.ctx, 'software_config_test_stack',
template.Template({ template.Template({
'HeatTemplateFormatVersion': '2012-12-12',
'Resources': { 'Resources': {
'config_mysql': { 'config_mysql': {
'Type': 'OS::Heat::SoftwareConfig', 'Type': 'OS::Heat::SoftwareConfig',

View File

@ -25,6 +25,7 @@ from heat.tests import utils
class SoftwareDeploymentTest(HeatTestCase): class SoftwareDeploymentTest(HeatTestCase):
template = { template = {
'HeatTemplateFormatVersion': '2012-12-12',
'Resources': { 'Resources': {
'deployment_mysql': { 'deployment_mysql': {
'Type': 'OS::Heat::SoftwareDeployment', 'Type': 'OS::Heat::SoftwareDeployment',
@ -38,6 +39,7 @@ class SoftwareDeploymentTest(HeatTestCase):
} }
template_with_server = { template_with_server = {
'HeatTemplateFormatVersion': '2012-12-12',
'Resources': { 'Resources': {
'deployment_mysql': { 'deployment_mysql': {
'Type': 'OS::Heat::SoftwareDeployment', 'Type': 'OS::Heat::SoftwareDeployment',
@ -59,6 +61,7 @@ class SoftwareDeploymentTest(HeatTestCase):
} }
template_no_signal = { template_no_signal = {
'HeatTemplateFormatVersion': '2012-12-12',
'Resources': { 'Resources': {
'deployment_mysql': { 'deployment_mysql': {
'Type': 'OS::Heat::SoftwareDeployment', 'Type': 'OS::Heat::SoftwareDeployment',
@ -74,6 +77,7 @@ class SoftwareDeploymentTest(HeatTestCase):
} }
template_delete_suspend_resume = { template_delete_suspend_resume = {
'HeatTemplateFormatVersion': '2012-12-12',
'Resources': { 'Resources': {
'deployment_mysql': { 'deployment_mysql': {
'Type': 'OS::Heat::SoftwareDeployment', 'Type': 'OS::Heat::SoftwareDeployment',

View File

@ -28,7 +28,8 @@ from heat.tests import generic_resource as generic_rsrc
from heat.tests import utils from heat.tests import utils
ws_res_snippet = {"Type": "some_magic_type", ws_res_snippet = {"HeatTemplateFormatVersion": "2012-12-12",
"Type": "some_magic_type",
"metadata": { "metadata": {
"key": "value", "key": "value",
"some": "more stuff"}} "some": "more stuff"}}
@ -105,7 +106,8 @@ class StackResourceTest(HeatTestCase):
MyStackResource) MyStackResource)
resource._register_class('GenericResource', resource._register_class('GenericResource',
generic_rsrc.GenericResource) generic_rsrc.GenericResource)
t = parser.Template({'Resources': t = parser.Template({'HeatTemplateFormatVersion': '2012-12-12',
'Resources':
{"provider_resource": ws_res_snippet}}) {"provider_resource": ws_res_snippet}})
self.parent_stack = parser.Stack(utils.dummy_context(), 'test_stack', self.parent_stack = parser.Stack(utils.dummy_context(), 'test_stack',
t, stack_id=str(uuid.uuid4())) t, stack_id=str(uuid.uuid4()))
@ -172,7 +174,8 @@ class StackResourceTest(HeatTestCase):
stack_resource = MyImplementedStackResource('test', stack_resource = MyImplementedStackResource('test',
ws_res_snippet, ws_res_snippet,
self.parent_stack) self.parent_stack)
stack_resource.child_template = mock.Mock(return_value={}) stack_resource.child_template = \
mock.Mock(return_value={'HeatTemplateFormatVersion': '2012-12-12'})
stack_resource.child_params = mock.Mock() stack_resource.child_params = mock.Mock()
exc = exception.RequestLimitExceeded(message='Validation Failed') exc = exception.RequestLimitExceeded(message='Validation Failed')
validation_mock = mock.Mock(side_effect=exc) validation_mock = mock.Mock(side_effect=exc)
@ -183,7 +186,8 @@ class StackResourceTest(HeatTestCase):
def test__validate_nested_resources_checks_num_of_resources(self): def test__validate_nested_resources_checks_num_of_resources(self):
stack_resource.cfg.CONF.set_override('max_resources_per_stack', 2) stack_resource.cfg.CONF.set_override('max_resources_per_stack', 2)
tmpl = {'Resources': [1]} tmpl = {'HeatTemplateFormatVersion': '2012-12-12',
'Resources': [1]}
template = stack_resource.parser.Template(tmpl) template = stack_resource.parser.Template(tmpl)
root_resources = mock.Mock(return_value=2) root_resources = mock.Mock(return_value=2)
self.parent_resource.stack.root_stack.total_resources = root_resources self.parent_resource.stack.root_stack.total_resources = root_resources

View File

@ -23,6 +23,7 @@ from heat.tests import utils
class StructuredConfigTestJSON(HeatTestCase): class StructuredConfigTestJSON(HeatTestCase):
template = { template = {
'HeatTemplateFormatVersion': '2012-12-12',
'Resources': { 'Resources': {
'config_mysql': { 'config_mysql': {
'Type': 'OS::Heat::StructuredConfig', 'Type': 'OS::Heat::StructuredConfig',
@ -70,6 +71,7 @@ class StructuredConfigTestJSON(HeatTestCase):
class StructuredDeploymentDerivedTest(HeatTestCase): class StructuredDeploymentDerivedTest(HeatTestCase):
template = { template = {
'HeatTemplateFormatVersion': '2012-12-12',
'Resources': { 'Resources': {
'deploy_mysql': { 'deploy_mysql': {
'Type': 'OS::Heat::StructuredDeployment' 'Type': 'OS::Heat::StructuredDeployment'

View File

@ -78,8 +78,10 @@ class TestTemplateVersion(HeatTestCase):
'foo': 'bar', 'foo': 'bar',
'Parameters': {} 'Parameters': {}
} }
self.assertEqual(('HeatTemplateFormatVersion', '2012-12-12'), ex = self.assertRaises(exception.InvalidTemplateVersion,
template.get_version(tmpl, self.versions)) template.get_version, tmpl, self.versions)
self.assertEqual('The template version is invalid: Template version '
'was not provided', str(ex))
def test_ambiguous_version(self): def test_ambiguous_version(self):
tmpl = { tmpl = {

View File

@ -172,8 +172,8 @@ class JsonYamlResolvedCompareTest(HeatTestCase):
def compare_stacks(self, json_file, yaml_file, parameters): def compare_stacks(self, json_file, yaml_file, parameters):
t1 = self.load_template(json_file) t1 = self.load_template(json_file)
t2 = self.load_template(yaml_file) t2 = self.load_template(yaml_file)
del(t2[u'HeatTemplateFormatVersion'])
del(t1[u'AWSTemplateFormatVersion']) del(t1[u'AWSTemplateFormatVersion'])
t1[u'HeatTemplateFormatVersion'] = t2[u'HeatTemplateFormatVersion']
stack1 = utils.parse_stack(t1, parameters) stack1 = utils.parse_stack(t1, parameters)
stack2 = utils.parse_stack(t2, parameters) stack2 = utils.parse_stack(t2, parameters)

View File

@ -46,7 +46,7 @@ class WatchRuleTest(HeatTestCase):
# must be associated with a stack # must be associated with a stack
ctx = utils.dummy_context() ctx = utils.dummy_context()
ctx.auth_token = 'abcd1234' ctx.auth_token = 'abcd1234'
empty_tmpl = {"template": {}} empty_tmpl = {'HeatTemplateFormatVersion': '2012-12-12'}
tmpl = parser.Template(empty_tmpl) tmpl = parser.Template(empty_tmpl)
stack_name = 'dummystack' stack_name = 'dummystack'
dummy_stack = parser.Stack(ctx, stack_name, tmpl) dummy_stack = parser.Stack(ctx, stack_name, tmpl)