diff --git a/heat/engine/resources/autoscaling.py b/heat/engine/resources/autoscaling.py index 139c4fd099..14fd9aee5e 100644 --- a/heat/engine/resources/autoscaling.py +++ b/heat/engine/resources/autoscaling.py @@ -301,7 +301,8 @@ class InstanceGroup(stack_resource.StackResource): old_resources = self._get_instance_templates() templates = template.resource_templates( 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): 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.""" tpl = super(AutoScalingResourceGroup, self)._create_template( *args, **kwargs) + tpl.pop('HeatTemplateFormatVersion', None) tpl['heat_template_version'] = '2013-05-23' tpl['resources'] = tpl.pop('Resources') return tpl diff --git a/heat/engine/resources/template_resource.py b/heat/engine/resources/template_resource.py index 1a1b8a73e3..3cff8ca128 100644 --- a/heat/engine/resources/template_resource.py +++ b/heat/engine/resources/template_resource.py @@ -86,7 +86,8 @@ class TemplateResource(stack_resource.StackResource): tmpl = template.Template(self.child_template()) except ValueError as 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. self.properties_schema = (properties.Properties diff --git a/heat/engine/template.py b/heat/engine/template.py index cc7f068b97..3dceb1a2db 100644 --- a/heat/engine/template.py +++ b/heat/engine/template.py @@ -25,8 +25,6 @@ logger = logging.getLogger(__name__) __all__ = ['Template'] -DEFAULT_VERSION = ('HeatTemplateFormatVersion', '2012-12-12') - _template_classes = None @@ -61,14 +59,15 @@ def get_version(template_data, available_versions): isinstance(v, basestring)) keys_present = version_keys & candidate_keys - if not keys_present: - return DEFAULT_VERSION if len(keys_present) > 1: explanation = _('Ambiguous versions (%s)') % ', '.join(keys_present) raise exception.InvalidTemplateVersion(explanation=explanation) - - version_key = keys_present.pop() + try: + 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] diff --git a/heat/tests/test_cloud_config.py b/heat/tests/test_cloud_config.py index 75f12eda6f..5ad66bf826 100644 --- a/heat/tests/test_cloud_config.py +++ b/heat/tests/test_cloud_config.py @@ -33,6 +33,7 @@ class CloudConfigTest(HeatTestCase): self.stack = parser.Stack( self.ctx, 'software_config_test_stack', template.Template({ + 'HeatTemplateFormatVersion': '2012-12-12', 'Resources': { 'config_mysql': { 'Type': 'OS::Heat::CloudConfig', diff --git a/heat/tests/test_engine_api_utils.py b/heat/tests/test_engine_api_utils.py index 237c8d207d..2238f6375d 100644 --- a/heat/tests/test_engine_api_utils.py +++ b/heat/tests/test_engine_api_utils.py @@ -34,6 +34,7 @@ class FormatTest(HeatTestCase): super(FormatTest, self).setUp() template = parser.Template({ + 'HeatTemplateFormatVersion': '2012-12-12', 'Resources': { 'generic1': {'Type': 'GenericResourceType'}, 'generic2': { diff --git a/heat/tests/test_engine_service.py b/heat/tests/test_engine_service.py index 1d63a2db2c..cb95f8de35 100644 --- a/heat/tests/test_engine_service.py +++ b/heat/tests/test_engine_service.py @@ -494,7 +494,7 @@ class StackServiceCreateUpdateDeleteTest(HeatTestCase): self.assertRaises(ValueError, 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): stack_name = 'service_create_test_stack_invalid_res' @@ -506,7 +506,7 @@ class StackServiceCreateUpdateDeleteTest(HeatTestCase): self.assertRaises(ValueError, self.man.create_stack, self.ctx, stack_name, - stack.t, {}, None, {}) + stack.t.t, {}, None, {}) def test_stack_create_no_credentials(self): stack_name = 'test_stack_create_no_credentials' @@ -557,7 +557,8 @@ class StackServiceCreateUpdateDeleteTest(HeatTestCase): params = {} res._register_class('GenericResourceType', generic_rsrc.GenericResource) - tpl = {'Resources': { + tpl = {'HeatTemplateFormatVersion': '2012-12-12', + 'Resources': { 'A': {'Type': 'GenericResourceType'}, 'B': {'Type': 'GenericResourceType'}, 'C': {'Type': 'GenericResourceType'}}} @@ -593,15 +594,15 @@ class StackServiceCreateUpdateDeleteTest(HeatTestCase): params = {} res._register_class('GenericResourceType', generic_rsrc.GenericResource) - tpl = {'Resources': { + tpl = {'HeatTemplateFormatVersion': '2012-12-12', + 'Resources': { 'A': {'Type': 'GenericResourceType'}, 'B': {'Type': 'GenericResourceType'}, 'C': {'Type': 'GenericResourceType'}}} - template = parser.Template(tpl) cfg.CONF.set_override('max_resources_per_stack', 2) ex = self.assertRaises(rpc_common.ClientException, self.man.create_stack, self.ctx, stack_name, - template, params, None, {}) + tpl, params, None, {}) self.assertEqual(ex._exc_info[0], exception.RequestLimitExceeded) self.assertIn(exception.StackResourceLimitExceeded.msg_fmt, str(ex._exc_info[1])) @@ -862,7 +863,8 @@ class StackServiceCreateUpdateDeleteTest(HeatTestCase): params = {} res._register_class('GenericResourceType', generic_rsrc.GenericResource) - tpl = {'Resources': { + tpl = {'HeatTemplateFormatVersion': '2012-12-12', + 'Resources': { 'A': {'Type': 'GenericResourceType'}, 'B': {'Type': 'GenericResourceType'}, 'C': {'Type': 'GenericResourceType'}}} @@ -1046,13 +1048,13 @@ class StackServiceCreateUpdateDeleteTest(HeatTestCase): params = {} res._register_class('GenericResourceType', generic_rsrc.GenericResource) - tpl = {'Resources': { + tpl = {'HeatTemplateFormatVersion': '2012-12-12', + 'Resources': { 'A': {'Type': 'GenericResourceType'}, 'B': {'Type': 'GenericResourceType'}, 'C': {'Type': 'GenericResourceType'}}} template = parser.Template(tpl) - old_stack = parser.Stack(self.ctx, stack_name, template) sid = old_stack.store() self.assertIsNotNone(sid) @@ -1061,7 +1063,7 @@ class StackServiceCreateUpdateDeleteTest(HeatTestCase): ex = self.assertRaises(rpc_common.ClientException, self.man.update_stack, self.ctx, - old_stack.identifier(), template, params, + old_stack.identifier(), tpl, params, None, {}) self.assertEqual(ex._exc_info[0], exception.RequestLimitExceeded) self.assertIn(exception.StackResourceLimitExceeded.msg_fmt, @@ -1507,7 +1509,7 @@ class StackServiceTest(HeatTestCase): def test_stack_create_existing(self): ex = self.assertRaises(rpc_common.ClientException, 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) @stack_context('service_name_tenants_test_stack', False) @@ -1581,7 +1583,8 @@ class StackServiceTest(HeatTestCase): return thread self.eng.thread_group_mgr.start = run - new_tmpl = {'Resources': {'AResource': {'Type': + new_tmpl = {'HeatTemplateFormatVersion': '2012-12-12', + 'Resources': {'AResource': {'Type': 'GenericResourceType'}}} self.m.StubOutWithMock(instances.Instance, 'handle_delete') @@ -2570,6 +2573,7 @@ class StackServiceTest(HeatTestCase): generic_rsrc.GenericResource) lazy_load_template = { + 'HeatTemplateFormatVersion': '2012-12-12', 'Resources': { 'foo': {'Type': 'GenericResourceType'}, 'bar': { @@ -2607,13 +2611,11 @@ class StackServiceTest(HeatTestCase): params = {} files = None stack_name = 'SampleStack' - tpl = { - 'Description': 'Lorem ipsum.', - 'Resources': { - 'SampleResource1': {'Type': 'GenericResource1'}, - 'SampleResource2': {'Type': 'GenericResource2'}, - } - } + tpl = {'HeatTemplateFormatVersion': '2012-12-12', + 'Description': 'Lorem ipsum.', + 'Resources': { + 'SampleResource1': {'Type': 'GenericResource1'}, + 'SampleResource2': {'Type': 'GenericResource2'}}} return self.eng.preview_stack(self.ctx, stack_name, tpl, params, files, args) @@ -2669,14 +2671,16 @@ class StackServiceTest(HeatTestCase): def test_validate_new_stack_checks_stack_limit(self, mock_db_count): cfg.CONF.set_override('max_stacks_per_tenant', 99) mock_db_count.return_value = 99 - template = service.parser.Template({}) + template = service.parser.Template( + {'HeatTemplateFormatVersion': '2012-12-12'}) self.assertRaises(exception.RequestLimitExceeded, self.eng._validate_new_stack, self.ctx, 'test_existing_stack', template) def test_validate_new_stack_checks_resource_limit(self): 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) self.assertRaises(exception.RequestLimitExceeded, self.eng._validate_new_stack, diff --git a/heat/tests/test_event.py b/heat/tests/test_event.py index 91e3af6037..c2c5be3ff4 100644 --- a/heat/tests/test_event.py +++ b/heat/tests/test_event.py @@ -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') tmpl = { + 'HeatTemplateFormatVersion': '2012-12-12', 'Resources': { 'EventTestResource': { 'Type': 'ResourceWithRequiredProps', @@ -144,7 +145,8 @@ class EventTest(HeatTestCase): self.assertIsNone(e.identifier()) def test_badprop(self): - tmpl = {'Type': 'ResourceWithRequiredProps', + tmpl = {'HeatTemplateFormatVersion': '2012-12-12', + 'Type': 'ResourceWithRequiredProps', 'Properties': {'Foo': False}} rname = 'bad_resource' res = generic_rsrc.ResourceWithRequiredProps(rname, tmpl, self.stack) diff --git a/heat/tests/test_hot.py b/heat/tests/test_hot.py index 28ca1e2de3..05e1d0be9c 100644 --- a/heat/tests/test_hot.py +++ b/heat/tests/test_hot.py @@ -561,7 +561,7 @@ class HOTemplateTest(HeatTestCase): 'UpdatePolicy': {"blarg": "wibble"}} parent_resource.stack = parser.Stack(utils.dummy_context(), 'toplevel_stack', - parser.Template({})) + parser.Template(hot_tpl_empty)) stack = parser.Stack(utils.dummy_context(), 'test_stack', parser.Template(hot_tpl_empty), parent_resource=parent_resource) @@ -579,7 +579,7 @@ class HOTemplateTest(HeatTestCase): parent_resource.metadata_set({"foo": "bar"}) parent_resource.stack = parser.Stack(utils.dummy_context(), 'toplevel_stack', - parser.Template({})) + parser.Template(hot_tpl_empty)) parent_snippet = {'DeletionPolicy': {'Fn::Join': ['eta', ['R', 'in']]}} parent_tmpl = parent_resource.stack.t.parse(parent_resource.stack, @@ -610,7 +610,7 @@ class HOTemplateTest(HeatTestCase): parent_resource.t = {} parent_resource.stack = parser.Stack(utils.dummy_context(), 'toplevel_stack', - parser.Template({})) + parser.Template(hot_tpl_empty)) stack = parser.Stack(utils.dummy_context(), 'test_stack', parser.Template(hot_tpl_empty), parent_resource=parent_resource) diff --git a/heat/tests/test_multi_part.py b/heat/tests/test_multi_part.py index 9e02ae676c..778177ec26 100644 --- a/heat/tests/test_multi_part.py +++ b/heat/tests/test_multi_part.py @@ -35,6 +35,7 @@ class MultipartMimeTest(HeatTestCase): stack = parser.Stack( self.ctx, 'software_config_test_stack', template.Template({ + 'HeatTemplateFormatVersion': '2012-12-12', 'Resources': { 'config_mysql': { 'Type': 'OS::Heat::MultipartMime', diff --git a/heat/tests/test_notifications.py b/heat/tests/test_notifications.py index 0f8094c18d..b1d2d810df 100644 --- a/heat/tests/test_notifications.py +++ b/heat/tests/test_notifications.py @@ -53,7 +53,8 @@ class NotificationTest(common.HeatTestCase): generic_resource.ResourceWithProps) def create_test_stack(self): - test_template = {'Parameters': {'Foo': {'Type': 'String'}, + test_template = {'HeatTemplateFormatVersion': '2012-12-12', + 'Parameters': {'Foo': {'Type': 'String'}, 'Pass': {'Type': 'String', 'NoEcho': True}}, 'Resources': diff --git a/heat/tests/test_parameters.py b/heat/tests/test_parameters.py index 6ab0a9cb17..8defef4e89 100644 --- a/heat/tests/test_parameters.py +++ b/heat/tests/test_parameters.py @@ -26,7 +26,8 @@ class ParameterTest(testtools.TestCase): def new_parameter(self, name, schema, value=None, validate_value=True): - tmpl = template.Template({'Parameters': {name: schema}}) + tmpl = template.Template({'HeatTemplateFormatVersion': '2012-12-12', + 'Parameters': {name: schema}}) schema = tmpl.param_schemata()[name] return parameters.Parameter(name, schema, value, validate_value) @@ -310,6 +311,7 @@ params_schema = json.loads('''{ class ParametersTest(testtools.TestCase): def new_parameters(self, stack_name, tmpl, user_params={}, stack_id=None, validate_value=True): + tmpl.update({'HeatTemplateFormatVersion': '2012-12-12'}) tmpl = template.Template(tmpl) return tmpl.parameters( identifier.HeatIdentifier('', stack_name, stack_id), diff --git a/heat/tests/test_parser.py b/heat/tests/test_parser.py index 673dd4d0e1..c52fdae3f4 100644 --- a/heat/tests/test_parser.py +++ b/heat/tests/test_parser.py @@ -170,7 +170,7 @@ class TemplateTest(HeatTestCase): return function.resolve(template.parse(stack, snippet)) def test_defaults(self): - empty = parser.Template({}) + empty = parser.Template(empty_template) self.assertNotIn('AWSTemplateFormatVersion', empty) self.assertEqual('No description', empty['Description']) self.assertEqual({}, empty['Mappings']) @@ -304,7 +304,8 @@ Mappings: self.assertRaises(ValueError, template_format.parse, parser_error) def test_invalid_section(self): - tmpl = parser.Template({'Foo': ['Bar']}) + tmpl = parser.Template({'HeatTemplateFormatVersion': '2012-12-12', + 'Foo': ['Bar']}) self.assertNotIn('Foo', tmpl) def test_find_in_map(self): @@ -460,7 +461,8 @@ Mappings: def test_get_azs_with_stack(self): tmpl = parser.Template(empty_template) snippet = {"Fn::GetAZs": ""} - stack = parser.Stack(self.ctx, 'test_stack', parser.Template({})) + stack = parser.Stack(self.ctx, 'test_stack', + parser.Template(empty_template)) self.m.StubOutWithMock(clients.OpenStackClients, 'nova') fc = fakes.FakeClient() clients.OpenStackClients.nova().MultipleTimes().AndReturn(fc) @@ -545,9 +547,9 @@ Mappings: parent_resource.t = {'DeletionPolicy': 'Retain', 'UpdatePolicy': {"blarg": "wibble"}} parent_resource.stack = parser.Stack(self.ctx, 'toplevel_stack', - parser.Template({})) + parser.Template(empty_template)) stack = parser.Stack(self.ctx, 'test_stack', - parser.Template({}), + parser.Template(empty_template), parent_resource=parent_resource) self.assertEqual({"foo": "bar"}, self.resolve(metadata_snippet, stack.t, stack)) @@ -562,7 +564,7 @@ Mappings: parent_resource = DummyClass() parent_resource.metadata_set({"foo": "bar"}) parent_resource.stack = parser.Stack(self.ctx, 'toplevel_stack', - parser.Template({})) + parser.Template(empty_template)) parent_snippet = {'DeletionPolicy': {'Fn::Join': ['eta', ['R', 'in']]}} parent_tmpl = parent_resource.stack.t.parse(parent_resource.stack, @@ -570,14 +572,15 @@ Mappings: parent_resource.t = parent_tmpl stack = parser.Stack(self.ctx, 'test_stack', - parser.Template({}), + parser.Template(empty_template), parent_resource=parent_resource) self.assertEqual('Retain', self.resolve(deletion_policy_snippet, stack.t, stack)) def test_resource_facade_invalid_arg(self): snippet = {'Fn::ResourceFacade': 'wibble'} - stack = parser.Stack(self.ctx, 'test_stack', parser.Template({})) + stack = parser.Stack(self.ctx, 'test_stack', + parser.Template(empty_template)) error = self.assertRaises(ValueError, self.resolve, snippet, @@ -589,17 +592,18 @@ Mappings: parent_resource = DummyClass() parent_resource.metadata_set({"foo": "bar"}) - parent_resource.t = {} + parent_resource.t = {'HeatTemplateFormatVersion': '2012-12-12'} parent_resource.stack = parser.Stack(self.ctx, 'toplevel_stack', - parser.Template({})) + parser.Template(empty_template)) stack = parser.Stack(self.ctx, 'test_stack', - parser.Template({}), + parser.Template(empty_template), parent_resource=parent_resource) self.assertEqual('Delete', self.resolve(snippet, stack.t, stack)) def test_prevent_parameters_access(self): expected_description = "This can be accessed" - tmpl = parser.Template({'Description': expected_description, + tmpl = parser.Template({'AWSTemplateFormatVersion': '2010-09-09', + 'Description': expected_description, 'Parameters': {'foo': {'Type': 'String', 'Required': True}}}) self.assertEqual(expected_description, tmpl['Description']) @@ -747,14 +751,15 @@ class ResolveDataTest(HeatTestCase): self.ctx = utils.dummy_context() self.stack = parser.Stack(self.ctx, 'resolve_test_stack', - template.Template({}), + template.Template(empty_template), environment.Environment({})) def resolve(self, snippet): return function.resolve(self.stack.t.parse(self.stack, snippet)) def test_stack_resolve_runtime_data_deprecated(self): - stack = parser.Stack(self.ctx, 'test_stack', parser.Template({}), + stack = parser.Stack(self.ctx, 'test_stack', + parser.Template(empty_template), tenant_id='bar') with warnings.catch_warnings(record=True) as ws: @@ -865,6 +870,7 @@ class StackTest(HeatTestCase): super(StackTest, self).setUp() self.username = 'parser_stack_test_user' + self.tmpl = parser.Template(empty_template) self.ctx = utils.dummy_context() @@ -878,35 +884,35 @@ class StackTest(HeatTestCase): self.m.ReplayAll() def test_stack_reads_tenant(self): - stack = parser.Stack(self.ctx, 'test_stack', parser.Template({}), + stack = parser.Stack(self.ctx, 'test_stack', self.tmpl, tenant_id='bar') self.assertEqual('bar', stack.tenant_id) def test_stack_reads_tenant_from_context_if_empty(self): self.ctx.tenant_id = 'foo' - stack = parser.Stack(self.ctx, 'test_stack', parser.Template({}), + stack = parser.Stack(self.ctx, 'test_stack', self.tmpl, tenant_id=None) self.assertEqual('foo', stack.tenant_id) def test_stack_string_repr(self): - stack = parser.Stack(self.ctx, 'test_stack', parser.Template({})) + stack = parser.Stack(self.ctx, 'test_stack', self.tmpl) expected = 'Stack "%s" [%s]' % (stack.name, stack.id) observed = str(stack) self.assertEqual(expected, observed) def test_state_defaults(self): - stack = parser.Stack(self.ctx, 'test_stack', parser.Template({})) + stack = parser.Stack(self.ctx, 'test_stack', self.tmpl) self.assertEqual((None, None), stack.state) self.assertEqual('', stack.status_reason) def test_timeout_secs_default(self): cfg.CONF.set_override('stack_action_timeout', 1000) - stack = parser.Stack(self.ctx, 'test_stack', parser.Template({})) + stack = parser.Stack(self.ctx, 'test_stack', self.tmpl) self.assertIsNone(stack.timeout_mins) self.assertEqual(1000, stack.timeout_secs()) def test_timeout_secs(self): - stack = parser.Stack(self.ctx, 'test_stack', parser.Template({}), + stack = parser.Stack(self.ctx, 'test_stack', self.tmpl, timeout_mins=10) self.assertEqual(600, stack.timeout_secs()) @@ -918,13 +924,13 @@ class StackTest(HeatTestCase): FakeKeystoneClient()) self.m.ReplayAll() - stack = parser.Stack(ctx, 'test_stack', parser.Template({})) + stack = parser.Stack(ctx, 'test_stack', self.tmpl) self.assertEqual('abcd1234', stack.clients.auth_token) self.m.VerifyAll() def test_state(self): - stack = parser.Stack(self.ctx, 'test_stack', parser.Template({}), + stack = parser.Stack(self.ctx, 'test_stack', self.tmpl, action=parser.Stack.CREATE, status=parser.Stack.IN_PROGRESS) self.assertEqual((parser.Stack.CREATE, parser.Stack.IN_PROGRESS), @@ -937,7 +943,7 @@ class StackTest(HeatTestCase): stack.state) def test_state_deleted(self): - stack = parser.Stack(self.ctx, 'test_stack', parser.Template({}), + stack = parser.Stack(self.ctx, 'test_stack', self.tmpl, action=parser.Stack.CREATE, status=parser.Stack.IN_PROGRESS) stack.id = '1234' @@ -953,7 +959,7 @@ class StackTest(HeatTestCase): self.m.VerifyAll() def test_state_bad(self): - stack = parser.Stack(self.ctx, 'test_stack', parser.Template({}), + stack = parser.Stack(self.ctx, 'test_stack', self.tmpl, action=parser.Stack.CREATE, status=parser.Stack.IN_PROGRESS) self.assertEqual((parser.Stack.CREATE, parser.Stack.IN_PROGRESS), @@ -964,7 +970,7 @@ class StackTest(HeatTestCase): parser.Stack.CREATE, 'oops', 'test') def test_status_reason(self): - stack = parser.Stack(self.ctx, 'test_stack', parser.Template({}), + stack = parser.Stack(self.ctx, 'test_stack', self.tmpl, status_reason='quux') self.assertEqual('quux', stack.status_reason) stack.state_set(parser.Stack.CREATE, parser.Stack.IN_PROGRESS, @@ -976,12 +982,13 @@ class StackTest(HeatTestCase): None, -1) def test_total_resources_empty(self): - stack = parser.Stack(self.ctx, 'test_stack', parser.Template({}), + stack = parser.Stack(self.ctx, 'test_stack', self.tmpl, status_reason='flimflam') self.assertEqual(0, stack.total_resources()) def test_total_resources_generic(self): - tpl = {'Resources': + tpl = {'HeatTemplateFormatVersion': '2012-12-12', + 'Resources': {'A': {'Type': 'GenericResourceType'}}} stack = parser.Stack(self.ctx, 'test_stack', parser.Template(tpl), status_reason='blarg') @@ -1025,7 +1032,7 @@ class StackTest(HeatTestCase): def test_load_parent_resource(self): self.stack = parser.Stack(self.ctx, 'load_parent_resource', - parser.Template({})) + self.tmpl) self.stack.store() stack = db_api.stack_get(self.ctx, self.stack.id) @@ -1060,7 +1067,7 @@ class StackTest(HeatTestCase): # to ensure the self.stack is properly cleaned up def test_identifier(self): self.stack = parser.Stack(self.ctx, 'identifier_test', - parser.Template({})) + self.tmpl) self.stack.store() identifier = self.stack.identifier() self.assertEqual(self.stack.tenant_id, identifier.tenant) @@ -1069,7 +1076,8 @@ class StackTest(HeatTestCase): self.assertFalse(identifier.path) def test_get_stack_abandon_data(self): - tpl = {'Resources': + tpl = {'HeatTemplateFormatVersion': '2012-12-12', + 'Resources': {'A': {'Type': 'GenericResourceType'}, 'B': {'Type': 'GenericResourceType'}}} resources = '''{"A": {"status": "COMPLETE", "name": "A", @@ -1091,7 +1099,7 @@ class StackTest(HeatTestCase): def test_set_param_id(self): self.stack = parser.Stack(self.ctx, 'param_arn_test', - parser.Template({})) + self.tmpl) exp_prefix = ('arn:openstack:heat::test_tenant_id' ':stacks/param_arn_test/') self.assertEqual(self.stack.parameters['AWS::StackId'], @@ -1105,7 +1113,8 @@ class StackTest(HeatTestCase): self.m.VerifyAll() def test_set_param_id_update(self): - tmpl = {'Resources': { + tmpl = {'HeatTemplateFormatVersion': '2012-12-12', + 'Resources': { 'AResource': {'Type': 'ResourceWithPropsType', 'Metadata': {'Bar': {'Ref': 'AWS::StackId'}}, 'Properties': {'Foo': 'abc'}}}} @@ -1119,7 +1128,8 @@ class StackTest(HeatTestCase): stack_arn = self.stack.parameters['AWS::StackId'] - tmpl2 = {'Resources': { + tmpl2 = {'HeatTemplateFormatVersion': '2012-12-12', + 'Resources': { 'AResource': {'Type': 'ResourceWithPropsType', 'Metadata': {'Bar': {'Ref': 'AWS::StackId'}}, 'Properties': {'Foo': 'xyz'}}}} @@ -1137,7 +1147,7 @@ class StackTest(HeatTestCase): def test_load_param_id(self): self.stack = parser.Stack(self.ctx, 'param_load_arn_test', - parser.Template({})) + self.tmpl) self.stack.store() identifier = self.stack.identifier() self.assertEqual(self.stack.parameters['AWS::StackId'], @@ -1148,7 +1158,7 @@ class StackTest(HeatTestCase): def test_load_reads_tenant_id(self): self.ctx.tenant_id = 'foobar' - self.stack = parser.Stack(self.ctx, 'stack_name', parser.Template({})) + self.stack = parser.Stack(self.ctx, 'stack_name', self.tmpl) self.stack.store() stack_id = self.stack.id self.ctx.tenant_id = None @@ -1157,26 +1167,28 @@ class StackTest(HeatTestCase): def test_created_time(self): self.stack = parser.Stack(self.ctx, 'creation_time_test', - parser.Template({})) + self.tmpl) self.assertIsNone(self.stack.created_time) self.stack.store() self.assertIsNotNone(self.stack.created_time) def test_updated_time(self): self.stack = parser.Stack(self.ctx, 'updated_time_test', - parser.Template({})) + self.tmpl) self.assertIsNone(self.stack.updated_time) self.stack.store() self.stack.create() - tmpl = {'Resources': {'R1': {'Type': 'GenericResourceType'}}} + tmpl = {'HeatTemplateFormatVersion': '2012-12-12', + 'Resources': {'R1': {'Type': 'GenericResourceType'}}} newstack = parser.Stack(self.ctx, 'updated_time_test', parser.Template(tmpl)) self.stack.update(newstack) self.assertIsNotNone(self.stack.updated_time) def test_access_policy_update(self): - tmpl = {'Resources': { + tmpl = {'HeatTemplateFormatVersion': '2012-12-12', + 'Resources': { 'R1': {'Type': 'GenericResourceType'}, 'Policy': { 'Type': 'OS::Heat::AccessPolicy', @@ -1192,7 +1204,8 @@ class StackTest(HeatTestCase): self.assertEqual((parser.Stack.CREATE, parser.Stack.COMPLETE), self.stack.state) - tmpl2 = {'Resources': { + tmpl2 = {'HeatTemplateFormatVersion': '2012-12-12', + 'Resources': { 'R1': {'Type': 'GenericResourceType'}, 'R2': {'Type': 'GenericResourceType'}, 'Policy': { @@ -1211,7 +1224,7 @@ class StackTest(HeatTestCase): def test_delete(self): self.stack = parser.Stack(self.ctx, 'delete_test', - parser.Template({})) + self.tmpl) stack_id = self.stack.store() db_s = db_api.stack_get(self.ctx, stack_id) @@ -1226,7 +1239,7 @@ class StackTest(HeatTestCase): def test_delete_user_creds(self): self.stack = parser.Stack(self.ctx, 'delete_test', - parser.Template({})) + self.tmpl) stack_id = self.stack.store() db_s = db_api.stack_get(self.ctx, stack_id) @@ -1256,7 +1269,7 @@ class StackTest(HeatTestCase): self.m.ReplayAll() self.stack = parser.Stack( - self.ctx, 'delete_trust', template.Template({})) + self.ctx, 'delete_trust', self.tmpl) stack_id = self.stack.store() db_s = db_api.stack_get(self.ctx, stack_id) @@ -1282,7 +1295,7 @@ class StackTest(HeatTestCase): self.m.ReplayAll() self.stack = parser.Stack( - self.ctx, 'delete_trust', template.Template({})) + self.ctx, 'delete_trust', self.tmpl) stack_id = self.stack.store() db_s = db_api.stack_get(self.ctx, stack_id) @@ -1308,7 +1321,7 @@ class StackTest(HeatTestCase): self.m.ReplayAll() self.stack = parser.Stack( - self.ctx, 'delete_trust', template.Template({})) + self.ctx, 'delete_trust', self.tmpl) stack_id = self.stack.store() db_s = db_api.stack_get(self.ctx, stack_id) @@ -1324,7 +1337,8 @@ class StackTest(HeatTestCase): def test_suspend_resume(self): self.m.ReplayAll() - tmpl = {'Resources': {'AResource': {'Type': 'GenericResourceType'}}} + tmpl = {'HeatTemplateFormatVersion': '2012-12-12', + 'Resources': {'AResource': {'Type': 'GenericResourceType'}}} self.stack = parser.Stack(self.ctx, 'suspend_test', parser.Template(tmpl)) self.stack.store() @@ -1345,7 +1359,8 @@ class StackTest(HeatTestCase): self.m.VerifyAll() def test_suspend_stack_suspended_ok(self): - tmpl = {'Resources': {'AResource': {'Type': 'GenericResourceType'}}} + tmpl = {'HeatTemplateFormatVersion': '2012-12-12', + 'Resources': {'AResource': {'Type': 'GenericResourceType'}}} self.stack = parser.Stack(self.ctx, 'suspend_test', parser.Template(tmpl)) self.stack.store() @@ -1367,7 +1382,8 @@ class StackTest(HeatTestCase): self.m.VerifyAll() def test_resume_stack_resumeed_ok(self): - tmpl = {'Resources': {'AResource': {'Type': 'GenericResourceType'}}} + tmpl = {'HeatTemplateFormatVersion': '2012-12-12', + 'Resources': {'AResource': {'Type': 'GenericResourceType'}}} self.stack = parser.Stack(self.ctx, 'suspend_test', parser.Template(tmpl)) self.stack.store() @@ -1393,7 +1409,8 @@ class StackTest(HeatTestCase): self.m.VerifyAll() def test_suspend_fail(self): - tmpl = {'Resources': {'AResource': {'Type': 'GenericResourceType'}}} + tmpl = {'HeatTemplateFormatVersion': '2012-12-12', + 'Resources': {'AResource': {'Type': 'GenericResourceType'}}} self.m.StubOutWithMock(generic_rsrc.GenericResource, 'handle_suspend') exc = Exception('foo') generic_rsrc.GenericResource.handle_suspend().AndRaise(exc) @@ -1416,7 +1433,8 @@ class StackTest(HeatTestCase): self.m.VerifyAll() def test_resume_fail(self): - tmpl = {'Resources': {'AResource': {'Type': 'GenericResourceType'}}} + tmpl = {'HeatTemplateFormatVersion': '2012-12-12', + 'Resources': {'AResource': {'Type': 'GenericResourceType'}}} self.m.StubOutWithMock(generic_rsrc.GenericResource, 'handle_resume') generic_rsrc.GenericResource.handle_resume().AndRaise(Exception('foo')) self.m.ReplayAll() @@ -1443,7 +1461,8 @@ class StackTest(HeatTestCase): self.m.VerifyAll() def test_suspend_timeout(self): - tmpl = {'Resources': {'AResource': {'Type': 'GenericResourceType'}}} + tmpl = {'HeatTemplateFormatVersion': '2012-12-12', + 'Resources': {'AResource': {'Type': 'GenericResourceType'}}} self.m.StubOutWithMock(generic_rsrc.GenericResource, 'handle_suspend') exc = scheduler.Timeout('foo', 0) generic_rsrc.GenericResource.handle_suspend().AndRaise(exc) @@ -1465,7 +1484,8 @@ class StackTest(HeatTestCase): self.m.VerifyAll() def test_resume_timeout(self): - tmpl = {'Resources': {'AResource': {'Type': 'GenericResourceType'}}} + tmpl = {'HeatTemplateFormatVersion': '2012-12-12', + 'Resources': {'AResource': {'Type': 'GenericResourceType'}}} self.m.StubOutWithMock(generic_rsrc.GenericResource, 'handle_resume') exc = scheduler.Timeout('foo', 0) generic_rsrc.GenericResource.handle_resume().AndRaise(exc) @@ -1494,7 +1514,7 @@ class StackTest(HeatTestCase): def test_delete_rollback(self): self.stack = parser.Stack(self.ctx, 'delete_rollback_test', - parser.Template({}), disable_rollback=False) + self.tmpl, disable_rollback=False) stack_id = self.stack.store() db_s = db_api.stack_get(self.ctx, stack_id) @@ -1509,7 +1529,7 @@ class StackTest(HeatTestCase): def test_delete_badaction(self): self.stack = parser.Stack(self.ctx, 'delete_badaction_test', - parser.Template({})) + self.tmpl) stack_id = self.stack.store() db_s = db_api.stack_get(self.ctx, stack_id) @@ -1541,6 +1561,7 @@ class StackTest(HeatTestCase): }''' tmpl = { + 'HeatTemplateFormatVersion': '2012-12-12', 'Resources': {'AResource': {'Type': 'GenericResourceType'}}, 'Outputs': {'TestOutput': {'Value': { 'Fn::GetAtt': ['AResource', 'Foo']}} @@ -1570,6 +1591,7 @@ class StackTest(HeatTestCase): }''' tmpl = template.Template({ + 'HeatTemplateFormatVersion': '2012-12-12', 'Resources': { 'foo': {'Type': 'GenericResourceType'}, @@ -1593,6 +1615,7 @@ class StackTest(HeatTestCase): }''' tmpl = template.Template({ + 'HeatTemplateFormatVersion': '2012-12-12', 'Resources': { 'foo': {'Type': 'GenericResourceType'}, @@ -1609,7 +1632,7 @@ class StackTest(HeatTestCase): self.stack.state) def test_update_badstate(self): - self.stack = parser.Stack(self.ctx, 'test_stack', parser.Template({}), + self.stack = parser.Stack(self.ctx, 'test_stack', self.tmpl, action=parser.Stack.CREATE, status=parser.Stack.FAILED) self.stack.store() @@ -1620,7 +1643,8 @@ class StackTest(HeatTestCase): self.stack.state) def test_resource_by_refid(self): - tmpl = {'Resources': {'AResource': {'Type': 'GenericResourceType'}}} + tmpl = {'HeatTemplateFormatVersion': '2012-12-12', + 'Resources': {'AResource': {'Type': 'GenericResourceType'}}} self.stack = parser.Stack(self.ctx, 'resource_by_refid_stack', template.Template(tmpl)) @@ -1652,7 +1676,8 @@ class StackTest(HeatTestCase): rsrc.state_set(rsrc.CREATE, rsrc.COMPLETE) def test_update_add(self): - tmpl = {'Resources': {'AResource': {'Type': 'GenericResourceType'}}} + tmpl = {'HeatTemplateFormatVersion': '2012-12-12', + 'Resources': {'AResource': {'Type': 'GenericResourceType'}}} self.stack = parser.Stack(self.ctx, 'update_test_stack', template.Template(tmpl)) @@ -1661,7 +1686,8 @@ class StackTest(HeatTestCase): self.assertEqual((parser.Stack.CREATE, parser.Stack.COMPLETE), self.stack.state) - tmpl2 = {'Resources': { + tmpl2 = {'HeatTemplateFormatVersion': '2012-12-12', + 'Resources': { 'AResource': {'Type': 'GenericResourceType'}, 'BResource': {'Type': 'GenericResourceType'}}} updated_stack = parser.Stack(self.ctx, 'updated_stack', @@ -1672,7 +1698,8 @@ class StackTest(HeatTestCase): self.assertIn('BResource', self.stack) def test_update_remove(self): - tmpl = {'Resources': { + tmpl = {'HeatTemplateFormatVersion': '2012-12-12', + 'Resources': { 'AResource': {'Type': 'GenericResourceType'}, 'BResource': {'Type': 'GenericResourceType'}}} @@ -1683,7 +1710,8 @@ class StackTest(HeatTestCase): self.assertEqual((parser.Stack.CREATE, parser.Stack.COMPLETE), self.stack.state) - tmpl2 = {'Resources': {'AResource': {'Type': 'GenericResourceType'}}} + tmpl2 = {'HeatTemplateFormatVersion': '2012-12-12', + 'Resources': {'AResource': {'Type': 'GenericResourceType'}}} updated_stack = parser.Stack(self.ctx, 'updated_stack', template.Template(tmpl2)) @@ -1693,7 +1721,8 @@ class StackTest(HeatTestCase): self.assertNotIn('BResource', self.stack) def test_update_description(self): - tmpl = {'Description': 'ATemplate', + tmpl = {'HeatTemplateFormatVersion': '2012-12-12', + 'Description': 'ATemplate', 'Resources': {'AResource': {'Type': 'GenericResourceType'}}} self.stack = parser.Stack(self.ctx, 'update_test_stack', @@ -1703,7 +1732,8 @@ class StackTest(HeatTestCase): self.assertEqual((parser.Stack.CREATE, parser.Stack.COMPLETE), self.stack.state) - tmpl2 = {'Description': 'BTemplate', + tmpl2 = {'HeatTemplateFormatVersion': '2012-12-12', + 'Description': 'BTemplate', 'Resources': {'AResource': {'Type': 'GenericResourceType'}}} updated_stack = parser.Stack(self.ctx, 'updated_stack', @@ -1738,7 +1768,8 @@ class StackTest(HeatTestCase): self.assertEqual(30, self.stack.timeout_mins) def test_update_disable_rollback(self): - tmpl = {'Description': 'ATemplate', + tmpl = {'HeatTemplateFormatVersion': '2012-12-12', + 'Description': 'ATemplate', 'Resources': {'AResource': {'Type': 'GenericResourceType'}}} self.stack = parser.Stack(self.ctx, 'update_test_stack', @@ -1749,7 +1780,8 @@ class StackTest(HeatTestCase): self.assertEqual((parser.Stack.CREATE, parser.Stack.COMPLETE), self.stack.state) - tmpl2 = {'Description': 'ATemplate', + tmpl2 = {'HeatTemplateFormatVersion': '2012-12-12', + 'Description': 'ATemplate', 'Resources': {'AResource': {'Type': 'GenericResourceType'}}} updated_stack = parser.Stack(self.ctx, 'updated_stack', @@ -1761,7 +1793,8 @@ class StackTest(HeatTestCase): self.assertEqual(True, self.stack.disable_rollback) def test_update_modify_ok_replace(self): - tmpl = {'Resources': {'AResource': {'Type': 'ResourceWithPropsType', + tmpl = {'HeatTemplateFormatVersion': '2012-12-12', + 'Resources': {'AResource': {'Type': 'ResourceWithPropsType', 'Properties': {'Foo': 'abc'}}}} self.stack = parser.Stack(self.ctx, 'update_test_stack', @@ -1771,7 +1804,8 @@ class StackTest(HeatTestCase): self.assertEqual((parser.Stack.CREATE, parser.Stack.COMPLETE), self.stack.state) - tmpl2 = {'Resources': {'AResource': {'Type': 'ResourceWithPropsType', + tmpl2 = {'HeatTemplateFormatVersion': '2012-12-12', + 'Resources': {'AResource': {'Type': 'ResourceWithPropsType', 'Properties': {'Foo': 'xyz'}}}} updated_stack = parser.Stack(self.ctx, 'updated_stack', @@ -1835,7 +1869,8 @@ class StackTest(HeatTestCase): self.m.VerifyAll() def test_update_modify_update_failed(self): - tmpl = {'Resources': {'AResource': {'Type': 'ResourceWithPropsType', + tmpl = {'HeatTemplateFormatVersion': '2012-12-12', + 'Resources': {'AResource': {'Type': 'ResourceWithPropsType', 'Properties': {'Foo': 'abc'}}}} self.stack = parser.Stack(self.ctx, 'update_test_stack', @@ -1850,7 +1885,8 @@ class StackTest(HeatTestCase): res.update_allowed_keys = ('Properties',) res.update_allowed_properties = ('Foo',) - tmpl2 = {'Resources': {'AResource': {'Type': 'ResourceWithPropsType', + tmpl2 = {'HeatTemplateFormatVersion': '2012-12-12', + 'Resources': {'AResource': {'Type': 'ResourceWithPropsType', 'Properties': {'Foo': 'xyz'}}}} updated_stack = parser.Stack(self.ctx, 'updated_stack', @@ -1871,7 +1907,8 @@ class StackTest(HeatTestCase): self.m.VerifyAll() def test_update_modify_replace_failed_delete(self): - tmpl = {'Resources': {'AResource': {'Type': 'ResourceWithPropsType', + tmpl = {'HeatTemplateFormatVersion': '2012-12-12', + 'Resources': {'AResource': {'Type': 'ResourceWithPropsType', 'Properties': {'Foo': 'abc'}}}} self.stack = parser.Stack(self.ctx, 'update_test_stack', @@ -1882,7 +1919,8 @@ class StackTest(HeatTestCase): self.assertEqual((parser.Stack.CREATE, parser.Stack.COMPLETE), self.stack.state) - tmpl2 = {'Resources': {'AResource': {'Type': 'ResourceWithPropsType', + tmpl2 = {'HeatTemplateFormatVersion': '2012-12-12', + 'Resources': {'AResource': {'Type': 'ResourceWithPropsType', 'Properties': {'Foo': 'xyz'}}}} updated_stack = parser.Stack(self.ctx, 'updated_stack', @@ -1905,7 +1943,8 @@ class StackTest(HeatTestCase): self.m.UnsetStubs() def test_update_modify_replace_failed_create(self): - tmpl = {'Resources': {'AResource': {'Type': 'ResourceWithPropsType', + tmpl = {'HeatTemplateFormatVersion': '2012-12-12', + 'Resources': {'AResource': {'Type': 'ResourceWithPropsType', 'Properties': {'Foo': 'abc'}}}} self.stack = parser.Stack(self.ctx, 'update_test_stack', @@ -1916,7 +1955,8 @@ class StackTest(HeatTestCase): self.assertEqual((parser.Stack.CREATE, parser.Stack.COMPLETE), self.stack.state) - tmpl2 = {'Resources': {'AResource': {'Type': 'ResourceWithPropsType', + tmpl2 = {'HeatTemplateFormatVersion': '2012-12-12', + 'Resources': {'AResource': {'Type': 'ResourceWithPropsType', 'Properties': {'Foo': 'xyz'}}}} updated_stack = parser.Stack(self.ctx, 'updated_stack', @@ -1937,7 +1977,8 @@ class StackTest(HeatTestCase): self.m.VerifyAll() def test_update_add_failed_create(self): - tmpl = {'Resources': {'AResource': {'Type': 'GenericResourceType'}}} + tmpl = {'HeatTemplateFormatVersion': '2012-12-12', + 'Resources': {'AResource': {'Type': 'GenericResourceType'}}} self.stack = parser.Stack(self.ctx, 'update_test_stack', template.Template(tmpl)) @@ -1946,7 +1987,8 @@ class StackTest(HeatTestCase): self.assertEqual((parser.Stack.CREATE, parser.Stack.COMPLETE), self.stack.state) - tmpl2 = {'Resources': { + tmpl2 = {'HeatTemplateFormatVersion': '2012-12-12', + 'Resources': { 'AResource': {'Type': 'GenericResourceType'}, 'BResource': {'Type': 'GenericResourceType'}}} updated_stack = parser.Stack(self.ctx, 'updated_stack', @@ -1969,7 +2011,8 @@ class StackTest(HeatTestCase): self.m.VerifyAll() def test_update_rollback(self): - tmpl = {'Resources': {'AResource': {'Type': 'ResourceWithPropsType', + tmpl = {'HeatTemplateFormatVersion': '2012-12-12', + 'Resources': {'AResource': {'Type': 'ResourceWithPropsType', 'Properties': {'Foo': 'abc'}}}} self.stack = parser.Stack(self.ctx, 'update_test_stack', @@ -1980,7 +2023,8 @@ class StackTest(HeatTestCase): self.assertEqual((parser.Stack.CREATE, parser.Stack.COMPLETE), self.stack.state) - tmpl2 = {'Resources': {'AResource': {'Type': 'ResourceWithPropsType', + tmpl2 = {'HeatTemplateFormatVersion': '2012-12-12', + 'Resources': {'AResource': {'Type': 'ResourceWithPropsType', 'Properties': {'Foo': 'xyz'}}}} updated_stack = parser.Stack(self.ctx, 'updated_stack', @@ -2004,7 +2048,8 @@ class StackTest(HeatTestCase): self.m.VerifyAll() def test_update_rollback_fail(self): - tmpl = {'Resources': {'AResource': {'Type': 'ResourceWithPropsType', + tmpl = {'HeatTemplateFormatVersion': '2012-12-12', + 'Resources': {'AResource': {'Type': 'ResourceWithPropsType', 'Properties': {'Foo': 'abc'}}}} self.stack = parser.Stack(self.ctx, 'update_test_stack', @@ -2015,7 +2060,8 @@ class StackTest(HeatTestCase): self.assertEqual((parser.Stack.CREATE, parser.Stack.COMPLETE), self.stack.state) - tmpl2 = {'Resources': {'AResource': {'Type': 'ResourceWithPropsType', + tmpl2 = {'HeatTemplateFormatVersion': '2012-12-12', + 'Resources': {'AResource': {'Type': 'ResourceWithPropsType', 'Properties': {'Foo': 'xyz'}}}} updated_stack = parser.Stack(self.ctx, 'updated_stack', @@ -2040,7 +2086,8 @@ class StackTest(HeatTestCase): self.m.VerifyAll() def test_update_rollback_add(self): - tmpl = {'Resources': {'AResource': {'Type': 'GenericResourceType'}}} + tmpl = {'HeatTemplateFormatVersion': '2012-12-12', + 'Resources': {'AResource': {'Type': 'GenericResourceType'}}} self.stack = parser.Stack(self.ctx, 'update_test_stack', template.Template(tmpl), @@ -2050,7 +2097,8 @@ class StackTest(HeatTestCase): self.assertEqual((parser.Stack.CREATE, parser.Stack.COMPLETE), self.stack.state) - tmpl2 = {'Resources': { + tmpl2 = {'HeatTemplateFormatVersion': '2012-12-12', + 'Resources': { 'AResource': {'Type': 'GenericResourceType'}, 'BResource': {'Type': 'GenericResourceType'}}} @@ -2071,7 +2119,8 @@ class StackTest(HeatTestCase): self.m.VerifyAll() def test_update_rollback_remove(self): - tmpl = {'Resources': { + tmpl = {'HeatTemplateFormatVersion': '2012-12-12', + 'Resources': { 'AResource': {'Type': 'GenericResourceType'}, 'BResource': {'Type': 'ResourceWithPropsType'}}} @@ -2083,7 +2132,8 @@ class StackTest(HeatTestCase): self.assertEqual((parser.Stack.CREATE, parser.Stack.COMPLETE), self.stack.state) - tmpl2 = {'Resources': {'AResource': {'Type': 'GenericResourceType'}}} + tmpl2 = {'HeatTemplateFormatVersion': '2012-12-12', + 'Resources': {'AResource': {'Type': 'GenericResourceType'}}} updated_stack = parser.Stack(self.ctx, 'updated_stack', template.Template(tmpl2), @@ -2104,7 +2154,8 @@ class StackTest(HeatTestCase): self.m.UnsetStubs() def test_update_rollback_replace(self): - tmpl = {'Resources': { + tmpl = {'HeatTemplateFormatVersion': '2012-12-12', + 'Resources': { 'AResource': {'Type': 'ResourceWithPropsType', 'Properties': {'Foo': 'foo'}}}} @@ -2116,7 +2167,8 @@ class StackTest(HeatTestCase): self.assertEqual((parser.Stack.CREATE, parser.Stack.COMPLETE), self.stack.state) - tmpl2 = {'Resources': {'AResource': {'Type': 'ResourceWithPropsType', + tmpl2 = {'HeatTemplateFormatVersion': '2012-12-12', + 'Resources': {'AResource': {'Type': 'ResourceWithPropsType', 'Properties': {'Foo': 'bar'}}}} updated_stack = parser.Stack(self.ctx, 'updated_stack', @@ -2143,13 +2195,15 @@ class StackTest(HeatTestCase): changes in dynamic attributes, due to other resources been updated are not ignored and can cause dependent resources to be updated. ''' - tmpl = {'Resources': { + tmpl = {'HeatTemplateFormatVersion': '2012-12-12', + 'Resources': { 'AResource': {'Type': 'ResourceWithPropsType', 'Properties': {'Foo': 'abc'}}, 'BResource': {'Type': 'ResourceWithPropsType', 'Properties': { 'Foo': {'Ref': 'AResource'}}}}} - tmpl2 = {'Resources': { + tmpl2 = {'HeatTemplateFormatVersion': '2012-12-12', + 'Resources': { 'AResource': {'Type': 'ResourceWithPropsType', 'Properties': {'Foo': 'smelly'}}, 'BResource': {'Type': 'ResourceWithPropsType', @@ -2196,10 +2250,12 @@ class StackTest(HeatTestCase): check, that during update with new resources which one has reference on second, reference will be correct resolved. ''' - tmpl = {'Resources': { + tmpl = {'HeatTemplateFormatVersion': '2012-12-12', + 'Resources': { 'CResource': {'Type': 'ResourceWithPropsType', 'Properties': {'Foo': 'abc'}}}} - tmpl2 = {'Resources': { + tmpl2 = {'HeatTemplateFormatVersion': '2012-12-12', + 'Resources': { 'CResource': {'Type': 'ResourceWithPropsType', 'Properties': {'Foo': 'abc'}}, 'AResource': {'Type': 'ResourceWithPropsType', @@ -2247,13 +2303,15 @@ class StackTest(HeatTestCase): check that rollback still works with dynamic metadata this test fails the first instance ''' - tmpl = {'Resources': { + tmpl = {'HeatTemplateFormatVersion': '2012-12-12', + 'Resources': { 'AResource': {'Type': 'ResourceWithPropsType', 'Properties': {'Foo': 'abc'}}, 'BResource': {'Type': 'ResourceWithPropsType', 'Properties': { 'Foo': {'Ref': 'AResource'}}}}} - tmpl2 = {'Resources': { + tmpl2 = {'HeatTemplateFormatVersion': '2012-12-12', + 'Resources': { 'AResource': {'Type': 'ResourceWithPropsType', 'Properties': {'Foo': 'smelly'}}, 'BResource': {'Type': 'ResourceWithPropsType', @@ -2317,13 +2375,15 @@ class StackTest(HeatTestCase): resource._register_class('ResourceTypeA', ResourceTypeA) - tmpl = {'Resources': { + tmpl = {'HeatTemplateFormatVersion': '2012-12-12', + 'Resources': { 'AResource': {'Type': 'ResourceTypeA', 'Properties': {'Foo': 'abc'}}, 'BResource': {'Type': 'ResourceWithPropsType', 'Properties': { 'Foo': {'Ref': 'AResource'}}}}} - tmpl2 = {'Resources': { + tmpl2 = {'HeatTemplateFormatVersion': '2012-12-12', + 'Resources': { 'AResource': {'Type': 'ResourceTypeA', 'Properties': {'Foo': 'smelly'}}, 'BResource': {'Type': 'ResourceWithPropsType', @@ -2376,7 +2436,8 @@ class StackTest(HeatTestCase): changes in static environment parameters are not ignored and can cause dependent resources to be updated. ''' - tmpl = {'Parameters': {'AParam': {'Type': 'String'}}, + tmpl = {'HeatTemplateFormatVersion': '2012-12-12', + 'Parameters': {'AParam': {'Type': 'String'}}, 'Resources': { 'AResource': {'Type': 'ResourceWithPropsType', 'Properties': {'Foo': {'Ref': 'AParam'}}}}} @@ -2405,7 +2466,7 @@ class StackTest(HeatTestCase): self.m.StubOutWithMock(scheduler.DependencyTaskGroup, '__call__') self.m.StubOutWithMock(scheduler, 'wallclock') - stack = parser.Stack(self.ctx, 's', parser.Template({})) + stack = parser.Stack(self.ctx, 's', self.tmpl) def dummy_task(): while True: @@ -2429,7 +2490,7 @@ class StackTest(HeatTestCase): def test_stack_delete_timeout(self): stack = parser.Stack(self.ctx, 'delete_test', - parser.Template({})) + self.tmpl) stack_id = stack.store() db_s = db_api.stack_get(self.ctx, stack_id) @@ -2457,7 +2518,8 @@ class StackTest(HeatTestCase): self.m.VerifyAll() def test_stack_delete_resourcefailure(self): - tmpl = {'Resources': {'AResource': {'Type': 'GenericResourceType'}}} + tmpl = {'HeatTemplateFormatVersion': '2012-12-12', + 'Resources': {'AResource': {'Type': 'GenericResourceType'}}} self.m.StubOutWithMock(generic_rsrc.GenericResource, 'handle_delete') exc = Exception('foo') generic_rsrc.GenericResource.handle_delete().AndRaise(exc) @@ -2480,55 +2542,56 @@ class StackTest(HeatTestCase): self.m.VerifyAll() def test_stack_name_valid(self): - stack = parser.Stack(self.ctx, 's', parser.Template({})) + stack = parser.Stack(self.ctx, 's', self.tmpl) self.assertIsInstance(stack, parser.Stack) - stack = parser.Stack(self.ctx, 'stack123', parser.Template({})) + stack = parser.Stack(self.ctx, 'stack123', self.tmpl) self.assertIsInstance(stack, parser.Stack) - stack = parser.Stack(self.ctx, 'test.stack', parser.Template({})) + stack = parser.Stack(self.ctx, 'test.stack', self.tmpl) self.assertIsInstance(stack, parser.Stack) - stack = parser.Stack(self.ctx, 'test_stack', parser.Template({})) + stack = parser.Stack(self.ctx, 'test_stack', self.tmpl) self.assertIsInstance(stack, parser.Stack) - stack = parser.Stack(self.ctx, 'TEST', parser.Template({})) + stack = parser.Stack(self.ctx, 'TEST', self.tmpl) self.assertIsInstance(stack, parser.Stack) - stack = parser.Stack(self.ctx, 'test-stack', parser.Template({})) + stack = parser.Stack(self.ctx, 'test-stack', self.tmpl) self.assertIsInstance(stack, parser.Stack) def test_stack_name_invalid(self): self.assertRaises(ValueError, parser.Stack, self.ctx, '_foo', - parser.Template({})) + self.tmpl) self.assertRaises(ValueError, parser.Stack, self.ctx, '1bad', - parser.Template({})) + self.tmpl) self.assertRaises(ValueError, parser.Stack, self.ctx, '.kcats', - parser.Template({})) + self.tmpl) self.assertRaises(ValueError, parser.Stack, self.ctx, 'test stack', - parser.Template({})) + self.tmpl) self.assertRaises(ValueError, parser.Stack, self.ctx, ' teststack', - parser.Template({})) + self.tmpl) self.assertRaises(ValueError, parser.Stack, self.ctx, '^-^', - parser.Template({})) + self.tmpl) self.assertRaises(ValueError, parser.Stack, self.ctx, '\"stack\"', - parser.Template({})) + self.tmpl) self.assertRaises(ValueError, parser.Stack, self.ctx, '1234', - parser.Template({})) + self.tmpl) self.assertRaises(ValueError, parser.Stack, self.ctx, 'cat|dog', - parser.Template({})) + self.tmpl) self.assertRaises(ValueError, parser.Stack, self.ctx, '$(foo)', - parser.Template({})) + self.tmpl) self.assertRaises(ValueError, parser.Stack, self.ctx, 'test/stack', - parser.Template({})) + self.tmpl) self.assertRaises(ValueError, parser.Stack, self.ctx, 'test\stack', - parser.Template({})) + self.tmpl) self.assertRaises(ValueError, parser.Stack, self.ctx, 'test::stack', - parser.Template({})) + self.tmpl) self.assertRaises(ValueError, parser.Stack, self.ctx, 'test;stack', - parser.Template({})) + self.tmpl) self.assertRaises(ValueError, parser.Stack, self.ctx, 'test~stack', - parser.Template({})) + self.tmpl) self.assertRaises(ValueError, parser.Stack, self.ctx, '#test', - parser.Template({})) + self.tmpl) def test_resource_state_get_att(self): tmpl = { + 'HeatTemplateFormatVersion': '2012-12-12', 'Resources': {'AResource': {'Type': 'GenericResourceType'}}, 'Outputs': {'TestOutput': {'Value': { 'Fn::GetAtt': ['AResource', 'Foo']}} @@ -2567,7 +2630,8 @@ class StackTest(HeatTestCase): self.assertIsNone(self.stack.output('TestOutput')) def test_resource_required_by(self): - tmpl = {'Resources': {'AResource': {'Type': 'GenericResourceType'}, + tmpl = {'HeatTemplateFormatVersion': '2012-12-12', + 'Resources': {'AResource': {'Type': 'GenericResourceType'}, 'BResource': {'Type': 'GenericResourceType', 'DependsOn': 'AResource'}, 'CResource': {'Type': 'GenericResourceType', @@ -2592,7 +2656,8 @@ class StackTest(HeatTestCase): self.assertIn(r, required_by) def test_resource_multi_required_by(self): - tmpl = {'Resources': {'AResource': {'Type': 'GenericResourceType'}, + tmpl = {'HeatTemplateFormatVersion': '2012-12-12', + 'Resources': {'AResource': {'Type': 'GenericResourceType'}, 'BResource': {'Type': 'GenericResourceType'}, 'CResource': {'Type': 'GenericResourceType'}, 'DResource': {'Type': 'GenericResourceType', @@ -2616,9 +2681,9 @@ class StackTest(HeatTestCase): The owner_id attribute of Store is saved to the database when stored. """ self.stack = parser.Stack( - self.ctx, 'owner_stack', template.Template({})) + self.ctx, 'owner_stack', self.tmpl) stack_ownee = parser.Stack( - self.ctx, 'ownee_stack', template.Template({}), + self.ctx, 'ownee_stack', self.tmpl, owner_id=self.stack.id) stack_ownee.store() db_stack = db_api.stack_get(self.ctx, stack_ownee.id) @@ -2629,7 +2694,7 @@ class StackTest(HeatTestCase): A user_creds entry is created on first stack store """ self.stack = parser.Stack( - self.ctx, 'creds_stack', template.Template({})) + self.ctx, 'creds_stack', self.tmpl) self.stack.store() # The store should've created a user_creds row and set user_creds_id @@ -2660,7 +2725,7 @@ class StackTest(HeatTestCase): self.m.ReplayAll() self.stack = parser.Stack( - self.ctx, 'creds_stack', template.Template({})) + self.ctx, 'creds_stack', self.tmpl) self.stack.store() # The store should've created a user_creds row and set user_creds_id @@ -2687,9 +2752,9 @@ class StackTest(HeatTestCase): resultant stack appropriately. """ self.stack = parser.Stack( - self.ctx, 'owner_stack', template.Template({})) + self.ctx, 'owner_stack', self.tmpl) stack_ownee = parser.Stack( - self.ctx, 'ownee_stack', template.Template({}), + self.ctx, 'ownee_stack', self.tmpl, owner_id=self.stack.id) stack_ownee.store() @@ -2697,7 +2762,8 @@ class StackTest(HeatTestCase): self.assertEqual(self.stack.id, saved_stack.owner_id) def test_requires_deferred_auth(self): - tmpl = {'Resources': {'AResource': {'Type': 'GenericResourceType'}, + tmpl = {'HeatTemplateFormatVersion': '2012-12-12', + 'Resources': {'AResource': {'Type': 'GenericResourceType'}, 'BResource': {'Type': 'GenericResourceType'}, 'CResource': {'Type': 'GenericResourceType'}}} @@ -2712,7 +2778,7 @@ class StackTest(HeatTestCase): def test_stack_user_project_id_default(self): self.stack = parser.Stack(self.ctx, 'user_project_none', - template.Template({})) + self.tmpl) self.stack.store() self.assertIsNone(self.stack.stack_user_project_id) db_stack = db_api.stack_get(self.ctx, self.stack.id) @@ -2724,7 +2790,7 @@ class StackTest(HeatTestCase): self.m.ReplayAll() self.stack = parser.Stack(self.ctx, 'user_project_init', - template.Template({}), + self.tmpl, stack_user_project_id='aproject1234') self.stack.store() self.assertEqual('aproject1234', self.stack.stack_user_project_id) @@ -2747,7 +2813,7 @@ class StackTest(HeatTestCase): self.m.ReplayAll() self.stack = parser.Stack(self.ctx, 'user_project_init', - template.Template({}), + self.tmpl, stack_user_project_id='aproject1234') self.stack.store() self.assertEqual('aproject1234', self.stack.stack_user_project_id) @@ -2766,7 +2832,7 @@ class StackTest(HeatTestCase): self.m.ReplayAll() self.stack = parser.Stack(self.ctx, 'user_project_init', - template.Template({})) + self.tmpl) self.stack.store() self.assertIsNone(self.stack.stack_user_project_id) self.stack.set_stack_user_project_id(project_id='aproject456') @@ -2780,7 +2846,8 @@ class StackTest(HeatTestCase): self.m.VerifyAll() def test_preview_resources_returns_list_of_resource_previews(self): - tmpl = {'Resources': {'AResource': {'Type': 'GenericResourceType'}}} + tmpl = {'HeatTemplateFormatVersion': '2012-12-12', + 'Resources': {'AResource': {'Type': 'GenericResourceType'}}} self.stack = parser.Stack(self.ctx, 'preview_stack', template.Template(tmpl)) res = mock.Mock() diff --git a/heat/tests/test_provider_template.py b/heat/tests/test_provider_template.py index 20be463f73..0ee9b32e48 100644 --- a/heat/tests/test_provider_template.py +++ b/heat/tests/test_provider_template.py @@ -31,6 +31,9 @@ from heat.tests import generic_resource as generic_rsrc from heat.tests import utils +empty_template = {"HeatTemplateFormatVersion": "2012-12-12"} + + class MyCloudResource(generic_rsrc.GenericResource): pass @@ -115,7 +118,8 @@ class ProviderTemplateTest(HeatTestCase): env.load({'resource_registry': {'DummyResource': 'test_resource.template'}}) 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())) map_prop_val = { @@ -174,7 +178,8 @@ class ProviderTemplateTest(HeatTestCase): env.load({'resource_registry': {'DummyResource': 'test_resource.template'}}) 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())) json_snippet = { @@ -187,6 +192,7 @@ class ProviderTemplateTest(HeatTestCase): def test_attributes_missing(self): provider = { + 'HeatTemplateFormatVersion': '2012-12-12', 'Outputs': { 'Blarg': {'Value': 'wibble'}, }, @@ -206,7 +212,8 @@ class ProviderTemplateTest(HeatTestCase): env.load({'resource_registry': {'DummyResource': 'test_resource.template'}}) 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())) temp_res = template_resource.TemplateResource('test_t_res', @@ -242,7 +249,8 @@ class ProviderTemplateTest(HeatTestCase): env.load({'resource_registry': {'DummyResource': 'test_resource.template'}}) 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())) temp_res = template_resource.TemplateResource('test_t_res', @@ -251,6 +259,7 @@ class ProviderTemplateTest(HeatTestCase): def test_properties_missing(self): provider = { + 'HeatTemplateFormatVersion': '2012-12-12', 'Parameters': { 'Blarg': {'Type': 'String', 'Default': 'wibble'}, }, @@ -272,7 +281,8 @@ class ProviderTemplateTest(HeatTestCase): env.load({'resource_registry': {'DummyResource': 'test_resource.template'}}) 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())) temp_res = template_resource.TemplateResource('test_t_res', @@ -282,6 +292,7 @@ class ProviderTemplateTest(HeatTestCase): def test_properties_extra_required(self): provider = { + 'HeatTemplateFormatVersion': '2012-12-12', 'Parameters': { 'Blarg': {'Type': 'String'}, }, @@ -304,7 +315,8 @@ class ProviderTemplateTest(HeatTestCase): env.load({'resource_registry': {'DummyResource': 'test_resource.template'}}) 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())) temp_res = template_resource.TemplateResource('test_t_res', @@ -337,7 +349,9 @@ class ProviderTemplateTest(HeatTestCase): env.load({'resource_registry': {'DummyResource': 'test_resource.template'}}) 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())) temp_res = template_resource.TemplateResource('test_t_res', @@ -411,7 +425,8 @@ class ProviderTemplateTest(HeatTestCase): } } 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, stack) self.m.VerifyAll() @@ -449,7 +464,7 @@ class ProviderTemplateTest(HeatTestCase): g_env.load({'resource_registry': {'Test::Frodo': test_templ_name}}) stack = parser.Stack(utils.dummy_context(), 'test_stack', - parser.Template({}), + parser.Template(empty_template), stack_id=str(uuid.uuid4())) minimal_temp = json.dumps({'HeatTemplateFormatVersion': '2012-12-12', @@ -475,7 +490,7 @@ class ProviderTemplateTest(HeatTestCase): env.load({'resource_registry': {'Test::Flippy': test_templ_name}}) stack = parser.Stack(utils.dummy_context(), 'test_stack', - parser.Template({}), env=env, + parser.Template(empty_template), env=env, stack_id=str(uuid.uuid4())) temp_res = template_resource.TemplateResource('test_t_res', @@ -495,7 +510,7 @@ class ProviderTemplateTest(HeatTestCase): g_env.load({'resource_registry': {'Test::Frodo': test_templ_name}}) stack = parser.Stack(utils.dummy_context(), 'test_stack', - parser.Template({}), + parser.Template(empty_template), stack_id=str(uuid.uuid4())) self.m.StubOutWithMock(urlfetch, "get") @@ -522,7 +537,7 @@ class ProviderTemplateTest(HeatTestCase): env.load({'resource_registry': {'Test::Flippy': test_templ_name}}) stack = parser.Stack(utils.dummy_context(), 'test_stack', - parser.Template({}), env=env, + parser.Template(empty_template), env=env, stack_id=str(uuid.uuid4())) self.m.StubOutWithMock(urlfetch, "get") @@ -548,7 +563,7 @@ class ProviderTemplateTest(HeatTestCase): env.load({'resource_registry': {'Test::Flippy': test_templ_name}}) stack = parser.Stack(utils.dummy_context(), 'test_stack', - parser.Template({}), env=env, + parser.Template(empty_template), env=env, stack_id=str(uuid.uuid4())) self.m.ReplayAll() diff --git a/heat/tests/test_resource.py b/heat/tests/test_resource.py index e91e6ad3a4..34b40f6e51 100644 --- a/heat/tests/test_resource.py +++ b/heat/tests/test_resource.py @@ -32,6 +32,9 @@ from heat.tests import generic_resource as generic_rsrc from heat.tests import utils +empty_template = {"HeatTemplateFormatVersion": "2012-12-12"} + + class ResourceTest(HeatTestCase): def setUp(self): super(ResourceTest, self).setUp() @@ -44,7 +47,7 @@ class ResourceTest(HeatTestCase): {u'OS::Test::GenericResource': u'GenericResourceType'}}) self.stack = parser.Stack(utils.dummy_context(), 'test_stack', - parser.Template({}), env=env, + parser.Template(empty_template), env=env, stack_id=str(uuid.uuid4())) def test_get_class_ok(self): @@ -295,7 +298,7 @@ class ResourceTest(HeatTestCase): tmpl2 = {'Type': 'Foo'} tmpl3 = {'Type': 'Bar'} 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) res2 = generic_rsrc.GenericResource('test_resource', tmpl2, stack2) res3 = generic_rsrc.GenericResource('test_resource2', tmpl3, stack2) @@ -747,6 +750,7 @@ class ResourceAdoptTest(HeatTestCase): def test_adopt_resource_success(self): adopt_data = '{}' tmpl = template.Template({ + 'HeatTemplateFormatVersion': '2012-12-12', 'Resources': { 'foo': {'Type': 'GenericResourceType'}, } @@ -773,6 +777,7 @@ class ResourceAdoptTest(HeatTestCase): def test_adopt_with_resource_data_and_metadata(self): adopt_data = '{}' tmpl = template.Template({ + 'HeatTemplateFormatVersion': '2012-12-12', 'Resources': { 'foo': {'Type': 'GenericResourceType'}, } @@ -806,6 +811,7 @@ class ResourceAdoptTest(HeatTestCase): "resources": {} }''' tmpl = template.Template({ + 'HeatTemplateFormatVersion': '2012-12-12', 'Resources': { 'foo': {'Type': 'GenericResourceType'}, } @@ -834,6 +840,7 @@ class ResourceDependenciesTest(HeatTestCase): def test_no_deps(self): tmpl = template.Template({ + 'HeatTemplateFormatVersion': '2012-12-12', 'Resources': { 'foo': {'Type': 'GenericResourceType'}, } @@ -848,6 +855,7 @@ class ResourceDependenciesTest(HeatTestCase): def test_ref(self): tmpl = template.Template({ + 'HeatTemplateFormatVersion': '2012-12-12', 'Resources': { 'foo': {'Type': 'GenericResourceType'}, 'bar': { @@ -892,6 +900,7 @@ class ResourceDependenciesTest(HeatTestCase): def test_ref_nested_dict(self): tmpl = template.Template({ + 'HeatTemplateFormatVersion': '2012-12-12', 'Resources': { 'foo': {'Type': 'GenericResourceType'}, 'bar': { @@ -935,6 +944,7 @@ class ResourceDependenciesTest(HeatTestCase): def test_ref_nested_deep(self): tmpl = template.Template({ + 'HeatTemplateFormatVersion': '2012-12-12', 'Resources': { 'foo': {'Type': 'GenericResourceType'}, 'bar': { @@ -982,6 +992,7 @@ class ResourceDependenciesTest(HeatTestCase): def test_ref_fail(self): tmpl = template.Template({ + 'HeatTemplateFormatVersion': '2012-12-12', 'Resources': { 'foo': {'Type': 'GenericResourceType'}, 'bar': { @@ -1017,6 +1028,7 @@ class ResourceDependenciesTest(HeatTestCase): def test_getatt(self): tmpl = template.Template({ + 'HeatTemplateFormatVersion': '2012-12-12', 'Resources': { 'foo': {'Type': 'GenericResourceType'}, 'bar': { @@ -1060,6 +1072,7 @@ class ResourceDependenciesTest(HeatTestCase): def test_getatt_nested_dict(self): tmpl = template.Template({ + 'HeatTemplateFormatVersion': '2012-12-12', 'Resources': { 'foo': {'Type': 'GenericResourceType'}, 'bar': { @@ -1103,6 +1116,7 @@ class ResourceDependenciesTest(HeatTestCase): def test_getatt_nested_deep(self): tmpl = template.Template({ + 'HeatTemplateFormatVersion': '2012-12-12', 'Resources': { 'foo': {'Type': 'GenericResourceType'}, 'bar': { @@ -1152,6 +1166,7 @@ class ResourceDependenciesTest(HeatTestCase): def test_getatt_fail(self): tmpl = template.Template({ + 'HeatTemplateFormatVersion': '2012-12-12', 'Resources': { 'foo': {'Type': 'GenericResourceType'}, 'bar': { @@ -1187,6 +1202,7 @@ class ResourceDependenciesTest(HeatTestCase): def test_getatt_fail_nested_deep(self): tmpl = template.Template({ + 'HeatTemplateFormatVersion': '2012-12-12', 'Resources': { 'foo': {'Type': 'GenericResourceType'}, 'bar': { @@ -1232,6 +1248,7 @@ class ResourceDependenciesTest(HeatTestCase): def test_dependson(self): tmpl = template.Template({ + 'HeatTemplateFormatVersion': '2012-12-12', 'Resources': { 'foo': {'Type': 'GenericResourceType'}, 'bar': { @@ -1271,6 +1288,7 @@ class ResourceDependenciesTest(HeatTestCase): def test_dependson_fail(self): tmpl = template.Template({ + 'HeatTemplateFormatVersion': '2012-12-12', 'Resources': { 'foo': { 'Type': 'GenericResourceType', @@ -1292,7 +1310,8 @@ class MetadataTest(HeatTestCase): 'Metadata': {'Test': 'Initial metadata'} } self.stack = parser.Stack(utils.dummy_context(), - 'test_stack', parser.Template({})) + 'test_stack', + parser.Template(empty_template)) self.stack.store() self.res = generic_rsrc.GenericResource('metadata_resource', tmpl, self.stack) diff --git a/heat/tests/test_software_config.py b/heat/tests/test_software_config.py index e24956f915..f3d753f856 100644 --- a/heat/tests/test_software_config.py +++ b/heat/tests/test_software_config.py @@ -39,6 +39,7 @@ class SoftwareConfigTest(HeatTestCase): self.stack = parser.Stack( self.ctx, 'software_config_test_stack', template.Template({ + 'HeatTemplateFormatVersion': '2012-12-12', 'Resources': { 'config_mysql': { 'Type': 'OS::Heat::SoftwareConfig', diff --git a/heat/tests/test_software_deployment.py b/heat/tests/test_software_deployment.py index b7af84ac86..23d2019d19 100644 --- a/heat/tests/test_software_deployment.py +++ b/heat/tests/test_software_deployment.py @@ -25,6 +25,7 @@ from heat.tests import utils class SoftwareDeploymentTest(HeatTestCase): template = { + 'HeatTemplateFormatVersion': '2012-12-12', 'Resources': { 'deployment_mysql': { 'Type': 'OS::Heat::SoftwareDeployment', @@ -38,6 +39,7 @@ class SoftwareDeploymentTest(HeatTestCase): } template_with_server = { + 'HeatTemplateFormatVersion': '2012-12-12', 'Resources': { 'deployment_mysql': { 'Type': 'OS::Heat::SoftwareDeployment', @@ -59,6 +61,7 @@ class SoftwareDeploymentTest(HeatTestCase): } template_no_signal = { + 'HeatTemplateFormatVersion': '2012-12-12', 'Resources': { 'deployment_mysql': { 'Type': 'OS::Heat::SoftwareDeployment', @@ -74,6 +77,7 @@ class SoftwareDeploymentTest(HeatTestCase): } template_delete_suspend_resume = { + 'HeatTemplateFormatVersion': '2012-12-12', 'Resources': { 'deployment_mysql': { 'Type': 'OS::Heat::SoftwareDeployment', diff --git a/heat/tests/test_stack_resource.py b/heat/tests/test_stack_resource.py index e6e59b36f7..e9a2e75cef 100644 --- a/heat/tests/test_stack_resource.py +++ b/heat/tests/test_stack_resource.py @@ -28,7 +28,8 @@ from heat.tests import generic_resource as generic_rsrc from heat.tests import utils -ws_res_snippet = {"Type": "some_magic_type", +ws_res_snippet = {"HeatTemplateFormatVersion": "2012-12-12", + "Type": "some_magic_type", "metadata": { "key": "value", "some": "more stuff"}} @@ -105,7 +106,8 @@ class StackResourceTest(HeatTestCase): MyStackResource) resource._register_class('GenericResource', generic_rsrc.GenericResource) - t = parser.Template({'Resources': + t = parser.Template({'HeatTemplateFormatVersion': '2012-12-12', + 'Resources': {"provider_resource": ws_res_snippet}}) self.parent_stack = parser.Stack(utils.dummy_context(), 'test_stack', t, stack_id=str(uuid.uuid4())) @@ -172,7 +174,8 @@ class StackResourceTest(HeatTestCase): stack_resource = MyImplementedStackResource('test', ws_res_snippet, 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() exc = exception.RequestLimitExceeded(message='Validation Failed') validation_mock = mock.Mock(side_effect=exc) @@ -183,7 +186,8 @@ class StackResourceTest(HeatTestCase): def test__validate_nested_resources_checks_num_of_resources(self): 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) root_resources = mock.Mock(return_value=2) self.parent_resource.stack.root_stack.total_resources = root_resources diff --git a/heat/tests/test_structured_config.py b/heat/tests/test_structured_config.py index 5b3585ca41..f61cbe2a9d 100644 --- a/heat/tests/test_structured_config.py +++ b/heat/tests/test_structured_config.py @@ -23,6 +23,7 @@ from heat.tests import utils class StructuredConfigTestJSON(HeatTestCase): template = { + 'HeatTemplateFormatVersion': '2012-12-12', 'Resources': { 'config_mysql': { 'Type': 'OS::Heat::StructuredConfig', @@ -70,6 +71,7 @@ class StructuredConfigTestJSON(HeatTestCase): class StructuredDeploymentDerivedTest(HeatTestCase): template = { + 'HeatTemplateFormatVersion': '2012-12-12', 'Resources': { 'deploy_mysql': { 'Type': 'OS::Heat::StructuredDeployment' diff --git a/heat/tests/test_template.py b/heat/tests/test_template.py index 00ad3d685e..4bc27d83ee 100644 --- a/heat/tests/test_template.py +++ b/heat/tests/test_template.py @@ -78,8 +78,10 @@ class TestTemplateVersion(HeatTestCase): 'foo': 'bar', 'Parameters': {} } - self.assertEqual(('HeatTemplateFormatVersion', '2012-12-12'), - template.get_version(tmpl, self.versions)) + ex = self.assertRaises(exception.InvalidTemplateVersion, + 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): tmpl = { diff --git a/heat/tests/test_template_format.py b/heat/tests/test_template_format.py index 0e977d62ee..031874066c 100644 --- a/heat/tests/test_template_format.py +++ b/heat/tests/test_template_format.py @@ -172,8 +172,8 @@ class JsonYamlResolvedCompareTest(HeatTestCase): def compare_stacks(self, json_file, yaml_file, parameters): t1 = self.load_template(json_file) t2 = self.load_template(yaml_file) - del(t2[u'HeatTemplateFormatVersion']) del(t1[u'AWSTemplateFormatVersion']) + t1[u'HeatTemplateFormatVersion'] = t2[u'HeatTemplateFormatVersion'] stack1 = utils.parse_stack(t1, parameters) stack2 = utils.parse_stack(t2, parameters) diff --git a/heat/tests/test_watch.py b/heat/tests/test_watch.py index e535c74d40..2c3a2f3964 100644 --- a/heat/tests/test_watch.py +++ b/heat/tests/test_watch.py @@ -46,7 +46,7 @@ class WatchRuleTest(HeatTestCase): # must be associated with a stack ctx = utils.dummy_context() ctx.auth_token = 'abcd1234' - empty_tmpl = {"template": {}} + empty_tmpl = {'HeatTemplateFormatVersion': '2012-12-12'} tmpl = parser.Template(empty_tmpl) stack_name = 'dummystack' dummy_stack = parser.Stack(ctx, stack_name, tmpl)