From 2dd1e3aea692a0977eb34c8b999d81c1a760b004 Mon Sep 17 00:00:00 2001 From: Avan Thakkar Date: Thu, 27 Jan 2022 19:43:22 +0530 Subject: [PATCH] mgr/dashboard: support snmp-gateway service creation from UI Fixes: https://tracker.ceph.com/issues/54034 Signed-off-by: Avan Thakkar (cherry picked from commit ad6fcfc05625b3fd8a088b8a2b5c3d5fbbf2c53a) --- .../service-form/service-form.component.html | 185 ++++++++++++++++++ .../service-form.component.spec.ts | 48 +++++ .../service-form/service-form.component.ts | 133 +++++++++++++ 3 files changed, 366 insertions(+) diff --git a/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/services/service-form/service-form.component.html b/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/services/service-form/service-form.component.html index 5582d300ddac8..34b272baea079 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/services/service-form/service-form.component.html +++ b/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/services/service-form/service-form.component.html @@ -422,6 +422,191 @@ + + + + +
+ +
+ + This field is required. +
+
+ +
+ +
+ + This field is required. +
+
+ +
+ +
+ + This field is required. +
+
+ +
+ +
+ + This field is required. +
+
+ +
+ +
+ +
+
+ +
+ Credentials + +
+ +
+ + This field is required. +
+
+ +
+ +
+ + This field is required. +
+
+ +
+ +
+ + This field is required. +
+
+ +
+ +
+ + This field is required. +
+
+
+
diff --git a/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/services/service-form/service-form.component.spec.ts b/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/services/service-form/service-form.component.spec.ts index 183fd77b8cf31..1667f6697b6e5 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/services/service-form/service-form.component.spec.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/services/service-form/service-form.component.spec.ts @@ -438,6 +438,54 @@ x4Ea7kGVgx9kWh5XjWz9wjZvY49UKIT5ppIAWPMbLl3UpfckiuNhTA== }); }); + 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' + } + }); + }); + }); + describe('check edit fields', () => { beforeEach(() => { component.editing = true; diff --git a/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/services/service-form/service-form.component.ts b/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/services/service-form/service-form.component.ts index d582922a0288c..28bae956298b0 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/services/service-form/service-form.component.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/services/service-form/service-form.component.ts @@ -212,6 +212,72 @@ export class ServiceFormComponent extends CdForm implements OnInit { [Validators.required, CdValidators.sslPrivKey()] ) ] + ], + // snmp-gateway + snmp_version: [null, [Validators.required]], + snmp_destination: [ + null, + [ + CdValidators.requiredIf({ + service_type: 'snmp-gateway', + unmanaged: false + }) + ] + ], + engine_id: [ + null, + [ + CdValidators.requiredIf({ + service_type: 'snmp-gateway', + unmanaged: false + }) + ] + ], + auth_protocol: [ + 'SHA', + [ + CdValidators.requiredIf({ + service_type: 'snmp-gateway', + unmanaged: false + }) + ] + ], + privacy_protocol: [null], + snmp_community: [ + null, + [ + CdValidators.requiredIf({ + service_type: 'snmp-gateway', + unmanaged: false + }) + ] + ], + snmp_v3_auth_username: [ + null, + [ + CdValidators.requiredIf({ + service_type: 'snmp-gateway', + unmanaged: false + }) + ] + ], + snmp_v3_auth_password: [ + null, + [ + CdValidators.requiredIf({ + service_type: 'snmp-gateway', + unmanaged: false + }) + ] + ], + snmp_v3_priv_password: [ + null, + [ + CdValidators.requiredIf({ + service_type: 'snmp-gateway', + unmanaged: false + }) + ] ] }); } @@ -314,6 +380,39 @@ export class ServiceFormComponent extends CdForm implements OnInit { this.serviceForm.get('ssl_key').setValue(response[0].spec?.ssl_key); } break; + case 'snmp-gateway': + const snmpCommonSpecKeys = ['snmp_version', 'snmp_destination']; + snmpCommonSpecKeys.forEach((key) => { + this.serviceForm.get(key).setValue(response[0].spec[key]); + }); + if (this.serviceForm.getValue('snmp_version') === 'V3') { + const snmpV3SpecKeys = [ + 'engine_id', + 'auth_protocol', + 'privacy_protocol', + 'snmp_v3_auth_username', + 'snmp_v3_auth_password', + 'snmp_v3_priv_password' + ]; + snmpV3SpecKeys.forEach((key) => { + if (key !== null) { + if ( + key === 'snmp_v3_auth_username' || + key === 'snmp_v3_auth_password' || + key === 'snmp_v3_priv_password' + ) { + this.serviceForm.get(key).setValue(response[0].spec['credentials'][key]); + } else { + this.serviceForm.get(key).setValue(response[0].spec[key]); + } + } + }); + } else { + this.serviceForm + .get('snmp_community') + .setValue(response[0].spec['credentials']['snmp_community']); + } + break; } }); } @@ -453,6 +552,23 @@ export class ServiceFormComponent extends CdForm implements OnInit { } serviceSpec['virtual_interface_networks'] = values['virtual_interface_networks']; break; + case 'snmp-gateway': + serviceSpec['credentials'] = {}; + serviceSpec['snmp_version'] = values['snmp_version']; + serviceSpec['snmp_destination'] = values['snmp_destination']; + if (values['snmp_version'] === 'V3') { + serviceSpec['engine_id'] = values['engine_id']; + serviceSpec['auth_protocol'] = values['auth_protocol']; + serviceSpec['credentials']['snmp_v3_auth_username'] = values['snmp_v3_auth_username']; + serviceSpec['credentials']['snmp_v3_auth_password'] = values['snmp_v3_auth_password']; + if (values['privacy_protocol'] !== null) { + serviceSpec['privacy_protocol'] = values['privacy_protocol']; + serviceSpec['credentials']['snmp_v3_priv_password'] = values['snmp_v3_priv_password']; + } + } else { + serviceSpec['credentials']['snmp_community'] = values['snmp_community']; + } + break; } } @@ -474,4 +590,21 @@ export class ServiceFormComponent extends CdForm implements OnInit { } }); } + + clearValidations() { + const snmpVersion = this.serviceForm.getValue('snmp_version'); + const privacyProtocol = this.serviceForm.getValue('privacy_protocol'); + if (snmpVersion === 'V3') { + this.serviceForm.get('snmp_community').clearValidators(); + } else { + this.serviceForm.get('engine_id').clearValidators(); + this.serviceForm.get('auth_protocol').clearValidators(); + this.serviceForm.get('privacy_protocol').clearValidators(); + this.serviceForm.get('snmp_v3_auth_username').clearValidators(); + this.serviceForm.get('snmp_v3_auth_password').clearValidators(); + } + if (privacyProtocol === null) { + this.serviceForm.get('snmp_v3_priv_password').clearValidators(); + } + } } -- 2.39.5