From fa63652a8b943b545f68b10fef04834a1acc7018 Mon Sep 17 00:00:00 2001 From: Patrick Donnelly Date: Wed, 31 May 2023 09:37:23 -0400 Subject: [PATCH] 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) --- src/pybind/mgr/devicehealth/module.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) 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 -- 2.39.5