Merge "Copy resource data in _delete_backup_stack"

This commit is contained in:
Jenkins 2015-09-18 13:14:57 +00:00 committed by Gerrit Code Review
commit 309f03e3f5
2 changed files with 15 additions and 0 deletions

View File

@ -1270,6 +1270,11 @@ class Stack(collections.Mapping):
return (child.action == child.CREATE and
child.status in (child.FAILED, child.IN_PROGRESS))
def copy_data(source_res, destination_res):
if source_res.data():
for key, val in six.iteritems(source_res.data()):
destination_res.data_set(key, val)
for key, backup_res in stack.resources.items():
# If UpdateReplace is failed, we must restore backup_res
# to existing_stack in case of it may have dependencies in
@ -1293,8 +1298,11 @@ class Stack(collections.Mapping):
# needed to delete it.
self.resources[key].resource_id = backup_res_id
self.resources[key].properties = backup_res.properties
copy_data(backup_res, self.resources[key])
stack.resources[key].resource_id = curr_res_id
stack.resources[key].properties = curr_res.properties
copy_data(curr_res, stack.resources[key])
stack.delete(backup=True)

View File

@ -1800,6 +1800,8 @@ class StackUpdateTest(common.HeatTestCase):
self.stack.state)
# assert that backup stack has been updated correctly
self.assertIn('Bres', self.stack._backup_stack())
# set data for Bres in main stack
self.stack['Bres'].data_set('test', '42')
# update the stack with resource that updated in-place
tmpl_update['resources']['Bres']['properties']['an_int'] = 1
@ -1812,3 +1814,8 @@ class StackUpdateTest(common.HeatTestCase):
# assert that resource in backup stack also has been updated
backup = self.stack._backup_stack()
self.assertEqual(1, backup['Bres'].properties['an_int'])
# check, that updated Bres in new stack has copied data.
# Bres in backup stack should have empty data.
self.assertEqual({}, backup['Bres'].data())
self.assertEqual({'test': '42'}, self.stack['Bres'].data())