From c7ba1ba15793f85ecfb6bcc8bea5ec14549cebfc Mon Sep 17 00:00:00 2001 From: Ernesto Puerta Date: Wed, 6 Feb 2019 12:55:35 +0100 Subject: [PATCH] mgr/dashboard: feature-toggles: minor fixes Fixes: http://tracker.ceph.com/issues/37530 Signed-off-by: Ernesto Puerta --- .../dashboard/health/health.component.html | 10 ++-- .../dashboard/health/health.component.spec.ts | 48 ++++++++++++++----- .../ceph/dashboard/health/health.component.ts | 4 +- .../navigation/navigation.component.html | 17 ++++--- .../navigation/navigation.component.ts | 4 +- .../frontend/src/locale/messages.xlf | 46 +++++++++--------- .../mgr/dashboard/plugins/feature_toggles.py | 7 +-- 7 files changed, 77 insertions(+), 59 deletions(-) diff --git a/src/pybind/mgr/dashboard/frontend/src/app/ceph/dashboard/health/health.component.html b/src/pybind/mgr/dashboard/frontend/src/app/ceph/dashboard/health/health.component.html index e9df42074acfc..358c712785b1f 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/ceph/dashboard/health/health.component.html +++ b/src/pybind/mgr/dashboard/frontend/src/app/ceph/dashboard/health/health.component.html @@ -1,5 +1,4 @@ - -
+ *ngIf="enabledFeature.rgw && healthData.rgw != null"> {{ healthData.rgw }} total @@ -112,7 +111,7 @@ link="/block/iscsi" class="col-sm-6 col-md-4 col-lg-3" contentClass="content-medium content-highlight" - *ngIf="enabled_feature.iscsi && healthData.iscsi_daemons != null"> + *ngIf="enabledFeature.iscsi && healthData.iscsi_daemons != null"> {{ healthData.iscsi_daemons }} total @@ -267,4 +266,3 @@
-
diff --git a/src/pybind/mgr/dashboard/frontend/src/app/ceph/dashboard/health/health.component.spec.ts b/src/pybind/mgr/dashboard/frontend/src/app/ceph/dashboard/health/health.component.spec.ts index 8bb61cf2cd879..cc5a3b61dbecc 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/ceph/dashboard/health/health.component.spec.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/ceph/dashboard/health/health.component.spec.ts @@ -46,17 +46,7 @@ describe('HealthComponent', () => { return new Permissions({ log: ['read'] }); } }; - const fakeFeatureTogglesService = { - get: () => { - return of({ - rbd: true, - mirroring: true, - iscsi: true, - cephfs: true, - rgw: true - }); - } - }; + let fakeFeatureTogglesService; configureTestBed({ imports: [SharedModule, HttpClientTestingModule, PopoverModule.forRoot()], @@ -72,12 +62,20 @@ describe('HealthComponent', () => { providers: [ i18nProviders, { provide: AuthStorageService, useValue: fakeAuthStorageService }, - { provide: FeatureTogglesService, useValue: fakeFeatureTogglesService }, PgCategoryService ] }); beforeEach(() => { + fakeFeatureTogglesService = spyOn(TestBed.get(FeatureTogglesService), 'get').and.returnValue( + of({ + rbd: true, + mirroring: true, + iscsi: true, + cephfs: true, + rgw: true + }) + ); fixture = TestBed.createComponent(HealthComponent); component = fixture.componentInstance; getHealthSpy = spyOn(TestBed.get(HealthService), 'getMinimalHealth'); @@ -98,6 +96,32 @@ describe('HealthComponent', () => { expect(infoCards.length).toBe(18); }); + describe('features disabled', () => { + beforeEach(() => { + fakeFeatureTogglesService.and.returnValue( + of({ + rbd: false, + mirroring: false, + iscsi: false, + cephfs: false, + rgw: false + }) + ); + fixture = TestBed.createComponent(HealthComponent); + component = fixture.componentInstance; + }); + + it('should not render cards related to disabled features', () => { + fixture.detectChanges(); + + const infoGroups = fixture.debugElement.nativeElement.querySelectorAll('cd-info-group'); + expect(infoGroups.length).toBe(3); + + const infoCards = fixture.debugElement.nativeElement.querySelectorAll('cd-info-card'); + expect(infoCards.length).toBe(15); + }); + }); + it('should render all except "Status" group and cards', () => { const payload = _.cloneDeep(healthPayload); payload.health.status = ''; diff --git a/src/pybind/mgr/dashboard/frontend/src/app/ceph/dashboard/health/health.component.ts b/src/pybind/mgr/dashboard/frontend/src/app/ceph/dashboard/health/health.component.ts index 713a05ea6c9f8..ae75eca648266 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/ceph/dashboard/health/health.component.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/ceph/dashboard/health/health.component.ts @@ -22,7 +22,7 @@ export class HealthComponent implements OnInit, OnDestroy { healthData: any; interval: number; permissions: Permissions; - enabled_feature$: FeatureTogglesMap$; + enabledFeature$: FeatureTogglesMap$; constructor( private healthService: HealthService, @@ -32,7 +32,7 @@ export class HealthComponent implements OnInit, OnDestroy { private featureToggles: FeatureTogglesService ) { this.permissions = this.authStorageService.getPermissions(); - this.enabled_feature$ = this.featureToggles.get(); + this.enabledFeature$ = this.featureToggles.get(); } ngOnInit() { diff --git a/src/pybind/mgr/dashboard/frontend/src/app/core/navigation/navigation/navigation.component.html b/src/pybind/mgr/dashboard/frontend/src/app/core/navigation/navigation/navigation.component.html index 307966699c621..a77c7d3703560 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/core/navigation/navigation/navigation.component.html +++ b/src/pybind/mgr/dashboard/frontend/src/app/core/navigation/navigation/navigation.component.html @@ -1,4 +1,3 @@ - - diff --git a/src/pybind/mgr/dashboard/frontend/src/app/core/navigation/navigation/navigation.component.ts b/src/pybind/mgr/dashboard/frontend/src/app/core/navigation/navigation/navigation.component.ts index 018df3f14bdd0..5f8d1f5a7e96a 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/core/navigation/navigation/navigation.component.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/core/navigation/navigation/navigation.component.ts @@ -20,7 +20,7 @@ export class NavigationComponent implements OnInit { isCollapsed = true; prometheusConfigured = false; - enabled_feature$: FeatureTogglesMap$; + enabledFeature$: FeatureTogglesMap$; constructor( private authStorageService: AuthStorageService, @@ -29,7 +29,7 @@ export class NavigationComponent implements OnInit { private featureToggles: FeatureTogglesService ) { this.permissions = this.authStorageService.getPermissions(); - this.enabled_feature$ = this.featureToggles.get(); + this.enabledFeature$ = this.featureToggles.get(); } ngOnInit() { diff --git a/src/pybind/mgr/dashboard/frontend/src/locale/messages.xlf b/src/pybind/mgr/dashboard/frontend/src/locale/messages.xlf index 6ddc58e45d3c5..c39f954b7fe1a 100644 --- a/src/pybind/mgr/dashboard/frontend/src/locale/messages.xlf +++ b/src/pybind/mgr/dashboard/frontend/src/locale/messages.xlf @@ -6,7 +6,7 @@ Toggle navigation app/core/navigation/navigation/navigation.component.html - 16 + 15 Dashboard @@ -28,7 +28,7 @@ app/ceph/dashboard/health/health.component.html - 82 + 81 Monitors @@ -38,7 +38,7 @@ app/ceph/dashboard/health/health.component.html - 49 + 48 OSDs @@ -48,7 +48,7 @@ app/ceph/dashboard/health/health.component.html - 58 + 57 Configuration @@ -86,7 +86,7 @@ app/ceph/dashboard/health/health.component.html - 191 + 190 app/ceph/cephfs/cephfs-detail/cephfs-detail.component.html @@ -1199,7 +1199,7 @@ app/ceph/dashboard/health/health.component.html - 4 + 3 Cluster ID @@ -2979,79 +2979,79 @@ Cluster Status app/ceph/dashboard/health/health.component.html - 16 + 15 Manager Daemons app/ceph/dashboard/health/health.component.html - 70 + 69 Object Gateways app/ceph/dashboard/health/health.component.html - 91 + 90 Metadata Servers app/ceph/dashboard/health/health.component.html - 99 + 98 iSCSI Gateways app/ceph/dashboard/health/health.component.html - 110 + 109 Client IOPS app/ceph/dashboard/health/health.component.html - 126 + 125 Client Throughput app/ceph/dashboard/health/health.component.html - 135 + 134 Client Read/Write app/ceph/dashboard/health/health.component.html - 144 + 143 Client Recovery app/ceph/dashboard/health/health.component.html - 162 + 161 Scrub app/ceph/dashboard/health/health.component.html - 171 + 170 Performance app/ceph/dashboard/health/health.component.html - 120 + 119 Raw Capacity app/ceph/dashboard/health/health.component.html - 201 + 200 Objects app/ceph/dashboard/health/health.component.html - 214 + 213 app/ceph/block/rbd-details/rbd-details.component.html @@ -3061,25 +3061,25 @@ PGs per OSD app/ceph/dashboard/health/health.component.html - 223 + 222 PG Status app/ceph/dashboard/health/health.component.html - 232 + 231 Capacity app/ceph/dashboard/health/health.component.html - 182 + 181 See Logs for more details. app/ceph/dashboard/health/health.component.html - 266 + 265 Move an image to trash diff --git a/src/pybind/mgr/dashboard/plugins/feature_toggles.py b/src/pybind/mgr/dashboard/plugins/feature_toggles.py index 22e1336ec3e37..7edbfa8f6adaf 100644 --- a/src/pybind/mgr/dashboard/plugins/feature_toggles.py +++ b/src/pybind/mgr/dashboard/plugins/feature_toggles.py @@ -54,7 +54,6 @@ class FeatureToggles(I.CanMgr, I.CanLog, I.Setupable, I.HasOptions, @PM.add_hook def setup(self): - url_prefix = self.mgr.get_module_option('url_prefix') self.Controller2Feature = { controller: feature for feature, controllers in Feature2Controller.items() @@ -104,7 +103,7 @@ class FeatureToggles(I.CanMgr, I.CanLog, I.Setupable, I.HasOptions, def _get_feature_from_request(self, request): try: return self.Controller2Feature[ - cherrypy.request.handler.callable.__self__] + request.handler.callable.__self__] except (AttributeError, KeyError): return None @@ -128,9 +127,7 @@ class FeatureToggles(I.CanMgr, I.CanLog, I.Setupable, I.HasOptions, @PM.add_hook def get_controllers(self): - from ..controllers import ApiController,\ - RESTController, Endpoint, ReadPermission - from ..security import Scope + from ..controllers import ApiController, RESTController @ApiController('/feature_toggles') class FeatureTogglesEndpoint(RESTController): -- 2.39.5