# -*- coding: utf-8 -*-
from __future__ import absolute_import
-from .helper import DashboardTestCase
+from .helper import DashboardTestCase, JObj
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))
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)
# -*- coding: utf-8 -*-
from __future__ import absolute_import
+import cherrypy
+
from . import ApiController, RESTController
from .. import mgr
from ..security import Scope
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()):
</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"
}
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)) {
-<cd-table [data]="counters"
+<cd-table *ngIf="counters; else warning"
+ [data]="counters"
[columns]="columns"
columnMode="flex"
[autoSave]="false"
{{ 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>
}
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;
+ }
+ }
+ );
}
}
);
});
- it('should redirect 404', (done) => {
- runRouterTest(
- {
- status: 404
- },
- [['/404']],
- done
- );
- });
-
it('should show notification (error string)', function(done) {
runNotificationTest(
'foobar',
case 403:
this.router.navigate(['/403']);
break;
- case 404:
- this.router.navigate(['/404']);
- break;
}
let timeoutId;