]> git.proxmox.com Git - ceph.git/blobdiff - ceph/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/services/service-form/service-form.component.spec.ts
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / pybind / mgr / dashboard / frontend / src / app / ceph / cluster / services / service-form / service-form.component.spec.ts
index 11c0663efd246fa85685ac7482d8b06a62735dd8..b2c965ee71b96a2d185ffe010175c715f35da83f 100644 (file)
@@ -4,11 +4,13 @@ import { ReactiveFormsModule } from '@angular/forms';
 import { By } from '@angular/platform-browser';
 import { RouterTestingModule } from '@angular/router/testing';
 
-import { NgbTypeaheadModule } from '@ng-bootstrap/ng-bootstrap';
+import { NgbActiveModal, NgbTypeaheadModule } from '@ng-bootstrap/ng-bootstrap';
 import _ from 'lodash';
 import { ToastrModule } from 'ngx-toastr';
+import { of } from 'rxjs';
 
 import { CephServiceService } from '~/app/shared/api/ceph-service.service';
+import { PaginateObservable } from '~/app/shared/api/paginate.model';
 import { CdFormGroup } from '~/app/shared/forms/cd-form-group';
 import { SharedModule } from '~/app/shared/shared.module';
 import { configureTestBed, FormHelper } from '~/testing/unit-test-helper';
