Skip to content

Commit c0b0f65

Browse files
Add cancel job test (#2583)
1 parent ddb8bb4 commit c0b0f65

File tree

3 files changed

+209
-11
lines changed

3 files changed

+209
-11
lines changed

cypress/e2e/awx/resources/hosts.cy.ts

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
import { Inventory } from '../../../../frontend/awx/interfaces/Inventory';
22
import { Organization } from '../../../../frontend/awx/interfaces/Organization';
33
import { Project } from '../../../../frontend/awx/interfaces/Project';
4-
import { AwxUser } from '../../../../frontend/awx/interfaces/User';
54
import {
65
checkFactsInHost,
76
checkHostGroup,
87
createAndEditAndDeleteHost,
98
createHostAndLaunchJob,
9+
createHostAndCancelJob,
1010
} from '../../../support/hostsfunctions';
1111

1212
describe('Host Tests', () => {
1313
let organization: Organization;
1414
let inventory: Inventory;
15-
let user: AwxUser;
1615
let project: Project;
1716

1817
before(() => {
@@ -21,19 +20,14 @@ describe('Host Tests', () => {
2120
cy.createAwxInventory({ organization: organization.id }).then((inv) => {
2221
inventory = inv;
2322
});
24-
cy.createAwxUser(organization).then((testUser) => {
25-
user = testUser;
26-
cy.createAwxProject({ organization: organization.id }).then((proj) => {
27-
project = proj;
28-
// cy.giveUserProjectAccess(project.name, user.id, 'Read');
29-
});
23+
cy.createAwxProject({ organization: organization.id }).then((proj) => {
24+
project = proj;
3025
});
3126
});
3227
});
3328

3429
after(() => {
3530
cy.deleteAwxInventory(inventory, { failOnStatusCode: false });
36-
cy.deleteAwxUser(user, { failOnStatusCode: false });
3731
cy.deleteAwxOrganization(organization, { failOnStatusCode: false });
3832
cy.deleteAwxProject(project, { failOnStatusCode: false });
3933
});
@@ -55,7 +49,9 @@ describe('Host Tests', () => {
5549
createHostAndLaunchJob(inventory, organization.id, project.id);
5650
});
5751

58-
it.skip('can cancel jobs from host jobs tab', () => {});
52+
it('can cancel jobs from host jobs tab', () => {
53+
createHostAndCancelJob(inventory, organization.id, project.id);
54+
});
5955

6056
it('can view host facts in stand alone host', () => {
6157
checkFactsInHost(inventory);

cypress/fixtures/awxRunningJobs.json

Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
{
2+
"count": 1,
3+
"next": null,
4+
"previous": null,
5+
"results": [
6+
{
7+
"id": 70,
8+
"type": "job",
9+
"url": "/api/v2/jobs/70/",
10+
"related": {
11+
"created_by": "/api/v2/users/3/",
12+
"labels": "/api/v2/jobs/70/labels/",
13+
"inventory": "/api/v2/inventories/107/",
14+
"project": "/api/v2/projects/8/",
15+
"organization": "/api/v2/organizations/2/",
16+
"credentials": "/api/v2/jobs/70/credentials/",
17+
"unified_job_template": "/api/v2/job_templates/75/",
18+
"stdout": "/api/v2/jobs/70/stdout/",
19+
"execution_environment": "/api/v2/execution_environments/1/",
20+
"job_events": "/api/v2/jobs/70/job_events/",
21+
"job_host_summaries": "/api/v2/jobs/70/job_host_summaries/",
22+
"activity_stream": "/api/v2/jobs/70/activity_stream/",
23+
"notifications": "/api/v2/jobs/70/notifications/",
24+
"create_schedule": "/api/v2/jobs/70/create_schedule/",
25+
"job_template": "/api/v2/job_templates/75/",
26+
"cancel": "/api/v2/jobs/70/cancel/",
27+
"relaunch": "/api/v2/jobs/70/relaunch/"
28+
},
29+
"summary_fields": {
30+
"organization": {
31+
"id": 2,
32+
"name": "Global Organization",
33+
"description": ""
34+
},
35+
"inventory": {
36+
"id": 107,
37+
"name": "E2E Inventory Bzlo",
38+
"description": "",
39+
"has_active_failures": true,
40+
"total_hosts": 1,
41+
"hosts_with_active_failures": 1,
42+
"total_groups": 0,
43+
"has_inventory_sources": true,
44+
"total_inventory_sources": 1,
45+
"inventory_sources_with_failures": 0,
46+
"organization_id": 2,
47+
"kind": ""
48+
},
49+
"execution_environment": {
50+
"id": 1,
51+
"name": "quay.io/ansible/awx-ee (latest)",
52+
"description": "",
53+
"image": "quay.io/ansible/awx-ee:latest"
54+
},
55+
"project": {
56+
"id": 8,
57+
"name": "Global Project",
58+
"description": "Global Read Only Project for E2E tests",
59+
"status": "successful",
60+
"scm_type": "git",
61+
"allow_override": false
62+
},
63+
"job_template": {
64+
"id": 75,
65+
"name": "E2E Job Template MBvv",
66+
"description": ""
67+
},
68+
"unified_job_template": {
69+
"id": 75,
70+
"name": "E2E Job Template MBvv",
71+
"description": "",
72+
"unified_job_type": "job"
73+
},
74+
"instance_group": {
75+
"id": 2,
76+
"name": "default",
77+
"is_container_group": true
78+
},
79+
"created_by": {
80+
"id": 3,
81+
"username": "dev",
82+
"first_name": "",
83+
"last_name": ""
84+
},
85+
"user_capabilities": {
86+
"delete": true,
87+
"start": true
88+
},
89+
"labels": {
90+
"count": 0,
91+
"results": []
92+
},
93+
"credentials": []
94+
},
95+
"created": "2024-06-25T08:12:19.281597Z",
96+
"modified": "2024-06-25T08:12:19.457639Z",
97+
"name": "E2E Job Template MBvv",
98+
"description": "",
99+
"unified_job_template": 75,
100+
"launch_type": "relaunch",
101+
"status": "running",
102+
"execution_environment": 1,
103+
"failed": true,
104+
"started": "2024-06-25T08:12:19.528109Z",
105+
"finished": "2024-06-25T08:12:25.144883Z",
106+
"canceled_on": null,
107+
"elapsed": 5.617,
108+
"job_explanation": "",
109+
"execution_node": "",
110+
"controller_node": "awx-task-54b4b675bd-72mfz",
111+
"launched_by": {
112+
"id": 3,
113+
"name": "dev",
114+
"type": "user",
115+
"url": "/api/v2/users/3/"
116+
},
117+
"work_unit_id": "86r1Cpyr",
118+
"job_type": "run",
119+
"inventory": 107,
120+
"project": 8,
121+
"playbook": "playbooks/hello_world.yml",
122+
"scm_branch": "",
123+
"forks": 0,
124+
"limit": "",
125+
"verbosity": 0,
126+
"extra_vars": "{}",
127+
"job_tags": "",
128+
"force_handlers": false,
129+
"skip_tags": "",
130+
"start_at_task": "",
131+
"timeout": 0,
132+
"use_fact_cache": false,
133+
"organization": 2,
134+
"job_template": 75,
135+
"passwords_needed_to_start": [],
136+
"allow_simultaneous": false,
137+
"artifacts": {},
138+
"scm_revision": "5354d08761d4ae951c87da0351e9e8dba603b6f9",
139+
"instance_group": 2,
140+
"diff_mode": false,
141+
"job_slice_number": 0,
142+
"job_slice_count": 1,
143+
"webhook_service": "",
144+
"webhook_credential": null,
145+
"webhook_guid": ""
146+
}
147+
]
148+
}

cypress/support/hostsfunctions.ts

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,60 @@ export function testHostBulkDelete(host_type: string, inventory: Inventory) {
255255
}
256256
}
257257

258+
export function createHostAndCancelJob(
259+
inventory: Inventory,
260+
organizationId: number,
261+
projectId: number,
262+
hostInInventory?: boolean
263+
) {
264+
cy.createAwxJobTemplate({
265+
inventory: inventory.id,
266+
organization: organizationId,
267+
project: projectId,
268+
}).then(() => {
269+
// go to inventory hosts
270+
cy.navigateTo('awx', 'inventories');
271+
cy.filterTableByMultiSelect('name', [inventory.name]);
272+
cy.get('[data-cy="name-column-cell"]').contains(inventory.name).click();
273+
cy.get('.pf-v5-c-tabs__item > a').contains('Hosts').click();
274+
// add a host
275+
const hostName = createHost('inventory_host', inventory.id);
276+
// go to inventory job templates
277+
cy.navigateTo('awx', 'inventories');
278+
cy.filterTableByMultiSelect('name', [inventory.name]);
279+
cy.get('[data-cy="name-column-cell"]').contains(inventory.name).click();
280+
cy.get('.pf-v5-c-tabs__item > a').contains('Job templates').click();
281+
// run a template and wait for request
282+
cy.intercept('POST', awxAPI`/job_templates/*/launch`).as('launch');
283+
cy.get('[data-cy="launch-template"]').first().click();
284+
cy.wait('@launch').should('exist');
285+
if (hostInInventory) {
286+
// go to the Hosts under Inventory
287+
cy.navigateTo('awx', 'inventories');
288+
cy.filterTableByMultiSelect('name', [inventory.name]);
289+
cy.get('[data-cy="name-column-cell"]').contains(inventory.name).click();
290+
cy.get('.pf-v5-c-tabs__item > a').contains('Hosts').click();
291+
} else {
292+
// go to the Hosts
293+
cy.navigateTo('awx', 'hosts');
294+
}
295+
cy.filterTableByMultiSelect('name', [hostName]);
296+
cy.get('[data-cy="name-column-cell"]').contains(hostName).click();
297+
cy.intercept(
298+
{ method: 'GET', url: awxAPI`/unified_jobs/*` },
299+
{ fixture: 'awxRunningJobs.json' }
300+
);
301+
cy.get('.pf-v5-c-tabs__item > a').contains('Jobs').click();
302+
// there should be cancel job button when jon is running
303+
cy.get('[data-cy="cancel-job"]').should('be.enabled');
304+
cy.get('[data-cy="cancel-job"]').click();
305+
cy.clickModalConfirmCheckbox();
306+
cy.contains('button', 'Cancel job').click();
307+
// expect cancel to fail as the running job is mocked
308+
cy.contains('Error').should('exist');
309+
});
310+
}
311+
258312
export function createHostAndLaunchJob(
259313
inventory: Inventory,
260314
organizationId: number,
@@ -280,7 +334,7 @@ export function createHostAndLaunchJob(
280334
cy.get('.pf-v5-c-tabs__item > a').contains('Job templates').click();
281335
// run a template and wait for request
282336
cy.intercept('POST', awxAPI`/job_templates/*/launch`).as('launch');
283-
cy.get('[data-cy="launch-template"]').click();
337+
cy.get('[data-cy="launch-template"]').first().click();
284338
cy.wait('@launch').should('exist');
285339
if (hostInInventory) {
286340
// go to the Hosts under Inventory

0 commit comments

Comments
 (0)