Remove the existing snapshots from the backend

We only have to remove the existing snapshots
for resources when stack delete.

Change-Id: Ia195f3c3380fe71e0888c8291209dd4562318951
Closes-Bug: #1716612
This commit is contained in:
huangtianhua 2017-09-14 10:16:01 +08:00
parent 668799d00c
commit 1861ad8867
3 changed files with 45 additions and 1 deletions

View File

@ -1937,7 +1937,8 @@ class Stack(collections.Mapping):
snapshot_data = snapshot.data
if snapshot_data:
data = snapshot.data['resources'].get(name)
scheduler.TaskRunner(rsrc.delete_snapshot, data)()
if data:
scheduler.TaskRunner(rsrc.delete_snapshot, data)()
def restore_data(self, snapshot):
env = environment.Environment(snapshot.data['environment'])

View File

@ -382,6 +382,9 @@ class ResourceWithRestoreType(ResWithComplexPropsAndAttrs):
props['a_string'] = value
return defn.freeze(properties=props)
def handle_delete_snapshot(self, snapshot):
return snapshot['resource_data'].get('a_string')
class ResourceTypeUnSupportedLiberty(GenericResource):
support_status = support.SupportStatus(

View File

@ -84,6 +84,46 @@ class StackTest(common.HeatTestCase):
self.assertEqual([], snapshot_object.Snapshot.get_all(
self.ctx, stack_id))
def test_delete_with_snapshot_after_stack_add_resource(self):
tpl = {'heat_template_version': 'queens',
'resources':
{'A': {'type': 'ResourceWithRestoreType'}}}
self.stack = stack.Stack(self.ctx, 'stack_delete_with_snapshot',
template.Template(tpl))
stack_id = self.stack.store()
self.stack.create()
data = copy.deepcopy(self.stack.prepare_abandon())
data['resources']['A']['resource_data']['a_string'] = 'foo'
snapshot_fake = {
'tenant': self.ctx.tenant_id,
'name': 'Snapshot',
'stack_id': stack_id,
'status': 'COMPLETE',
'data': data
}
snapshot_object.Snapshot.create(self.ctx, snapshot_fake)
self.assertIsNotNone(snapshot_object.Snapshot.get_all(
self.ctx, stack_id))
new_tmpl = {'heat_template_version': 'queens',
'resources':
{'A': {'type': 'ResourceWithRestoreType'},
'B': {'type': 'ResourceWithRestoreType'}}}
updated_stack = stack.Stack(self.ctx, 'update_stack_add_res',
template.Template(new_tmpl))
self.stack.update(updated_stack)
self.assertEqual(2, len(self.stack.resources))
self.stack.delete()
db_s = stack_object.Stack.get_by_id(self.ctx, stack_id)
self.assertIsNone(db_s)
self.assertEqual((stack.Stack.DELETE, stack.Stack.COMPLETE),
self.stack.state)
self.assertEqual([], snapshot_object.Snapshot.get_all(
self.ctx, stack_id))
def test_delete_user_creds(self):
self.stack = stack.Stack(self.ctx, 'delete_test', self.tmpl)
stack_id = self.stack.store()