blob: 8cfb5c372cb889dd011658a19c853908bcf78447 [file] [log] [blame]
Steve Bakerf547ec32014-10-20 14:34:41 +13001# 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
13import logging
14
15from heat_integrationtests.common import test
16
17
18LOG = logging.getLogger(__name__)
19
20
21class UpdateStackTest(test.HeatIntegrationTest):
22
23 template = '''
24heat_template_version: 2013-05-23
25resources:
26 random1:
27 type: OS::Heat::RandomString
28'''
29 update_template = '''
30heat_template_version: 2013-05-23
31resources:
32 random1:
33 type: OS::Heat::RandomString
34 random2:
35 type: OS::Heat::RandomString
36'''
37
38 def setUp(self):
39 super(UpdateStackTest, self).setUp()
40 self.client = self.orchestration_client
41
42 def update_stack(self, stack_identifier, template):
43 stack_name = stack_identifier.split('/')[0]
44 self.client.stacks.update(
45 stack_id=stack_identifier,
46 stack_name=stack_name,
47 template=template,
48 files={},
49 disable_rollback=True,
50 parameters={},
51 environment={}
52 )
53 self._wait_for_stack_status(stack_identifier, 'UPDATE_COMPLETE')
54
55 def list_resources(self, stack_identifier):
56 resources = self.client.resources.list(stack_identifier)
57 return dict((r.resource_name, r.resource_type) for r in resources)
58
59 def test_stack_update_nochange(self):
60 stack_name = self._stack_rand_name()
61 self.client.stacks.create(
62 stack_name=stack_name,
63 template=self.template,
64 files={},
65 disable_rollback=True,
66 parameters={},
67 environment={}
68 )
69 self.addCleanup(self.client.stacks.delete, stack_name)
70
71 stack = self.client.stacks.get(stack_name)
72 stack_identifier = '%s/%s' % (stack_name, stack.id)
73
74 self._wait_for_stack_status(stack_identifier, 'CREATE_COMPLETE')
75 expected_resources = {'random1': 'OS::Heat::RandomString'}
76 self.assertEqual(expected_resources,
77 self.list_resources(stack_identifier))
78
79 # Update with no changes, resources should be unchanged
80 self.update_stack(stack_identifier, self.template)
81 self.assertEqual(expected_resources,
82 self.list_resources(stack_identifier))
83
84 def test_stack_update_add_remove(self):
85 stack_name = self._stack_rand_name()
86
87 self.client.stacks.create(
88 stack_name=stack_name,
89 template=self.template,
90 files={},
91 disable_rollback=True,
92 parameters={},
93 environment={}
94 )
95 self.addCleanup(self.client.stacks.delete, stack_name)
96
97 stack = self.client.stacks.get(stack_name)
98 stack_identifier = '%s/%s' % (stack_name, stack.id)
99
100 self._wait_for_stack_status(stack_identifier, 'CREATE_COMPLETE')
101 initial_resources = {'random1': 'OS::Heat::RandomString'}
102 self.assertEqual(initial_resources,
103 self.list_resources(stack_identifier))
104
105 # Add one resource via a stack update
106 self.update_stack(stack_identifier, self.update_template)
107 stack = self.client.stacks.get(stack_identifier)
108 updated_resources = {'random1': 'OS::Heat::RandomString',
109 'random2': 'OS::Heat::RandomString'}
110 self.assertEqual(updated_resources,
111 self.list_resources(stack_identifier))
112
113 # Then remove it by updating with the original template
114 self.update_stack(stack_identifier, self.template)
115 self.assertEqual(initial_resources,
116 self.list_resources(stack_identifier))