Merge pull request #46636 from nmshelke/fix-55759

mgr/volumes: subvolume ls command crashes if groupname as '_nogroup'

Reviewed-by: Venky Shankar <vshankar@redhat.com>
Reviewed-by: Ramana Raja <rraja@redhat.com>
Reviewed-by: Kotresh HR <khiremat@redhat.com>
This commit is contained in:
Venky Shankar 2022-06-20 09:48:35 +05:30 committed by GitHub
commit 0fb05df9ec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 37 additions and 1 deletions

View File

@ -2029,6 +2029,41 @@ class TestSubvolumes(TestVolumesHelper):
# verify trash dir is clean
self._wait_for_trash_empty()
def test_subvolume_create_and_ls_providing_group_as_nogroup(self):
"""
That a 'subvolume create' and 'subvolume ls' should throw
permission denied error if option --group=_nogroup is provided.
"""
subvolname = self._generate_random_subvolume_name()
# try to create subvolume providing --group_name=_nogroup option
try:
self._fs_cmd("subvolume", "create", self.volname, subvolname, "--group_name", "_nogroup")
except CommandFailedError as ce:
self.assertEqual(ce.exitstatus, errno.EPERM)
else:
self.fail("expected the 'fs subvolume create' command to fail")
# create subvolume
self._fs_cmd("subvolume", "create", self.volname, subvolname)
# try to list subvolumes providing --group_name=_nogroup option
try:
self._fs_cmd("subvolume", "ls", self.volname, "--group_name", "_nogroup")
except CommandFailedError as ce:
self.assertEqual(ce.exitstatus, errno.EPERM)
else:
self.fail("expected the 'fs subvolume ls' command to fail")
# list subvolumes
self._fs_cmd("subvolume", "ls", self.volname)
self._fs_cmd("subvolume", "rm", self.volname, subvolname)
# verify trash dir is clean.
self._wait_for_trash_empty()
def test_subvolume_expand(self):
"""
That a subvolume can be expanded in size and its quota matches the expected size.

View File

@ -20,7 +20,8 @@ class Group(GroupTemplate):
NO_GROUP_NAME = "_nogroup"
def __init__(self, fs, vol_spec, groupname):
assert groupname != Group.NO_GROUP_NAME
if groupname == Group.NO_GROUP_NAME:
raise VolumeException(-errno.EPERM, "Operation not permitted for group '{0}' as it is an internal group.".format(groupname))
self.fs = fs
self.user_id = None
self.group_id = None