From: Michael Fritch Date: Wed, 4 Nov 2020 18:12:34 +0000 (-0700) Subject: mgr/cephadm: handle JSONDecodeError in the serve loop X-Git-Tag: v15.2.9~88^2~24 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=6d9d8b28ae669604f8b91eab1a81e02d09cc93b7;p=ceph.git mgr/cephadm: handle JSONDecodeError in the serve loop 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 (cherry picked from commit 6d759fb5deac0c52b3c738a2e695738228749420) --- diff --git a/src/pybind/mgr/cephadm/serve.py b/src/pybind/mgr/cephadm/serve.py index 99cfa79e369..7d20f262ea7 100644 --- a/src/pybind/mgr/cephadm/serve.py +++ b/src/pybind/mgr/cephadm/serve.py @@ -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)