]> git.proxmox.com Git - ceph.git/blob - ceph/src/pybind/mgr/dashboard/frontend/cypress/integration/cluster/hosts.po.ts
import ceph quincy 17.2.6
[ceph.git] / ceph / src / pybind / mgr / dashboard / frontend / cypress / integration / cluster / hosts.po.ts
1 import { PageHelper } from '../page-helper.po';
2
3 const pages = {
4 index: { url: '#/hosts', id: 'cd-hosts' },
5 add: { url: '#/hosts/(modal:add)', id: 'cd-host-form' }
6 };
7
8 export class HostsPageHelper extends PageHelper {
9 pages = pages;
10
11 columnIndex = {
12 hostname: 2,
13 services: 3,
14 labels: 4,
15 status: 5
16 };
17
18 check_for_host() {
19 this.getTableCount('total').should('not.be.eq', 0);
20 }
21
22 add(hostname: string, exist?: boolean, maintenance?: boolean, labels: string[] = []) {
23 cy.get(`${this.pages.add.id}`).within(() => {
24 cy.get('#hostname').type(hostname);
25 if (maintenance) {
26 cy.get('label[for=maintenance]').click();
27 }
28 if (exist) {
29 cy.get('#hostname').should('have.class', 'ng-invalid');
30 }
31 });
32
33 if (labels.length) {
34 this.selectPredefinedLabels(labels);
35 }
36
37 cy.get('cd-submit-button').click();
38 // back to host list
39 cy.get(`${this.pages.index.id}`);
40 }
41
42 selectPredefinedLabels(labels: string[]) {
43 cy.get('a[data-testid=select-menu-edit]').click();
44 for (const label of labels) {
45 cy.get('.popover-body div.select-menu-item-content').contains(label).click();
46 }
47 }
48
49 checkExist(hostname: string, exist: boolean) {
50 this.getTableCell(this.columnIndex.hostname, hostname).should(($elements) => {
51 const hosts = $elements.map((_, el) => el.textContent).get();
52 if (exist) {
53 expect(hosts).to.include(hostname);
54 } else {
55 expect(hosts).to.not.include(hostname);
56 }
57 });
58 }
59
60 remove(hostname: string) {
61 super.delete(hostname, this.columnIndex.hostname, 'hosts');
62 }
63
64 // Add or remove labels on a host, then verify labels in the table
65 editLabels(hostname: string, labels: string[], add: boolean) {
66 this.getTableCell(this.columnIndex.hostname, hostname).click();
67 this.clickActionButton('edit');
68
69 // add or remove label badges
70 if (add) {
71 cy.get('cd-modal').find('.select-menu-edit').click();
72 for (const label of labels) {
73 cy.contains('cd-modal .badge', new RegExp(`^${label}$`)).should('not.exist');
74 cy.get('.popover-body input').type(`${label}{enter}`);
75 }
76 } else {
77 for (const label of labels) {
78 cy.contains('cd-modal .badge', new RegExp(`^${label}$`))
79 .find('.badge-remove')
80 .click();
81 }
82 }
83 cy.get('cd-modal cd-submit-button').click();
84 this.checkLabelExists(hostname, labels, add);
85 }
86
87 checkLabelExists(hostname: string, labels: string[], add: boolean) {
88 // Verify labels are added or removed from Labels column
89 // First find row with hostname, then find labels in the row
90 this.getTableCell(this.columnIndex.hostname, hostname)
91 .click()
92 .parent()
93 .find(`datatable-body-cell:nth-child(${this.columnIndex.labels}) .badge`)
94 .should(($ele) => {
95 const newLabels = $ele.toArray().map((v) => v.innerText);
96 for (const label of labels) {
97 if (add) {
98 expect(newLabels).to.include(label);
99 } else {
100 expect(newLabels).to.not.include(label);
101 }
102 }
103 });
104 }
105
106 @PageHelper.restrictTo(pages.index.url)
107 maintenance(hostname: string, exit = false, force = false) {
108 this.clearTableSearchInput();
109 if (force) {
110 this.getTableCell(this.columnIndex.hostname, hostname).click();
111 this.clickActionButton('enter-maintenance');
112
113 cy.get('cd-modal').within(() => {
114 cy.contains('button', 'Continue').click();
115 });
116
117 this.getTableCell(this.columnIndex.hostname, hostname)
118 .parent()
119 .find(`datatable-body-cell:nth-child(${this.columnIndex.status}) .badge`)
120 .should(($ele) => {
121 const status = $ele.toArray().map((v) => v.innerText);
122 expect(status).to.include('maintenance');
123 });
124 }
125 if (exit) {
126 this.getTableCell(this.columnIndex.hostname, hostname)
127 .click()
128 .parent()
129 .find(`datatable-body-cell:nth-child(${this.columnIndex.status})`)
130 .then(($ele) => {
131 const status = $ele.toArray().map((v) => v.innerText);
132 if (status[0].includes('maintenance')) {
133 this.clickActionButton('exit-maintenance');
134 }
135 });
136
137 this.getTableCell(this.columnIndex.hostname, hostname)
138 .parent()
139 .find(`datatable-body-cell:nth-child(${this.columnIndex.status})`)
140 .should(($ele) => {
141 const status = $ele.toArray().map((v) => v.innerText);
142 expect(status).to.not.include('maintenance');
143 });
144 } else {
145 this.getTableCell(this.columnIndex.hostname, hostname).click();
146 this.clickActionButton('enter-maintenance');
147
148 this.getTableCell(this.columnIndex.hostname, hostname)
149 .parent()
150 .find(`datatable-body-cell:nth-child(${this.columnIndex.status}) .badge`)
151 .should(($ele) => {
152 const status = $ele.toArray().map((v) => v.innerText);
153 expect(status).to.include('maintenance');
154 });
155 }
156 }
157
158 @PageHelper.restrictTo(pages.index.url)
159 drain(hostname: string) {
160 this.getTableCell(this.columnIndex.hostname, hostname).click();
161 this.clickActionButton('start-drain');
162 this.checkLabelExists(hostname, ['_no_schedule'], true);
163
164 this.clickTab('cd-host-details', hostname, 'Daemons');
165 cy.get('cd-host-details').within(() => {
166 cy.wait(20000);
167 this.expectTableCount('total', 0);
168 });
169 }
170
171 checkServiceInstancesExist(hostname: string, instances: string[]) {
172 this.getTableCell(this.columnIndex.hostname, hostname)
173 .parent()
174 .find(`datatable-body-cell:nth-child(${this.columnIndex.services}) .badge`)
175 .should(($ele) => {
176 const serviceInstances = $ele.toArray().map((v) => v.innerText);
177 for (const instance of instances) {
178 expect(serviceInstances).to.include(instance);
179 }
180 });
181 }
182 }