]> git.proxmox.com Git - ceph.git/blob - ceph/src/pybind/mgr/dashboard/frontend/cypress/integration/cluster/hosts.po.ts
b769c880a87d0930cedb1dd433c22293dff98e67
[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 .parent()
92 .find(`datatable-body-cell:nth-child(${this.columnIndex.labels}) .badge`)
93 .should(($ele) => {
94 const newLabels = $ele.toArray().map((v) => v.innerText);
95 for (const label of labels) {
96 if (add) {
97 expect(newLabels).to.include(label);
98 } else {
99 expect(newLabels).to.not.include(label);
100 }
101 }
102 });
103 }
104
105 @PageHelper.restrictTo(pages.index.url)
106 maintenance(hostname: string, exit = false, force = false) {
107 this.clearTableSearchInput();
108 this.getTableCell(this.columnIndex.hostname, hostname).click();
109 if (force) {
110 this.clickActionButton('enter-maintenance');
111
112 cy.get('cd-modal').within(() => {
113 cy.contains('button', 'Continue').click();
114 });
115
116 this.getTableCell(this.columnIndex.hostname, hostname)
117 .parent()
118 .find(`datatable-body-cell:nth-child(${this.columnIndex.status}) .badge`)
119 .should(($ele) => {
120 const status = $ele.toArray().map((v) => v.innerText);
121 expect(status).to.include('maintenance');
122 });
123 }
124 if (exit) {
125 this.getTableCell(this.columnIndex.hostname, hostname)
126 .parent()
127 .find(`datatable-body-cell:nth-child(${this.columnIndex.status})`)
128 .then(($ele) => {
129 const status = $ele.toArray().map((v) => v.innerText);
130 if (status[0].includes('maintenance')) {
131 this.clickActionButton('exit-maintenance');
132 }
133 });
134
135 this.getTableCell(this.columnIndex.hostname, hostname)
136 .parent()
137 .find(`datatable-body-cell:nth-child(${this.columnIndex.status})`)
138 .should(($ele) => {
139 const status = $ele.toArray().map((v) => v.innerText);
140 expect(status).to.not.include('maintenance');
141 });
142 } else {
143 this.clickActionButton('enter-maintenance');
144
145 this.getTableCell(this.columnIndex.hostname, hostname)
146 .parent()
147 .find(`datatable-body-cell:nth-child(${this.columnIndex.status}) .badge`)
148 .should(($ele) => {
149 const status = $ele.toArray().map((v) => v.innerText);
150 expect(status).to.include('maintenance');
151 });
152 }
153 }
154
155 @PageHelper.restrictTo(pages.index.url)
156 drain(hostname: string) {
157 this.getTableCell(this.columnIndex.hostname, hostname).click();
158 this.clickActionButton('start-drain');
159 this.checkLabelExists(hostname, ['_no_schedule'], true);
160
161 // unselect it to avoid colliding with any other selection
162 // in different steps
163 this.getTableCell(this.columnIndex.hostname, hostname).click();
164
165 this.clickTab('cd-host-details', hostname, 'Daemons');
166 cy.get('cd-host-details').within(() => {
167 cy.wait(20000);
168 this.expectTableCount('total', 0);
169 });
170 }
171
172 checkServiceInstancesExist(hostname: string, instances: string[]) {
173 this.getTableCell(this.columnIndex.hostname, hostname)
174 .parent()
175 .find(`datatable-body-cell:nth-child(${this.columnIndex.services}) .badge`)
176 .should(($ele) => {
177 const serviceInstances = $ele.toArray().map((v) => v.innerText);
178 for (const instance of instances) {
179 expect(serviceInstances).to.include(instance);
180 }
181 });
182 }
183 }