Make sure to delete stack when SNAPSHOT_IN_PROGRESS

If there is no snapshot data, no need to start a task runner
of rsrc.delete_snapshot.

Change-Id: I1b868eda8a7a0a2ed5f30aa01a41f4c9820193a5
Closes-Bug: #1437588
This commit is contained in:
huangtianhua 2015-03-28 17:05:10 +08:00
parent 04546ca8c9
commit 42727797d3
2 changed files with 12 additions and 2 deletions

View File

@ -1181,8 +1181,10 @@ class Stack(collections.Mapping):
def delete_snapshot(self, snapshot):
'''Remove a snapshot from the backends.'''
for name, rsrc in six.iteritems(self.resources):
data = snapshot.data['resources'].get(name)
scheduler.TaskRunner(rsrc.delete_snapshot, data)()
snapshot_data = snapshot.data
if snapshot_data:
data = snapshot.data['resources'].get(name)
scheduler.TaskRunner(rsrc.delete_snapshot, data)()
@profiler.trace('Stack.restore', hide_args=False)
def restore(self, snapshot):

View File

@ -1495,6 +1495,14 @@ class StackTest(common.HeatTestCase):
self.stack.delete_snapshot(fake_snapshot)
self.assertEqual([data['resources']['AResource']], snapshots)
def test_delete_snapshot_without_data(self):
tmpl = {'HeatTemplateFormatVersion': '2012-12-12',
'Resources': {'R1': {'Type': 'GenericResourceType'}}}
self.stack = stack.Stack(self.ctx, 'snapshot_stack',
template.Template(tmpl))
fake_snapshot = collections.namedtuple('Snapshot', ('data',))(None)
self.assertIsNone(self.stack.delete_snapshot(fake_snapshot))
def test_incorrect_outputs_cfn_get_attr(self):
tmpl = {'HeatTemplateFormatVersion': '2012-12-12',
'Resources': {