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