blob: d41e20371e11f730bc387619117053773f5f0983 [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
Rabi Mishra477efc92015-07-31 13:01:45 +053013from heat_integrationtests.functional import functional_base
Tetiana Lashchova1d74d3d2015-01-29 15:05:05 +020014
15
Rabi Mishra477efc92015-07-31 13:01:45 +053016class HeatAutoscalingTest(functional_base.FunctionalTestsBase):
Tetiana Lashchova1d74d3d2015-01-29 15:05:05 +020017 template = '''
18heat_template_version: 2014-10-16
19
20resources:
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
29outputs:
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 = '''
41heat_template_version: 2014-10-16
42
43resources:
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
52outputs:
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 = '''
64heat_template_version: 2013-05-23
65
66resources:
67 random_str:
68 type: OS::Heat::RandomString
69
70outputs:
71 random_str:
72 value: {get_attr: [random_str, value]}
73'''
74
Tetiana Lashchova1d74d3d2015-01-29 15:05:05 +020075 def _assert_output_values(self, stack_id):
76 stack = self.client.stacks.get(stack_id)
77 all_values = self._stack_output(stack, 'all_values')
78 self.assertEqual(10, len(all_values))
79 self.assertEqual(all_values[0], self._stack_output(stack, 'value_0'))
80 self.assertEqual(all_values[5], self._stack_output(stack, 'value_5'))
81 self.assertEqual(all_values[9], self._stack_output(stack, 'value_9'))
82
83 def test_path_attrs(self):
84 stack_id = self.stack_create(template=self.template)
85 expected_resources = {'random_group': 'OS::Heat::AutoScalingGroup'}
86 self.assertEqual(expected_resources, self.list_resources(stack_id))
87 self._assert_output_values(stack_id)
88
89 def test_path_attrs_nested(self):
90 files = {'randomstr.yaml': self.template_randomstr}
91 stack_id = self.stack_create(template=self.template_nested,
92 files=files)
93 expected_resources = {'random_group': 'OS::Heat::AutoScalingGroup'}
94 self.assertEqual(expected_resources, self.list_resources(stack_id))
95 self._assert_output_values(stack_id)
kairat_kushaev6f9f8602015-03-16 11:32:24 +100096
97
Rabi Mishra477efc92015-07-31 13:01:45 +053098class AutoScalingGroupUpdateWithNoChanges(functional_base.FunctionalTestsBase):
kairat_kushaev6f9f8602015-03-16 11:32:24 +100099
100 template = '''
101heat_template_version: 2013-05-23
102
103resources:
104 test_group:
105 type: OS::Heat::AutoScalingGroup
106 properties:
107 desired_capacity: 0
108 max_size: 0
109 min_size: 0
110 resource:
111 type: OS::Heat::RandomString
112 test_policy:
113 type: OS::Heat::ScalingPolicy
114 properties:
115 adjustment_type: change_in_capacity
116 auto_scaling_group_id: { get_resource: test_group }
117 scaling_adjustment: 1
118'''
119
kairat_kushaev6f9f8602015-03-16 11:32:24 +1000120 def test_as_group_update_without_resource_changes(self):
121 stack_identifier = self.stack_create(template=self.template)
122 new_template = self.template.replace(
123 'scaling_adjustment: 1',
124 'scaling_adjustment: 2')
125
126 self.update_stack(stack_identifier, template=new_template)