]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/dashboard: dashboard turns telemetry off when configuring report
authorSarthak0702 <sarthak.0702@gmail.com>
Thu, 10 Feb 2022 19:50:42 +0000 (01:20 +0530)
committerErnesto Puerta <epuertat@redhat.com>
Mon, 21 Feb 2022 16:21:53 +0000 (17:21 +0100)
Signed-off-by: Sarthak0702 <sarthak.0702@gmail.com>
(cherry picked from commit 97c57adf8565756dbf24f3c46ed3916303903fb7)

src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/telemetry/telemetry.component.spec.ts
src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/telemetry/telemetry.component.ts

index 72215f6176f9a71c9ccf4c3782d02c367af260a4..baf43e3ffc90dce40c75790c6f6d27e7a980051b 100644 (file)
@@ -120,16 +120,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 () {
@@ -303,16 +293,24 @@ describe('TelemetryComponent', () => {
       });
     });
 
-    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('/');
     });
   });
 });
index 41d9f677553e5dc8d99bff6cfc4a37d8b9d5878d..47ebae3be199d7cd784d644f6aa1705be81d6a92 100644 (file)
@@ -25,6 +25,7 @@ export class TelemetryComponent extends CdForm implements OnInit {
   licenseAgrmt = false;
   moduleEnabled: boolean;
   options: Object = {};
+  updatedConfig: Object = {};
   previewForm: CdFormGroup;
   requiredFields = [
     'channel_basic',
@@ -176,6 +177,23 @@ export class TelemetryComponent extends CdForm 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.loadingStart();
 
@@ -183,6 +201,7 @@ export class TelemetryComponent extends CdForm implements OnInit {
       (resp: object) => {
         this.report = resp;
         this.reportId = resp['report']['report_id'];
+        this.updateChannelsInReport(this.updatedConfig);
         this.createPreviewForm();
         this.loadingReady();
         this.step++;
@@ -198,30 +217,19 @@ export class TelemetryComponent extends CdForm 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.mgrModuleService.updateConfig('telemetry', config).subscribe(
-      () => {
-        this.disableModule(
-          $localize`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.updatedConfig[option.name] = control.value;
       }
-    );
+    }
+    this.getReport();
   }
 
   disableModule(message: string = null, followUpFunc: Function = null) {
@@ -251,13 +259,33 @@ export class TelemetryComponent extends CdForm implements OnInit {
   }
 
   onSubmit() {
-    this.telemetryService.enable().subscribe(() => {
-      this.telemetryNotificationService.setVisibility(false);
-      this.notificationService.show(
-        NotificationType.success,
-        $localize`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,
+          $localize`The Telemetry module has been configured and activated successfully.`
+        );
+      },
+      () => {
+        this.telemetryNotificationService.setVisibility(false);
+        this.notificationService.show(
+          NotificationType.error,
+          $localize`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(['']);
+      }
+    );
   }
 }