Add integration tests for preview update

Change-Id: Ie67da09ad32185a18493fded18e24894b8c195d4
BP: update-dry-run
This commit is contained in:
Jason Dunsmore 2015-09-09 16:57:04 -05:00
parent ac09876049
commit c9dbc34db7
2 changed files with 192 additions and 0 deletions

View File

@ -367,6 +367,25 @@ class HeatIntegrationTest(testscenarios.WithScenarios,
self._wait_for_stack_status(**kwargs)
def preview_update_stack(self, stack_identifier, template,
environment=None, files=None, parameters=None,
tags=None, disable_rollback=True):
env = environment or {}
env_files = files or {}
parameters = parameters or {}
stack_name = stack_identifier.split('/')[0]
return self.client.stacks.preview_update(
stack_id=stack_identifier,
stack_name=stack_name,
template=template,
files=env_files,
disable_rollback=disable_rollback,
parameters=parameters,
environment=env,
tags=tags
)
def assert_resource_is_a_stack(self, stack_identifier, res_name,
wait=False):
build_timeout = self.conf.build_timeout

View File

@ -0,0 +1,173 @@
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from heat_integrationtests.functional import functional_base
test_template_one_resource = {
'heat_template_version': '2013-05-23',
'description': 'Test template to create one instance.',
'resources': {
'test1': {
'type': 'OS::Heat::TestResource',
'properties': {
'value': 'Test1',
'fail': False,
'update_replace': False,
'wait_secs': 0
}
}
}
}
test_template_two_resource = {
'heat_template_version': '2013-05-23',
'description': 'Test template to create two instance.',
'resources': {
'test1': {
'type': 'OS::Heat::TestResource',
'properties': {
'value': 'Test1',
'fail': False,
'update_replace': False,
'wait_secs': 0
}
},
'test2': {
'type': 'OS::Heat::TestResource',
'properties': {
'value': 'Test1',
'fail': False,
'update_replace': False,
'wait_secs': 0
}
}
}
}
class UpdatePreviewStackTest(functional_base.FunctionalTestsBase):
def setUp(self):
super(UpdatePreviewStackTest, self).setUp()
self.stack_identifier = self.stack_create(
template=test_template_one_resource)
def test_add_resource(self):
result = self.preview_update_stack(self.stack_identifier,
test_template_two_resource)
changes = result['resource_changes']
unchanged = changes['unchanged'][0]['resource_name']
self.assertEqual('test1', unchanged)
added = changes['added'][0]['resource_name']
self.assertEqual('test2', added)
empty_sections = ('updated', 'replaced', 'deleted')
for section in empty_sections:
self.assertEqual([], changes[section])
def test_no_change(self):
result = self.preview_update_stack(self.stack_identifier,
test_template_one_resource)
changes = result['resource_changes']
unchanged = changes['unchanged'][0]['resource_name']
self.assertEqual('test1', unchanged)
empty_sections = ('updated', 'replaced', 'deleted', 'added')
for section in empty_sections:
self.assertEqual([], changes[section])
def test_update_resource(self):
test_template_updated_resource = {
'heat_template_version': '2013-05-23',
'description': 'Test template to create one instance.',
'resources': {
'test1': {
'type': 'OS::Heat::TestResource',
'properties': {
'value': 'Test1 foo',
'fail': False,
'update_replace': False,
'wait_secs': 0
}
}
}
}
result = self.preview_update_stack(self.stack_identifier,
test_template_updated_resource)
changes = result['resource_changes']
updated = changes['updated'][0]['resource_name']
self.assertEqual('test1', updated)
empty_sections = ('added', 'unchanged', 'replaced', 'deleted')
for section in empty_sections:
self.assertEqual([], changes[section])
def test_replaced_resource(self):
orig_template = {
'heat_template_version': '2013-05-23',
'description': 'Test template to create one instance.',
'resources': {
'test1': {
'type': 'OS::Heat::TestResource',
'properties': {
'update_replace': False,
}
}
}
}
new_template = {
'heat_template_version': '2013-05-23',
'description': 'Test template to create one instance.',
'resources': {
'test1': {
'type': 'OS::Heat::TestResource',
'properties': {
'update_replace': True,
}
}
}
}
stack_identifier = self.stack_create(template=orig_template)
result = self.preview_update_stack(stack_identifier, new_template)
changes = result['resource_changes']
replaced = changes['replaced'][0]['resource_name']
self.assertEqual('test1', replaced)
empty_sections = ('added', 'unchanged', 'updated', 'deleted')
for section in empty_sections:
self.assertEqual([], changes[section])
def test_delete_resource(self):
stack_identifier = self.stack_create(
template=test_template_two_resource)
result = self.preview_update_stack(stack_identifier,
test_template_one_resource)
changes = result['resource_changes']
unchanged = changes['unchanged'][0]['resource_name']
self.assertEqual('test1', unchanged)
deleted = changes['deleted'][0]['resource_name']
self.assertEqual('test2', deleted)
empty_sections = ('updated', 'replaced', 'added')
for section in empty_sections:
self.assertEqual([], changes[section])