From: Ricardo Dias Date: Thu, 22 Mar 2018 12:22:41 +0000 (+0000) Subject: mgr/dashboard: fix dashboard python 3 support X-Git-Tag: wip-pdonnell-testing-20180329.205607~61^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=25c75a952daf40e1432aed808f160b92f35eef3b;p=ceph-ci.git mgr/dashboard: fix dashboard python 3 support Signed-off-by: Ricardo Dias --- diff --git a/qa/tasks/mgr/dashboard/helper.py b/qa/tasks/mgr/dashboard/helper.py index 3e0c836e8b0..ae4e9d1b851 100644 --- a/qa/tasks/mgr/dashboard/helper.py +++ b/qa/tasks/mgr/dashboard/helper.py @@ -78,7 +78,11 @@ class DashboardTestCase(MgrTestCase): log.info("request %s to %s", method, url) if method == 'GET': self._resp = self._session.get(url) - return self._resp.json() + try: + return self._resp.json() + except ValueError as ex: + log.exception("Failed to decode response: %s", self._resp.text) + raise ex elif method == 'POST': self._resp = self._session.post(url, json=data) elif method == 'DELETE': diff --git a/src/pybind/mgr/dashboard/.pylintrc b/src/pybind/mgr/dashboard/.pylintrc index ab5d1f8a777..13e23167f60 100644 --- a/src/pybind/mgr/dashboard/.pylintrc +++ b/src/pybind/mgr/dashboard/.pylintrc @@ -3,7 +3,7 @@ # A comma-separated list of package or module names from where C extensions may # be loaded. Extensions are loading into the active Python interpreter and may # run arbitrary code -extension-pkg-whitelist=rados,rbd +extension-pkg-whitelist=rados,rbd,math # Add files or directories to the blacklist. They should be base names, not # paths. diff --git a/src/pybind/mgr/dashboard/controllers/cephfs.py b/src/pybind/mgr/dashboard/controllers/cephfs.py index c4786cebaf9..ea893560eb2 100644 --- a/src/pybind/mgr/dashboard/controllers/cephfs.py +++ b/src/pybind/mgr/dashboard/controllers/cephfs.py @@ -192,7 +192,7 @@ class CephFS(BaseController): # Find the standby replays # pylint: disable=unused-variable - for gid_str, daemon_info in mdsmap['info'].iteritems(): + for gid_str, daemon_info in mdsmap['info'].items(): if daemon_info['state'] != "up:standby-replay": continue diff --git a/src/pybind/mgr/dashboard/controllers/osd.py b/src/pybind/mgr/dashboard/controllers/osd.py index e847b1fd891..f777f083457 100644 --- a/src/pybind/mgr/dashboard/controllers/osd.py +++ b/src/pybind/mgr/dashboard/controllers/osd.py @@ -58,7 +58,7 @@ class Osd(RESTController): # Gauge stats for s in ['osd.numpg', 'osd.stat_bytes', 'osd.stat_bytes_used']: o['stats'][s.split('.')[1]] = self.get_latest(osd_spec, s) - return osds.values() + return list(osds.values()) def get_osd_map(self): osds = {} diff --git a/src/pybind/mgr/dashboard/controllers/perf_counters.py b/src/pybind/mgr/dashboard/controllers/perf_counters.py index 59692d3309a..5e6988af178 100644 --- a/src/pybind/mgr/dashboard/controllers/perf_counters.py +++ b/src/pybind/mgr/dashboard/controllers/perf_counters.py @@ -22,8 +22,8 @@ class PerfCounter(RESTController): return 0 def get(self, service_id): - schema = mgr.get_perf_schema( - self._service_type, str(service_id)).values()[0] + schema_dict = mgr.get_perf_schema(self._service_type, str(service_id)) + schema = schema_dict["{}.{}".format(self._service_type, service_id)] counters = [] for key, value in sorted(schema.items()): diff --git a/src/pybind/mgr/dashboard/controllers/rbd.py b/src/pybind/mgr/dashboard/controllers/rbd.py index b73697b0a16..8823bcc5cfa 100644 --- a/src/pybind/mgr/dashboard/controllers/rbd.py +++ b/src/pybind/mgr/dashboard/controllers/rbd.py @@ -77,6 +77,10 @@ class Rbd(RESTController): stat['features'] = features stat['features_name'] = self._format_bitmask(features) + # the following keys are deprecated + del stat['parent_pool'] + del stat['parent_name'] + try: parent_info = i.parent_info() parent = "{}@{}".format(parent_info[0], parent_info[1]) diff --git a/src/pybind/mgr/dashboard/tools.py b/src/pybind/mgr/dashboard/tools.py index 8775a708730..e949b96122e 100644 --- a/src/pybind/mgr/dashboard/tools.py +++ b/src/pybind/mgr/dashboard/tools.py @@ -124,6 +124,12 @@ class RequestLoggingTool(cherrypy.Tool): def _format_bytes(self, num): units = ['B', 'K', 'M', 'G'] + if isinstance(num, str): + try: + num = int(num) + except ValueError: + return "n/a" + format_str = "{:.0f}{}" for i, unit in enumerate(units): div = 2**(10*i)