]> git.apps.os.sepia.ceph.com Git - ceph.git/blob
e9b49ce80ea02d8498483d51af1aa689ae55a398
[ceph.git] /
1 import { HttpClientTestingModule } from '@angular/common/http/testing';
2 import { ComponentFixture, TestBed } from '@angular/core/testing';
3
4 import _ from 'lodash';
5 import { NgxPipeFunctionModule } from 'ngx-pipe-function';
6 import { of } from 'rxjs';
7
8 import { CephModule } from '~/app/ceph/ceph.module';
9 import { CoreModule } from '~/app/core/core.module';
10 import { CephServiceService } from '~/app/shared/api/ceph-service.service';
11 import { HostService } from '~/app/shared/api/host.service';
12 import { CdTableFetchDataContext } from '~/app/shared/models/cd-table-fetch-data-context';
13 import { SharedModule } from '~/app/shared/shared.module';
14 import { configureTestBed } from '~/testing/unit-test-helper';
15 import { ServiceDaemonListComponent } from './service-daemon-list.component';
16
17 describe('ServiceDaemonListComponent', () => {
18   let component: ServiceDaemonListComponent;
19   let fixture: ComponentFixture<ServiceDaemonListComponent>;
20
21   const daemons = [
22     {
23       hostname: 'osd0',
24       container_id: '003c10beafc8c27b635bcdfed1ed832e4c1005be89bb1bb05ad4cc6c2b98e41b',
25       container_image_id: 'e70344c77bcbf3ee389b9bf5128f635cf95f3d59e005c5d8e67fc19bcc74ed23',
26       container_image_name: 'docker.io/ceph/daemon-base:latest-master-devel',
27       daemon_id: '3',
28       daemon_type: 'osd',
29       version: '15.1.0-1174-g16a11f7',
30       status: 1,
31       status_desc: 'running',
32       last_refresh: '2020-02-25T04:33:26.465699'
33     },
34     {
35       hostname: 'osd0',
36       container_id: 'baeec41a01374b3ed41016d542d19aef4a70d69c27274f271e26381a0cc58e7a',
37       container_image_id: 'e70344c77bcbf3ee389b9bf5128f635cf95f3d59e005c5d8e67fc19bcc74ed23',
38       container_image_name: 'docker.io/ceph/daemon-base:latest-master-devel',
39       daemon_id: '4',
40       daemon_type: 'osd',
41       version: '15.1.0-1174-g16a11f7',
42       status: 1,
43       status_desc: 'running',
44       last_refresh: '2020-02-25T04:33:26.465822'
45     },
46     {
47       hostname: 'osd0',
48       container_id: '8483de277e365bea4365cee9e1f26606be85c471e4da5d51f57e4b85a42c616e',
49       container_image_id: 'e70344c77bcbf3ee389b9bf5128f635cf95f3d59e005c5d8e67fc19bcc74ed23',
50       container_image_name: 'docker.io/ceph/daemon-base:latest-master-devel',
51       daemon_id: '5',
52       daemon_type: 'osd',
53       version: '15.1.0-1174-g16a11f7',
54       status: 1,
55       status_desc: 'running',
56       last_refresh: '2020-02-25T04:33:26.465886'
57     },
58     {
59       hostname: 'mon0',
60       container_id: '6ca0574f47e300a6979eaf4e7c283a8c4325c2235ae60358482fc4cd58844a21',
61       container_image_id: 'e70344c77bcbf3ee389b9bf5128f635cf95f3d59e005c5d8e67fc19bcc74ed23',
62       container_image_name: 'docker.io/ceph/daemon-base:latest-master-devel',
63       daemon_id: 'a',
64       daemon_type: 'mon',
65       version: '15.1.0-1174-g16a11f7',
66       status: 1,
67       status_desc: 'running',
68       last_refresh: '2020-02-25T04:33:26.465886'
69     }
70   ];
71
72   const services = [
73     {
74       service_type: 'osd',
75       service_name: 'osd',
76       status: {
77         container_image_id: 'e70344c77bcbf3ee389b9bf5128f635cf95f3d59e005c5d8e67fc19bcc74ed23',
78         container_image_name: 'docker.io/ceph/daemon-base:latest-master-devel',
79         size: 3,
80         running: 3,
81         last_refresh: '2020-02-25T04:33:26.465699'
82       },
83       events: '2021-03-22T07:34:48.582163Z service:osd [INFO] "service was created"'
84     },
85     {
86       service_type: 'crash',
87       service_name: 'crash',
88       status: {
89         container_image_id: 'e70344c77bcbf3ee389b9bf5128f635cf95f3d59e005c5d8e67fc19bcc74ed23',
90         container_image_name: 'docker.io/ceph/daemon-base:latest-master-devel',
91         size: 1,
92         running: 1,
93         last_refresh: '2020-02-25T04:33:26.465766'
94       },
95       events: '2021-03-22T07:34:48.582163Z service:osd [INFO] "service was created"'
96     }
97   ];
98
99   const getDaemonsByHostname = (hostname?: string) => {
100     return hostname ? _.filter(daemons, { hostname: hostname }) : daemons;
101   };
102
103   const getDaemonsByServiceName = (serviceName?: string) => {
104     return serviceName ? _.filter(daemons, { daemon_type: serviceName }) : daemons;
105   };
106
107   configureTestBed({
108     imports: [HttpClientTestingModule, CephModule, CoreModule, NgxPipeFunctionModule, SharedModule]
109   });
110
111   beforeEach(() => {
112     fixture = TestBed.createComponent(ServiceDaemonListComponent);
113     component = fixture.componentInstance;
114     const hostService = TestBed.inject(HostService);
115     const cephServiceService = TestBed.inject(CephServiceService);
116     spyOn(hostService, 'getDaemons').and.callFake(() =>
117       of(getDaemonsByHostname(component.hostname))
118     );
119     spyOn(cephServiceService, 'getDaemons').and.callFake(() =>
120       of(getDaemonsByServiceName(component.serviceName))
121     );
122     spyOn(cephServiceService, 'list').and.returnValue(of(services));
123     fixture.detectChanges();
124   });
125
126   it('should create', () => {
127     expect(component).toBeTruthy();
128   });
129
130   it('should list daemons by host', () => {
131     component.hostname = 'mon0';
132     component.getDaemons(new CdTableFetchDataContext(() => undefined));
133     expect(component.daemons.length).toBe(1);
134   });
135
136   it('should list daemons by service', () => {
137     component.serviceName = 'osd';
138     component.getDaemons(new CdTableFetchDataContext(() => undefined));
139     expect(component.daemons.length).toBe(3);
140   });
141
142   it('should list services', () => {
143     component.getServices(new CdTableFetchDataContext(() => undefined));
144     expect(component.services.length).toBe(2);
145   });
146
147   it('should not display doc panel if orchestrator is available', () => {
148     expect(component.showDocPanel).toBeFalsy();
149   });
150 });