Skip to content

Commit

Permalink
inventory host jobs test (#2598)
Browse files Browse the repository at this point in the history
  • Loading branch information
MilanPospisil authored Jul 2, 2024
1 parent b876d92 commit 40e9376
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 25 deletions.
7 changes: 5 additions & 2 deletions cypress/e2e/awx/resources/hosts.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
checkFactsInHost,
checkHostGroup,
createAndEditAndDeleteHost,
createHostAndLaunchJob,
launchHostJob,
createHostAndCancelJob,
} from '../../../support/hostsfunctions';

Expand Down Expand Up @@ -46,7 +46,10 @@ describe('Host Tests', () => {
});

it('can see and launch jobs from host jobs tab', () => {
createHostAndLaunchJob(inventory, organization.id, project.id);
cy.createInventoryHost(organization, '').then((result) => {
launchHostJob(result.inventory, result.host, organization.id, project.id, 'Host');
cy.deleteAwxInventory(result.inventory, { failOnStatusCode: false });
});
});

it('can cancel jobs from host jobs tab', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { InventoryGroup } from '../../../../../frontend/awx/interfaces/Inventory
import { Organization } from '../../../../../frontend/awx/interfaces/Organization';
import { runCommand } from './runCommandFunction';
import { checkHiddenButton, checkHiddenTab } from '../../../../support/hostsfunctions';
import { launchHostJob } from '../../../../support/hostsfunctions';

describe('Inventory Host Tab Tests for contructed inventory', () => {
let organization: Organization;
Expand Down Expand Up @@ -104,10 +105,17 @@ describe('Inventory Host Tab Tests for contructed inventory', () => {
});
});

it.skip('can launch a job template that uses an inventory with a particular host and view the job on the host jobs tab inside the inventory', () => {
it('can launch a job template that uses an inventory with a particular host and view the job on the host jobs tab inside the inventory', () => {
//1) Use inventory and host
//2) create a job template that uses that inventory, launch the job template, wait for job to finish
//3) Navigate back to inventory -> host tab -> jobs tab -> assert presence of job in that list
cy.createAwxProject({ organization: organization.id }).then((project) => {
cy.createInventoryHost(organization, 'constructed').then((result) => {
launchHostJob(result.inventory, result.host, organization.id, project.id, 'InventoryHost');
cy.deleteAwxInventory(result.inventory, { failOnStatusCode: false });
cy.deleteAwxProject(project, { failOnStatusCode: false });
});
});
});

//there is NO jobs tab in constructed inventory -> host
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Organization } from '../../../../../frontend/awx/interfaces/Organizatio
import { AwxUser } from '../../../../../frontend/awx/interfaces/User';
import { runCommand } from './runCommandFunction';
import { randomString } from '../../../../../framework/utils/random-string';
import { launchHostJob } from '../../../../support/hostsfunctions';
import { Project } from '../../../../../frontend/awx/interfaces/Project';

import {
Expand Down Expand Up @@ -79,10 +80,17 @@ describe('Inventory Host Tab Tests for regular inventory', () => {
checkFactsInHost(inventory, 'inventory_host');
});

it.skip('can launch a job template that uses an inventory with a particular host and view the job on the host jobs tab inside the inventory', () => {
it('can launch a job template that uses an inventory with a particular host and view the job on the host jobs tab inside the inventory', () => {
//1) Use inventory and host
//2) create a job template that uses that inventory, launch the job template, wait for job to finish
//3) Navigate back to inventory -> host tab -> jobs tab -> assert presence of job in that list
cy.createAwxProject({ organization: organization.id }).then((project) => {
cy.createInventoryHost(organization, '').then((result) => {
launchHostJob(result.inventory, result.host, organization.id, project.id, 'InventoryHost');
cy.deleteAwxInventory(result.inventory, { failOnStatusCode: false });
cy.deleteAwxProject(project, { failOnStatusCode: false });
});
});
});

it('can cancel a currently running job from the host jobs tab inside an inventory', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { Organization } from '../../../../../frontend/awx/interfaces/Organizatio
import { AwxUser } from '../../../../../frontend/awx/interfaces/User';
import { runCommand } from './runCommandFunction';
import { checkHiddenButton, checkHiddenTab } from '../../../../support/hostsfunctions';
import { launchHostJob } from '../../../../support/hostsfunctions';

describe('Inventory Host Tab Tests for smart inventory', () => {
let organization: Organization;
Expand Down Expand Up @@ -68,10 +69,17 @@ describe('Inventory Host Tab Tests for smart inventory', () => {
//5) Navigate back to the Inventory -> Jobs Tab to assert that the Run Command job shows up there
});

it.skip('can launch a job template that uses an inventory with a particular host and view the job on the host jobs tab inside the inventory', () => {
it('can launch a job template that uses an inventory with a particular host and view the job on the host jobs tab inside the inventory', () => {
//1) Use inventory and host
//2) create a job template that uses that inventory, launch the job template, wait for job to finish
//3) Navigate back to inventory -> host tab -> jobs tab -> assert presence of job in that list
cy.createAwxProject({ organization: organization.id }).then((project) => {
cy.createInventoryHost(organization, 'smart').then((result) => {
launchHostJob(result.inventory, result.host, organization.id, project.id, 'InventoryHost');
cy.deleteAwxInventory(result.inventory, { failOnStatusCode: false });
cy.deleteAwxProject(project, { failOnStatusCode: false });
});
});
});

//there is NO jobs tab in smart inventory -> host
Expand Down
3 changes: 3 additions & 0 deletions cypress/e2e/awx/resources/inventoryHost/runCommandFunction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ export function runCommand(params: {
cy.getByDataCy('forks').contains(params.forks.toString());

cy.getByDataCy('execution-environment').contains(executionEnvironment.name);

cy.deleteAwxCredential(credential, { failOnStatusCode: false });
cy.deleteAwxExecutionEnvironment(executionEnvironment, { failOnStatusCode: false });
});
}
);
Expand Down
41 changes: 21 additions & 20 deletions cypress/support/hostsfunctions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -308,50 +308,51 @@ export function createHostAndCancelJob(
});
}

export function createHostAndLaunchJob(
export function launchHostJob(
inventory: Inventory,
host: AwxHost,
organizationId: number,
projectId: number,
hostInInventory?: boolean
type: 'Host' | 'InventoryHost'
) {
cy.createAwxJobTemplate({
inventory: inventory.id,
organization: organizationId,
project: projectId,
}).then(() => {
// go to inventory hosts
cy.navigateTo('awx', 'inventories');
cy.filterTableByMultiSelect('name', [inventory.name]);
cy.get('[data-cy="name-column-cell"]').contains(inventory.name).click();
cy.get('.pf-v5-c-tabs__item > a').contains('Hosts').click();
// add a host
const hostName = createHost('inventory_host', inventory.id);
// go to inventory job templates
cy.navigateTo('awx', 'inventories');
cy.filterTableByMultiSelect('name', [inventory.name]);
cy.get('[data-cy="name-column-cell"]').contains(inventory.name).click();
cy.get('.pf-v5-c-tabs__item > a').contains('Job templates').click();
// run a template and wait for redirect to Job output
cy.get('[data-cy="launch-template"]').first().click();
cy.location('pathname').should('match', /\/output$/);
if (hostInInventory) {
cy.contains(`[role='tab']`, 'Job templates').click();

// run a template and wait for request
cy.intercept('POST', awxAPI`/job_templates/*/launch`).as('launch');
cy.get('[data-cy="launch-template"]').click();
cy.wait('@launch').should('exist');

cy.contains('span', 'Failed', { timeout: 60000 });

if (type === 'InventoryHost') {
// go to the Hosts under Inventory
cy.navigateTo('awx', 'inventories');
cy.filterTableByMultiSelect('name', [inventory.name]);
cy.get('[data-cy="name-column-cell"]').contains(inventory.name).click();
cy.get('.pf-v5-c-tabs__item > a').contains('Hosts').click();
cy.contains(`[role='tab']`, 'Jobs').click();
} else {
// go to the Hosts
cy.navigateTo('awx', 'hosts');
cy.filterTableByMultiSelect('name', [host.name]);
cy.get('[data-cy="name-column-cell"]').contains(host.name).click();

// go to Jobs tab
cy.contains(`[role='tab']`, 'Jobs').click();
}
cy.filterTableByMultiSelect('name', [hostName]);
cy.get('[data-cy="name-column-cell"]').contains(hostName).click();
// go to Jobs tab
cy.get('.pf-v5-c-tabs__item > a').contains('Jobs').click();

cy.get('[data-cy="relaunch-using-host-parameters"]').should('exist');
cy.get('[data-cy="relaunch-using-host-parameters"]').click();
cy.get('[data-cy="relaunch-on-all-hosts"]').should('exist');
cy.get('[data-cy="relaunch-on-failed-hosts"]').should('exist');

// relaunch job
cy.intercept('POST', awxAPI`/jobs/*/relaunch`).as('relaunch');
cy.get('[data-cy="relaunch-on-all-hosts"]').click();
Expand Down

0 comments on commit 40e9376

Please sign in to comment.