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 | |
| 95 | def setUp(self): |
| 96 | super(HeatAutoscalingTest, self).setUp() |
Tetiana Lashchova | 1d74d3d | 2015-01-29 15:05:05 +0200 | [diff] [blame] | 97 | |
| 98 | def _assert_output_values(self, stack_id): |
| 99 | stack = self.client.stacks.get(stack_id) |
| 100 | all_values = self._stack_output(stack, 'all_values') |
Rakesh H S | de6ad90 | 2016-04-28 15:30:54 +0530 | [diff] [blame^] | 101 | self.assertEqual(3, len(all_values)) |
Tetiana Lashchova | 1d74d3d | 2015-01-29 15:05:05 +0200 | [diff] [blame] | 102 | self.assertEqual(all_values[0], self._stack_output(stack, 'value_0')) |
Rakesh H S | de6ad90 | 2016-04-28 15:30:54 +0530 | [diff] [blame^] | 103 | self.assertEqual(all_values[1], self._stack_output(stack, 'value_1')) |
| 104 | self.assertEqual(all_values[2], self._stack_output(stack, 'value_2')) |
| 105 | |
| 106 | def test_asg_scale_up_max_size(self): |
| 107 | stack_id = self.stack_create(template=self.template, |
| 108 | expected_status='CREATE_COMPLETE') |
| 109 | stack = self.client.stacks.get(stack_id) |
| 110 | asg_size = self._stack_output(stack, 'asg_size') |
| 111 | # Ensure that initial desired capacity is met |
| 112 | self.assertEqual(3, asg_size) |
| 113 | |
| 114 | # send scale up signals and ensure that asg honors max_size |
| 115 | asg = self.client.resources.get(stack_id, 'random_group') |
| 116 | max_size = 5 |
| 117 | for num in range(asg_size+1, max_size+2): |
| 118 | expected_resources = num if num <= max_size else max_size |
| 119 | self.client.resources.signal(stack_id, 'scale_up_policy') |
| 120 | test.call_until_true(self.conf.build_timeout, |
| 121 | self.conf.build_interval, |
| 122 | self.check_autoscale_complete, |
| 123 | asg.physical_resource_id, expected_resources) |
| 124 | |
| 125 | def test_asg_scale_down_min_size(self): |
| 126 | stack_id = self.stack_create(template=self.template, |
| 127 | expected_status='CREATE_COMPLETE') |
| 128 | stack = self.client.stacks.get(stack_id) |
| 129 | asg_size = self._stack_output(stack, 'asg_size') |
| 130 | # Ensure that initial desired capacity is met |
| 131 | self.assertEqual(3, asg_size) |
| 132 | |
| 133 | # send scale down signals and ensure that asg honors min_size |
| 134 | asg = self.client.resources.get(stack_id, 'random_group') |
| 135 | min_size = 2 |
| 136 | for num in range(asg_size-1, 0, -1): |
| 137 | expected_resources = num if num >= min_size else min_size |
| 138 | self.client.resources.signal(stack_id, 'scale_down_policy') |
| 139 | test.call_until_true(self.conf.build_timeout, |
| 140 | self.conf.build_interval, |
| 141 | self.check_autoscale_complete, |
| 142 | asg.physical_resource_id, expected_resources) |
Tetiana Lashchova | 1d74d3d | 2015-01-29 15:05:05 +0200 | [diff] [blame] | 143 | |
| 144 | def test_path_attrs(self): |
| 145 | stack_id = self.stack_create(template=self.template) |
Rakesh H S | de6ad90 | 2016-04-28 15:30:54 +0530 | [diff] [blame^] | 146 | expected_resources = {'random_group': 'OS::Heat::AutoScalingGroup', |
| 147 | 'scale_up_policy': 'OS::Heat::ScalingPolicy', |
| 148 | 'scale_down_policy': 'OS::Heat::ScalingPolicy'} |
Tetiana Lashchova | 1d74d3d | 2015-01-29 15:05:05 +0200 | [diff] [blame] | 149 | self.assertEqual(expected_resources, self.list_resources(stack_id)) |
| 150 | self._assert_output_values(stack_id) |
| 151 | |
| 152 | def test_path_attrs_nested(self): |
| 153 | files = {'randomstr.yaml': self.template_randomstr} |
| 154 | stack_id = self.stack_create(template=self.template_nested, |
| 155 | files=files) |
| 156 | expected_resources = {'random_group': 'OS::Heat::AutoScalingGroup'} |
| 157 | self.assertEqual(expected_resources, self.list_resources(stack_id)) |
| 158 | self._assert_output_values(stack_id) |
kairat_kushaev | 6f9f860 | 2015-03-16 11:32:24 +1000 | [diff] [blame] | 159 | |
| 160 | |
Rabi Mishra | 477efc9 | 2015-07-31 13:01:45 +0530 | [diff] [blame] | 161 | class AutoScalingGroupUpdateWithNoChanges(functional_base.FunctionalTestsBase): |
kairat_kushaev | 6f9f860 | 2015-03-16 11:32:24 +1000 | [diff] [blame] | 162 | |
| 163 | template = ''' |
| 164 | heat_template_version: 2013-05-23 |
| 165 | |
| 166 | resources: |
| 167 | test_group: |
| 168 | type: OS::Heat::AutoScalingGroup |
| 169 | properties: |
| 170 | desired_capacity: 0 |
| 171 | max_size: 0 |
| 172 | min_size: 0 |
| 173 | resource: |
| 174 | type: OS::Heat::RandomString |
| 175 | test_policy: |
| 176 | type: OS::Heat::ScalingPolicy |
| 177 | properties: |
| 178 | adjustment_type: change_in_capacity |
| 179 | auto_scaling_group_id: { get_resource: test_group } |
| 180 | scaling_adjustment: 1 |
| 181 | ''' |
| 182 | |
| 183 | def setUp(self): |
| 184 | super(AutoScalingGroupUpdateWithNoChanges, self).setUp() |
kairat_kushaev | 6f9f860 | 2015-03-16 11:32:24 +1000 | [diff] [blame] | 185 | |
| 186 | def test_as_group_update_without_resource_changes(self): |
| 187 | stack_identifier = self.stack_create(template=self.template) |
| 188 | new_template = self.template.replace( |
| 189 | 'scaling_adjustment: 1', |
| 190 | 'scaling_adjustment: 2') |
| 191 | |
| 192 | self.update_stack(stack_identifier, template=new_template) |