]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/dashboard: rgw daemon list: add realm column 43983/head
authorAlfonso Martínez <almartin@redhat.com>
Wed, 17 Nov 2021 08:29:38 +0000 (09:29 +0100)
committerAlfonso Martínez <almartin@redhat.com>
Wed, 17 Nov 2021 08:29:38 +0000 (09:29 +0100)
- Some refactoring and cleanup.

Fixes: https://tracker.ceph.com/issues/53301
Signed-off-by: Alfonso Martínez <almartin@redhat.com>
src/pybind/mgr/dashboard/frontend/src/app/ceph/rgw/rgw-daemon-list/rgw-daemon-list.component.spec.ts
src/pybind/mgr/dashboard/frontend/src/app/ceph/rgw/rgw-daemon-list/rgw-daemon-list.component.ts
src/pybind/mgr/dashboard/frontend/src/app/ceph/rgw/rgw-user-list/rgw-user-list.component.ts
src/pybind/mgr/dashboard/frontend/src/app/shared/api/rgw-daemon.service.spec.ts
src/pybind/mgr/dashboard/frontend/src/app/shared/api/rgw-daemon.service.ts

index 4278b0c0d3a59c7b59c5f616db7d8debc62a50f8..ecf0bedf961d0d5fb5942e91bcd453daffd93554 100644 (file)
@@ -1,5 +1,6 @@
 import { HttpClientTestingModule } from '@angular/common/http/testing';
-import { ComponentFixture, TestBed } from '@angular/core/testing';
+import { ComponentFixture, fakeAsync, TestBed, tick } from '@angular/core/testing';
+import { By } from '@angular/platform-browser';
 import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
 import { RouterTestingModule } from '@angular/router/testing';
 
@@ -7,6 +8,8 @@ import { NgbNavModule } from '@ng-bootstrap/ng-bootstrap';
 import { of } from 'rxjs';
 
 import { PerformanceCounterModule } from '~/app/ceph/performance-counter/performance-counter.module';
+import { RgwDaemon } from '~/app/ceph/rgw/models/rgw-daemon';
+import { RgwDaemonService } from '~/app/shared/api/rgw-daemon.service';
 import { RgwSiteService } from '~/app/shared/api/rgw-site.service';
 import { Permissions } from '~/app/shared/models/permissions';
 import { AuthStorageService } from '~/app/shared/services/auth-storage.service';
