]> git.proxmox.com Git - ceph.git/blob - ceph/src/pybind/mgr/dashboard/frontend/cypress/integration/cluster/services.po.ts
481d6bc9b4d3a66d7a0df5b9c3a3fd25e5e45954
[ceph.git] / ceph / src / pybind / mgr / dashboard / frontend / cypress / integration / cluster / services.po.ts
1 import { PageHelper } from '../page-helper.po';
2
3 const pages = {
4 index: { url: '#/services', id: 'cd-services' },
5 create: { url: '#/services/(modal:create)', id: 'cd-service-form' }
6 };
7
8 export class ServicesPageHelper extends PageHelper {
9 pages = pages;
10
11 columnIndex = {
12 service_name: 2,
13 placement: 3,
14 running: 4,
15 size: 5,
16 last_refresh: 6
17 };
18
19 serviceDetailColumnIndex = {
20 daemonName: 2,
21 status: 4
22 };
23
24 check_for_service() {
25 this.getTableCount('total').should('not.be.eq', 0);
26 }
27
28 private selectServiceType(serviceType: string) {
29 return this.selectOption('service_type', serviceType);
30 }
31
32 clickServiceTab(serviceName: string, tabName: string) {
33 this.getExpandCollapseElement(serviceName).click();
34 cy.get('cd-service-details').within(() => {
35 this.getTab(tabName).click();
36 });
37 }
38
39 addService(
40 serviceType: string,
41 exist?: boolean,
42 count = '1',
43 snmpVersion?: string,
44 snmpPrivProtocol?: boolean,
45 unmanaged = false
46 ) {
47 cy.get(`${this.pages.create.id}`).within(() => {
48 this.selectServiceType(serviceType);
49 switch (serviceType) {
50 case 'rgw':
51 cy.get('#service_id').type('foo');
52 unmanaged ? cy.get('label[for=unmanaged]').click() : cy.get('#count').type(count);
53 break;
54
55 case 'ingress':
56 if (unmanaged) {
57 cy.get('label[for=unmanaged]').click();
58 }
59 this.selectOption('backend_service', 'rgw.foo');
60 cy.get('#service_id').should('have.value', 'rgw.foo');
61 cy.get('#virtual_ip').type('192.168.100.1/24');
62 cy.get('#frontend_port').type('8081');
63 cy.get('#monitor_port').type('8082');
64 break;
65
66 case 'nfs':
67 cy.get('#service_id').type('testnfs');
68 unmanaged ? cy.get('label[for=unmanaged]').click() : cy.get('#count').type(count);
69 break;
70
71 case 'snmp-gateway':
72 this.selectOption('snmp_version', snmpVersion);
73 cy.get('#snmp_destination').type('192.168.0.1:8443');
74 if (snmpVersion === 'V2c') {
75 cy.get('#snmp_community').type('public');
76 } else {
77 cy.get('#engine_id').type('800C53F00000');
78 this.selectOption('auth_protocol', 'SHA');
79 if (snmpPrivProtocol) {
80 this.selectOption('privacy_protocol', 'DES');
81 cy.get('#snmp_v3_priv_password').type('testencrypt');
82 }
83
84 // Credentials
85 cy.get('#snmp_v3_auth_username').type('test');
86 cy.get('#snmp_v3_auth_password').type('testpass');
87 }
88 break;
89
90 default:
91 cy.get('#service_id').type('test');
92 unmanaged ? cy.get('label[for=unmanaged]').click() : cy.get('#count').type(count);
93 break;
94 }
95 if (serviceType === 'snmp-gateway') {
96 cy.get('cd-submit-button').dblclick();
97 } else {
98 cy.get('cd-submit-button').click();
99 }
100 });
101 if (exist) {
102 cy.get('#service_id').should('have.class', 'ng-invalid');
103 } else {
104 // back to service list
105 cy.get(`${this.pages.index.id}`);
106 }
107 }
108
109 editService(name: string, daemonCount: string) {
110 this.navigateEdit(name, true, false);
111 cy.get(`${this.pages.create.id}`).within(() => {
112 cy.get('#service_type').should('be.disabled');
113 cy.get('#service_id').should('be.disabled');
114 cy.get('#count').clear().type(daemonCount);
115 cy.get('cd-submit-button').click();
116 });
117 }
118
119 checkServiceStatus(daemon: string, expectedStatus = 'running') {
120 let daemonNameIndex = this.serviceDetailColumnIndex.daemonName;
121 let statusIndex = this.serviceDetailColumnIndex.status;
122
123 // since hostname row is hidden from the hosts details table,
124 // we'll need to manually override the indexes when this check is being
125 // done for the daemons in host details page. So we'll get the url and
126 // verify if the current page is not the services index page
127 cy.url().then((url) => {
128 if (!url.includes(pages.index.url)) {
129 daemonNameIndex = 1;
130 statusIndex = 3;
131 }
132
133 cy.get('cd-service-daemon-list').within(() => {
134 this.getTableCell(daemonNameIndex, daemon, true)
135 .parent()
136 .find(`datatable-body-cell:nth-child(${statusIndex}) .badge`)
137 .should(($ele) => {
138 const status = $ele.toArray().map((v) => v.innerText);
139 expect(status).to.include(expectedStatus);
140 });
141 });
142 });
143 }
144
145 expectPlacementCount(serviceName: string, expectedCount: string) {
146 this.getTableCell(this.columnIndex.service_name, serviceName)
147 .parent()
148 .find(`datatable-body-cell:nth-child(${this.columnIndex.placement})`)
149 .should(($ele) => {
150 const running = $ele.text().split(';');
151 expect(running).to.include(`count:${expectedCount}`);
152 });
153 }
154
155 checkExist(serviceName: string, exist: boolean) {
156 this.getTableCell(this.columnIndex.service_name, serviceName).should(($elements) => {
157 const services = $elements.map((_, el) => el.textContent).get();
158 if (exist) {
159 expect(services).to.include(serviceName);
160 } else {
161 expect(services).to.not.include(serviceName);
162 }
163 });
164 }
165
166 isUnmanaged(serviceName: string, unmanaged: boolean) {
167 this.getTableCell(this.columnIndex.service_name, serviceName)
168 .parent()
169 .find(`datatable-body-cell:nth-child(${this.columnIndex.placement})`)
170 .should(($ele) => {
171 const placement = $ele.text().split(';');
172 unmanaged
173 ? expect(placement).to.include('unmanaged')
174 : expect(placement).to.not.include('unmanaged');
175 });
176 }
177
178 deleteService(serviceName: string) {
179 const getRow = this.getTableCell.bind(this, this.columnIndex.service_name);
180 getRow(serviceName).click();
181
182 // Clicks on table Delete button
183 this.clickActionButton('delete');
184
185 // Confirms deletion
186 cy.get('cd-modal .custom-control-label').click();
187 cy.contains('cd-modal button', 'Delete').click();
188
189 // Wait for modal to close
190 cy.get('cd-modal').should('not.exist');
191 this.checkExist(serviceName, false);
192 }
193
194 daemonAction(daemon: string, action: string) {
195 cy.get('cd-service-daemon-list').within(() => {
196 this.getTableRow(daemon).click();
197 this.clickActionButton(action);
198
199 // unselect it to avoid colliding with any other selection
200 // in different steps
201 this.getTableRow(daemon).click();
202 });
203 }
204 }