]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/pybind/snap_schedule: do not fail when no fs snapshot schedules are available
authorSébastien Han <seb@redhat.com>
Tue, 16 Mar 2021 17:04:06 +0000 (18:04 +0100)
committerSébastien Han <seb@redhat.com>
Wed, 2 Jun 2021 13:55:57 +0000 (15:55 +0200)
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 <seb@redhat.com>
(cherry picked from commit 74a7cdda6b4b3f310bdc845cc84bca11a7a0539c)

qa/tasks/cephfs/test_snap_schedules.py
src/pybind/mgr/snap_schedule/module.py

index f0e5a342368b4ed66881654b89bb0e04c2342dd3..459003031f0fc9226fe9270c41bcc550b8468737 100644 (file)
@@ -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')
index a1a34e08b07aceb0d1a958d68149120483547859..405fb895692bc5294ad6e9b42ac46d263fd7da93 100644 (file)
@@ -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])