@@ -20,7 +23,18 @@ describe('RgwDaemonListComponent', () => {
   let fixture: ComponentFixture<RgwDaemonListComponent>;
   let getPermissionsSpy: jasmine.Spy;
   let getRealmsSpy: jasmine.Spy;
+  let listDaemonsSpy: jest.SpyInstance;
   const permissions = new Permissions({ grafana: ['read'] });
+  const daemon: RgwDaemon = {
+    id: '8000',
+    service_map_id: '4803',
+    version: 'ceph version',
+    server_hostname: 'ceph',
+    realm_name: 'realm1',
+    zonegroup_name: 'zg1-realm1',
+    zone_name: 'zone1-zg1-realm1',
+    default: true
+  };
 
   const expectTabsAndHeading = (length: number, heading: string) => {
     const tabs = TabHelper.getTextContents(fixture);
@@ -45,6 +59,9 @@ describe('RgwDaemonListComponent', () => {
     getPermissionsSpy.and.returnValue(new Permissions({}));
     getRealmsSpy = spyOn(TestBed.inject(RgwSiteService), 'get');
     getRealmsSpy.and.returnValue(of([]));
+    listDaemonsSpy = jest
+      .spyOn(TestBed.inject(RgwDaemonService), 'list')
+      .mockReturnValue(of([daemon]));
     fixture = TestBed.createComponent(RgwDaemonListComponent);
     component = fixture.componentInstance;
   });
@@ -54,6 +71,18 @@ describe('RgwDaemonListComponent', () => {
     expect(component).toBeTruthy();
   });
 
+  it('should show a row with daemon info', fakeAsync(() => {
+    fixture.detectChanges();
+    tick();
+    expect(listDaemonsSpy).toHaveBeenCalledTimes(1);
+    expect(component.daemons).toEqual([daemon]);
+    expect(fixture.debugElement.query(By.css('cd-table')).nativeElement.textContent).toContain(
+      'total 1'
+    );
+
+    fixture.destroy();
+  }));
+
   it('should only show Daemons List tab', () => {
     fixture.detectChanges();
 
index 96a7938942c3394e8d71a01906e819672556a73c..c620843fb8acd85dabd90f6bbb4d49217a3770e3 100644 (file)
@@ -1,7 +1,5 @@
 import { Component, OnInit } from '@angular/core';
 
-import { take } from 'rxjs/operators';
-
 import { RgwDaemon } from '~/app/ceph/rgw/models/rgw-daemon';
 import { RgwDaemonService } from '~/app/shared/api/rgw-daemon.service';
 import { RgwSiteService } from '~/app/shared/api/rgw-site.service';
@@ -19,7 +17,7 @@ import { AuthStorageService } from '~/app/shared/services/auth-storage.service';
 })
 export class RgwDaemonListComponent extends ListWithDetails implements OnInit {
   columns: CdTableColumn[] = [];
-  daemons: object[] = [];
+  daemons: RgwDaemon[] = [];
   grafanaPermission: Permission;
   isMultiSite: boolean;
 
@@ -45,14 +43,19 @@ export class RgwDaemonListComponent extends ListWithDetails implements OnInit {
         prop: 'server_hostname',
         flexGrow: 2
       },
+      {
+        name: $localize`Zone`,
+        prop: 'zone_name',
+        flexGrow: 2
+      },
       {
         name: $localize`Zone Group`,
         prop: 'zonegroup_name',
         flexGrow: 2
       },
       {
-        name: $localize`Zone`,
-        prop: 'zone_name',
+        name: $localize`Realm`,
+        prop: 'realm_name',
         flexGrow: 2
       },
       {
@@ -68,13 +71,12 @@ export class RgwDaemonListComponent extends ListWithDetails implements OnInit {
   }
 
   getDaemonList(context: CdTableFetchDataContext) {
-    this.rgwDaemonService.daemons$.pipe(take(1)).subscribe(
-      (resp: RgwDaemon[]) => {
-        this.daemons = resp;
-      },
-      () => {
-        context.error();
-      }
-    );
+    this.rgwDaemonService.list().subscribe(this.updateDaemons, () => {
+      context.error();
+    });
   }
+
+  private updateDaemons = (daemons: RgwDaemon[]) => {
+    this.daemons = daemons;
+  };
 }
index e48aaa7c406409de9f70440c9a81244ca1d2790e..34cccb9409d6bcc595c55c03e497061ef9574957 100644 (file)
@@ -1,6 +1,5 @@
 import { Component, NgZone, OnInit, TemplateRef, ViewChild } from '@angular/core';
 
-import _ from 'lodash';
 import { forkJoin as observableForkJoin, Observable, Subscriber } from 'rxjs';
 
 import { RgwUserService } from '~/app/shared/api/rgw-user.service';
index 6f96c6ab51a593754d0f116d1c08e3aad6dc5272..93ef3378693672386fefbd25c5057661e704d10d 100644 (file)
@@ -50,7 +50,7 @@ describe('RgwDaemonService', () => {
     expect(service['daemons'].getValue()).toEqual(daemonList);
   });
 
-  it('should get daemon ', () => {
+  it('should call "get daemon"', () => {
     service.get('foo').subscribe();
     const req = httpTesting.expectOne('api/rgw/daemon/foo');
     expect(req.request.method).toBe('GET');
index bc81dacf47e0c9174055c2c3f615e4fd8f249db4..c947f3ed4559728f3b5d006cd80877057dc84294 100644 (file)
@@ -3,7 +3,7 @@ import { Injectable } from '@angular/core';
 
 import _ from 'lodash';
 import { BehaviorSubject, Observable, of, throwError } from 'rxjs';
-import { mergeMap, retryWhen, take, tap } from 'rxjs/operators';
+import { mergeMap, take, tap } from 'rxjs/operators';
 
 import { RgwDaemon } from '~/app/ceph/rgw/models/rgw-daemon';
 import { cdEncode } from '~/app/shared/decorators/cd-encode';
@@ -59,17 +59,15 @@ export class RgwDaemonService {
   request(next: (params: HttpParams) => Observable<any>) {
     return this.selectedDaemon.pipe(
       mergeMap((daemon: RgwDaemon) =>
-        // If there is no selected daemon, retrieve daemon list (default daemon will be selected)
-        // and try again if daemon list is not empty.
+        // If there is no selected daemon, retrieve daemon list so default daemon will be selected.
         _.isEmpty(daemon)
-          ? this.list().pipe(mergeMap((daemons) => throwError(!_.isEmpty(daemons))))
+          ? this.list().pipe(
+              mergeMap((daemons) =>
+                _.isEmpty(daemons) ? throwError('No RGW daemons found!') : this.selectedDaemon$
+              )
+            )
           : of(daemon)
       ),
-      retryWhen((error) =>
-        error.pipe(
-          mergeMap((hasToRetry) => (hasToRetry ? error : throwError('No RGW daemons found!')))
-        )
-      ),
       take(1),
       mergeMap((daemon: RgwDaemon) => {
         let params = new HttpParams();