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:
parent
668799d00c
commit
1861ad8867
@ -1937,6 +1937,7 @@ class Stack(collections.Mapping):
|
||||
snapshot_data = snapshot.data
|
||||
if snapshot_data:
|
||||
data = snapshot.data['resources'].get(name)
|
||||
if data:
|
||||
scheduler.TaskRunner(rsrc.delete_snapshot, data)()
|
||||
|
||||
def restore_data(self, snapshot):
|
||||
|
@ -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(
|
||||
|
@ -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()
|
||||
|
Loading…
Reference in New Issue
Block a user