From: Sébastien Han Date: Tue, 16 Mar 2021 17:04:06 +0000 (+0100) Subject: mgr/pybind/snap_schedule: do not fail when no fs snapshot schedules are available X-Git-Tag: v17.1.0~2138^2~1 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=74a7cdda6b4b3f310bdc845cc84bca11a7a0539c;p=ceph-ci.git mgr/pybind/snap_schedule: do not fail when no fs snapshot schedules are available When listing for available snapshot schedules, we should not an error in case there is none. We should just return 0 with an empty dict. Fixes: https://tracker.ceph.com/issues/49837 Signed-off-by: Sébastien Han --- diff --git a/qa/tasks/cephfs/test_snap_schedules.py b/qa/tasks/cephfs/test_snap_schedules.py index 789a082af10..db3c402bc18 100644 --- a/qa/tasks/cephfs/test_snap_schedules.py +++ b/qa/tasks/cephfs/test_snap_schedules.py @@ -173,7 +173,7 @@ class TestSnapSchedules(CephFSTestCase): def test_non_existent_snap_schedule_list(self): """Test listing snap schedules on a non-existing filesystem path failure""" try: - self.fs_snap_schedule_cmd('list', f'path={TestSnapSchedules.TEST_DIRECTORY}', 'format=json') + self.fs_snap_schedule_cmd('list', f'path={TestSnapSchedules.TEST_DIRECTORY}') except CommandFailedError as ce: if ce.exitstatus != errno.ENOENT: raise RuntimeError('incorrect errno when listing a non-existing snap schedule') @@ -185,7 +185,7 @@ class TestSnapSchedules(CephFSTestCase): self.mount_a.run_shell(['mkdir', '-p', TestSnapSchedules.TEST_DIRECTORY]) try: - self.fs_snap_schedule_cmd('list', f'path={TestSnapSchedules.TEST_DIRECTORY}', 'format=json') + self.fs_snap_schedule_cmd('list', f'path={TestSnapSchedules.TEST_DIRECTORY}') except CommandFailedError as ce: if ce.exitstatus != errno.ENOENT: raise RuntimeError('incorrect errno when listing a non-existing snap schedule') @@ -203,7 +203,7 @@ class TestSnapSchedules(CephFSTestCase): self.fs_snap_schedule_cmd('remove', f'path={TestSnapSchedules.TEST_DIRECTORY}') try: - self.fs_snap_schedule_cmd('list', f'path={TestSnapSchedules.TEST_DIRECTORY}', 'format=json') + self.fs_snap_schedule_cmd('list', f'path={TestSnapSchedules.TEST_DIRECTORY}') except CommandFailedError as ce: if ce.exitstatus != errno.ENOENT: raise RuntimeError('incorrect errno when listing a non-existing snap schedule') diff --git a/src/pybind/mgr/snap_schedule/module.py b/src/pybind/mgr/snap_schedule/module.py index 84b04c4bb7a..ec4b30513cc 100644 --- a/src/pybind/mgr/snap_schedule/module.py +++ b/src/pybind/mgr/snap_schedule/module.py @@ -100,6 +100,9 @@ class Module(MgrModule): except CephfsConnectionException as e: return e.to_tuple() if not scheds: + if format == 'json': + output: Dict[str, str] = {} + return 0, json.dumps(output), '' return -errno.ENOENT, '', f'SnapSchedule for {path} not found' if format == 'json': # json_list = ','.join([sched.json_list() for sched in scheds])