From: Patrick Donnelly Date: Wed, 31 May 2023 13:37:23 +0000 (-0400) Subject: pybind/mgr/devicehealth: do not crash if db not ready X-Git-Tag: v18.2.1~405^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=fa63652a8b943b545f68b10fef04834a1acc7018;p=ceph.git pybind/mgr/devicehealth: do not crash if db not ready This is a remote method called by telemtry so the @CLIRequiresDB decorator isn't appropriate. Fixes: https://tracker.ceph.com/issues/56239 Signed-off-by: Patrick Donnelly (cherry picked from commit 30570686cd73ff434e6ef41c2a5e1a5d3dd15e37) --- diff --git a/src/pybind/mgr/devicehealth/module.py b/src/pybind/mgr/devicehealth/module.py index 04986bb17b1..e924870352f 100644 --- a/src/pybind/mgr/devicehealth/module.py +++ b/src/pybind/mgr/devicehealth/module.py @@ -4,7 +4,7 @@ Device health monitoring import errno import json -from mgr_module import MgrModule, CommandResult, CLIRequiresDB, CLICommand, CLIReadCommand, Option +from mgr_module import MgrModule, CommandResult, CLIRequiresDB, CLICommand, CLIReadCommand, Option, MgrDBNotReady import operator import rados import re @@ -761,7 +761,10 @@ CREATE TABLE DeviceHealthMetrics ( return -1, '', 'unable to invoke diskprediction local or remote plugin' def get_recent_device_metrics(self, devid: str, min_sample: str) -> Dict[str, Dict[str, Any]]: - return self._get_device_metrics(devid, min_sample=min_sample) + try: + return self._get_device_metrics(devid, min_sample=min_sample) + except MgrDBNotReady: + return dict() def get_time_format(self) -> str: return TIME_FORMAT