From 824726393b185b8e5a8f17e66487dfde9f3c8b5c Mon Sep 17 00:00:00 2001 From: Tiago Melo Date: Tue, 19 Feb 2019 22:17:26 +0000 Subject: [PATCH] mgr/dashboard: Add NFS status endpoint Currently each time NFS page is opened and NFS Ganesha is not configured an error notification is thrown and no extra information is given. Now the user will be redirected to an information page. Removed the orchestrator information since it no longer applies. Fixes: http://tracker.ceph.com/issues/38399 Signed-off-by: Tiago Melo --- qa/tasks/mgr/dashboard/test_ganesha.py | 20 ++++++++ .../mgr/dashboard/controllers/nfsganesha.py | 18 ++++++- .../frontend/src/app/app-routing.module.ts | 17 ++++++- .../ceph/nfs/nfs-501/nfs-501.component.html | 5 ++ .../ceph/nfs/nfs-501/nfs-501.component.scss | 0 .../nfs/nfs-501/nfs-501.component.spec.ts | 28 +++++++++++ .../app/ceph/nfs/nfs-501/nfs-501.component.ts | 50 +++++++++++++++++++ .../ceph/nfs/nfs-list/nfs-list.component.html | 5 -- .../frontend/src/app/ceph/nfs/nfs.module.ts | 10 +++- .../frontend/src/locale/messages.xlf | 30 +++++------ 10 files changed, 160 insertions(+), 23 deletions(-) create mode 100644 src/pybind/mgr/dashboard/frontend/src/app/ceph/nfs/nfs-501/nfs-501.component.html create mode 100644 src/pybind/mgr/dashboard/frontend/src/app/ceph/nfs/nfs-501/nfs-501.component.scss create mode 100644 src/pybind/mgr/dashboard/frontend/src/app/ceph/nfs/nfs-501/nfs-501.component.spec.ts create mode 100644 src/pybind/mgr/dashboard/frontend/src/app/ceph/nfs/nfs-501/nfs-501.component.ts diff --git a/qa/tasks/mgr/dashboard/test_ganesha.py b/qa/tasks/mgr/dashboard/test_ganesha.py index f58fe3c9e1b..277a5395fbf 100644 --- a/qa/tasks/mgr/dashboard/test_ganesha.py +++ b/qa/tasks/mgr/dashboard/test_ganesha.py @@ -147,3 +147,23 @@ class GaneshaTest(DashboardTestCase): export2 = self._get("/api/nfs-ganesha/export/cluster2/2") self.assertDictEqual(export2, data2) + + def test_invalid_status(self): + self._ceph_cmd(['dashboard', 'set-ganesha-clusters-rados-pool-namespace', '']) + + data = self._get('/api/nfs-ganesha/status') + self.assertStatus(200) + self.assertIn('available', data) + self.assertIn('message', data) + self.assertFalse(data['available']) + self.assertIn('Ganesha config location is not configured. Please set the GANESHA_RADOS_POOL_NAMESPACE setting.', + data['message']) + + self._ceph_cmd(['dashboard', 'set-ganesha-clusters-rados-pool-namespace', 'cluster1:ganesha/ganesha1,cluster2:ganesha/ganesha2']) + + def test_valid_status(self): + data = self._get('/api/nfs-ganesha/status') + self.assertStatus(200) + self.assertIn('available', data) + self.assertIn('message', data) + self.assertTrue(data['available']) diff --git a/src/pybind/mgr/dashboard/controllers/nfsganesha.py b/src/pybind/mgr/dashboard/controllers/nfsganesha.py index 90ccfdb5028..24b17da47c8 100644 --- a/src/pybind/mgr/dashboard/controllers/nfsganesha.py +++ b/src/pybind/mgr/dashboard/controllers/nfsganesha.py @@ -7,7 +7,7 @@ import cherrypy import cephfs from . import ApiController, RESTController, UiApiController, BaseController, \ - Endpoint, Task + Endpoint, Task, ReadPermission from .. import logger from ..security import Scope from ..services.cephfs import CephFS @@ -26,6 +26,22 @@ def NfsTask(name, metadata, wait_for): return composed_decorator +@ApiController('/nfs-ganesha', Scope.NFS_GANESHA) +class NFSGanesha(RESTController): + + @Endpoint() + @ReadPermission + def status(self): + status = {'available': True, 'message': None} + try: + Ganesha.get_ganesha_clusters() + except NFSException as e: + status['message'] = str(e) + status['available'] = False + + return status + + @ApiController('/nfs-ganesha/export', Scope.NFS_GANESHA) class NFSGaneshaExports(RESTController): RESOURCE_ID = "cluster_id/export_id" diff --git a/src/pybind/mgr/dashboard/frontend/src/app/app-routing.module.ts b/src/pybind/mgr/dashboard/frontend/src/app/app-routing.module.ts index ecd38e4330b..c870c4cb254 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/app-routing.module.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/app-routing.module.ts @@ -17,6 +17,7 @@ import { MonitorComponent } from './ceph/cluster/monitor/monitor.component'; import { OsdListComponent } from './ceph/cluster/osd/osd-list/osd-list.component'; import { PrometheusListComponent } from './ceph/cluster/prometheus/prometheus-list/prometheus-list.component'; import { DashboardComponent } from './ceph/dashboard/dashboard/dashboard.component'; +import { Nfs501Component } from './ceph/nfs/nfs-501/nfs-501.component'; import { NfsFormComponent } from './ceph/nfs/nfs-form/nfs-form.component'; import { NfsListComponent } from './ceph/nfs/nfs-list/nfs-list.component'; import { PerformanceCounterComponent } from './ceph/performance-counter/performance-counter/performance-counter.component'; @@ -308,11 +309,23 @@ const routes: Routes = [ ] }, // NFS + { + path: 'nfs/501/:message', + component: Nfs501Component, + canActivate: [AuthGuardService], + data: { breadcrumbs: 'NFS' } + }, { path: 'nfs', canActivate: [AuthGuardService], - canActivateChild: [AuthGuardService], - data: { breadcrumbs: 'NFS' }, + canActivateChild: [AuthGuardService, ModuleStatusGuardService], + data: { + moduleStatusGuardConfig: { + apiPath: 'nfs-ganesha', + redirectTo: 'nfs/501' + }, + breadcrumbs: 'NFS' + }, children: [ { path: '', component: NfsListComponent }, { path: 'add', component: NfsFormComponent, data: { breadcrumbs: 'Add' } }, diff --git a/src/pybind/mgr/dashboard/frontend/src/app/ceph/nfs/nfs-501/nfs-501.component.html b/src/pybind/mgr/dashboard/frontend/src/app/ceph/nfs/nfs-501/nfs-501.component.html new file mode 100644 index 00000000000..e3db036f1b7 --- /dev/null +++ b/src/pybind/mgr/dashboard/frontend/src/app/ceph/nfs/nfs-501/nfs-501.component.html @@ -0,0 +1,5 @@ + + {{ message }}
+ Please consult the documentation + on how to configure and enable the NFS Ganesha management functionality. +
diff --git a/src/pybind/mgr/dashboard/frontend/src/app/ceph/nfs/nfs-501/nfs-501.component.scss b/src/pybind/mgr/dashboard/frontend/src/app/ceph/nfs/nfs-501/nfs-501.component.scss new file mode 100644 index 00000000000..e69de29bb2d diff --git a/src/pybind/mgr/dashboard/frontend/src/app/ceph/nfs/nfs-501/nfs-501.component.spec.ts b/src/pybind/mgr/dashboard/frontend/src/app/ceph/nfs/nfs-501/nfs-501.component.spec.ts new file mode 100644 index 00000000000..bde06ba857b --- /dev/null +++ b/src/pybind/mgr/dashboard/frontend/src/app/ceph/nfs/nfs-501/nfs-501.component.spec.ts @@ -0,0 +1,28 @@ +import { HttpClientTestingModule } from '@angular/common/http/testing'; +import { ComponentFixture, TestBed } from '@angular/core/testing'; +import { RouterTestingModule } from '@angular/router/testing'; + +import { configureTestBed, i18nProviders } from '../../../../testing/unit-test-helper'; +import { SharedModule } from '../../../shared/shared.module'; +import { Nfs501Component } from './nfs-501.component'; + +describe('Nfs501Component', () => { + let component: Nfs501Component; + let fixture: ComponentFixture; + + configureTestBed({ + declarations: [Nfs501Component], + imports: [HttpClientTestingModule, RouterTestingModule, SharedModule], + providers: i18nProviders + }); + + beforeEach(() => { + fixture = TestBed.createComponent(Nfs501Component); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/src/pybind/mgr/dashboard/frontend/src/app/ceph/nfs/nfs-501/nfs-501.component.ts b/src/pybind/mgr/dashboard/frontend/src/app/ceph/nfs/nfs-501/nfs-501.component.ts new file mode 100644 index 00000000000..77b3b649332 --- /dev/null +++ b/src/pybind/mgr/dashboard/frontend/src/app/ceph/nfs/nfs-501/nfs-501.component.ts @@ -0,0 +1,50 @@ +import { Component, OnDestroy, OnInit } from '@angular/core'; +import { ActivatedRoute } from '@angular/router'; + +import { I18n } from '@ngx-translate/i18n-polyfill'; + +import { CephReleaseNamePipe } from '../../../shared/pipes/ceph-release-name.pipe'; +import { SummaryService } from '../../../shared/services/summary.service'; + +@Component({ + selector: 'cd-nfs-501', + templateUrl: './nfs-501.component.html', + styleUrls: ['./nfs-501.component.scss'] +}) +export class Nfs501Component implements OnInit, OnDestroy { + docsUrl: string; + message = this.i18n('The NFS Ganesha service is not configured.'); + routeParamsSubscribe: any; + + constructor( + private route: ActivatedRoute, + private summaryService: SummaryService, + private cephReleaseNamePipe: CephReleaseNamePipe, + private i18n: I18n + ) {} + + ngOnInit() { + const subs = this.summaryService.subscribe((summary: any) => { + if (!summary) { + return; + } + + const releaseName = this.cephReleaseNamePipe.transform(summary.version); + this.docsUrl = + `http://docs.ceph.com/docs/${releaseName}/mgr/dashboard/` + + `#configuring-nfs-ganesha-in-the-dashboard`; + + setTimeout(() => { + subs.unsubscribe(); + }, 0); + }); + + this.routeParamsSubscribe = this.route.params.subscribe((params: { message: string }) => { + this.message = params.message; + }); + } + + ngOnDestroy() { + this.routeParamsSubscribe.unsubscribe(); + } +} diff --git a/src/pybind/mgr/dashboard/frontend/src/app/ceph/nfs/nfs-list/nfs-list.component.html b/src/pybind/mgr/dashboard/frontend/src/app/ceph/nfs/nfs-list/nfs-list.component.html index d41cf65261d..ef42aa2929c 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/ceph/nfs/nfs-list/nfs-list.component.html +++ b/src/pybind/mgr/dashboard/frontend/src/app/ceph/nfs/nfs-list/nfs-list.component.html @@ -1,8 +1,3 @@ -To apply any changes you have to restart the Ganisha services. - app/ceph/nfs/nfs-list/nfs-list.component.html - 32 + 27 Daemons @@ -1673,6 +1673,13 @@ app/ceph/dashboard/dashboard/dashboard.component.html 8 + + Please consult the documentation + on how to configure and enable the NFS Ganesha management functionality. + + app/ceph/nfs/nfs-501/nfs-501.component.html + 3 + Clients @@ -2030,23 +2037,11 @@ app/ceph/nfs/nfs-form/nfs-form.component.html 493 - - To apply any changes you have to restart the Ganisha services. - - app/ceph/nfs/nfs-list/nfs-list.component.html - 4 - - - Orchestrator not available - - app/ceph/nfs/nfs-list/nfs-list.component.html - 2 - CephFS app/ceph/nfs/nfs-list/nfs-list.component.html - 30 + 25 Add erasure code profile @@ -5457,6 +5452,13 @@ 1 + + The NFS Ganesha service is not configured. + + src/app/ceph/nfs/nfs-501/nfs-501.component.ts + 1 + + Transport -- 2.39.5