]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/dashboard: Fix errors when clicking on new OSD 24369/head
authorPatrick Nawracay <pnawracay@suse.com>
Tue, 2 Oct 2018 13:35:09 +0000 (15:35 +0200)
committerPatrick Nawracay <pnawracay@suse.com>
Mon, 8 Oct 2018 08:45:58 +0000 (10:45 +0200)
Fixes: http://tracker.ceph.com/issues/36245
Signed-off-by: Patrick Nawracay <pnawracay@suse.com>
qa/tasks/mgr/dashboard/test_perf_counters.py
src/pybind/mgr/dashboard/controllers/perf_counters.py
src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/osd/osd-details/osd-details.component.html
src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/osd/osd-details/osd-details.component.ts
src/pybind/mgr/dashboard/frontend/src/app/ceph/performance-counter/table-performance-counter/table-performance-counter.component.html
src/pybind/mgr/dashboard/frontend/src/app/ceph/performance-counter/table-performance-counter/table-performance-counter.component.ts
src/pybind/mgr/dashboard/frontend/src/app/shared/services/api-interceptor.service.spec.ts
src/pybind/mgr/dashboard/frontend/src/app/shared/services/api-interceptor.service.ts

index 069e667b927c4b594d749830dac661710c996a4e..cd016434646ab328bd4d933123430f42e417367a 100644 (file)
@@ -1,7 +1,7 @@
 # -*- coding: utf-8 -*-
 from __future__ import absolute_import
 
-from .helper import DashboardTestCase
+from .helper import DashboardTestCase, JObj
 
 
 class PerfCountersControllerTest(DashboardTestCase):
@@ -32,7 +32,6 @@ class PerfCountersControllerTest(DashboardTestCase):
             self.assertIn('unit', counter)
             self.assertIn('value', counter)
 
-
     def test_perf_counters_mon_get(self):
         mon = self.mons()[0]
         data = self._get('/api/perf_counters/mon/{}'.format(mon))
@@ -57,3 +56,18 @@ class PerfCountersControllerTest(DashboardTestCase):
             data = self._get('/api/perf_counters/osd/{}'.format(osd))
             self.assertStatus(200)
             self._validate_perf(osd, 'osd', data, allow_empty=False)
+
+    def test_perf_counters_not_found(self):
+        osds = self.ceph_cluster.mon_manager.get_osd_dump()
+        unused_id = int(list(map(lambda o: o['osd'], osds)).pop()) + 1
+
+        self._get('/api/perf_counters/osd/{}'.format(unused_id))
+        self.assertStatus(404)
+        schema = JObj(sub_elems={
+            'status': str,
+            'version': str,
+            'detail': str,
+            'traceback': str,
+        })
+        self.assertEqual(self._resp.json()['detail'], 'osd.{} not found'.format(unused_id))
+        self.assertSchemaBody(schema)
index 152d59b73e3c2472b892f91229f08684bd399991..130dc1024ad1f55a9a54816d791809407ccd9543 100644 (file)
@@ -1,6 +1,8 @@
 # -*- coding: utf-8 -*-
 from __future__ import absolute_import
 
+import cherrypy
+
 from . import ApiController, RESTController
 from .. import mgr
 from ..security import Scope
@@ -12,7 +14,10 @@ class PerfCounter(RESTController):
 
     def get(self, service_id):
         schema_dict = mgr.get_perf_schema(self.service_type, str(service_id))
-        schema = schema_dict["{}.{}".format(self.service_type, service_id)]
+        try:
+            schema = schema_dict["{}.{}".format(self.service_type, service_id)]
+        except KeyError as e:
+            raise cherrypy.HTTPError(404, "{0} not found".format(e.message))
         counters = []
 
         for key, value in sorted(schema.items()):
index d5773faf446312017f4328c95cab2500412068e6..4476bc22c409b9eaa4e4b473c002ddb1fef4dcc5 100644 (file)
@@ -5,10 +5,15 @@
     </cd-table-key-value>
   </tab>
   <tab heading="Metadata">
-    <cd-table-key-value *ngIf="osd.loaded"
+    <cd-table-key-value *ngIf="osd.loaded && osd.details.osd_metadata; else noMetaData"
                         (fetchData)="osd.autoRefresh()"
                         [data]="osd.details.osd_metadata">
     </cd-table-key-value>
+    <ng-template #noMetaData>
+      <cd-warning-panel i18n>
+        Metadata not available
+      </cd-warning-panel>
+    </ng-template>
   </tab>
   <tab heading="Performance counter">
     <cd-table-performance-counter *ngIf="osd.loaded"
index 08bf6e3f00187b7cc39bf656940e4771dc69c646..07c969a1b2dda5a502446126884d2600cc4aff68 100644 (file)
@@ -32,7 +32,7 @@ export class OsdDetailsComponent implements OnChanges {
   }
 
   refresh() {
-    this.osdService.getDetails(this.osd.tree.id).subscribe((data: any) => {
+    this.osdService.getDetails(this.osd.id).subscribe((data: any) => {
       this.osd.details = data;
       this.osd.histogram_failed = '';
       if (!_.isObject(data.histogram)) {
index eff5c856383291c66c9785952b05d5398bf24b7a..862bf205c602977f2b7c5ad7fbb86ce74cdb95e1 100644 (file)
@@ -1,4 +1,5 @@
-<cd-table [data]="counters"
+<cd-table *ngIf="counters; else warning"
+          [data]="counters"
           [columns]="columns"
           columnMode="flex"
           [autoSave]="false"
@@ -7,3 +8,8 @@
     {{ row.value | dimless }} {{ row.unit }}
   </ng-template>
 </cd-table>
+<ng-template #warning>
+  <cd-warning-panel i18n>
+    Performance counters not available
+  </cd-warning-panel>
+</ng-template>
index a18f08c52622d066d4e938aa52f987d282001936..5b9aa29cffec313a05a98c7f745f0cf0daf0da37 100644 (file)
@@ -53,10 +53,16 @@ export class TablePerformanceCounterComponent implements OnInit {
   }
 
   getCounters() {
-    this.performanceCounterService
-      .get(this.serviceType, this.serviceId)
-      .subscribe((resp: object[]) => {
+    this.performanceCounterService.get(this.serviceType, this.serviceId).subscribe(
+      (resp: object[]) => {
         this.counters = resp;
-      });
+      },
+      (error) => {
+        if (error.status === 404) {
+          error.preventDefault();
+          this.counters = null;
+        }
+      }
+    );
   }
 }
index 6d98709fae340204167d60c3392d8dd5123a770a..f7513368c9dabbbdcc427a26922246c91b61dfb0 100644 (file)
@@ -82,16 +82,6 @@ describe('ApiInterceptorService', () => {
     );
   });
 
-  it('should redirect 404', (done) => {
-    runRouterTest(
-      {
-        status: 404
-      },
-      [['/404']],
-      done
-    );
-  });
-
   it('should show notification (error string)', function(done) {
     runNotificationTest(
       'foobar',
index 60c41debc56084c06a9924e6ea86e036981d4b50..d6d34886a3fa78cdb660ad6d22470db0df35535c 100644 (file)
@@ -59,9 +59,6 @@ export class ApiInterceptorService implements HttpInterceptor {
             case 403:
               this.router.navigate(['/403']);
               break;
-            case 404:
-              this.router.navigate(['/404']);
-              break;
           }
 
           let timeoutId;