blob: c422a26ba41874759d561a91bdc97fef4dd9c8b1 [file] [log] [blame]
Jay Dobiesa4211da2015-11-25 15:36:27 -05001#
2# Licensed under the Apache License, Version 2.0 (the "License"); you may
3# not use this file except in compliance with the License. You may obtain
4# a copy of the License at
5#
6# http://www.apache.org/licenses/LICENSE-2.0
7#
8# Unless required by applicable law or agreed to in writing, software
9# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
10# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
11# License for the specific language governing permissions and limitations
12# under the License.
13
14from heat_integrationtests.functional import functional_base
15
16
17TEMPLATE_SIMPLE = '''
18heat_template_version: 2016-04-08
19parameters:
20 string-length:
21 type: number
22resources:
23 my-chain:
24 type: OS::Heat::ResourceChain
25 properties:
26 resources: ['OS::Heat::RandomString', 'OS::Heat::RandomString']
27 resource_properties:
28 length: { get_param: string-length }
29outputs:
30 resource-ids:
31 value: { get_attr: [my-chain, refs] }
32 resource-0-value:
33 value: { get_attr: [my-chain, resource.0, value] }
34 all-resource-attrs:
35 value: { get_attr: [my-chain, attributes, value] }
36'''
37
38TEMPLATE_PARAM_DRIVEN = '''
39heat_template_version: 2016-04-08
40parameters:
41 chain-types:
42 type: comma_delimited_list
43resources:
44 my-chain:
45 type: OS::Heat::ResourceChain
46 properties:
47 resources: { get_param: chain-types }
48'''
49
50
51class ResourceChainTests(functional_base.FunctionalTestsBase):
52
53 def test_create(self):
54 # Test
55 params = {'string-length': 8}
56 stack_id = self.stack_create(template=TEMPLATE_SIMPLE,
57 parameters=params)
58
59 # Verify
60 stack = self.client.stacks.get(stack_id)
61 self.assertTrue(stack is not None)
62
63 # Top-level resource for chain
64 expected = {'my-chain': 'OS::Heat::ResourceChain'}
65 found = self.list_resources(stack_id)
66 self.assertEqual(expected, found)
67
68 # Nested stack exists and has two resources
69 nested_id = self.group_nested_identifier(stack_id, 'my-chain')
70 expected = {'0': 'OS::Heat::RandomString',
71 '1': 'OS::Heat::RandomString'}
72 found = self.list_resources(nested_id)
73 self.assertEqual(expected, found)
74
75 # Outputs
76 resource_ids = self._stack_output(stack, 'resource-ids')
77 self.assertTrue(resource_ids is not None)
78 self.assertEqual(2, len(resource_ids))
79
80 resource_value = self._stack_output(stack, 'resource-0-value')
81 self.assertTrue(resource_value is not None)
82 self.assertEqual(8, len(resource_value)) # from parameter
83
84 resource_attrs = self._stack_output(stack, 'all-resource-attrs')
85 self.assertTrue(resource_attrs is not None)
LiuNanke35db11a2016-01-03 03:34:58 +080086 self.assertIsInstance(resource_attrs, dict)
Jay Dobiesa4211da2015-11-25 15:36:27 -050087 self.assertEqual(2, len(resource_attrs))
88 self.assertEqual(8, len(resource_attrs['0']))
89 self.assertEqual(8, len(resource_attrs['1']))
90
91 def test_update(self):
92 # Setup
93 params = {'string-length': 8}
94 stack_id = self.stack_create(template=TEMPLATE_SIMPLE,
95 parameters=params)
96
97 update_tmpl = '''
98 heat_template_version: 2016-04-08
99 parameters:
100 string-length:
101 type: number
102 resources:
103 my-chain:
104 type: OS::Heat::ResourceChain
105 properties:
106 resources: ['OS::Heat::None']
107 '''
108
109 # Test
110 self.update_stack(stack_id, template=update_tmpl, parameters=params)
111
112 # Verify
113 # Nested stack only has the None resource
114 nested_id = self.group_nested_identifier(stack_id, 'my-chain')
115 expected = {'0': 'OS::Heat::None'}
116 found = self.list_resources(nested_id)
117 self.assertEqual(expected, found)
118
119 def test_resources_param_driven(self):
120 # Setup
121 params = {'chain-types':
122 'OS::Heat::None,OS::Heat::RandomString,OS::Heat::None'}
123
124 # Test
125 stack_id = self.stack_create(template=TEMPLATE_PARAM_DRIVEN,
126 parameters=params)
127
128 # Verify
129 nested_id = self.group_nested_identifier(stack_id, 'my-chain')
130 expected = {'0': 'OS::Heat::None',
131 '1': 'OS::Heat::RandomString',
132 '2': 'OS::Heat::None'}
133 found = self.list_resources(nested_id)
134 self.assertEqual(expected, found)
135
136 def test_resources_env_defined(self):
137 # Setup
138 env = {'parameters': {'chain-types': 'OS::Heat::None'}}
139
140 # Test
141 stack_id = self.stack_create(template=TEMPLATE_PARAM_DRIVEN,
142 environment=env)
143
144 # Verify
145 nested_id = self.group_nested_identifier(stack_id, 'my-chain')
146 expected = {'0': 'OS::Heat::None'}
147 found = self.list_resources(nested_id)
148 self.assertEqual(expected, found)