Merge "Fix snapshot delete in convergence"
This commit is contained in:
commit
ff8d741dd5
|
@ -1409,6 +1409,7 @@ class EngineService(service.ServiceBase):
|
||||||
def convergence_delete():
|
def convergence_delete():
|
||||||
stack.thread_group_mgr = self.thread_group_mgr
|
stack.thread_group_mgr = self.thread_group_mgr
|
||||||
self.worker_service.stop_all_workers(stack)
|
self.worker_service.stop_all_workers(stack)
|
||||||
|
stack.delete_all_snapshots()
|
||||||
template = templatem.Template.create_empty_template(
|
template = templatem.Template.create_empty_template(
|
||||||
from_template=stack.t)
|
from_template=stack.t)
|
||||||
stack.converge_stack(template=template, action=stack.DELETE)
|
stack.converge_stack(template=template, action=stack.DELETE)
|
||||||
|
|
|
@ -1293,14 +1293,6 @@ class Stack(collections.Mapping):
|
||||||
LOG.info('convergence_dependencies: %s',
|
LOG.info('convergence_dependencies: %s',
|
||||||
self.convergence_dependencies)
|
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
|
# create sync_points for resources in DB
|
||||||
for rsrc_id, is_update in self.convergence_dependencies:
|
for rsrc_id, is_update in self.convergence_dependencies:
|
||||||
sync_point.create(self.context, rsrc_id,
|
sync_point.create(self.context, rsrc_id,
|
||||||
|
@ -1782,11 +1774,7 @@ class Stack(collections.Mapping):
|
||||||
'Failed to %s : %s' % (action, failure))
|
'Failed to %s : %s' % (action, failure))
|
||||||
return
|
return
|
||||||
|
|
||||||
snapshots = snapshot_object.Snapshot.get_all(self.context,
|
self.delete_all_snapshots()
|
||||||
self.id)
|
|
||||||
for snapshot in snapshots:
|
|
||||||
self.delete_snapshot(snapshot)
|
|
||||||
snapshot_object.Snapshot.delete(self.context, snapshot.id)
|
|
||||||
|
|
||||||
if not backup:
|
if not backup:
|
||||||
try:
|
try:
|
||||||
|
@ -1898,6 +1886,13 @@ class Stack(collections.Mapping):
|
||||||
pre_completion_func=save_snapshot_func)
|
pre_completion_func=save_snapshot_func)
|
||||||
sus_task(timeout=self.timeout_secs())
|
sus_task(timeout=self.timeout_secs())
|
||||||
|
|
||||||
|
def delete_all_snapshots(self):
|
||||||
|
"""Remove all snapshots for this stack."""
|
||||||
|
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)
|
||||||
|
|
||||||
@profiler.trace('Stack.delete_snapshot', hide_args=False)
|
@profiler.trace('Stack.delete_snapshot', hide_args=False)
|
||||||
def delete_snapshot(self, snapshot):
|
def delete_snapshot(self, snapshot):
|
||||||
"""Remove a snapshot from the backends."""
|
"""Remove a snapshot from the backends."""
|
||||||
|
|
|
@ -21,7 +21,6 @@ from heat.engine import stack as parser
|
||||||
from heat.engine import template as templatem
|
from heat.engine import template as templatem
|
||||||
from heat.objects import raw_template as raw_template_object
|
from heat.objects import raw_template as raw_template_object
|
||||||
from heat.objects import resource as resource_objects
|
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 stack as stack_object
|
||||||
from heat.objects import sync_point as sync_point_object
|
from heat.objects import sync_point as sync_point_object
|
||||||
from heat.rpc import worker_client
|
from heat.rpc import worker_client
|
||||||
|
@ -553,37 +552,6 @@ class StackConvergenceCreateUpdateDeleteTest(common.HeatTestCase):
|
||||||
self.assertTrue(mock_syncpoint_del.called)
|
self.assertTrue(mock_syncpoint_del.called)
|
||||||
self.assertTrue(mock_ccu.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()
|
|
||||||
stack.thread_group_mgr = tools.DummyThreadGroupManager()
|
|
||||||
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')
|
@mock.patch.object(parser.Stack, '_persist_state')
|
||||||
class TestConvgStackStateSet(common.HeatTestCase):
|
class TestConvgStackStateSet(common.HeatTestCase):
|
||||||
|
|
Loading…
Reference in New Issue