From 74a7cdda6b4b3f310bdc845cc84bca11a7a0539c Mon Sep 17 00:00:00 2001 From: =?utf8?q?S=C3=A9bastien=20Han?= Date: Tue, 16 Mar 2021 18:04:06 +0100 Subject: [PATCH] mgr/pybind/snap_schedule: do not fail when no fs snapshot schedules are available MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 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 --- qa/tasks/cephfs/test_snap_schedules.py | 6 +++--- src/pybind/mgr/snap_schedule/module.py | 3 +++ 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/qa/tasks/cephfs/test_snap_schedules.py b/qa/tasks/cephfs/test_snap_schedules.py index 789a082af10a..db3c402bc180 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 84b04c4bb7a2..ec4b30513cc1 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]) -- 2.47.3