Skip to content

Commit ddb8bb4

Browse files
authored
add tests for ad-hoc commands for regular and smart inventories (#2584)
1 parent dcac521 commit ddb8bb4

File tree

3 files changed

+89
-5
lines changed

3 files changed

+89
-5
lines changed

cypress/e2e/awx/resources/inventoryHost/inventoryHostRegular.cy.ts

Lines changed: 63 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
1+
import { awxAPI } from '../../../../../frontend/awx/common/api/awx-utils';
12
import { Inventory } from '../../../../../frontend/awx/interfaces/Inventory';
23
import { Organization } from '../../../../../frontend/awx/interfaces/Organization';
34
import { AwxUser } from '../../../../../frontend/awx/interfaces/User';
5+
import { runCommand } from './runCommandFunction';
6+
import { randomString } from '../../../../../framework/utils/random-string';
7+
48
import {
59
checkHostGroup,
610
createAndEditAndDeleteHost,
711
testHostBulkDelete,
12+
createHost,
813
} from '../../../../support/hostsfunctions';
914

1015
describe('Inventory Host Tab Tests for regular inventory', () => {
@@ -80,19 +85,75 @@ describe('Inventory Host Tab Tests for regular inventory', () => {
8085
//5) Cancel the job and assert that it has been canceled
8186
});
8287

83-
it.skip(`can run an ad-hoc command against a host on the inventory hosts tab`, () => {
88+
it(`can run an ad-hoc command against a host on the inventory hosts tab`, () => {
8489
//1) Use the inventory created in before, access the host tab of that inventory
8590
//2) Use a host, EE, and credential - these resources are needed to run a command against a host
8691
//3) Assert redirect to the job output screen
8792
//4) Navigate to the details page of the job and assert the values there match what was entered in the Run Command Wizard
8893
//5) Navigate back to the Inventory -> Jobs Tab to assert that the Run Command job shows up there
94+
createHost('inventory_host', inventory.id);
95+
96+
cy.navigateTo('awx', 'inventories');
97+
cy.intercept('get', awxAPI`/inventories/?name=${inventory.name}*`).as('getInventories');
98+
cy.filterTableByMultiSelect('name', [inventory.name]);
99+
cy.wait('@getInventories');
100+
101+
cy.contains('a', inventory.name).click();
102+
cy.contains(`a[role="tab"]`, 'Hosts').click();
103+
104+
cy.getByDataCy('run-command').click();
105+
106+
runCommand({
107+
selections: 'all',
108+
module: 'shell',
109+
verbosity: '0-(normal)',
110+
forks: 2,
111+
show_changes: true,
112+
become_enabled: true,
113+
organization,
114+
});
89115
});
90116

91-
it.skip('can run an ad-hoc command against the host on the groups tab of a host-inventory from the host details page', () => {
117+
it('can run an ad-hoc command against the host on the groups tab of a host-inventory from the host details page', () => {
92118
//1) Use the inventory created in before, access the host tab of that inventory, visit the host details page
93119
//2) Use a host, EE, and credential - these resources are needed to run a command against a host
94120
//3) Assert redirect to the job output screen
95121
//4) Navigate to the details page of the job and assert the values there match what was entered in the Run Command Wizard
96122
//5) Navigate back to the Inventory -> Jobs Tab to assert that the Run Command job shows up there
123+
124+
createHost('inventory_host', inventory.id);
125+
const groupName = 'E2E group ' + randomString(4);
126+
cy.createInventoryGroup(inventory, groupName);
127+
cy.log(`inv: ${inventory.name}, group: ${groupName}`);
128+
129+
cy.navigateTo('awx', 'inventories');
130+
131+
cy.intercept('get', awxAPI`/inventories/?name=${inventory.name}*`).as('getInventories');
132+
cy.filterTableByMultiSelect('name', [inventory.name]);
133+
cy.wait('@getInventories');
134+
135+
cy.contains('a', inventory.name).click();
136+
137+
cy.contains(`a[role="tab"]`, 'Groups').click();
138+
cy.reload();
139+
cy.contains('a', groupName).click();
140+
141+
cy.contains(`a[role="tab"]`, 'Hosts').click();
142+
// add existing host
143+
cy.getByDataCy('add-existing-host').click();
144+
cy.getByDataCy('select-all').click();
145+
cy.clickModalButton('Add hosts');
146+
147+
cy.getByDataCy('run-command').click();
148+
149+
runCommand({
150+
selections: 'all',
151+
module: 'shell',
152+
verbosity: '0-(normal)',
153+
forks: 2,
154+
show_changes: true,
155+
become_enabled: true,
156+
organization,
157+
});
97158
});
98159
});

cypress/e2e/awx/resources/inventoryHost/inventoryHostSmart.cy.ts

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
/* eslint-disable @typescript-eslint/no-unsafe-call */
2+
import { awxAPI } from '../../../../../frontend/awx/common/api/awx-utils';
23
import { Inventory } from '../../../../../frontend/awx/interfaces/Inventory';
34
import { Organization } from '../../../../../frontend/awx/interfaces/Organization';
45
import { AwxUser } from '../../../../../frontend/awx/interfaces/User';
6+
import { runCommand } from './runCommandFunction';
57
import { checkHiddenButton, checkHiddenTab } from '../../../../support/hostsfunctions';
68

79
describe('Inventory Host Tab Tests for smart inventory', () => {
@@ -16,6 +18,7 @@ describe('Inventory Host Tab Tests for smart inventory', () => {
1618
const { inventory: inv } = result;
1719
inventory = inv;
1820
});
21+
1922
cy.createAwxUser(organization).then((testUser) => {
2023
user = testUser;
2124
});
@@ -29,14 +32,34 @@ describe('Inventory Host Tab Tests for smart inventory', () => {
2932
});
3033

3134
//tests
32-
it.skip(`can run an ad-hoc command against a host on the inventory hosts tab`, () => {
35+
it(`can run an ad-hoc command against a host on the inventory hosts tab`, () => {
3336
//1) Use the inventory created in before, access the host tab of that inventory
3437
//2) Use a host, EE, and credential - these resources are needed to run a command against a host
3538
//3) Assert redirect to the job output screen
3639
//4) Navigate to the details page of the job and assert the values there match what was entered in the Run Command Wizard
3740
//5) Navigate back to the Inventory -> Jobs Tab to assert that the Run Command job shows up there
41+
cy.navigateTo('awx', 'inventories');
42+
cy.intercept('get', awxAPI`/inventories/?name=${inventory.name}*`).as('getInventories');
43+
cy.filterTableByMultiSelect('name', [inventory.name]);
44+
cy.wait('@getInventories');
45+
46+
cy.contains('a', inventory.name).click();
47+
cy.contains(`a[role="tab"]`, 'Hosts').click();
48+
49+
cy.getByDataCy('run-command').click();
50+
51+
runCommand({
52+
selections: 'all',
53+
module: 'shell',
54+
verbosity: '0-(normal)',
55+
forks: 2,
56+
show_changes: true,
57+
become_enabled: true,
58+
organization,
59+
});
3860
});
3961

62+
//there is NO group tab in smart inventory
4063
it.skip('can run an ad-hoc command against the host on the groups tab of a host-inventory from the host details page', () => {
4164
//1) Use the inventory created in before, access the host tab of that inventory, visit the host details page
4265
//2) Use a host, EE, and credential - these resources are needed to run a command against a host

cypress/support/hostsfunctions.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export function createAndCheckHost(host_type: string, inventory: string) {
4545
return hostName;
4646
}
4747

48-
function createHost(host_type: string, inventoryID: number) {
48+
export function createHost(host_type: string, inventoryID: number) {
4949
const hostName = 'E2E Host ' + randomString(4);
5050
// create host with no verify
5151
if (host_type === 'inventory_host') {
@@ -126,7 +126,7 @@ function navigateToHost(host_type: string, name: string, data: string, inventory
126126
cy.get(data).click();
127127
}
128128

129-
function navigateToBaseView(host_type: string, inventoryName: string) {
129+
export function navigateToBaseView(host_type: string, inventoryName: string) {
130130
//function for navigeate to host list view or inventory host list view
131131
if (host_type === 'inventory_host') {
132132
cy.navigateTo('awx', 'inventories');

0 commit comments

Comments
 (0)