Skip to content

Commit 651fb2e

Browse files
committed
mgr/snap_schedule: catch all exceptions for cli
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 <[email protected]>
1 parent 2318326 commit 651fb2e

File tree

1 file changed

+26
-10
lines changed

1 file changed

+26
-10
lines changed

src/pybind/mgr/snap_schedule/module.py

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ def snap_schedule_get(self,
7272
ret_scheds = self.client.get_snap_schedules(use_fs, path)
7373
except CephfsConnectionException as e:
7474
return e.to_tuple()
75+
except Exception as e:
76+
return -errno.EIO, '', str(e)
7577
if format == 'json':
7678
json_report = ','.join([ret_sched.report_json() for ret_sched in ret_scheds])
7779
return 0, f'[{json_report}]', ''
@@ -93,6 +95,8 @@ def snap_schedule_list(self, path: str,
9395
self.log.debug(f'recursive is {recursive}')
9496
except CephfsConnectionException as e:
9597
return e.to_tuple()
98+
except Exception as e:
99+
return -errno.EIO, '', str(e)
96100
if not scheds:
97101
if format == 'json':
98102
output: Dict[str, str] = {}
@@ -136,6 +140,8 @@ def snap_schedule_add(self,
136140
return -errno.ENOENT, '', str(e)
137141
except CephfsConnectionException as e:
138142
return e.to_tuple()
143+
except Exception as e:
144+
return -errno.EIO, '', str(e)
139145
return 0, suc_msg, ''
140146

141147
@CLIWriteCommand('fs snap-schedule remove')
@@ -153,10 +159,12 @@ def snap_schedule_rm(self,
153159
return -errno.EINVAL, '', f"no such filesystem: {use_fs}"
154160
abs_path = path
155161
self.client.rm_snap_schedule(use_fs, abs_path, repeat, start)
156-
except CephfsConnectionException as e:
157-
return e.to_tuple()
158162
except ValueError as e:
159163
return -errno.ENOENT, '', str(e)
164+
except CephfsConnectionException as e:
165+
return e.to_tuple()
166+
except Exception as e:
167+
return -errno.EIO, '', str(e)
160168
return 0, 'Schedule removed for path {}'.format(path), ''
161169

162170
@CLIWriteCommand('fs snap-schedule retention add')
@@ -176,10 +184,12 @@ def snap_schedule_retention_add(self,
176184
self.client.add_retention_spec(use_fs, abs_path,
177185
retention_spec_or_period,
178186
retention_count)
179-
except CephfsConnectionException as e:
180-
return e.to_tuple()
181187
except ValueError as e:
182188
return -errno.ENOENT, '', str(e)
189+
except CephfsConnectionException as e:
190+
return e.to_tuple()
191+
except Exception as e:
192+
return -errno.EIO, '', str(e)
183193
return 0, 'Retention added to path {}'.format(path), ''
184194

185195
@CLIWriteCommand('fs snap-schedule retention remove')
@@ -199,10 +209,12 @@ def snap_schedule_retention_rm(self,
199209
self.client.rm_retention_spec(use_fs, abs_path,
200210
retention_spec_or_period,
201211
retention_count)
202-
except CephfsConnectionException as e:
203-
return e.to_tuple()
204212
except ValueError as e:
205213
return -errno.ENOENT, '', str(e)
214+
except CephfsConnectionException as e:
215+
return e.to_tuple()
216+
except Exception as e:
217+
return -errno.EIO, '', str(e)
206218
return 0, 'Retention removed from path {}'.format(path), ''
207219

208220
@CLIWriteCommand('fs snap-schedule activate')
@@ -220,10 +232,12 @@ def snap_schedule_activate(self,
220232
return -errno.EINVAL, '', f"no such filesystem: {use_fs}"
221233
abs_path = path
222234
self.client.activate_snap_schedule(use_fs, abs_path, repeat, start)
223-
except CephfsConnectionException as e:
224-
return e.to_tuple()
225235
except ValueError as e:
226236
return -errno.ENOENT, '', str(e)
237+
except CephfsConnectionException as e:
238+
return e.to_tuple()
239+
except Exception as e:
240+
return -errno.EIO, '', str(e)
227241
return 0, 'Schedule activated for path {}'.format(path), ''
228242

229243
@CLIWriteCommand('fs snap-schedule deactivate')
@@ -241,8 +255,10 @@ def snap_schedule_deactivate(self,
241255
return -errno.EINVAL, '', f"no such filesystem: {use_fs}"
242256
abs_path = path
243257
self.client.deactivate_snap_schedule(use_fs, abs_path, repeat, start)
244-
except CephfsConnectionException as e:
245-
return e.to_tuple()
246258
except ValueError as e:
247259
return -errno.ENOENT, '', str(e)
260+
except CephfsConnectionException as e:
261+
return e.to_tuple()
262+
except Exception as e:
263+
return -errno.EIO, '', str(e)
248264
return 0, 'Schedule deactivated for path {}'.format(path), ''

0 commit comments

Comments
 (0)