blob: afd9f5519cf37b5ebe12d3487f0747f8ea5e2d6f [file] [log] [blame]
Steven Hardy6f0bda82014-12-12 17:49:10 +00001# Licensed under the Apache License, Version 2.0 (the "License"); you may
2# not use this file except in compliance with the License. You may obtain
3# a copy of the License at
4#
5# http://www.apache.org/licenses/LICENSE-2.0
6#
7# Unless required by applicable law or agreed to in writing, software
8# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
9# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
10# License for the specific language governing permissions and limitations
11# under the License.
12
13import six
14
15from heatclient import exc
16
17from heat_integrationtests.common import test
18
19
20class ResourceGroupTest(test.HeatIntegrationTest):
21
22 def setUp(self):
23 super(ResourceGroupTest, self).setUp()
24 self.client = self.orchestration_client
25
26 def _group_nested_identifier(self, stack_identifier,
27 group_name='random_group'):
28 # Get the nested stack identifier from the group
29 rsrc = self.client.resources.get(stack_identifier, group_name)
30 physical_resource_id = rsrc.physical_resource_id
31
32 nested_stack = self.client.stacks.get(physical_resource_id)
33 nested_identifier = '%s/%s' % (nested_stack.stack_name,
34 nested_stack.id)
35 parent_id = stack_identifier.split("/")[-1]
36 self.assertEqual(parent_id, nested_stack.parent)
37 return nested_identifier
38
39 def test_resource_group_zero_novalidate(self):
40 # Nested resources should be validated only when size > 0
41 # This allows features to be disabled via size=0 without
42 # triggering validation of nested resource custom contraints
43 # e.g images etc in the nested schema.
44 nested_template_fail = '''
45heat_template_version: 2013-05-23
46resources:
47 random:
48 type: OS::Heat::RandomString
49 properties:
50 length: BAD
51'''
52
53 template_zero_nested = '''
54heat_template_version: 2013-05-23
55resources:
56 random_group:
57 type: OS::Heat::ResourceGroup
58 properties:
59 count: 0
60 resource_def:
61 type: My::RandomString
62'''
63
64 files = {'provider.yaml': nested_template_fail}
65 env = {'resource_registry':
66 {'My::RandomString': 'provider.yaml'}}
67 stack_identifier = self.stack_create(
68 template=template_zero_nested,
69 files=files,
70 environment=env
71 )
72
73 self.assertEqual({u'random_group': u'OS::Heat::ResourceGroup'},
74 self.list_resources(stack_identifier))
75
76 # Check we created an empty nested stack
77 nested_identifier = self._group_nested_identifier(stack_identifier)
78 self.assertEqual({}, self.list_resources(nested_identifier))
79
80 # Prove validation works for non-zero create/update
81 template_two_nested = template_zero_nested.replace("count: 0",
82 "count: 2")
83 expected_err = "length Value 'BAD' is not an integer"
84 ex = self.assertRaises(exc.HTTPBadRequest, self.update_stack,
85 stack_identifier, template_two_nested,
86 environment=env, files=files)
87 self.assertIn(expected_err, six.text_type(ex))
88
89 ex = self.assertRaises(exc.HTTPBadRequest, self.stack_create,
90 template=template_two_nested,
91 environment=env, files=files)
92 self.assertIn(expected_err, six.text_type(ex))