]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/snap_schedule: catch all exceptions for cli 52753/head
authorMilind Changire <mchangir@redhat.com>
Wed, 26 Apr 2023 07:04:10 +0000 (12:34 +0530)
committerMilind Changire <mchangir@redhat.com>
Wed, 2 Aug 2023 06:38:18 +0000 (12:08 +0530)
Any unknown exception causes the module to be unloaded and unresponsive.
So, it'll be ideal to catch all exceptions during command-line interaction
and report them instead of crashing with a traceback.

Fixes: https://tracker.ceph.com/issues/58195
Signed-off-by: Milind Changire <mchangir@redhat.com>
(cherry picked from commit 651fb2e3b515c80e9dc4a24638c9d1a0d487c729)

src/pybind/mgr/snap_schedule/module.py

index 93770f350363ba4763ca114514e775478414afa6..94876506e7f4f6b6ae4c5a41e8924ec39964773e 100644 (file)
@@ -70,6 +70,8 @@ class Module(MgrModule):
             ret_scheds = self.client.get_snap_schedules(use_fs, path)
         except CephfsConnectionException as e:
             return e.to_tuple()
+        except Exception as e:
+            return -errno.EIO, '', str(e)
         if format == 'json':
             json_report = ','.join([ret_sched.report_json() for ret_sched in ret_scheds])
             return 0, f'[{json_report}]', ''
@@ -90,6 +92,8 @@ class Module(MgrModule):
             self.log.debug(f'recursive is {recursive}')
         except CephfsConnectionException as e:
             return e.to_tuple()
+        except Exception as e:
+            return -errno.EIO, '', str(e)
         if not scheds:
             if format == 'json':
                 output = {} # type: Dict[str,str]
@@ -133,6 +137,8 @@ class Module(MgrModule):
             return -errno.ENOENT, '', str(e)
         except CephfsConnectionException as e:
             return e.to_tuple()
+        except Exception as e:
+            return -errno.EIO, '', str(e)
         return 0, suc_msg, ''
 
     @CLIWriteCommand('fs snap-schedule remove')
@@ -150,10 +156,12 @@ class Module(MgrModule):
                 return -errno.EINVAL, '', f"no such filesystem: {use_fs}"
             abs_path = path
             self.client.rm_snap_schedule(use_fs, abs_path, repeat, start)
-        except CephfsConnectionException as e:
-            return e.to_tuple()
         except ValueError as e:
             return -errno.ENOENT, '', str(e)
+        except CephfsConnectionException as e:
+            return e.to_tuple()
+        except Exception as e:
+            return -errno.EIO, '', str(e)
         return 0, 'Schedule removed for path {}'.format(path), ''
 
     @CLIWriteCommand('fs snap-schedule retention add')
@@ -173,10 +181,12 @@ class Module(MgrModule):
             self.client.add_retention_spec(use_fs, abs_path,
                                           retention_spec_or_period,
                                           retention_count)
-        except CephfsConnectionException as e:
-            return e.to_tuple()
         except ValueError as e:
             return -errno.ENOENT, '', str(e)
+        except CephfsConnectionException as e:
+            return e.to_tuple()
+        except Exception as e:
+            return -errno.EIO, '', str(e)
         return 0, 'Retention added to path {}'.format(path), ''
 
     @CLIWriteCommand('fs snap-schedule retention remove')
@@ -196,10 +206,12 @@ class Module(MgrModule):
             self.client.rm_retention_spec(use_fs, abs_path,
                                           retention_spec_or_period,
                                           retention_count)
-        except CephfsConnectionException as e:
-            return e.to_tuple()
         except ValueError as e:
             return -errno.ENOENT, '', str(e)
+        except CephfsConnectionException as e:
+            return e.to_tuple()
+        except Exception as e:
+            return -errno.EIO, '', str(e)
         return 0, 'Retention removed from path {}'.format(path), ''
 
     @CLIWriteCommand('fs snap-schedule activate')
@@ -217,10 +229,12 @@ class Module(MgrModule):
                 return -errno.EINVAL, '', f"no such filesystem: {use_fs}"
             abs_path = path
             self.client.activate_snap_schedule(use_fs, abs_path, repeat, start)
-        except CephfsConnectionException as e:
-            return e.to_tuple()
         except ValueError as e:
             return -errno.ENOENT, '', str(e)
+        except CephfsConnectionException as e:
+            return e.to_tuple()
+        except Exception as e:
+            return -errno.EIO, '', str(e)
         return 0, 'Schedule activated for path {}'.format(path), ''
 
     @CLIWriteCommand('fs snap-schedule deactivate')
@@ -238,8 +252,10 @@ class Module(MgrModule):
                 return -errno.EINVAL, '', f"no such filesystem: {use_fs}"
             abs_path = path
             self.client.deactivate_snap_schedule(use_fs, abs_path, repeat, start)
-        except CephfsConnectionException as e:
-            return e.to_tuple()
         except ValueError as e:
             return -errno.ENOENT, '', str(e)
+        except CephfsConnectionException as e:
+            return e.to_tuple()
+        except Exception as e:
+            return -errno.EIO, '', str(e)
         return 0, 'Schedule deactivated for path {}'.format(path), ''