Tetiana Lashchova | 1d74d3d | 2015-01-29 15:05:05 +0200 | [diff] [blame] | 1 | # 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 S | de6ad90 | 2016-04-28 15:30:54 +0530 | [diff] [blame] | 13 | from heat_integrationtests.common import test |
Rabi Mishra | 477efc9 | 2015-07-31 13:01:45 +0530 | [diff] [blame] | 14 | from heat_integrationtests.functional import functional_base |
Tetiana Lashchova | 1d74d3d | 2015-01-29 15:05:05 +0200 | [diff] [blame] | 15 | |
| 16 | |
Rabi Mishra | 477efc9 | 2015-07-31 13:01:45 +0530 | [diff] [blame] | 17 | class HeatAutoscalingTest(functional_base.FunctionalTestsBase): |
Tetiana Lashchova | 1d74d3d | 2015-01-29 15:05:05 +0200 | [diff] [blame] | 18 | template = ''' |
| 19 | heat_template_version: 2014-10-16 |
| 20 | |
| 21 | resources: |
| 22 | random_group: |
| 23 | type: OS::Heat::AutoScalingGroup |
| 24 | properties: |
Rakesh H S | de6ad90 | 2016-04-28 15:30:54 +0530 | [diff] [blame] | 25 | cooldown: 0 |
| 26 | desired_capacity: 3 |
| 27 | max_size: 5 |
| 28 | min_size: 2 |
Tetiana Lashchova | 1d74d3d | 2015-01-29 15:05:05 +0200 | [diff] [blame] | 29 | resource: |
| 30 | type: OS::Heat::RandomString |
| 31 | |
Rakesh H S | de6ad90 | 2016-04-28 15:30:54 +0530 | [diff] [blame] | 32 | 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 Lashchova | 1d74d3d | 2015-01-29 15:05:05 +0200 | [diff] [blame] | 46 | outputs: |
| 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 S | de6ad90 | 2016-04-28 15:30:54 +0530 | [diff] [blame] | 51 | 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 Lashchova | 1d74d3d | 2015-01-29 15:05:05 +0200 | [diff] [blame] | 57 | ''' |
| 58 | |
| 59 | template_nested = ''' |
| 60 | heat_template_version: 2014-10-16 |
| 61 | |
| 62 | resources: |
| 63 | random_group: |
| 64 | type: OS::Heat::AutoScalingGroup |
| 65 | properties: |
Rakesh H S | de6ad90 | 2016-04-28 15:30:54 +0530 | [diff] [blame] | 66 | desired_capacity: 3 |
| 67 | max_size: 5 |
| 68 | min_size: 2 |
Tetiana Lashchova | 1d74d3d | 2015-01-29 15:05:05 +0200 | [diff] [blame] | 69 | resource: |
| 70 | type: randomstr.yaml |
| 71 | |
| 72 | outputs: |
| 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 S | de6ad90 | 2016-04-28 15:30:54 +0530 | [diff] [blame] | 77 | 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 Lashchova | 1d74d3d | 2015-01-29 15:05:05 +0200 | [diff] [blame] | 81 | ''' |
| 82 | |
| 83 | template_randomstr = ''' |
| 84 | heat_template_version: 2013-05-23 |
| 85 | |
| 86 | resources: |
| 87 | random_str: |
| 88 | type: OS::Heat::RandomString |
| 89 | |
| 90 | outputs: |
| 91 | random_str: |
| 92 | value: {get_attr: [random_str, value]} |
| 93 | ''' |
| 94 | |
Tetiana Lashchova | 1d74d3d | 2015-01-29 15:05:05 +0200 | [diff] [blame] | 95 | 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 S | de6ad90 | 2016-04-28 15:30:54 +0530 | [diff] [blame] | 98 | self.assertEqual(3, len(all_values)) |
Tetiana Lashchova | 1d74d3d | 2015-01-29 15:05:05 +0200 | [diff] [blame] | 99 | self.assertEqual(all_values[0], self._stack_output(stack, 'value_0')) |
Rakesh H S | de6ad90 | 2016-04-28 15:30:54 +0530 | [diff] [blame] | 100 | 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 Lashchova | 1d74d3d | 2015-01-29 15:05:05 +0200 | [diff] [blame] | 140 | |
Rakesh H S | 20d93d5 | 2016-05-02 14:23:24 +0530 | [diff] [blame] | 141 | 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 Lashchova | 1d74d3d | 2015-01-29 15:05:05 +0200 | [diff] [blame] | 161 | def test_path_attrs(self): |
| 162 | stack_id = self.stack_create(template=self.template) |
Rakesh H S | de6ad90 | 2016-04-28 15:30:54 +0530 | [diff] [blame] | 163 | expected_resources = {'random_group': 'OS::Heat::AutoScalingGroup', |
| 164 | 'scale_up_policy': 'OS::Heat::ScalingPolicy', |
| 165 | 'scale_down_policy': 'OS::Heat::ScalingPolicy'} |
Tetiana Lashchova | 1d74d3d | 2015-01-29 15:05:05 +0200 | [diff] [blame] | 166 | 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_kushaev | 6f9f860 | 2015-03-16 11:32:24 +1000 | [diff] [blame] | 176 | |
| 177 | |
Rabi Mishra | 477efc9 | 2015-07-31 13:01:45 +0530 | [diff] [blame] | 178 | class AutoScalingGroupUpdateWithNoChanges(functional_base.FunctionalTestsBase): |
kairat_kushaev | 6f9f860 | 2015-03-16 11:32:24 +1000 | [diff] [blame] | 179 | |
| 180 | template = ''' |
| 181 | heat_template_version: 2013-05-23 |
| 182 | |
| 183 | resources: |
| 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_kushaev | 6f9f860 | 2015-03-16 11:32:24 +1000 | [diff] [blame] | 200 | 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) |