blob: 25ceb1c33bcb862c96d61a202872aeb20df1252a [file] [log] [blame]
Tetiana Lashchova1d74d3d2015-01-29 15:05:05 +02001# 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
Rakesh H Sde6ad902016-04-28 15:30:54 +053013from heat_integrationtests.common import test
Rabi Mishra477efc92015-07-31 13:01:45 +053014from heat_integrationtests.functional import functional_base
Tetiana Lashchova1d74d3d2015-01-29 15:05:05 +020015
16
Rabi Mishra477efc92015-07-31 13:01:45 +053017class HeatAutoscalingTest(functional_base.FunctionalTestsBase):
Tetiana Lashchova1d74d3d2015-01-29 15:05:05 +020018 template = '''
19heat_template_version: 2014-10-16
20
21resources:
22 random_group:
23 type: OS::Heat::AutoScalingGroup
24 properties:
Rakesh H Sde6ad902016-04-28 15:30:54 +053025 cooldown: 0
26 desired_capacity: 3
27 max_size: 5
28 min_size: 2
Tetiana Lashchova1d74d3d2015-01-29 15:05:05 +020029 resource:
30 type: OS::Heat::RandomString
31
Rakesh H Sde6ad902016-04-28 15:30:54 +053032 scale_up_policy:
33 type: OS::Heat::ScalingPolicy
34 properties:
35 adjustment_type: change_in_capacity
36 auto_scaling_group_id: { get_resource: random_group }
37 scaling_adjustment: 1
38
39 scale_down_policy:
40 type: OS::Heat::ScalingPolicy
41 properties:
42 adjustment_type: change_in_capacity
43 auto_scaling_group_id: { get_resource: random_group }
44 scaling_adjustment: -1
45
Tetiana Lashchova1d74d3d2015-01-29 15:05:05 +020046outputs:
47 all_values:
48 value: {get_attr: [random_group, outputs_list, value]}
49 value_0:
50 value: {get_attr: [random_group, resource.0.value]}
Rakesh H Sde6ad902016-04-28 15:30:54 +053051 value_1:
52 value: {get_attr: [random_group, resource.1.value]}
53 value_2:
54 value: {get_attr: [random_group, resource.2.value]}
55 asg_size:
56 value: {get_attr: [random_group, current_size]}
Tetiana Lashchova1d74d3d2015-01-29 15:05:05 +020057'''
58
59 template_nested = '''
60heat_template_version: 2014-10-16
61
62resources:
63 random_group:
64 type: OS::Heat::AutoScalingGroup
65 properties:
Rakesh H Sde6ad902016-04-28 15:30:54 +053066 desired_capacity: 3
67 max_size: 5
68 min_size: 2
Tetiana Lashchova1d74d3d2015-01-29 15:05:05 +020069 resource:
70 type: randomstr.yaml
71
72outputs:
73 all_values:
74 value: {get_attr: [random_group, outputs_list, random_str]}
75 value_0:
76 value: {get_attr: [random_group, resource.0.random_str]}
Rakesh H Sde6ad902016-04-28 15:30:54 +053077 value_1:
78 value: {get_attr: [random_group, resource.1.random_str]}
79 value_2:
80 value: {get_attr: [random_group, resource.2.random_str]}
Tetiana Lashchova1d74d3d2015-01-29 15:05:05 +020081'''
82
83 template_randomstr = '''
84heat_template_version: 2013-05-23
85
86resources:
87 random_str:
88 type: OS::Heat::RandomString
89
90outputs:
91 random_str:
92 value: {get_attr: [random_str, value]}
93'''
94
Tetiana Lashchova1d74d3d2015-01-29 15:05:05 +020095 def _assert_output_values(self, stack_id):
96 stack = self.client.stacks.get(stack_id)
97 all_values = self._stack_output(stack, 'all_values')
Rakesh H Sde6ad902016-04-28 15:30:54 +053098 self.assertEqual(3, len(all_values))
Tetiana Lashchova1d74d3d2015-01-29 15:05:05 +020099 self.assertEqual(all_values[0], self._stack_output(stack, 'value_0'))
Rakesh H Sde6ad902016-04-28 15:30:54 +0530100 self.assertEqual(all_values[1], self._stack_output(stack, 'value_1'))
101 self.assertEqual(all_values[2], self._stack_output(stack, 'value_2'))
102
103 def test_asg_scale_up_max_size(self):
104 stack_id = self.stack_create(template=self.template,
105 expected_status='CREATE_COMPLETE')
106 stack = self.client.stacks.get(stack_id)
107 asg_size = self._stack_output(stack, 'asg_size')
108 # Ensure that initial desired capacity is met
109 self.assertEqual(3, asg_size)
110
111 # send scale up signals and ensure that asg honors max_size
112 asg = self.client.resources.get(stack_id, 'random_group')
113 max_size = 5
114 for num in range(asg_size+1, max_size+2):
115 expected_resources = num if num <= max_size else max_size
116 self.client.resources.signal(stack_id, 'scale_up_policy')
117 test.call_until_true(self.conf.build_timeout,
118 self.conf.build_interval,
119 self.check_autoscale_complete,
120 asg.physical_resource_id, expected_resources)
121
122 def test_asg_scale_down_min_size(self):
123 stack_id = self.stack_create(template=self.template,
124 expected_status='CREATE_COMPLETE')
125 stack = self.client.stacks.get(stack_id)
126 asg_size = self._stack_output(stack, 'asg_size')
127 # Ensure that initial desired capacity is met
128 self.assertEqual(3, asg_size)
129
130 # send scale down signals and ensure that asg honors min_size
131 asg = self.client.resources.get(stack_id, 'random_group')
132 min_size = 2
133 for num in range(asg_size-1, 0, -1):
134 expected_resources = num if num >= min_size else min_size
135 self.client.resources.signal(stack_id, 'scale_down_policy')
136 test.call_until_true(self.conf.build_timeout,
137 self.conf.build_interval,
138 self.check_autoscale_complete,
139 asg.physical_resource_id, expected_resources)
Tetiana Lashchova1d74d3d2015-01-29 15:05:05 +0200140
Rakesh H S20d93d52016-05-02 14:23:24 +0530141 def test_asg_cooldown(self):
142 cooldown_tmpl = self.template.replace('cooldown: 0',
143 'cooldown: 10')
144 stack_id = self.stack_create(template=cooldown_tmpl,
145 expected_status='CREATE_COMPLETE')
146 stack = self.client.stacks.get(stack_id)
147 asg_size = self._stack_output(stack, 'asg_size')
148 # Ensure that initial desired capacity is met
149 self.assertEqual(3, asg_size)
150
151 # send scale up signal.
152 # Since cooldown is in effect, number of resources should not change
153 asg = self.client.resources.get(stack_id, 'random_group')
154 expected_resources = 3
155 self.client.resources.signal(stack_id, 'scale_up_policy')
156 test.call_until_true(self.conf.build_timeout,
157 self.conf.build_interval,
158 self.check_autoscale_complete,
159 asg.physical_resource_id, expected_resources)
160
Tetiana Lashchova1d74d3d2015-01-29 15:05:05 +0200161 def test_path_attrs(self):
162 stack_id = self.stack_create(template=self.template)
Rakesh H Sde6ad902016-04-28 15:30:54 +0530163 expected_resources = {'random_group': 'OS::Heat::AutoScalingGroup',
164 'scale_up_policy': 'OS::Heat::ScalingPolicy',
165 'scale_down_policy': 'OS::Heat::ScalingPolicy'}
Tetiana Lashchova1d74d3d2015-01-29 15:05:05 +0200166 self.assertEqual(expected_resources, self.list_resources(stack_id))
167 self._assert_output_values(stack_id)
168
169 def test_path_attrs_nested(self):
170 files = {'randomstr.yaml': self.template_randomstr}
171 stack_id = self.stack_create(template=self.template_nested,
172 files=files)
173 expected_resources = {'random_group': 'OS::Heat::AutoScalingGroup'}
174 self.assertEqual(expected_resources, self.list_resources(stack_id))
175 self._assert_output_values(stack_id)
kairat_kushaev6f9f8602015-03-16 11:32:24 +1000176
177
Rabi Mishra477efc92015-07-31 13:01:45 +0530178class AutoScalingGroupUpdateWithNoChanges(functional_base.FunctionalTestsBase):
kairat_kushaev6f9f8602015-03-16 11:32:24 +1000179
180 template = '''
181heat_template_version: 2013-05-23
182
183resources:
184 test_group:
185 type: OS::Heat::AutoScalingGroup
186 properties:
187 desired_capacity: 0
188 max_size: 0
189 min_size: 0
190 resource:
191 type: OS::Heat::RandomString
192 test_policy:
193 type: OS::Heat::ScalingPolicy
194 properties:
195 adjustment_type: change_in_capacity
196 auto_scaling_group_id: { get_resource: test_group }
197 scaling_adjustment: 1
198'''
199
kairat_kushaev6f9f8602015-03-16 11:32:24 +1000200 def test_as_group_update_without_resource_changes(self):
201 stack_identifier = self.stack_create(template=self.template)
202 new_template = self.template.replace(
203 'scaling_adjustment: 1',
204 'scaling_adjustment: 2')
205
206 self.update_stack(stack_identifier, template=new_template)