]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/cephadm: handle JSONDecodeError in the serve loop
authorMichael Fritch <mfritch@suse.com>
Wed, 4 Nov 2020 18:12:34 +0000 (11:12 -0700)
committerSebastian Wagner <sebastian.wagner@suse.com>
Thu, 7 Jan 2021 12:02:21 +0000 (13:02 +0100)
avoid exceptions when attempting to parse invalid JSON output as this
will later cause the cephadm module to fail with a MGR_MODULE_ERROR err

Fixes: https://tracker.ceph.com/issues/48118
Signed-off-by: Michael Fritch <mfritch@suse.com>
(cherry picked from commit 6d759fb5deac0c52b3c738a2e695738228749420)

src/pybind/mgr/cephadm/serve.py

index 99cfa79e369089baf52faedddb6c73f62876a580..7d20f262ea74b374e2cbbe280964f7775ece9728 100644 (file)
@@ -207,9 +207,13 @@ class CephadmServe:
             if code:
                 return 'host %s cephadm ls returned %d: %s' % (
                     host, code, err)
+            ls = json.loads(''.join(out))
+        except ValueError:
+            msg = 'host %s scrape failed: Cannot decode JSON' % host
+            self.log.exception('%s: \'%s\'' % (msg, ''.join(out)))
+            return msg
         except Exception as e:
             return 'host %s scrape failed: %s' % (host, e)
-        ls = json.loads(''.join(out))
         dm = {}
         for d in ls:
             if not d['style'].startswith('cephadm'):
@@ -276,9 +280,13 @@ class CephadmServe:
             if code:
                 return 'host %s ceph-volume inventory returned %d: %s' % (
                     host, code, err)
+            devices = json.loads(''.join(out))
+        except ValueError:
+            msg = 'host %s scrape failed: Cannot decode JSON' % host
+            self.log.exception('%s: \'%s\'' % (msg, ''.join(out)))
+            return msg
         except Exception as e:
             return 'host %s ceph-volume inventory failed: %s' % (host, e)
-        devices = json.loads(''.join(out))
         try:
             out, err, code = self.mgr._run_cephadm(
                 host, 'mon',
@@ -288,9 +296,13 @@ class CephadmServe:
             if code:
                 return 'host %s list-networks returned %d: %s' % (
                     host, code, err)
+            networks = json.loads(''.join(out))
+        except ValueError:
+            msg = 'host %s scrape failed: Cannot decode JSON' % host
+            self.log.exception('%s: \'%s\'' % (msg, ''.join(out)))
+            return msg
         except Exception as e:
             return 'host %s list-networks failed: %s' % (host, e)
-        networks = json.loads(''.join(out))
         self.log.debug('Refreshed host %s devices (%d) networks (%s)' % (
             host, len(devices), len(networks)))
         devices = inventory.Devices.from_json(devices)