blob: e87badb83120b1050efbc1ec48a1705bcaacd49d [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
75 def setUp(self):
76 super(HeatAutoscalingTest, self).setUp()
Tetiana Lashchova1d74d3d2015-01-29 15:05:05 +020077
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_kushaev6f9f8602015-03-16 11:32:24 +100099
100
Rabi Mishra477efc92015-07-31 13:01:45 +0530101class AutoScalingGroupUpdateWithNoChanges(functional_base.FunctionalTestsBase):
kairat_kushaev6f9f8602015-03-16 11:32:24 +1000102
103 template = '''
104heat_template_version: 2013-05-23
105
106resources:
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_kushaev6f9f8602015-03-16 11:32:24 +1000125
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)