Skip to content

Commit

Permalink
mgr/devicehealth: fix 'device get-health-metrics' when no metrics are…
Browse files Browse the repository at this point in the history
… stored

Signed-off-by: Sage Weil <[email protected]>
  • Loading branch information
liewegas committed Jun 11, 2018
1 parent 1fd80de commit c138c85
Showing 1 changed file with 19 additions and 11 deletions.
30 changes: 19 additions & 11 deletions src/pybind/mgr/devicehealth/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,22 +225,30 @@ def put_device_metrics(self, ioctx, devid, data):
ioctx.operate_write_op(op, devid)

def show_device_metrics(self, devid, sample):
# verify device exists
r = self.get("device " + devid)
if not r or 'device' not in r.keys():
return (-errno.ENOENT, '', 'device ' + devid + ' not found')
# fetch metrics
ioctx = self.open_connection()
res = {}
with rados.ReadOpCtx() as op:
iter, ret = ioctx.get_omap_vals(op, "", sample or '', 500) # fixme
assert ret == 0
ioctx.operate_read_op(op, devid)
for key, value in list(iter):
if sample and key != sample:
break
try:
v = json.loads(value)
except:
self.log.debug('unable to parse value for %s: "%s"' %
(key, value))
pass
res[key] = v
try:
ioctx.operate_read_op(op, devid)
for key, value in list(iter):
if sample and key != sample:
break
try:
v = json.loads(value)
except:
self.log.debug('unable to parse value for %s: "%s"' %
(key, value))
pass
res[key] = v
except:
pass
return (0, json.dumps(res, indent=4), '')

def extract_smart_features(self, raw):
Expand Down

0 comments on commit c138c85

Please sign in to comment.