From ef6c675ef76c1e5be1a7cc8559d09dd9d699b575 Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Sun, 31 Jan 2021 18:33:43 +0800 Subject: [PATCH] pybind/mgr/crash: define options using Option more type safe this way Signed-off-by: Kefu Chai --- src/pybind/mgr/crash/module.py | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/src/pybind/mgr/crash/module.py b/src/pybind/mgr/crash/module.py index e0235465848..7f52f95e711 100644 --- a/src/pybind/mgr/crash/module.py +++ b/src/pybind/mgr/crash/module.py @@ -1,5 +1,5 @@ import hashlib -from mgr_module import CLICommand, CLIReadCommand, CLIWriteCommand, MgrModule +from mgr_module import CLICommand, CLIReadCommand, CLIWriteCommand, MgrModule, Option import datetime import errno import functools @@ -27,27 +27,25 @@ def with_crashes(func: FuncT) -> FuncT: with self.crashes_lock: if not self.crashes: self._load_crashes() - return func(*args, **kwargs) + return func(self, *args, **kwargs) wrapper.__signature__ = inspect.signature(func) # type: ignore[attr-defined] return cast(FuncT, wrapper) class Module(MgrModule): MODULE_OPTIONS = [ - { - 'name': 'warn_recent_interval', - 'type': 'secs', - 'default': 60*60*24*14, - 'desc': 'time interval in which to warn about recent crashes', - 'runtime': True, - }, - { - 'name': 'retain_interval', - 'type': 'secs', - 'default': 60*60*24 * 365, - 'desc': 'how long to retain crashes before pruning them', - 'runtime': True, - }, + Option( + name='warn_recent_interval', + type='secs', + default=60*60*24*14, + desc='time interval in which to warn about recent crashes', + runtime=True), + Option( + name='retain_interval', + type='secs', + default=60*60*24 * 365, + desc='how long to retain crashes before pruning them', + runtime=True), ] def __init__(self, *args, **kwargs): -- 2.39.5