Fix update preview to consider type comparison

Currently the update preview code only considers _needs_update, but
the actual update code does a type comparison which is used to decide
whether to attempt an in-place update vs a replacement.

Thus, we currently erroneously say a resource is either unchanged or
updated during update --dry-run when the type changes, but during
the actual update we replace the resource.  So instead use the same
type comparison used during update to provide a more accurate preview.

Change-Id: Idb2d9a55d47748007a438f84bb1f2259e553c067
Partial-Bug: #1521971
This commit is contained in:
Steven Hardy 2016-01-18 10:56:13 +00:00
parent be20bd0489
commit 0a4249f5d1
2 changed files with 18 additions and 0 deletions

View File

@ -238,6 +238,11 @@ class StackUpdate(object):
updated_props = updated_res.frozen_definition().properties(
updated_res.properties_schema, updated_res.context)
# type comparison must match that in _process_new_resource_update
if type(current_res) is not type(updated_res):
replaced_keys.append(key)
continue
try:
if current_res._needs_update(updated_res.frozen_definition(),
current_res.frozen_definition(),

View File

@ -786,6 +786,19 @@ resources:
section_contents = [x for x in result[section]]
self.assertEqual([], section_contents)
def test_stack_update_preview_replaced_type(self):
# new template with a different type for web_server
new_tmpl = self.old_tmpl.replace('OS::Nova::Server', 'OS::Heat::None')
result = self._test_stack_update_preview(self.old_tmpl, new_tmpl)
replaced = [x for x in result['replaced']][0]
self.assertEqual('web_server', replaced['resource_name'])
empty_sections = ('added', 'deleted', 'unchanged', 'updated')
for section in empty_sections:
section_contents = [x for x in result[section]]
self.assertEqual([], section_contents)
def test_stack_update_preview_updated(self):
# new template changes to flavor of server
new_tmpl = self.old_tmpl.replace('m1.large', 'm1.small')