blob: 7817c2bc412c05fc4badf583a4c7ee36fdac3c05 [file] [log] [blame]
Steven Hardyd448dae2016-06-14 14:57:28 +01001# 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
13from heat_integrationtests.functional import functional_base
14
15
16class SoftwareDeploymentGroupTest(functional_base.FunctionalTestsBase):
17 sd_template = '''
18heat_template_version: 2016-10-14
19
20parameters:
21 input:
22 type: string
23 default: foo_input
24
25resources:
26 config:
27 type: OS::Heat::SoftwareConfig
28 properties:
29 group: script
30 inputs:
31 - name: foo
32
33 deployment:
34 type: OS::Heat::SoftwareDeploymentGroup
35 properties:
36 config: {get_resource: config}
37 input_values:
38 foo: {get_param: input}
39 servers:
40 '0': dummy0
41 '1': dummy1
42 '2': dummy2
43 '3': dummy3
44'''
45
46 enable_cleanup = True
47
48 def test_deployments_crud(self):
49 stack_identifier = self.stack_create(
50 template=self.sd_template,
51 enable_cleanup=self.enable_cleanup,
52 expected_status='CREATE_IN_PROGRESS')
53 self._wait_for_resource_status(
54 stack_identifier, 'deployment', 'CREATE_IN_PROGRESS')
55 nested_identifier = self.assert_resource_is_a_stack(
56 stack_identifier, 'deployment')
57 group_resources = self.list_group_resources(
58 stack_identifier, 'deployment', minimal=False)
59
60 self.assertEqual(4, len(group_resources))
61 self.signal_deployments(group_resources)
62 self._wait_for_stack_status(stack_identifier, 'CREATE_COMPLETE')
63
64 self.check_input_values(group_resources, 'foo_input')
65
66 self.update_stack(stack_identifier,
67 template=self.sd_template,
68 environment={'parameters': {'input': 'input2'}},
69 expected_status='UPDATE_IN_PROGRESS')
70 nested_identifier = self.assert_resource_is_a_stack(
71 stack_identifier, 'deployment')
72 self.assertEqual(4, len(group_resources))
73 self.signal_deployments(group_resources)
74 self._wait_for_stack_status(stack_identifier, 'UPDATE_COMPLETE')
75
76 self.check_input_values(group_resources, 'input2')
77
78 # We explicitly test delete here, vs just via cleanup and check
79 # the nested stack is gone
80 self._stack_delete(stack_identifier)
81 self._wait_for_stack_status(
82 nested_identifier, 'DELETE_COMPLETE',
83 success_on_not_found=True)
84
85 def test_deployments_create_delete_in_progress(self):
86 stack_identifier = self.stack_create(
87 template=self.sd_template,
88 enable_cleanup=self.enable_cleanup,
89 expected_status='CREATE_IN_PROGRESS')
90 self._wait_for_resource_status(
91 stack_identifier, 'deployment', 'CREATE_IN_PROGRESS')
92 nested_identifier = self.assert_resource_is_a_stack(
93 stack_identifier, 'deployment')
94 group_resources = self.list_group_resources(
95 stack_identifier, 'deployment', minimal=False)
96
97 self.assertEqual(4, len(group_resources))
98 # Now test delete while the stacks are still IN_PROGRESS
99 self._stack_delete(stack_identifier)
100 self._wait_for_stack_status(
101 nested_identifier, 'DELETE_COMPLETE',
102 success_on_not_found=True)
103
104 def check_input_values(self, group_resources, value):
105 # Check inputs for deployment and derived config
106 for r in group_resources:
107 d = self.client.software_deployments.get(
108 r.physical_resource_id)
109 self.assertEqual({'foo': value}, d.input_values)
110 c = self.client.software_configs.get(
111 d.config_id)
112 foo_input_c = [i for i in c.inputs if i.get('name') == 'foo'][0]
113 self.assertEqual(value, foo_input_c.get('value'))
114
115 def signal_deployments(self, resources):
116 # Signal all IN_PROGRESS deployment resources
117 for r in resources:
118 if 'IN_PROGRESS' in r.resource_status:
119 stack_id = self.get_resource_stack_id(r)
120 self.client.resources.signal(stack_id, r.resource_name)