Merge "Do not delete group if group snapshot exists"
This commit is contained in:
commit
54d6c2da9c
@ -517,6 +517,12 @@ class API(base.Base):
|
||||
"but current status is: %s") % group.status
|
||||
raise exception.InvalidGroup(reason=msg)
|
||||
|
||||
# NOTE(tommylikehu): Admin context is required to load group snapshots.
|
||||
with group.obj_as_admin():
|
||||
if group.group_snapshots:
|
||||
raise exception.InvalidGroup(
|
||||
reason=_("Group has existing snapshots."))
|
||||
|
||||
volumes = self.db.volume_get_all_by_generic_group(context.elevated(),
|
||||
group.id)
|
||||
if volumes and not delete_volumes:
|
||||
|
@ -654,6 +654,29 @@ class GroupsAPITestCase(test.TestCase):
|
||||
self.controller.delete_group,
|
||||
req, self.group1.id, body)
|
||||
|
||||
def test_delete_group_with_group_snapshot(self):
|
||||
self.group1.status = fields.GroupStatus.AVAILABLE
|
||||
self.group1.save()
|
||||
g_snapshot = utils.create_group_snapshot(self.ctxt, self.group1.id)
|
||||
|
||||
req = fakes.HTTPRequest.blank('/v3/%s/groups/%s/action' %
|
||||
(fake.PROJECT_ID, self.group1.id),
|
||||
version=GROUP_MICRO_VERSION)
|
||||
body = {"delete": {"delete-volumes": True}}
|
||||
self.assertRaises(webob.exc.HTTPBadRequest,
|
||||
self.controller.delete_group,
|
||||
req, self.group1.id, body)
|
||||
|
||||
g_snapshot.destroy()
|
||||
|
||||
res_dict = self.controller.delete_group(
|
||||
req, self.group1.id, body)
|
||||
|
||||
group = objects.Group.get_by_id(
|
||||
self.ctxt, self.group1.id)
|
||||
self.assertEqual(http_client.ACCEPTED, res_dict.status_int)
|
||||
self.assertEqual(fields.GroupStatus.DELETING, group.status)
|
||||
|
||||
def test_delete_group_delete_volumes(self):
|
||||
self.group1.status = fields.GroupStatus.AVAILABLE
|
||||
self.group1.save()
|
||||
|
@ -114,6 +114,7 @@ class GroupAPITestCase(test.TestCase):
|
||||
ret_group.host = "test_host@fakedrv#fakepool"
|
||||
ret_group.status = fields.GroupStatus.AVAILABLE
|
||||
ret_group.assert_not_frozen = mock.Mock(return_value=True)
|
||||
ret_group.group_snapshots = []
|
||||
self.group_api.delete(self.ctxt, ret_group, delete_volumes=True)
|
||||
mock_volume_get_all.assert_called_once_with(mock.ANY, ret_group.id)
|
||||
mock_volumes_update.assert_called_once_with(self.ctxt, [])
|
||||
|
@ -0,0 +1,3 @@
|
||||
---
|
||||
fixes:
|
||||
- Prohibit the deletion of group if group snapshot exists.
|
Loading…
Reference in New Issue
Block a user