]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
pybind/mgr/devicehealth: do not crash if db not ready
authorPatrick Donnelly <pdonnell@redhat.com>
Wed, 31 May 2023 13:37:23 +0000 (09:37 -0400)
committerPatrick Donnelly <pdonnell@redhat.com>
Tue, 27 Jun 2023 18:08:28 +0000 (14:08 -0400)
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 <pdonnell@redhat.com>
(cherry picked from commit 30570686cd73ff434e6ef41c2a5e1a5d3dd15e37)

src/pybind/mgr/devicehealth/module.py

index 04986bb17b1bbf446ffe47b339a7ad90c5e52f3b..e924870352f86eb46e63535a44ab3eb9328f33b7 100644 (file)
@@ -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