blob: 98761ac78e35bf5253766d20cc8c6c6a409b3150 [file] [log] [blame]
Steven Hardya1e1ee82014-03-27 15:09:53 +00001# 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 tempest.api.orchestration import base
16from tempest.common.utils import data_utils
Sean Dague0ef007a2014-04-16 14:53:26 -040017from tempest import test
Steven Hardya1e1ee82014-03-27 15:09:53 +000018
19
20LOG = logging.getLogger(__name__)
21
22
23class UpdateStackTestJSON(base.BaseOrchestrationTest):
24 _interface = 'json'
25
26 template = '''
27heat_template_version: 2013-05-23
28resources:
29 random1:
30 type: OS::Heat::RandomString
31'''
32 update_template = '''
33heat_template_version: 2013-05-23
34resources:
35 random1:
36 type: OS::Heat::RandomString
37 random2:
38 type: OS::Heat::RandomString
39'''
40
41 def update_stack(self, stack_identifier, template):
42 stack_name = stack_identifier.split('/')[0]
Joseph Lanoux2707a0f2014-08-22 11:05:21 +000043 self.client.update_stack(
Steven Hardya1e1ee82014-03-27 15:09:53 +000044 stack_identifier=stack_identifier,
45 name=stack_name,
46 template=template)
Steven Hardya1e1ee82014-03-27 15:09:53 +000047 self.client.wait_for_stack_status(stack_identifier, 'UPDATE_COMPLETE')
48
Sean Dague0ef007a2014-04-16 14:53:26 -040049 @test.attr(type='gate')
Steven Hardya1e1ee82014-03-27 15:09:53 +000050 def test_stack_update_nochange(self):
51 stack_name = data_utils.rand_name('heat')
52 stack_identifier = self.create_stack(stack_name, self.template)
53 self.client.wait_for_stack_status(stack_identifier, 'CREATE_COMPLETE')
54 expected_resources = {'random1': 'OS::Heat::RandomString'}
55 self.assertEqual(expected_resources,
56 self.list_resources(stack_identifier))
57
58 # Update with no changes, resources should be unchanged
59 self.update_stack(stack_identifier, self.template)
60 self.assertEqual(expected_resources,
61 self.list_resources(stack_identifier))
62
Sean Dague0ef007a2014-04-16 14:53:26 -040063 @test.attr(type='gate')
Steven Hardya1e1ee82014-03-27 15:09:53 +000064 def test_stack_update_add_remove(self):
65 stack_name = data_utils.rand_name('heat')
66 stack_identifier = self.create_stack(stack_name, self.template)
67 self.client.wait_for_stack_status(stack_identifier, 'CREATE_COMPLETE')
68 initial_resources = {'random1': 'OS::Heat::RandomString'}
69 self.assertEqual(initial_resources,
70 self.list_resources(stack_identifier))
71
72 # Add one resource via a stack update
73 self.update_stack(stack_identifier, self.update_template)
74 updated_resources = {'random1': 'OS::Heat::RandomString',
75 'random2': 'OS::Heat::RandomString'}
76 self.assertEqual(updated_resources,
77 self.list_resources(stack_identifier))
78
79 # Then remove it by updating with the original template
80 self.update_stack(stack_identifier, self.template)
81 self.assertEqual(initial_resources,
82 self.list_resources(stack_identifier))