From a4956b40b2e520c3f0146e06b27746bc947b3f06 Mon Sep 17 00:00:00 2001 From: Patrick Nawracay Date: Tue, 2 Oct 2018 15:35:09 +0200 Subject: [PATCH] mgr/dashboard: Fix errors when clicking on new OSD Fixes: http://tracker.ceph.com/issues/36245 Signed-off-by: Patrick Nawracay --- qa/tasks/mgr/dashboard/test_perf_counters.py | 18 ++++++++++++++++-- .../mgr/dashboard/controllers/perf_counters.py | 7 ++++++- .../osd/osd-details/osd-details.component.html | 7 ++++++- .../osd/osd-details/osd-details.component.ts | 2 +- .../table-performance-counter.component.html | 8 +++++++- .../table-performance-counter.component.ts | 14 ++++++++++---- .../services/api-interceptor.service.spec.ts | 10 ---------- .../shared/services/api-interceptor.service.ts | 3 --- 8 files changed, 46 insertions(+), 23 deletions(-) diff --git a/qa/tasks/mgr/dashboard/test_perf_counters.py b/qa/tasks/mgr/dashboard/test_perf_counters.py index 069e667b927c4..cd016434646ab 100644 --- a/qa/tasks/mgr/dashboard/test_perf_counters.py +++ b/qa/tasks/mgr/dashboard/test_perf_counters.py @@ -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) diff --git a/src/pybind/mgr/dashboard/controllers/perf_counters.py b/src/pybind/mgr/dashboard/controllers/perf_counters.py index 152d59b73e3c2..130dc1024ad1f 100644 --- a/src/pybind/mgr/dashboard/controllers/perf_counters.py +++ b/src/pybind/mgr/dashboard/controllers/perf_counters.py @@ -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()): diff --git a/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/osd/osd-details/osd-details.component.html b/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/osd/osd-details/osd-details.component.html index d5773faf44631..4476bc22c409b 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/osd/osd-details/osd-details.component.html +++ b/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/osd/osd-details/osd-details.component.html @@ -5,10 +5,15 @@ - + + + Metadata not available + + { + this.osdService.getDetails(this.osd.id).subscribe((data: any) => { this.osd.details = data; this.osd.histogram_failed = ''; if (!_.isObject(data.histogram)) { diff --git a/src/pybind/mgr/dashboard/frontend/src/app/ceph/performance-counter/table-performance-counter/table-performance-counter.component.html b/src/pybind/mgr/dashboard/frontend/src/app/ceph/performance-counter/table-performance-counter/table-performance-counter.component.html index eff5c85638329..862bf205c6029 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/ceph/performance-counter/table-performance-counter/table-performance-counter.component.html +++ b/src/pybind/mgr/dashboard/frontend/src/app/ceph/performance-counter/table-performance-counter/table-performance-counter.component.html @@ -1,4 +1,5 @@ - + + + Performance counters not available + + diff --git a/src/pybind/mgr/dashboard/frontend/src/app/ceph/performance-counter/table-performance-counter/table-performance-counter.component.ts b/src/pybind/mgr/dashboard/frontend/src/app/ceph/performance-counter/table-performance-counter/table-performance-counter.component.ts index a18f08c52622d..5b9aa29cffec3 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/ceph/performance-counter/table-performance-counter/table-performance-counter.component.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/ceph/performance-counter/table-performance-counter/table-performance-counter.component.ts @@ -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; + } + } + ); } } diff --git a/src/pybind/mgr/dashboard/frontend/src/app/shared/services/api-interceptor.service.spec.ts b/src/pybind/mgr/dashboard/frontend/src/app/shared/services/api-interceptor.service.spec.ts index 6d98709fae340..f7513368c9dab 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/shared/services/api-interceptor.service.spec.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/shared/services/api-interceptor.service.spec.ts @@ -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', diff --git a/src/pybind/mgr/dashboard/frontend/src/app/shared/services/api-interceptor.service.ts b/src/pybind/mgr/dashboard/frontend/src/app/shared/services/api-interceptor.service.ts index 60c41debc5608..d6d34886a3fa7 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/shared/services/api-interceptor.service.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/shared/services/api-interceptor.service.ts @@ -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; -- 2.39.5