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 | |
Rabi Mishra | 477efc9 | 2015-07-31 13:01:45 +0530 | [diff] [blame^] | 13 | from heat_integrationtests.functional import functional_base |
Tetiana Lashchova | 1d74d3d | 2015-01-29 15:05:05 +0200 | [diff] [blame] | 14 | |
| 15 | |
Rabi Mishra | 477efc9 | 2015-07-31 13:01:45 +0530 | [diff] [blame^] | 16 | class HeatAutoscalingTest(functional_base.FunctionalTestsBase): |
Tetiana Lashchova | 1d74d3d | 2015-01-29 15:05:05 +0200 | [diff] [blame] | 17 | template = ''' |
| 18 | heat_template_version: 2014-10-16 |
| 19 | |
| 20 | resources: |
| 21 | random_group: |
| 22 | type: OS::Heat::AutoScalingGroup |
| 23 | properties: |
| 24 | max_size: 10 |
| 25 | min_size: 10 |
| 26 | resource: |
| 27 | type: OS::Heat::RandomString |
| 28 | |
| 29 | outputs: |
| 30 | all_values: |
| 31 | value: {get_attr: [random_group, outputs_list, value]} |
| 32 | value_0: |
| 33 | value: {get_attr: [random_group, resource.0.value]} |
| 34 | value_5: |
| 35 | value: {get_attr: [random_group, resource.5.value]} |
| 36 | value_9: |
| 37 | value: {get_attr: [random_group, resource.9.value]} |
| 38 | ''' |
| 39 | |
| 40 | template_nested = ''' |
| 41 | heat_template_version: 2014-10-16 |
| 42 | |
| 43 | resources: |
| 44 | random_group: |
| 45 | type: OS::Heat::AutoScalingGroup |
| 46 | properties: |
| 47 | max_size: 10 |
| 48 | min_size: 10 |
| 49 | resource: |
| 50 | type: randomstr.yaml |
| 51 | |
| 52 | outputs: |
| 53 | all_values: |
| 54 | value: {get_attr: [random_group, outputs_list, random_str]} |
| 55 | value_0: |
| 56 | value: {get_attr: [random_group, resource.0.random_str]} |
| 57 | value_5: |
| 58 | value: {get_attr: [random_group, resource.5.random_str]} |
| 59 | value_9: |
| 60 | value: {get_attr: [random_group, resource.9.random_str]} |
| 61 | ''' |
| 62 | |
| 63 | template_randomstr = ''' |
| 64 | heat_template_version: 2013-05-23 |
| 65 | |
| 66 | resources: |
| 67 | random_str: |
| 68 | type: OS::Heat::RandomString |
| 69 | |
| 70 | outputs: |
| 71 | random_str: |
| 72 | value: {get_attr: [random_str, value]} |
| 73 | ''' |
| 74 | |
| 75 | def setUp(self): |
| 76 | super(HeatAutoscalingTest, self).setUp() |
Tetiana Lashchova | 1d74d3d | 2015-01-29 15:05:05 +0200 | [diff] [blame] | 77 | |
| 78 | def _assert_output_values(self, stack_id): |
| 79 | stack = self.client.stacks.get(stack_id) |
| 80 | all_values = self._stack_output(stack, 'all_values') |
| 81 | self.assertEqual(10, len(all_values)) |
| 82 | self.assertEqual(all_values[0], self._stack_output(stack, 'value_0')) |
| 83 | self.assertEqual(all_values[5], self._stack_output(stack, 'value_5')) |
| 84 | self.assertEqual(all_values[9], self._stack_output(stack, 'value_9')) |
| 85 | |
| 86 | def test_path_attrs(self): |
| 87 | stack_id = self.stack_create(template=self.template) |
| 88 | expected_resources = {'random_group': 'OS::Heat::AutoScalingGroup'} |
| 89 | self.assertEqual(expected_resources, self.list_resources(stack_id)) |
| 90 | self._assert_output_values(stack_id) |
| 91 | |
| 92 | def test_path_attrs_nested(self): |
| 93 | files = {'randomstr.yaml': self.template_randomstr} |
| 94 | stack_id = self.stack_create(template=self.template_nested, |
| 95 | files=files) |
| 96 | expected_resources = {'random_group': 'OS::Heat::AutoScalingGroup'} |
| 97 | self.assertEqual(expected_resources, self.list_resources(stack_id)) |
| 98 | self._assert_output_values(stack_id) |
kairat_kushaev | 6f9f860 | 2015-03-16 11:32:24 +1000 | [diff] [blame] | 99 | |
| 100 | |
Rabi Mishra | 477efc9 | 2015-07-31 13:01:45 +0530 | [diff] [blame^] | 101 | class AutoScalingGroupUpdateWithNoChanges(functional_base.FunctionalTestsBase): |
kairat_kushaev | 6f9f860 | 2015-03-16 11:32:24 +1000 | [diff] [blame] | 102 | |
| 103 | template = ''' |
| 104 | heat_template_version: 2013-05-23 |
| 105 | |
| 106 | resources: |
| 107 | test_group: |
| 108 | type: OS::Heat::AutoScalingGroup |
| 109 | properties: |
| 110 | desired_capacity: 0 |
| 111 | max_size: 0 |
| 112 | min_size: 0 |
| 113 | resource: |
| 114 | type: OS::Heat::RandomString |
| 115 | test_policy: |
| 116 | type: OS::Heat::ScalingPolicy |
| 117 | properties: |
| 118 | adjustment_type: change_in_capacity |
| 119 | auto_scaling_group_id: { get_resource: test_group } |
| 120 | scaling_adjustment: 1 |
| 121 | ''' |
| 122 | |
| 123 | def setUp(self): |
| 124 | super(AutoScalingGroupUpdateWithNoChanges, self).setUp() |
kairat_kushaev | 6f9f860 | 2015-03-16 11:32:24 +1000 | [diff] [blame] | 125 | |
| 126 | def test_as_group_update_without_resource_changes(self): |
| 127 | stack_identifier = self.stack_create(template=self.template) |
| 128 | new_template = self.template.replace( |
| 129 | 'scaling_adjustment: 1', |
| 130 | 'scaling_adjustment: 2') |
| 131 | |
| 132 | self.update_stack(stack_identifier, template=new_template) |