Not allow to delete in-progress snapshot
Do not allow to delete in-progress snapshot by snapshot_delete API. Change-Id: Ibdd20e8430a6d39dccf460bdd0d3860344c50e2a Closes-Bug: #1438002
This commit is contained in:
parent
ced97f55ef
commit
8c08de003c
|
@ -1326,6 +1326,10 @@ class EngineService(service.Service):
|
|||
stack = parser.Stack.load(cnxt, stack=s)
|
||||
snapshot = snapshot_object.Snapshot.get_snapshot_by_stack(
|
||||
cnxt, snapshot_id, s)
|
||||
if snapshot.status == stack.IN_PROGRESS:
|
||||
msg = _('Deleting in-progress snapshot')
|
||||
raise exception.NotSupported(feature=msg)
|
||||
|
||||
self.thread_group_mgr.start(
|
||||
stack.id, _delete_snapshot, stack, snapshot)
|
||||
|
||||
|
|
|
@ -20,6 +20,7 @@ from heat.common import exception
|
|||
from heat.common import template_format
|
||||
from heat.engine import service
|
||||
from heat.engine import stack
|
||||
from heat.objects import snapshot as snapshot_objects
|
||||
from heat.tests import common
|
||||
from heat.tests.engine import tools
|
||||
from heat.tests import utils
|
||||
|
@ -154,6 +155,23 @@ class SnapshotServiceTest(common.HeatTestCase):
|
|||
mock_load.assert_called_once_with(self.ctx, stack=mock.ANY)
|
||||
mock_load.reset_mock()
|
||||
|
||||
@mock.patch.object(stack.Stack, 'load')
|
||||
def test_delete_snapshot_in_progress(self, mock_load):
|
||||
# can not delete the snapshot in snapshotting
|
||||
stk = self._create_stack('test_delete_snapshot_in_progress')
|
||||
mock_load.return_value = stk
|
||||
snapshot = mock.Mock()
|
||||
snapshot.id = str(uuid.uuid4())
|
||||
snapshot.status = 'IN_PROGRESS'
|
||||
self.patchobject(snapshot_objects.Snapshot,
|
||||
'get_snapshot_by_stack').return_value = snapshot
|
||||
ex = self.assertRaises(dispatcher.ExpectedException,
|
||||
self.engine.delete_snapshot,
|
||||
self.ctx, stk.identifier(), snapshot.id)
|
||||
msg = 'Deleting in-progress snapshot is not supported'
|
||||
self.assertIn(msg, six.text_type(ex.exc_info[1]))
|
||||
self.assertEqual(exception.NotSupported, ex.exc_info[0])
|
||||
|
||||
@mock.patch.object(stack.Stack, 'load')
|
||||
def test_delete_snapshot(self, mock_load):
|
||||
stk = self._create_stack('stack_snapshot_delete_normal')
|
||||
|
|
Loading…
Reference in New Issue