]> git.proxmox.com Git - ceph.git/blob - ceph/src/pybind/mgr/dashboard/frontend/src/app/shared/api/osd.service.spec.ts
update source to Ceph Pacific 16.2.2
[ceph.git] / ceph / src / pybind / mgr / dashboard / frontend / src / app / shared / api / osd.service.spec.ts
1 import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing';
2 import { TestBed } from '@angular/core/testing';
3
4 import { configureTestBed } from '~/testing/unit-test-helper';
5 import { OsdService } from './osd.service';
6
7 describe('OsdService', () => {
8 let service: OsdService;
9 let httpTesting: HttpTestingController;
10
11 configureTestBed({
12 providers: [OsdService],
13 imports: [HttpClientTestingModule]
14 });
15
16 beforeEach(() => {
17 service = TestBed.inject(OsdService);
18 httpTesting = TestBed.inject(HttpTestingController);
19 });
20
21 afterEach(() => {
22 httpTesting.verify();
23 });
24
25 it('should be created', () => {
26 expect(service).toBeTruthy();
27 });
28
29 it('should call create', () => {
30 const post_data = {
31 method: 'drive_groups',
32 data: [
33 {
34 service_name: 'osd',
35 service_id: 'all_hdd',
36 host_pattern: '*',
37 data_devices: {
38 rotational: true
39 }
40 },
41 {
42 service_name: 'osd',
43 service_id: 'host1_ssd',
44 host_pattern: 'host1',
45 data_devices: {
46 rotational: false
47 }
48 }
49 ],
50 tracking_id: 'all_hdd, host1_ssd'
51 };
52 service.create(post_data.data).subscribe();
53 const req = httpTesting.expectOne('api/osd');
54 expect(req.request.method).toBe('POST');
55 expect(req.request.body).toEqual(post_data);
56 });
57
58 it('should call delete', () => {
59 const id = 1;
60 service.delete(id, true, true).subscribe();
61 const req = httpTesting.expectOne(`api/osd/${id}?preserve_id=true&force=true`);
62 expect(req.request.method).toBe('DELETE');
63 });
64
65 it('should call getList', () => {
66 service.getList().subscribe();
67 const req = httpTesting.expectOne('api/osd');
68 expect(req.request.method).toBe('GET');
69 });
70
71 it('should call getDetails', () => {
72 service.getDetails(1).subscribe();
73 const req = httpTesting.expectOne('api/osd/1');
74 expect(req.request.method).toBe('GET');
75 });
76
77 it('should call scrub, with deep=true', () => {
78 service.scrub('foo', true).subscribe();
79 const req = httpTesting.expectOne('api/osd/foo/scrub?deep=true');
80 expect(req.request.method).toBe('POST');
81 });
82
83 it('should call scrub, with deep=false', () => {
84 service.scrub('foo', false).subscribe();
85 const req = httpTesting.expectOne('api/osd/foo/scrub?deep=false');
86 expect(req.request.method).toBe('POST');
87 });
88
89 it('should call getFlags', () => {
90 service.getFlags().subscribe();
91 const req = httpTesting.expectOne('api/osd/flags');
92 expect(req.request.method).toBe('GET');
93 });
94
95 it('should call updateFlags', () => {
96 service.updateFlags(['foo']).subscribe();
97 const req = httpTesting.expectOne('api/osd/flags');
98 expect(req.request.method).toBe('PUT');
99 expect(req.request.body).toEqual({ flags: ['foo'] });
100 });
101
102 it('should call updateIndividualFlags to update individual flags', () => {
103 const flags = { noin: true, noout: true };
104 const ids = [0, 1];
105 service.updateIndividualFlags(flags, ids).subscribe();
106 const req = httpTesting.expectOne('api/osd/flags/individual');
107 expect(req.request.method).toBe('PUT');
108 expect(req.request.body).toEqual({ flags: flags, ids: ids });
109 });
110
111 it('should mark the OSD out', () => {
112 service.markOut(1).subscribe();
113 const req = httpTesting.expectOne('api/osd/1/mark');
114 expect(req.request.method).toBe('PUT');
115 expect(req.request.body).toEqual({ action: 'out' });
116 });
117
118 it('should mark the OSD in', () => {
119 service.markIn(1).subscribe();
120 const req = httpTesting.expectOne('api/osd/1/mark');
121 expect(req.request.method).toBe('PUT');
122 expect(req.request.body).toEqual({ action: 'in' });
123 });
124
125 it('should mark the OSD down', () => {
126 service.markDown(1).subscribe();
127 const req = httpTesting.expectOne('api/osd/1/mark');
128 expect(req.request.method).toBe('PUT');
129 expect(req.request.body).toEqual({ action: 'down' });
130 });
131
132 it('should reweight an OSD', () => {
133 service.reweight(1, 0.5).subscribe();
134 const req = httpTesting.expectOne('api/osd/1/reweight');
135 expect(req.request.method).toBe('POST');
136 expect(req.request.body).toEqual({ weight: 0.5 });
137 });
138
139 it('should update OSD', () => {
140 service.update(1, 'hdd').subscribe();
141 const req = httpTesting.expectOne('api/osd/1');
142 expect(req.request.method).toBe('PUT');
143 expect(req.request.body).toEqual({ device_class: 'hdd' });
144 });
145
146 it('should mark an OSD lost', () => {
147 service.markLost(1).subscribe();
148 const req = httpTesting.expectOne('api/osd/1/mark');
149 expect(req.request.method).toBe('PUT');
150 expect(req.request.body).toEqual({ action: 'lost' });
151 });
152
153 it('should purge an OSD', () => {
154 service.purge(1).subscribe();
155 const req = httpTesting.expectOne('api/osd/1/purge');
156 expect(req.request.method).toBe('POST');
157 });
158
159 it('should destroy an OSD', () => {
160 service.destroy(1).subscribe();
161 const req = httpTesting.expectOne('api/osd/1/destroy');
162 expect(req.request.method).toBe('POST');
163 });
164
165 it('should return if it is safe to destroy an OSD', () => {
166 service.safeToDestroy('[0,1]').subscribe();
167 const req = httpTesting.expectOne('api/osd/safe_to_destroy?ids=[0,1]');
168 expect(req.request.method).toBe('GET');
169 });
170
171 it('should call the devices endpoint to retrieve smart data', () => {
172 service.getDevices(1).subscribe();
173 const req = httpTesting.expectOne('api/osd/1/devices');
174 expect(req.request.method).toBe('GET');
175 });
176 });