]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/dashboard: fix 500 error on block device iSCSI status page 20928/head
authorJason Dillaman <dillaman@redhat.com>
Thu, 15 Mar 2018 21:41:20 +0000 (17:41 -0400)
committerJason Dillaman <dillaman@redhat.com>
Fri, 16 Mar 2018 12:28:55 +0000 (08:28 -0400)
Signed-off-by: Jason Dillaman <dillaman@redhat.com>
src/pybind/mgr/dashboard/controllers/tcmu_iscsi.py
src/pybind/mgr/dashboard/tests/test_tcmu_iscsi.py

index f4849b7daa54a0b42c762e3c4635f7ca8ca134b8..068fa84374694f7afc539beff860d323588eab17 100644 (file)
@@ -11,6 +11,13 @@ SERVICE_TYPE = 'tcmu-runner'
 @ApiController('tcmuiscsi')
 @AuthRequired()
 class TcmuIscsi(RESTController):
+    def _get_rate(self, daemon_type, daemon_name, stat):
+        data = mgr.get_counter(daemon_type, daemon_name, stat)[stat]
+
+        if data and len(data) > 1:
+            return (data[-1][1] - data[-2][1]) / float(data[-1][0] - data[-2][0])
+        return 0
+
     # pylint: disable=too-many-locals,too-many-nested-blocks
     def list(self):  # pylint: disable=unused-argument
         daemons = {}
@@ -62,7 +69,7 @@ class TcmuIscsi(RESTController):
                     image['stats_history'] = {}
                     for s in ['rd', 'wr', 'rd_bytes', 'wr_bytes']:
                         perf_key = "{}{}".format(perf_key_prefix, s)
-                        image['stats'][s] = mgr.get_rate(
+                        image['stats'][s] = self._get_rate(
                             'tcmu-runner', service_id, perf_key)
                         image['stats_history'][s] = mgr.get_counter(
                             'tcmu-runner', service_id, perf_key)[perf_key]
index 88077cbb5bc329533db42e548a3a4c73a70a2b28..84cd7eccc47043f687b7fc8794255b94fe6cbbf4 100644 (file)
@@ -26,14 +26,12 @@ mocked_get_daemon_status = {
 
 mocked_get_counter = {
     'librbd-42-pool1-image1.lock_acquired_time': [[10000.0, 10000.0]],
-    'librbd-42-pool1-image1.rd': 43,
-    'librbd-42-pool1-image1.wr': 44,
-    'librbd-42-pool1-image1.rd_bytes': 45,
-    'librbd-42-pool1-image1.wr_bytes': 46,
+    'librbd-42-pool1-image1.rd': [[0, 0], [1, 43]],
+    'librbd-42-pool1-image1.wr': [[0, 0], [1, 44]],
+    'librbd-42-pool1-image1.rd_bytes': [[0, 0], [1, 45]],
+    'librbd-42-pool1-image1.wr_bytes': [[0, 0], [1, 46]],
 }
 
-mocked_get_rate = 47
-
 
 class TcmuIscsiControllerTest(ControllerTestCase):
 
@@ -43,7 +41,6 @@ class TcmuIscsiControllerTest(ControllerTestCase):
         mgr.get_metadata.return_value = mocked_metadata
         mgr.get_daemon_status.return_value = mocked_get_daemon_status
         mgr.get_counter.return_value = mocked_get_counter
-        mgr.get_rate.return_value = mocked_get_rate
         mgr.url_prefix = ''
         TcmuIscsi._cp_config['tools.authenticate.on'] = False  # pylint: disable=protected-access
 
@@ -64,8 +61,15 @@ class TcmuIscsiControllerTest(ControllerTestCase):
                 'id': '42', 'optimized_paths': ['ceph-dev'],
                 'non_optimized_paths': [],
                 'optimized_since': 1e-05,
-                'stats': {'rd': 47, 'rd_bytes': 47, 'wr': 47, 'wr_bytes': 47},
+                'stats': {
+                    'rd': 43.0,
+                    'wr': 44.0,
+                    'rd_bytes': 45.0,
+                    'wr_bytes': 46.0},
                 'stats_history': {
-                    'rd': 43, 'wr': 44, 'rd_bytes': 45, 'wr_bytes': 46}
+                    'rd': [[0, 0], [1, 43]],
+                    'wr': [[0, 0], [1, 44]],
+                    'rd_bytes': [[0, 0], [1, 45]],
+                    'wr_bytes': [[0, 0], [1, 46]]}
             }]
         })