]> git.proxmox.com Git - ceph.git/blame - ceph/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/services/service-form/service-form.component.spec.ts
import ceph pacific 16.2.5
[ceph.git] / ceph / src / pybind / mgr / dashboard / frontend / src / app / ceph / cluster / services / service-form / service-form.component.spec.ts
CommitLineData
adb31ebb
TL
1import { HttpClientTestingModule } from '@angular/common/http/testing';
2import { ComponentFixture, TestBed } from '@angular/core/testing';
3import { ReactiveFormsModule } from '@angular/forms';
4import { RouterTestingModule } from '@angular/router/testing';
5
f67539c2
TL
6import { NgbTypeaheadModule } from '@ng-bootstrap/ng-bootstrap';
7import _ from 'lodash';
adb31ebb
TL
8import { ToastrModule } from 'ngx-toastr';
9
f67539c2
TL
10import { CephServiceService } from '~/app/shared/api/ceph-service.service';
11import { CdFormGroup } from '~/app/shared/forms/cd-form-group';
12import { SharedModule } from '~/app/shared/shared.module';
13import { configureTestBed, FormHelper } from '~/testing/unit-test-helper';
adb31ebb
TL
14import { ServiceFormComponent } from './service-form.component';
15
16describe('ServiceFormComponent', () => {
17 let component: ServiceFormComponent;
18 let fixture: ComponentFixture<ServiceFormComponent>;
19 let cephServiceService: CephServiceService;
20 let form: CdFormGroup;
21 let formHelper: FormHelper;
22
23 configureTestBed({
24 declarations: [ServiceFormComponent],
25 imports: [
26 HttpClientTestingModule,
f67539c2 27 NgbTypeaheadModule,
adb31ebb
TL
28 ReactiveFormsModule,
29 RouterTestingModule,
30 SharedModule,
31 ToastrModule.forRoot()
f67539c2 32 ]
adb31ebb
TL
33 });
34
35 beforeEach(() => {
36 fixture = TestBed.createComponent(ServiceFormComponent);
37 component = fixture.componentInstance;
38 form = component.serviceForm;
39 formHelper = new FormHelper(form);
40 fixture.detectChanges();
41 });
42
43 it('should create', () => {
44 expect(component).toBeTruthy();
45 });
46
47 describe('should test form', () => {
48 beforeEach(() => {
f67539c2 49 cephServiceService = TestBed.inject(CephServiceService);
adb31ebb
TL
50 spyOn(cephServiceService, 'create').and.stub();
51 });
52
53 it('should test placement (host)', () => {
54 formHelper.setValue('service_type', 'crash');
55 formHelper.setValue('placement', 'hosts');
56 formHelper.setValue('hosts', ['mgr0', 'mon0', 'osd0']);
57 formHelper.setValue('count', 2);
58 component.onSubmit();
59 expect(cephServiceService.create).toHaveBeenCalledWith({
60 service_type: 'crash',
61 placement: {
62 hosts: ['mgr0', 'mon0', 'osd0'],
63 count: 2
64 },
65 unmanaged: false
66 });
67 });
68
69 it('should test placement (label)', () => {
70 formHelper.setValue('service_type', 'mgr');
71 formHelper.setValue('placement', 'label');
72 formHelper.setValue('label', 'foo');
73 component.onSubmit();
74 expect(cephServiceService.create).toHaveBeenCalledWith({
75 service_type: 'mgr',
76 placement: {
77 label: 'foo'
78 },
79 unmanaged: false
80 });
81 });
82
83 it('should submit valid count', () => {
84 formHelper.setValue('count', 1);
85 component.onSubmit();
86 formHelper.expectValid('count');
87 });
88
89 it('should submit invalid count (1)', () => {
90 formHelper.setValue('count', 0);
91 component.onSubmit();
92 formHelper.expectError('count', 'min');
93 });
94
95 it('should submit invalid count (2)', () => {
96 formHelper.setValue('count', 'abc');
97 component.onSubmit();
98 formHelper.expectError('count', 'pattern');
99 });
100
101 it('should test unmanaged', () => {
102 formHelper.setValue('service_type', 'rgw');
103 formHelper.setValue('placement', 'label');
104 formHelper.setValue('label', 'bar');
105 formHelper.setValue('rgw_frontend_port', 4567);
106 formHelper.setValue('unmanaged', true);
107 component.onSubmit();
108 expect(cephServiceService.create).toHaveBeenCalledWith({
109 service_type: 'rgw',
110 placement: {},
111 unmanaged: true
112 });
113 });
114
115 it('should test various services', () => {
116 _.forEach(
117 [
118 'alertmanager',
119 'crash',
120 'grafana',
121 'mds',
122 'mgr',
123 'mon',
124 'node-exporter',
125 'prometheus',
126 'rbd-mirror'
127 ],
128 (serviceType) => {
129 formHelper.setValue('service_type', serviceType);
130 component.onSubmit();
131 expect(cephServiceService.create).toHaveBeenCalledWith({
132 service_type: serviceType,
133 placement: {},
134 unmanaged: false
135 });
136 }
137 );
138 });
139
140 describe('should test service nfs', () => {
141 beforeEach(() => {
142 formHelper.setValue('service_type', 'nfs');
143 formHelper.setValue('pool', 'foo');
144 });
145
146 it('should submit nfs with namespace', () => {
147 formHelper.setValue('namespace', 'bar');
148 component.onSubmit();
149 expect(cephServiceService.create).toHaveBeenCalledWith({
150 service_type: 'nfs',
151 placement: {},
152 unmanaged: false,
153 pool: 'foo',
154 namespace: 'bar'
155 });
156 });
157
158 it('should submit nfs w/o namespace', () => {
159 component.onSubmit();
160 expect(cephServiceService.create).toHaveBeenCalledWith({
161 service_type: 'nfs',
162 placement: {},
163 unmanaged: false,
164 pool: 'foo'
165 });
166 });
167 });
168
169 describe('should test service rgw', () => {
170 beforeEach(() => {
171 formHelper.setValue('service_type', 'rgw');
172 });
173
174 it('should test rgw valid service id', () => {
175 formHelper.setValue('service_id', 'foo.bar');
176 formHelper.expectValid('service_id');
177 formHelper.setValue('service_id', 'foo.bar.bas');
178 formHelper.expectValid('service_id');
179 });
180
181 it('should test rgw invalid service id', () => {
182 formHelper.setValue('service_id', 'foo');
183 formHelper.expectError('service_id', 'rgwPattern');
184 formHelper.setValue('service_id', 'foo.');
185 formHelper.expectError('service_id', 'rgwPattern');
186 formHelper.setValue('service_id', 'foo.bar.');
187 formHelper.expectError('service_id', 'rgwPattern');
188 formHelper.setValue('service_id', 'foo.bar.bas.');
189 formHelper.expectError('service_id', 'rgwPattern');
190 });
191
192 it('should submit rgw with port', () => {
193 formHelper.setValue('rgw_frontend_port', 1234);
194 formHelper.setValue('ssl', true);
195 component.onSubmit();
196 expect(cephServiceService.create).toHaveBeenCalledWith({
197 service_type: 'rgw',
198 placement: {},
199 unmanaged: false,
200 rgw_frontend_port: 1234,
201 rgw_frontend_ssl_certificate: '',
202 rgw_frontend_ssl_key: '',
203 ssl: true
204 });
205 });
206
207 it('should submit valid rgw port (1)', () => {
208 formHelper.setValue('rgw_frontend_port', 1);
209 component.onSubmit();
210 formHelper.expectValid('rgw_frontend_port');
211 });
212
213 it('should submit valid rgw port (2)', () => {
214 formHelper.setValue('rgw_frontend_port', 65535);
215 component.onSubmit();
216 formHelper.expectValid('rgw_frontend_port');
217 });
218
219 it('should submit invalid rgw port (1)', () => {
220 formHelper.setValue('rgw_frontend_port', 0);
221 component.onSubmit();
222 formHelper.expectError('rgw_frontend_port', 'min');
223 });
224
225 it('should submit invalid rgw port (2)', () => {
226 formHelper.setValue('rgw_frontend_port', 65536);
227 component.onSubmit();
228 formHelper.expectError('rgw_frontend_port', 'max');
229 });
230
231 it('should submit invalid rgw port (3)', () => {
232 formHelper.setValue('rgw_frontend_port', 'abc');
233 component.onSubmit();
234 formHelper.expectError('rgw_frontend_port', 'pattern');
235 });
236
237 it('should submit rgw w/o port', () => {
238 formHelper.setValue('ssl', false);
239 component.onSubmit();
240 expect(cephServiceService.create).toHaveBeenCalledWith({
241 service_type: 'rgw',
242 placement: {},
243 unmanaged: false,
244 ssl: false
245 });
246 });
247 });
248
249 describe('should test service iscsi', () => {
250 beforeEach(() => {
251 formHelper.setValue('service_type', 'iscsi');
252 formHelper.setValue('pool', 'xyz');
253 formHelper.setValue('api_user', 'user');
254 formHelper.setValue('api_password', 'password');
255 formHelper.setValue('ssl', false);
256 });
257
258 it('should submit iscsi', () => {
259 component.onSubmit();
260 expect(cephServiceService.create).toHaveBeenCalledWith({
261 service_type: 'iscsi',
262 placement: {},
263 unmanaged: false,
264 pool: 'xyz',
265 api_user: 'user',
266 api_password: 'password',
267 api_secure: false
268 });
269 });
270
271 it('should submit iscsi with trusted ips', () => {
272 formHelper.setValue('ssl', true);
f67539c2 273 formHelper.setValue('trusted_ip_list', ' 172.16.0.5, 192.1.1.10 ');
adb31ebb
TL
274 component.onSubmit();
275 expect(cephServiceService.create).toHaveBeenCalledWith({
276 service_type: 'iscsi',
277 placement: {},
278 unmanaged: false,
279 pool: 'xyz',
280 api_user: 'user',
281 api_password: 'password',
282 api_secure: true,
283 ssl_cert: '',
284 ssl_key: '',
f67539c2 285 trusted_ip_list: '172.16.0.5, 192.1.1.10'
adb31ebb
TL
286 });
287 });
288
289 it('should submit iscsi with port', () => {
290 formHelper.setValue('api_port', 456);
291 component.onSubmit();
292 expect(cephServiceService.create).toHaveBeenCalledWith({
293 service_type: 'iscsi',
294 placement: {},
295 unmanaged: false,
296 pool: 'xyz',
297 api_user: 'user',
298 api_password: 'password',
299 api_secure: false,
300 api_port: 456
301 });
302 });
303
304 it('should submit valid iscsi port (1)', () => {
305 formHelper.setValue('api_port', 1);
306 component.onSubmit();
307 formHelper.expectValid('api_port');
308 });
309
310 it('should submit valid iscsi port (2)', () => {
311 formHelper.setValue('api_port', 65535);
312 component.onSubmit();
313 formHelper.expectValid('api_port');
314 });
315
316 it('should submit invalid iscsi port (1)', () => {
317 formHelper.setValue('api_port', 0);
318 component.onSubmit();
319 formHelper.expectError('api_port', 'min');
320 });
321
322 it('should submit invalid iscsi port (2)', () => {
323 formHelper.setValue('api_port', 65536);
324 component.onSubmit();
325 formHelper.expectError('api_port', 'max');
326 });
327
328 it('should submit invalid iscsi port (3)', () => {
329 formHelper.setValue('api_port', 'abc');
330 component.onSubmit();
331 formHelper.expectError('api_port', 'pattern');
332 });
333 });
b3b6e05e
TL
334
335 describe('should test service ingress', () => {
336 beforeEach(() => {
337 formHelper.setValue('service_type', 'ingress');
338 formHelper.setValue('backend_service', 'rgw.foo');
339 formHelper.setValue('virtual_ip', '192.168.20.1/24');
340 formHelper.setValue('ssl', false);
341 });
342
343 it('should submit ingress', () => {
344 component.onSubmit();
345 expect(cephServiceService.create).toHaveBeenCalledWith({
346 service_type: 'ingress',
347 placement: {},
348 unmanaged: false,
349 backend_service: 'rgw.foo',
350 service_id: 'rgw.foo',
351 virtual_ip: '192.168.20.1/24',
352 virtual_interface_networks: null,
353 ssl: false
354 });
355 });
356
357 it('should pre-populate the service id', () => {
358 component.prePopulateId();
359 const prePopulatedID = component.serviceForm.getValue('service_id');
360 expect(prePopulatedID).toBe('rgw.foo');
361 });
362
363 it('should submit valid frontend and monitor port', () => {
364 // min value
365 formHelper.setValue('frontend_port', 1);
366 formHelper.setValue('monitor_port', 1);
367 component.onSubmit();
368 formHelper.expectValid('frontend_port');
369 formHelper.expectValid('monitor_port');
370
371 // max value
372 formHelper.setValue('frontend_port', 65535);
373 formHelper.setValue('monitor_port', 65535);
374 component.onSubmit();
375 formHelper.expectValid('frontend_port');
376 formHelper.expectValid('monitor_port');
377 });
378
379 it('should submit invalid frontend and monitor port', () => {
380 // min
381 formHelper.setValue('frontend_port', 0);
382 formHelper.setValue('monitor_port', 0);
383 component.onSubmit();
384 formHelper.expectError('frontend_port', 'min');
385 formHelper.expectError('monitor_port', 'min');
386
387 // max
388 formHelper.setValue('frontend_port', 65536);
389 formHelper.setValue('monitor_port', 65536);
390 component.onSubmit();
391 formHelper.expectError('frontend_port', 'max');
392 formHelper.expectError('monitor_port', 'max');
393
394 // pattern
395 formHelper.setValue('frontend_port', 'abc');
396 formHelper.setValue('monitor_port', 'abc');
397 component.onSubmit();
398 formHelper.expectError('frontend_port', 'pattern');
399 formHelper.expectError('monitor_port', 'pattern');
400 });
401 });
adb31ebb
TL
402 });
403});