From 6ae302ba0ce01cd150ff46c34a554f40e83c7f14 Mon Sep 17 00:00:00 2001 From: Volker Theile Date: Wed, 23 Mar 2022 13:24:04 +0100 Subject: [PATCH] mgr/dashboard: RGW users and buckets tables are empty if the selected gateway is down Fixes: https://tracker.ceph.com/issues/54983 Signed-off-by: Volker Theile (cherry picked from commit 347d43d6e2bbf55fb0606af81ffb32d8d0447586) --- .../src/app/shared/api/rgw-daemon.service.spec.ts | 13 ++++++++++++- .../src/app/shared/api/rgw-daemon.service.ts | 5 ++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/pybind/mgr/dashboard/frontend/src/app/shared/api/rgw-daemon.service.spec.ts b/src/pybind/mgr/dashboard/frontend/src/app/shared/api/rgw-daemon.service.spec.ts index 93ef337869367..d669ddefcb3fb 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/shared/api/rgw-daemon.service.spec.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/shared/api/rgw-daemon.service.spec.ts @@ -12,7 +12,7 @@ describe('RgwDaemonService', () => { let httpTesting: HttpTestingController; let selectDaemonSpy: jasmine.Spy; - const daemonList = RgwHelper.getDaemonList(); + const daemonList: Array = RgwHelper.getDaemonList(); const retrieveDaemonList = (reqDaemonList: RgwDaemon[], daemon: RgwDaemon) => { service .request((params) => of(params)) @@ -76,4 +76,15 @@ describe('RgwDaemonService', () => { expect(selectDaemonSpy).toHaveBeenCalledTimes(1); expect(selectDaemonSpy).toHaveBeenCalledWith(noDefaultDaemonList[0]); })); + + it('should update default daemon if not exist in daemon list', fakeAsync(() => { + const tmpDaemonList = [...daemonList]; + service.selectDaemon(tmpDaemonList[1]); // Select 'default' daemon. + tmpDaemonList.splice(1, 1); // Remove 'default' daemon. + tmpDaemonList[0].default = true; // Set new 'default' daemon. + service.list().subscribe(); + const testReq = httpTesting.expectOne('api/rgw/daemon'); + testReq.flush(tmpDaemonList); + expect(service['selectedDaemon'].getValue()).toEqual(tmpDaemonList[0]); + })); }); diff --git a/src/pybind/mgr/dashboard/frontend/src/app/shared/api/rgw-daemon.service.ts b/src/pybind/mgr/dashboard/frontend/src/app/shared/api/rgw-daemon.service.ts index c947f3ed45597..5c513c7f1fa1c 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/shared/api/rgw-daemon.service.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/shared/api/rgw-daemon.service.ts @@ -25,7 +25,10 @@ export class RgwDaemonService { return this.http.get(this.url).pipe( tap((daemons: RgwDaemon[]) => { this.daemons.next(daemons); - if (_.isEmpty(this.selectedDaemon.getValue())) { + const selectedDaemon = this.selectedDaemon.getValue(); + // Set or re-select the default daemon if the current one is not + // in the list anymore. + if (_.isEmpty(selectedDaemon) || undefined === _.find(daemons, { id: selectedDaemon.id })) { this.selectDefaultDaemon(daemons); } }) -- 2.39.5