Skip to content

Commit a88c5ec

Browse files
Merge pull request ceph#53989 from mchangir/mds-handle-bad-arguments-during-subvolume-create-2
mgr/volumes: handle bad arguments during subvolume create Reviewed-by: Rishabh Dave <[email protected]>
2 parents e44e1e4 + 0d53436 commit a88c5ec

File tree

6 files changed

+61
-6
lines changed

6 files changed

+61
-6
lines changed

doc/_ext/ceph_commands.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ class CmdParam(object):
8383

8484
def __init__(self, type, name,
8585
who=None, n=None, req=True, range=None, strings=None,
86-
goodchars=None, positional=True):
86+
goodchars=None, positional=True, **kwargs):
8787
self.type = type
8888
self.name = name
8989
self.who = who
@@ -93,6 +93,7 @@ def __init__(self, type, name,
9393
self.strings = strings.split('|') if strings else []
9494
self.goodchars = goodchars
9595
self.positional = positional != 'false'
96+
self.allowempty = kwargs.pop('allowempty', True) in (True, 'True', 'true')
9697

9798
assert who is None
9899

@@ -108,6 +109,8 @@ def help(self):
108109
advanced.append('goodchars= ``{}`` '.format(self.goodchars))
109110
if self.n:
110111
advanced.append('(can be repeated)')
112+
if self.allowempty:
113+
advanced.append('(can be empty string)')
111114

112115
advanced = advanced or ["(string)"]
113116
return ' '.join(advanced)

qa/suites/fs/volumes/tasks/volumes/test/basic.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ tasks:
66
- tasks.cephfs.test_volumes.TestVolumeCreate
77
- tasks.cephfs.test_volumes.TestSubvolumeGroups
88
- tasks.cephfs.test_volumes.TestSubvolumes
9+
- tasks.cephfs.test_volumes.TestEmptyStringForCreates
910
- tasks.cephfs.test_subvolume

qa/tasks/cephfs/filesystem.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -834,7 +834,7 @@ def create(self, **kwargs):
834834
assert(subvols['create'] > 0)
835835

836836
self.run_ceph_cmd('fs', 'subvolumegroup', 'create', self.name, 'qa')
837-
subvol_options = self.fs_config.get('subvol_options', '')
837+
subvol_options = self.fs_config.get('subvol_options', None)
838838

839839
for sv in range(0, subvols['create']):
840840
sv_name = f'sv_{sv}'

qa/tasks/cephfs/test_volumes.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9162,3 +9162,48 @@ def test_volumes_module_finisher_thread(self):
91629162

91639163
# verify trash dir is clean
91649164
self._wait_for_trash_empty()
9165+
9166+
class TestEmptyStringForCreates(CephFSTestCase):
9167+
CLIENTS_REQUIRED = 1
9168+
MDSS_REQUIRED = 1
9169+
9170+
def setUp(self):
9171+
super().setUp()
9172+
result = json.loads(self.get_ceph_cmd_stdout("fs", "volume", "ls"))
9173+
self.assertTrue(len(result) > 0)
9174+
self.volname = result[0]['name']
9175+
9176+
def tearDown(self):
9177+
# clean up
9178+
super().tearDown()
9179+
9180+
def test_empty_name_string_for_subvolumegroup_name(self):
9181+
"""
9182+
To test that an empty string is unacceptable for a subvolumegroup name
9183+
"""
9184+
with self.assertRaises(CommandFailedError):
9185+
self.run_ceph_cmd("fs", "subvolumegroup", "create", self.volname, "")
9186+
9187+
with self.assertRaises(CommandFailedError):
9188+
self.run_ceph_cmd("fs", "subvolumegroup", "create", self.volname, "''")
9189+
9190+
def test_empty_name_string_for_subvolume_name(self):
9191+
"""
9192+
To test that an empty string is unacceptable for a subvolume name
9193+
"""
9194+
with self.assertRaises(CommandFailedError):
9195+
self.run_ceph_cmd("fs", "subvolume", "create", "")
9196+
9197+
with self.assertRaises(CommandFailedError):
9198+
self.run_ceph_cmd("fs", "subvolume", "create", "''")
9199+
9200+
def test_empty_name_string_for_subvolumegroup_name_argument(self):
9201+
"""
9202+
To test that an empty string is unacceptable for a subvolumegroup name
9203+
argument when creating a subvolume
9204+
"""
9205+
with self.assertRaises(CommandFailedError):
9206+
self.run_ceph_cmd("fs", "subvolume", "create", self.volname, "sv1", "--group_name")
9207+
9208+
with self.assertRaises(CommandFailedError):
9209+
self.run_ceph_cmd("fs", "subvolume", "create", self.volname, "sv1", "--group_name", "''")

src/pybind/ceph_argparse.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ class CephString(CephArgtype):
327327
"""
328328
String; pretty generic. goodchars is a RE char class of valid chars
329329
"""
330-
def __init__(self, goodchars=''):
330+
def __init__(self, goodchars='', allowempty=True):
331331
from string import printable
332332
try:
333333
re.compile(goodchars)
@@ -338,8 +338,12 @@ def __init__(self, goodchars=''):
338338
self.goodset = frozenset(
339339
[c for c in printable if re.match(goodchars, c)]
340340
)
341+
self.allowempty = allowempty in (True, 'True', 'true')
341342

342343
def valid(self, s: str, partial: bool = False) -> None:
344+
if not self.allowempty and s == "":
345+
raise ArgumentFormat("argument can't be an empty string")
346+
343347
sset = set(s)
344348
if self.goodset and not sset <= self.goodset:
345349
raise ArgumentFormat("invalid chars {0} in {1}".
@@ -350,6 +354,7 @@ def __str__(self) -> str:
350354
b = ''
351355
if self.goodchars:
352356
b += '(goodchars {0})'.format(self.goodchars)
357+
b += f'(allowempty {self.allowempty})'
353358
return '<string{0}>'.format(b)
354359

355360
def complete(self, s) -> List[str]:
@@ -361,6 +366,7 @@ def complete(self, s) -> List[str]:
361366
def argdesc(self, attrs):
362367
if self.goodchars:
363368
attrs['goodchars'] = self.goodchars
369+
attrs['allowempty'] = repr(self.allowempty)
364370
return super().argdesc(attrs)
365371

366372

src/pybind/mgr/volumes/module.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ class Module(orchestrator.OrchestratorClientMixin, MgrModule):
8686
{
8787
'cmd': 'fs subvolumegroup create '
8888
'name=vol_name,type=CephString '
89-
f'name=group_name,type=CephString,goodchars={goodchars} '
89+
f'name=group_name,type=CephString,goodchars={goodchars},allowempty=false '
9090
'name=size,type=CephInt,req=false '
9191
'name=pool_layout,type=CephString,req=false '
9292
'name=uid,type=CephInt,req=false '
@@ -136,9 +136,9 @@ class Module(orchestrator.OrchestratorClientMixin, MgrModule):
136136
{
137137
'cmd': 'fs subvolume create '
138138
'name=vol_name,type=CephString '
139-
f'name=sub_name,type=CephString,goodchars={goodchars} '
139+
f'name=sub_name,type=CephString,goodchars={goodchars},allowempty=false '
140140
'name=size,type=CephInt,req=false '
141-
'name=group_name,type=CephString,req=false '
141+
f'name=group_name,type=CephString,req=false,goodchars={goodchars},allowempty=false '
142142
'name=pool_layout,type=CephString,req=false '
143143
'name=uid,type=CephInt,req=false '
144144
'name=gid,type=CephInt,req=false '

0 commit comments

Comments
 (0)