Merge PR #32696 into master

* refs/pull/32696/head:
	mgr/volumes: fail removing subvolume with snapshots

Reviewed-by: Patrick Donnelly <pdonnell@redhat.com>
This commit is contained in:
Patrick Donnelly 2020-01-20 11:07:55 -08:00
commit 721c959ab3
No known key found for this signature in database
GPG Key ID: 3A2A7E25BEA8AADB
2 changed files with 30 additions and 0 deletions

View File

@ -1234,3 +1234,31 @@ class TestVolumes(CephFSTestCase):
# remove group
self._fs_cmd("subvolumegroup", "rm", self.volname, group)
def test_subvolume_rm_with_snapshots(self):
subvolume = self._generate_random_subvolume_name()
snapshot = self._generate_random_snapshot_name()
# create subvolume
self._fs_cmd("subvolume", "create", self.volname, subvolume)
# snapshot subvolume
self._fs_cmd("subvolume", "snapshot", "create", self.volname, subvolume, snapshot)
# remove subvolume -- should fail with ENOTEMPTY since it has snapshots
try:
self._fs_cmd("subvolume", "rm", self.volname, subvolume)
except CommandFailedError as ce:
if ce.exitstatus != errno.ENOTEMPTY:
raise RuntimeError("invalid error code returned when deleting subvolume with snapshots")
else:
raise RuntimeError("expected subvolume deletion to fail")
# remove snapshot
self._fs_cmd("subvolume", "snapshot", "rm", self.volname, subvolume, snapshot)
# remove subvolume
self._fs_cmd("subvolume", "rm", self.volname, subvolume)
# verify trash dir is clean
self._wait_for_trash_empty()

View File

@ -39,6 +39,8 @@ def remove_subvol(fs, vol_spec, group, subvolname):
:return: None
"""
with open_subvol(fs, vol_spec, group, subvolname) as subvolume:
if subvolume.list_snapshots():
raise VolumeException(-errno.ENOTEMPTY, "subvolume '{0}' has snapshots".format(subvolname))
subvolume.remove()
@contextmanager