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: v16.2.5~79^2~1 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=e6d6274e43364e92405ccd34d01f227e5cd538dd;p=ceph.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 (cherry picked from commit 74a7cdda6b4b3f310bdc845cc84bca11a7a0539c) --- diff --git a/qa/tasks/cephfs/test_snap_schedules.py b/qa/tasks/cephfs/test_snap_schedules.py index f0e5a342368b..459003031f0f 100644 --- a/qa/tasks/cephfs/test_snap_schedules.py +++ b/qa/tasks/cephfs/test_snap_schedules.py @@ -165,7 +165,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') @@ -177,7 +177,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') @@ -195,7 +195,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 a1a34e08b07a..405fb895692b 100644 --- a/src/pybind/mgr/snap_schedule/module.py +++ b/src/pybind/mgr/snap_schedule/module.py @@ -6,7 +6,7 @@ LGPL2.1. See file COPYING. import errno import json import sqlite3 -from typing import Sequence, Optional +from typing import Dict, Sequence, Optional from .fs.schedule_client import SnapSchedClient from mgr_module import MgrModule, CLIReadCommand, CLIWriteCommand, Option from mgr_util import CephfsConnectionException @@ -92,6 +92,9 @@ class Module(MgrModule): except CephfsConnectionException as e: return e.to_tuple() if not scheds: + if format == 'json': + output = {} # type: 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])