From 85667ad225882cdf4af58166b0d302e69b2d17c0 Mon Sep 17 00:00:00 2001 From: Yanhu Cao Date: Mon, 9 Oct 2017 13:47:11 +0800 Subject: [PATCH] mgr: fix "osd status" command exception if OSD not in pgmap stats Fixes: http://tracker.ceph.com/issues/21707 Signed-off-by: Yanhu Cao (cherry picked from commit ce3953248a04c065643938898029cfbf9c843ea3) --- src/pybind/mgr/status/module.py | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/pybind/mgr/status/module.py b/src/pybind/mgr/status/module.py index 606fb93e638c..70a7e36e6b07 100644 --- a/src/pybind/mgr/status/module.py +++ b/src/pybind/mgr/status/module.py @@ -279,12 +279,20 @@ class Module(MgrModule): if bucket_filter and osd_id not in filter_osds: continue - metadata = self.get_metadata('osd', "%s" % osd_id) - stats = osd_stats[osd_id] - - osd_table.add_row([osd_id, metadata['hostname'], - self.format_bytes(stats['kb_used'] * 1024, 5), - self.format_bytes(stats['kb_avail'] * 1024, 5), + hostname = "" + kb_used = 0 + kb_avail = 0 + + if osd_id in osd_stats: + metadata = self.get_metadata('osd', "%s" % osd_id) + stats = osd_stats[osd_id] + hostname = metadata['hostname'] + kb_used = stats['kb_used'] * 1024 + kb_avail = stats['kb_avail'] * 1024 + + osd_table.add_row([osd_id, hostname, + self.format_bytes(kb_used, 5), + self.format_bytes(kb_avail, 5), self.format_dimless(self.get_rate("osd", osd_id.__str__(), "osd.op_w") + self.get_rate("osd", osd_id.__str__(), "osd.op_rw"), 5), self.format_bytes(self.get_rate("osd", osd_id.__str__(), "osd.op_in_bytes"), 5), -- 2.47.3