From: Sarthak0702 Date: Thu, 10 Feb 2022 19:50:42 +0000 (+0530) Subject: mgr/dashboard: dashboard turns telemetry off when configuring report X-Git-Tag: v15.2.17~116^2~2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=5a38889733cb7d3a9a74c341ad082c64185e83d6;p=ceph.git mgr/dashboard: dashboard turns telemetry off when configuring report Signed-off-by: Sarthak0702 (cherry picked from commit 97c57adf8565756dbf24f3c46ed3916303903fb7) Conflicts: src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/telemetry/telemetry.component.ts - `this.i18n()` was used in Octopus instead of `$localize` --- diff --git a/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/telemetry/telemetry.component.spec.ts b/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/telemetry/telemetry.component.spec.ts index cc56046df62..ab4c0afdc1e 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/telemetry/telemetry.component.spec.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/telemetry/telemetry.component.spec.ts @@ -96,16 +96,6 @@ describe('TelemetryComponent', () => { }); }); - it('should update the Telemetry configuration', () => { - component.updateConfig(); - const req = httpTesting.expectOne('api/mgr/module/telemetry'); - expect(req.request.method).toBe('PUT'); - expect(req.request.body).toEqual({ - config: {} - }); - req.flush({}); - }); - it('should disable the Telemetry module', () => { const message = 'Module disabled message.'; const followUpFunc = function () { @@ -162,16 +152,24 @@ describe('TelemetryComponent', () => { expect(downloadSpy).toHaveBeenCalledWith(JSON.stringify(reportText, null, 2), filename); }); - it('should submit', () => { + it('should submit ', () => { component.onSubmit(); - const req = httpTesting.expectOne('api/telemetry'); - expect(req.request.method).toBe('PUT'); - expect(req.request.body).toEqual({ + const req1 = httpTesting.expectOne('api/telemetry'); + expect(req1.request.method).toBe('PUT'); + expect(req1.request.body).toEqual({ enable: true, license_name: 'sharing-1-0' }); - req.flush({}); - expect(router.navigate).toHaveBeenCalledWith(['']); + req1.flush({}); + const req2 = httpTesting.expectOne({ + url: 'api/mgr/module/telemetry', + method: 'PUT' + }); + expect(req2.request.body).toEqual({ + config: {} + }); + req2.flush({}); + expect(router.url).toBe('/'); }); }); }); diff --git a/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/telemetry/telemetry.component.ts b/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/telemetry/telemetry.component.ts index d6d928e1950..e8d700a5095 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/telemetry/telemetry.component.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/telemetry/telemetry.component.ts @@ -32,6 +32,7 @@ export class TelemetryComponent implements OnInit { loading = false; moduleEnabled: boolean; options: Object = {}; + updatedConfig: Object = {}; previewForm: CdFormGroup; requiredFields = [ 'channel_basic', @@ -126,12 +127,30 @@ export class TelemetryComponent implements OnInit { return result; } + private updateChannelsInReport(updatedConfig: Object = {}) { + const channels: string[] = this.report['report']['channels']; + const availableChannels: string[] = this.report['report']['channels_available']; + const updatedChannels = []; + for (const channel of availableChannels) { + const key = `channel_${channel}`; + // channel unchanged or toggled on + if ( + (!updatedConfig.hasOwnProperty(key) && channels.includes(channel)) || + updatedConfig[key] + ) { + updatedChannels.push(channel); + } + } + this.report['report']['channels'] = updatedChannels; + } + private getReport() { this.loading = true; this.telemetryService.getReport().subscribe( (resp: object) => { this.report = resp; this.reportId = resp['report']['report_id']; + this.updateChannelsInReport(this.updatedConfig); this.createPreviewForm(); this.loading = false; this.step++; @@ -143,32 +162,19 @@ export class TelemetryComponent implements OnInit { } updateConfig() { - const config = {}; - _.forEach(Object.values(this.options), (option) => { + this.updatedConfig = {}; + for (const option of Object.values(this.options)) { const control = this.configForm.get(option.name); + if (!control.valid) { + this.configForm.setErrors({ cdSubmitButton: true }); + return; + } // Append the option only if the value has been modified. if (control.dirty && control.valid) { - config[option.name] = control.value; + this.updatedConfig[option.name] = control.value; } - }); - this.mgrModuleService.updateConfig('telemetry', config).subscribe( - () => { - this.disableModule( - this.i18n( - `Your settings have been applied successfully. \ -Due to privacy/legal reasons the Telemetry module is now disabled until you \ -complete the next step and accept the license.` - ), - () => { - this.getReport(); - } - ); - }, - () => { - // Reset the 'Submit' button. - this.configForm.setErrors({ cdSubmitButton: true }); - } - ); + } + this.getReport(); } download(report: object, fileName: string) { @@ -202,13 +208,35 @@ complete the next step and accept the license.` } onSubmit() { - this.telemetryService.enable().subscribe(() => { - this.telemetryNotificationService.setVisibility(false); - this.notificationService.show( - NotificationType.success, - this.i18n('The Telemetry module has been configured and activated successfully.') - ); - this.router.navigate(['']); - }); + const observables = [ + this.telemetryService.enable(), + this.mgrModuleService.updateConfig('telemetry', this.updatedConfig) + ]; + + observableForkJoin(observables).subscribe( + () => { + this.telemetryNotificationService.setVisibility(false); + this.notificationService.show( + NotificationType.success, + this.i18n('The Telemetry module has been configured and activated successfully.') + ); + }, + () => { + this.telemetryNotificationService.setVisibility(false); + this.notificationService.show( + NotificationType.error, + this.i18n( + 'An Error occurred while updating the Telemetry module configuration.\ + Please Try again' + ) + ); + // Reset the 'Update' button. + this.previewForm.setErrors({ cdSubmitButton: true }); + }, + () => { + this.updatedConfig = {}; + this.router.navigate(['']); + } + ); } }