From: Kotresh HR Date: Tue, 14 Jul 2020 06:08:15 +0000 (+0530) Subject: mgr/volumes: Fix traceback of ops when volume doesn't exist X-Git-Tag: wip-pdonnell-testing-20200918.022351~524^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=e4ebdb1a5d634476774d64c118285e5f890fbaf8;p=ceph-ci.git mgr/volumes: Fix traceback of ops when volume doesn't exist Subvolume operations throw a traceback if the volume doesn't exist. This patch fixes the same. Fixes: https://tracker.ceph.com/issues/46496 Signed-off-by: Kotresh HR --- diff --git a/qa/tasks/cephfs/test_volumes.py b/qa/tasks/cephfs/test_volumes.py index 0f5dad54879..a8315074735 100644 --- a/qa/tasks/cephfs/test_volumes.py +++ b/qa/tasks/cephfs/test_volumes.py @@ -2530,3 +2530,72 @@ class TestVolumes(CephFSTestCase): # verify trash dir is clean self._wait_for_trash_empty() + + def test_subvolume_ops_on_nonexistent_vol(self): + # tests the fs subvolume operations on non existing volume + + volname = "non_existent_subvolume" + + # try subvolume operations + for op in ("create", "rm", "getpath", "info", "resize", "pin", "ls"): + try: + if op == "resize": + self._fs_cmd("subvolume", "resize", volname, "subvolname_1", "inf") + elif op == "pin": + self._fs_cmd("subvolume", "pin", volname, "subvolname_1", "export", "1") + elif op == "ls": + self._fs_cmd("subvolume", "ls", volname) + else: + self._fs_cmd("subvolume", op, volname, "subvolume_1") + except CommandFailedError as ce: + self.assertEqual(ce.exitstatus, errno.ENOENT) + else: + self.fail("expected the 'fs subvolume {0}' command to fail".format(op)) + + # try subvolume snapshot operations and clone create + for op in ("create", "rm", "info", "protect", "unprotect", "ls", "clone"): + try: + if op == "ls": + self._fs_cmd("subvolume", "snapshot", op, volname, "subvolume_1") + elif op == "clone": + self._fs_cmd("subvolume", "snapshot", op, volname, "subvolume_1", "snapshot_1", "clone_1") + else: + self._fs_cmd("subvolume", "snapshot", op, volname, "subvolume_1", "snapshot_1") + except CommandFailedError as ce: + self.assertEqual(ce.exitstatus, errno.ENOENT) + else: + self.fail("expected the 'fs subvolume snapshot {0}' command to fail".format(op)) + + # try, clone status + try: + self._fs_cmd("clone", "status", volname, "clone_1") + except CommandFailedError as ce: + self.assertEqual(ce.exitstatus, errno.ENOENT) + else: + self.fail("expected the 'fs clone status' command to fail") + + # try subvolumegroup operations + for op in ("create", "rm", "getpath", "pin", "ls"): + try: + if op == "pin": + self._fs_cmd("subvolumegroup", "pin", volname, "group_1", "export", "0") + elif op == "ls": + self._fs_cmd("subvolumegroup", op, volname) + else: + self._fs_cmd("subvolumegroup", op, volname, "group_1") + except CommandFailedError as ce: + self.assertEqual(ce.exitstatus, errno.ENOENT) + else: + self.fail("expected the 'fs subvolumegroup {0}' command to fail".format(op)) + + # try subvolumegroup snapshot operations + for op in ("create", "rm", "ls"): + try: + if op == "ls": + self._fs_cmd("subvolumegroup", "snapshot", op, volname, "group_1") + else: + self._fs_cmd("subvolumegroup", "snapshot", op, volname, "group_1", "snapshot_1") + except CommandFailedError as ce: + self.assertEqual(ce.exitstatus, errno.ENOENT) + else: + self.fail("expected the 'fs subvolumegroup snapshot {0}' command to fail".format(op)) diff --git a/src/pybind/mgr/volumes/fs/operations/volume.py b/src/pybind/mgr/volumes/fs/operations/volume.py index 64859a44e27..441a877f28e 100644 --- a/src/pybind/mgr/volumes/fs/operations/volume.py +++ b/src/pybind/mgr/volumes/fs/operations/volume.py @@ -12,7 +12,7 @@ from .lock import GlobalLock from ..exception import VolumeException from ..fs_util import create_pool, remove_pool, create_filesystem, \ remove_filesystem, create_mds, volume_exists -from mgr_util import open_filesystem +from mgr_util import open_filesystem, CephfsConnectionException log = logging.getLogger(__name__) @@ -135,8 +135,11 @@ def open_volume(vc, volname): """ g_lock = GlobalLock() with g_lock.lock_op(): - with open_filesystem(vc, volname) as fs_handle: - yield fs_handle + try: + with open_filesystem(vc, volname) as fs_handle: + yield fs_handle + except CephfsConnectionException as ce: + raise VolumeException(ce.errno, ce.error_str) @contextmanager @@ -149,5 +152,8 @@ def open_volume_lockless(vc, volname): :param volname: volume name :return: yields a volume handle (ceph filesystem handle) """ - with open_filesystem(vc, volname) as fs_handle: - yield fs_handle + try: + with open_filesystem(vc, volname) as fs_handle: + yield fs_handle + except CephfsConnectionException as ce: + raise VolumeException(ce.errno, ce.error_str) diff --git a/src/pybind/mgr/volumes/fs/volume.py b/src/pybind/mgr/volumes/fs/volume.py index f0a39cd41c3..af49d41447b 100644 --- a/src/pybind/mgr/volumes/fs/volume.py +++ b/src/pybind/mgr/volumes/fs/volume.py @@ -526,12 +526,14 @@ class VolumeClient(CephfsClient): def list_subvolume_groups(self, **kwargs): volname = kwargs['vol_name'] ret = 0, '[]', "" + volume_exists = False try: with open_volume(self, volname) as fs_handle: + volume_exists = True groups = listdir(fs_handle, self.volspec.base_dir) ret = 0, name_to_json(groups), "" except VolumeException as ve: - if not ve.errno == -errno.ENOENT: + if not ve.errno == -errno.ENOENT or not volume_exists: ret = self.volume_exception_to_retval(ve) return ret