Delete snaphots on deleting stack

Currently if convergence is enabled then deleting stack does not
deletes the snapshots. This patch deletes the snapshots before
deleting the stack.

Co-Authored-By: Rakesh H S <rh-s@hpe.com>

Change-Id: I1cb321a3878a0abce9b41832f76bf77c25bf7cb4
Closes-Bug: #1508299
changes/60/272960/3
tyagi 7 years ago committed by Rakesh H S
parent 2f9b344c67
commit 4b46151a64
  1. 8
      heat/engine/stack.py
  2. 31
      heat/tests/test_convg_stack.py

@ -1199,6 +1199,14 @@ class Stack(collections.Mapping):
LOG.info(_LI('convergence_dependencies: %s'),
self.convergence_dependencies)
# Delete all the snapshots before starting delete operation
if self.action == self.DELETE:
snapshots = snapshot_object.Snapshot.get_all(self.context,
self.id)
for snapshot in snapshots:
self.delete_snapshot(snapshot)
snapshot_object.Snapshot.delete(self.context, snapshot.id)
# create sync_points for resources in DB
for rsrc_id, is_update in self.convergence_dependencies:
sync_point.create(self.context, rsrc_id,

@ -21,6 +21,7 @@ from heat.engine import stack as parser
from heat.engine import template as templatem
from heat.objects import raw_template as raw_template_object
from heat.objects import resource as resource_objects
from heat.objects import snapshot as snapshot_objects
from heat.objects import stack as stack_object
from heat.objects import sync_point as sync_point_object
from heat.rpc import worker_client
@ -525,6 +526,36 @@ class StackConvergenceCreateUpdateDeleteTest(common.HeatTestCase):
self.assertTrue(mock_syncpoint_del.called)
self.assertTrue(mock_ccu.called)
def test_snapshot_delete(self, mock_cr):
tmpl = {'HeatTemplateFormatVersion': '2012-12-12',
'Resources': {'R1': {'Type': 'GenericResourceType'}}}
stack = parser.Stack(utils.dummy_context(), 'updated_time_test',
templatem.Template(tmpl))
stack.current_traversal = 'prev_traversal'
stack.action, stack.status = stack.CREATE, stack.COMPLETE
stack.store()
snapshot_values = {
'stack_id': stack.id,
'name': 'fake_snapshot',
'tenant': stack.context.tenant_id,
'status': 'COMPLETE',
'data': None
}
snapshot_objects.Snapshot.create(stack.context, snapshot_values)
# Ensure that snapshot is not deleted on stack update
stack.converge_stack(template=stack.t, action=stack.UPDATE)
db_snapshot_obj = snapshot_objects.Snapshot.get_all(
stack.context, stack.id)
self.assertEqual('fake_snapshot', db_snapshot_obj[0].name)
self.assertEqual(stack.id, db_snapshot_obj[0].stack_id)
# Ensure that snapshot is deleted on stack delete
stack.converge_stack(template=stack.t, action=stack.DELETE)
self.assertEqual([], snapshot_objects.Snapshot.get_all(
stack.context, stack.id))
self.assertTrue(mock_cr.called)
@mock.patch.object(parser.Stack, '_persist_state')
class TestConvgStackStateSet(common.HeatTestCase):

Loading…
Cancel
Save