@@ -23,6 +25,7 @@ describe('ServiceFormComponent', () => {
 
   configureTestBed({
     declarations: [ServiceFormComponent],
+    providers: [NgbActiveModal],
     imports: [
       HttpClientTestingModule,
       NgbTypeaheadModule,
@@ -36,6 +39,7 @@ describe('ServiceFormComponent', () => {
   beforeEach(() => {
     fixture = TestBed.createComponent(ServiceFormComponent);
     component = fixture.componentInstance;
+    component.ngOnInit();
     form = component.serviceForm;
     formHelper = new FormHelper(form);
     fixture.detectChanges();
@@ -116,17 +120,7 @@ describe('ServiceFormComponent', () => {
 
     it('should test various services', () => {
       _.forEach(
-        [
-          'alertmanager',
-          'crash',
-          'grafana',
-          'mds',
-          'mgr',
-          'mon',
-          'node-exporter',
-          'prometheus',
-          'rbd-mirror'
-        ],
+        ['alertmanager', 'crash', 'mds', 'mgr', 'mon', 'node-exporter', 'prometheus', 'rbd-mirror'],
         (serviceType) => {
           formHelper.setValue('service_type', serviceType);
           component.onSubmit();
@@ -139,31 +133,47 @@ describe('ServiceFormComponent', () => {
       );
     });
 
-    describe('should test service nfs', () => {
+    describe('should test service grafana', () => {
       beforeEach(() => {
-        formHelper.setValue('service_type', 'nfs');
-        formHelper.setValue('pool', 'foo');
+        formHelper.setValue('service_type', 'grafana');
       });
 
-      it('should submit nfs with namespace', () => {
-        formHelper.setValue('namespace', 'bar');
+      it('should sumbit grafana', () => {
         component.onSubmit();
         expect(cephServiceService.create).toHaveBeenCalledWith({
-          service_type: 'nfs',
+          service_type: 'grafana',
           placement: {},
           unmanaged: false,
-          pool: 'foo',
-          namespace: 'bar'
+          initial_admin_password: null,
+          port: null
         });
       });
 
-      it('should submit nfs w/o namespace', () => {
+      it('should sumbit grafana with custom port and initial password', () => {
+        formHelper.setValue('grafana_port', 1234);
+        formHelper.setValue('grafana_admin_password', 'foo');
         component.onSubmit();
         expect(cephServiceService.create).toHaveBeenCalledWith({
-          service_type: 'nfs',
+          service_type: 'grafana',
           placement: {},
           unmanaged: false,
-          pool: 'foo'
+          initial_admin_password: 'foo',
+          port: 1234
+        });
+      });
+    });
+
+    describe('should test service nfs', () => {
+      beforeEach(() => {
+        formHelper.setValue('service_type', 'nfs');
+      });
+
+      it('should submit nfs', () => {
+        component.onSubmit();
+        expect(cephServiceService.create).toHaveBeenCalledWith({
+          service_type: 'nfs',
+          placement: {},
+          unmanaged: false
         });
       });
     });
@@ -239,13 +249,13 @@ describe('ServiceFormComponent', () => {
 
       it('should submit invalid rgw port (1)', () => {
         formHelper.setValue('rgw_frontend_port', 0);
-        component.onSubmit();
+        fixture.detectChanges();
         formHelper.expectError('rgw_frontend_port', 'min');
       });
 
       it('should submit invalid rgw port (2)', () => {
         formHelper.setValue('rgw_frontend_port', 65536);
-        component.onSubmit();
+        fixture.detectChanges();
         formHelper.expectError('rgw_frontend_port', 'max');
       });
 
@@ -361,13 +371,13 @@ x4Ea7kGVgx9kWh5XjWz9wjZvY49UKIT5ppIAWPMbLl3UpfckiuNhTA==
 
       it('should submit invalid iscsi port (1)', () => {
         formHelper.setValue('api_port', 0);
-        component.onSubmit();
+        fixture.detectChanges();
         formHelper.expectError('api_port', 'min');
       });
 
       it('should submit invalid iscsi port (2)', () => {
         formHelper.setValue('api_port', 65536);
-        component.onSubmit();
+        fixture.detectChanges();
         formHelper.expectError('api_port', 'max');
       });
 
@@ -376,6 +386,10 @@ x4Ea7kGVgx9kWh5XjWz9wjZvY49UKIT5ppIAWPMbLl3UpfckiuNhTA==
         component.onSubmit();
         formHelper.expectError('api_port', 'pattern');
       });
+
+      it('should throw error when there is no pool', () => {
+        formHelper.expectErrorChange('pool', '', 'required');
+      });
     });
 
     describe('should test service ingress', () => {
@@ -410,14 +424,14 @@ x4Ea7kGVgx9kWh5XjWz9wjZvY49UKIT5ppIAWPMbLl3UpfckiuNhTA==
         // min value
         formHelper.setValue('frontend_port', 1);
         formHelper.setValue('monitor_port', 1);
-        component.onSubmit();
+        fixture.detectChanges();
         formHelper.expectValid('frontend_port');
         formHelper.expectValid('monitor_port');
 
         // max value
         formHelper.setValue('frontend_port', 65535);
         formHelper.setValue('monitor_port', 65535);
-        component.onSubmit();
+        fixture.detectChanges();
         formHelper.expectValid('frontend_port');
         formHelper.expectValid('monitor_port');
       });
@@ -426,14 +440,14 @@ x4Ea7kGVgx9kWh5XjWz9wjZvY49UKIT5ppIAWPMbLl3UpfckiuNhTA==
         // min
         formHelper.setValue('frontend_port', 0);
         formHelper.setValue('monitor_port', 0);
-        component.onSubmit();
+        fixture.detectChanges();
         formHelper.expectError('frontend_port', 'min');
         formHelper.expectError('monitor_port', 'min');
 
         // max
         formHelper.setValue('frontend_port', 65536);
         formHelper.setValue('monitor_port', 65536);
-        component.onSubmit();
+        fixture.detectChanges();
         formHelper.expectError('frontend_port', 'max');
         formHelper.expectError('monitor_port', 'max');
 
@@ -444,6 +458,140 @@ x4Ea7kGVgx9kWh5XjWz9wjZvY49UKIT5ppIAWPMbLl3UpfckiuNhTA==
         formHelper.expectError('frontend_port', 'pattern');
         formHelper.expectError('monitor_port', 'pattern');
       });
+
+      it('should not show private key field with ssl enabled', () => {
+        formHelper.setValue('ssl', true);
+        fixture.detectChanges();
+        const ssl_key = fixture.debugElement.query(By.css('#ssl_key'));
+        expect(ssl_key).toBeNull();
+      });
+
+      it('should test .pem file with ssl enabled', () => {
+        const pemCert = `
+-----BEGIN CERTIFICATE-----
+iJ5IbgzlKPssdYwuAEI3yPZxX/g5vKBrgcyD3LttLL/DlElq/1xCnwVrv7WROSNu
+-----END CERTIFICATE-----
+-----BEGIN CERTIFICATE-----
+mn/S7BNBEC7AGe5ajmN+8hBTGdACUXe8rwMNrtTy/MwBZ0VpJsAAjJh+aptZh5yB
+-----END CERTIFICATE-----
+-----BEGIN RSA PRIVATE KEY-----
+x4Ea7kGVgx9kWh5XjWz9wjZvY49UKIT5ppIAWPMbLl3UpfckiuNhTA==
+-----END RSA PRIVATE KEY-----`;
+        formHelper.setValue('ssl', true);
+        formHelper.setValue('ssl_cert', pemCert);
+        fixture.detectChanges();
+        formHelper.expectValid('ssl_cert');
+      });
+    });
+
+    describe('should test service snmp-gateway', () => {
+      beforeEach(() => {
+        formHelper.setValue('service_type', 'snmp-gateway');
+        formHelper.setValue('snmp_destination', '192.168.20.1:8443');
+      });
+
+      it('should test snmp-gateway service with V2c', () => {
+        formHelper.setValue('snmp_version', 'V2c');
+        formHelper.setValue('snmp_community', 'public');
+        component.onSubmit();
+        expect(cephServiceService.create).toHaveBeenCalledWith({
+          service_type: 'snmp-gateway',
+          placement: {},
+          unmanaged: false,
+          snmp_version: 'V2c',
+          snmp_destination: '192.168.20.1:8443',
+          credentials: {
+            snmp_community: 'public'
+          }
+        });
+      });
+
+      it('should test snmp-gateway service with V3', () => {
+        formHelper.setValue('snmp_version', 'V3');
+        formHelper.setValue('engine_id', '800C53F00000');
+        formHelper.setValue('auth_protocol', 'SHA');
+        formHelper.setValue('privacy_protocol', 'DES');
+        formHelper.setValue('snmp_v3_auth_username', 'testuser');
+        formHelper.setValue('snmp_v3_auth_password', 'testpass');
+        formHelper.setValue('snmp_v3_priv_password', 'testencrypt');
+        component.onSubmit();
+        expect(cephServiceService.create).toHaveBeenCalledWith({
+          service_type: 'snmp-gateway',
+          placement: {},
+          unmanaged: false,
+          snmp_version: 'V3',
+          snmp_destination: '192.168.20.1:8443',
+          engine_id: '800C53F00000',
+          auth_protocol: 'SHA',
+          privacy_protocol: 'DES',
+          credentials: {
+            snmp_v3_auth_username: 'testuser',
+            snmp_v3_auth_password: 'testpass',
+            snmp_v3_priv_password: 'testencrypt'
+          }
+        });
+      });
+
+      it('should submit invalid snmp destination', () => {
+        formHelper.setValue('snmp_version', 'V2c');
+        formHelper.setValue('snmp_destination', '192.168.20.1');
+        formHelper.setValue('snmp_community', 'public');
+        formHelper.expectError('snmp_destination', 'snmpDestinationPattern');
+      });
+
+      it('should submit invalid snmp engine id', () => {
+        formHelper.setValue('snmp_version', 'V3');
+        formHelper.setValue('snmp_destination', '192.168.20.1');
+        formHelper.setValue('engine_id', 'AABBCCDDE');
+        formHelper.setValue('auth_protocol', 'SHA');
+        formHelper.setValue('privacy_protocol', 'DES');
+        formHelper.setValue('snmp_v3_auth_username', 'testuser');
+        formHelper.setValue('snmp_v3_auth_password', 'testpass');
+
+        formHelper.expectError('engine_id', 'snmpEngineIdPattern');
+      });
+    });
+
+    describe('should test service mds', () => {
+      beforeEach(() => {
+        formHelper.setValue('service_type', 'mds');
+        const paginate_obs = new PaginateObservable<any>(of({}));
+        spyOn(cephServiceService, 'list').and.returnValue(paginate_obs);
+      });
+
+      it('should test mds valid service id', () => {
+        formHelper.setValue('service_id', 'svc123');
+        formHelper.expectValid('service_id');
+        formHelper.setValue('service_id', 'svc_id-1');
+        formHelper.expectValid('service_id');
+      });
+
+      it('should test mds invalid service id', () => {
+        formHelper.setValue('service_id', '123');
+        formHelper.expectError('service_id', 'mdsPattern');
+        formHelper.setValue('service_id', '123svc');
+        formHelper.expectError('service_id', 'mdsPattern');
+        formHelper.setValue('service_id', 'svc#1');
+        formHelper.expectError('service_id', 'mdsPattern');
+      });
+    });
+
+    describe('check edit fields', () => {
+      beforeEach(() => {
+        component.editing = true;
+      });
+
+      it('should check whether edit field is correctly loaded', () => {
+        const paginate_obs = new PaginateObservable<any>(of({}));
+        const cephServiceSpy = spyOn(cephServiceService, 'list').and.returnValue(paginate_obs);
+        component.ngOnInit();
+        expect(cephServiceSpy).toBeCalledTimes(2);
+        expect(component.action).toBe('Edit');
+        const serviceType = fixture.debugElement.query(By.css('#service_type')).nativeElement;
+        const serviceId = fixture.debugElement.query(By.css('#service_id')).nativeElement;
+        expect(serviceType.disabled).toBeTruthy();
+        expect(serviceId.disabled).toBeTruthy();
+      });
     });
   });
 });