From: Neeraj Pratap Singh Date: Wed, 21 Jan 2026 09:50:55 +0000 (+0530) Subject: src: fixing assert_valid_host X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=c25b452414a79d1efb8595d63882c32736fda612;p=ceph.git src: fixing assert_valid_host Removed the stacktrace from command output in case of error Fixes: https://tracker.ceph.com/issues/68420 Signed-off-by: Neeraj Pratap Singh --- diff --git a/src/pybind/mgr/volumes/fs/fs_util.py b/src/pybind/mgr/volumes/fs/fs_util.py index e37bfe29d06b..b656b4c9020e 100644 --- a/src/pybind/mgr/volumes/fs/fs_util.py +++ b/src/pybind/mgr/volumes/fs/fs_util.py @@ -47,9 +47,12 @@ def rename_filesystem(mgr, fs_name, new_fs_name): return mgr.mon_command(command) def create_mds(mgr, fs_name, placement): - spec = ServiceSpec(service_type='mds', - service_id=fs_name, - placement=PlacementSpec.from_string(placement)) + try: + spec = ServiceSpec(service_type='mds', + service_id=fs_name, + placement=PlacementSpec.from_string(placement)) + except Exception as e: + return -errno.EINVAL, "", str(e) try: completion = mgr.apply([spec], no_overwrite=True) orchestrator.raise_if_exception(completion) diff --git a/src/python-common/ceph/deployment/hostspec.py b/src/python-common/ceph/deployment/hostspec.py index f17ba81cf09b..c73c818bfacb 100644 --- a/src/python-common/ceph/deployment/hostspec.py +++ b/src/python-common/ceph/deployment/hostspec.py @@ -6,14 +6,18 @@ from typing import Optional, List, Any, Dict def assert_valid_host(name: str) -> None: p = re.compile('^[a-zA-Z0-9-]+$') - try: - assert len(name) <= 250, 'name is too long (max 250 chars)' - for part in name.split('.'): - assert len(part) > 0, '.-delimited name component must not be empty' - assert len(part) <= 63, '.-delimited name component must not be more than 63 chars' - assert p.match(part), 'name component must include only a-z, 0-9, and -' - except AssertionError as e: - raise SpecValidationError(str(e) + f'. Got "{name}"') + if len(name) > 250: + raise AssertionError(f'{name}: name is too long (max 250 chars)') from None + for part in name.split('.'): + if len(part) == 0: + raise AssertionError('.-delimited name component must not be empty ' + f'but got {name}') from None + if len(part) > 63: + raise AssertionError('.-delimited name component must not be more ' + f'than 63 chars but got {name}') from None + if not p.match(part): + raise AssertionError('name component must include only a-z, 0-9, ' + f'and - but got {name}') from None def assert_valid_oob(oob: Dict[str, str]) -> None: