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:
@@ -1937,6 +1937,7 @@ class Stack(collections.Mapping):
|
|||||||
snapshot_data = snapshot.data
|
snapshot_data = snapshot.data
|
||||||
if snapshot_data:
|
if snapshot_data:
|
||||||
data = snapshot.data['resources'].get(name)
|
data = snapshot.data['resources'].get(name)
|
||||||
|
if data:
|
||||||
scheduler.TaskRunner(rsrc.delete_snapshot, data)()
|
scheduler.TaskRunner(rsrc.delete_snapshot, data)()
|
||||||
|
|
||||||
def restore_data(self, snapshot):
|
def restore_data(self, snapshot):
|
||||||
|
|||||||
@@ -382,6 +382,9 @@ class ResourceWithRestoreType(ResWithComplexPropsAndAttrs):
|
|||||||
props['a_string'] = value
|
props['a_string'] = value
|
||||||
return defn.freeze(properties=props)
|
return defn.freeze(properties=props)
|
||||||
|
|
||||||
|
def handle_delete_snapshot(self, snapshot):
|
||||||
|
return snapshot['resource_data'].get('a_string')
|
||||||
|
|
||||||
|
|
||||||
class ResourceTypeUnSupportedLiberty(GenericResource):
|
class ResourceTypeUnSupportedLiberty(GenericResource):
|
||||||
support_status = support.SupportStatus(
|
support_status = support.SupportStatus(
|
||||||
|
|||||||
@@ -84,6 +84,46 @@ class StackTest(common.HeatTestCase):
|
|||||||
self.assertEqual([], snapshot_object.Snapshot.get_all(
|
self.assertEqual([], snapshot_object.Snapshot.get_all(
|
||||||
self.ctx, stack_id))
|
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):
|
def test_delete_user_creds(self):
|
||||||
self.stack = stack.Stack(self.ctx, 'delete_test', self.tmpl)
|
self.stack = stack.Stack(self.ctx, 'delete_test', self.tmpl)
|
||||||
stack_id = self.stack.store()
|
stack_id = self.stack.store()
|
||||||
|
|||||||
Reference in New Issue
Block a user