Skip to content

Commit

Permalink
Remove custom virtual env
Browse files Browse the repository at this point in the history
Remove custom virtual from the UI.

Also, surface missing-resource warnings on list items for UJTs that were using
custom virtualenvs.

Fix some uni-tests warnings.

See: #9190
Also: #9207
  • Loading branch information
nixocio committed Mar 15, 2021
1 parent f10bf4c commit 99c7beb
Show file tree
Hide file tree
Showing 51 changed files with 418 additions and 332 deletions.
2 changes: 0 additions & 2 deletions awx/ui_next/src/components/AppContainer/AppContainer.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,12 @@ jest.mock('../../api');

describe('<AppContainer />', () => {
const ansible_version = '111';
const custom_virtualenvs = [];
const version = '222';

beforeEach(() => {
ConfigAPI.read.mockResolvedValue({
data: {
ansible_version,
custom_virtualenvs,
version,
},
});
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import React from 'react';
import { bool, string } from 'prop-types';
import { Link } from 'react-router-dom';
import { withI18n } from '@lingui/react';
import { t } from '@lingui/macro';
import { Tooltip } from '@patternfly/react-core';
import styled from 'styled-components';

import { ExclamationTriangleIcon as PFExclamationTriangleIcon } from '@patternfly/react-icons';

import { Detail } from '../DetailList';
import { ExecutionEnvironment } from '../../types';

const ExclamationTriangleIcon = styled(PFExclamationTriangleIcon)`
color: var(--pf-global--warning-color--100);
margin-left: 18px;
`;

function ExecutionEnvironmentDetail({
virtualEnvironment,
executionEnvironment,
isDefaultEnvironment,
i18n,
}) {
const label = isDefaultEnvironment
? i18n._(t`Default Execution Environment`)
: i18n._(t`Execution Environment`);

if (executionEnvironment) {
return (
<Detail
label={label}
value={
<Link
to={`/execution_environments/${executionEnvironment.id}/details`}
>
{executionEnvironment.name}
</Link>
}
dataCy="execution-environment-detail"
/>
);
}
if (virtualEnvironment && !executionEnvironment) {
return (
<Detail
label={label}
value={
<>
{i18n._(t`Missing resource`)}
<span>
<Tooltip
content={i18n._(
t`Custom virtual environment ${virtualEnvironment} must be replaced by an execution environment.`
)}
position="right"
>
<ExclamationTriangleIcon />
</Tooltip>
</span>
</>
}
dataCy="missing-execution-environment-detail"
/>
);
}
return null;
}

ExecutionEnvironmentDetail.propTypes = {
executionEnvironment: ExecutionEnvironment,
isDefaultEnvironment: bool,
virtualEnvironment: string,
};

ExecutionEnvironmentDetail.defaultProps = {
isDefaultEnvironment: false,
executionEnvironment: null,
virtualEnvironment: '',
};

export default withI18n()(ExecutionEnvironmentDetail);
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import React from 'react';
import { mountWithContexts } from '../../../testUtils/enzymeHelpers';

import ExecutionEnvironmentDetail from './ExecutionEnvironmentDetail';

const mockExecutionEnvironment = {
id: 2,
name: 'Foo',
image: 'quay.io/ansible/awx-ee',
pull: 'missing',
description: '',
};

const virtualEnvironment = 'var/lib/awx/custom_env';

describe('<ExecutionEnvironmentDetail/>', () => {
test('should display execution environment detail', async () => {
const wrapper = mountWithContexts(
<ExecutionEnvironmentDetail
executionEnvironment={mockExecutionEnvironment}
/>
);
const executionEnvironment = wrapper.find('ExecutionEnvironmentDetail');
expect(executionEnvironment).toHaveLength(1);
expect(executionEnvironment.find('dt').text()).toEqual(
'Execution Environment'
);
expect(executionEnvironment.find('dd').text()).toEqual(
mockExecutionEnvironment.name
);
});

test('should display execution environment detail even with a previous virtual env present', async () => {
const wrapper = mountWithContexts(
<ExecutionEnvironmentDetail
executionEnvironment={mockExecutionEnvironment}
virtualEnvironment={virtualEnvironment}
/>
);
const executionEnvironment = wrapper.find('ExecutionEnvironmentDetail');
expect(executionEnvironment).toHaveLength(1);
expect(executionEnvironment.find('dt').text()).toEqual(
'Execution Environment'
);
expect(executionEnvironment.find('dd').text()).toEqual(
mockExecutionEnvironment.name
);
});

test('should display warning missing execution environment', async () => {
const wrapper = mountWithContexts(
<ExecutionEnvironmentDetail virtualEnvironment={virtualEnvironment} />
);
const executionEnvironment = wrapper.find('ExecutionEnvironmentDetail');
expect(executionEnvironment).toHaveLength(1);
expect(executionEnvironment.find('dt').text()).toEqual(
'Execution Environment'
);
expect(executionEnvironment.find('dd').text()).toEqual('Missing resource');
expect(wrapper.find('Tooltip').prop('content')).toEqual(
`Custom virtual environment ${virtualEnvironment} must be replaced by an execution environment.`
);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from './ExecutionEnvironmentDetail';
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { Detail, DeletedDetail } from '../DetailList';
import { VariablesDetail } from '../CodeEditor';
import CredentialChip from '../CredentialChip';
import ChipGroup from '../ChipGroup';
import ExecutionEnvironmentDetail from '../ExecutionEnvironmentDetail';

function PromptInventorySourceDetail({ i18n, resource }) {
const {
Expand Down Expand Up @@ -83,10 +84,6 @@ function PromptInventorySourceDetail({ i18n, resource }) {
/>
)}
<Detail label={i18n._(t`Source`)} value={source} />
<Detail
label={i18n._(t`Ansible Environment`)}
value={custom_virtualenv}
/>
{summary_fields?.source_project && (
<Detail
label={i18n._(t`Project`)}
Expand All @@ -97,6 +94,10 @@ function PromptInventorySourceDetail({ i18n, resource }) {
}
/>
)}
<ExecutionEnvironmentDetail
virtualEnvironment={custom_virtualenv}
executionEnvironment={summary_fields?.execution_environment}
/>
<Detail label={i18n._(t`Inventory File`)} value={source_path} />
<Detail label={i18n._(t`Verbosity`)} value={VERBOSITY[verbosity]} />
<Detail
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import ChipGroup from '../ChipGroup';
import Sparkline from '../Sparkline';
import { Detail, DeletedDetail } from '../DetailList';
import { VariablesDetail } from '../CodeEditor';
import ExecutionEnvironmentDetail from '../ExecutionEnvironmentDetail';
import { toTitleCase } from '../../util/strings';

function PromptJobTemplateDetail({ i18n, resource }) {
Expand All @@ -34,6 +35,7 @@ function PromptJobTemplateDetail({ i18n, resource }) {
verbosity,
webhook_key,
webhook_service,
custom_virtualenv,
} = resource;

const VERBOSITY = {
Expand Down Expand Up @@ -128,6 +130,10 @@ function PromptJobTemplateDetail({ i18n, resource }) {
) : (
<DeletedDetail label={i18n._(t`Project`)} />
)}
<ExecutionEnvironmentDetail
virtualEnvironment={custom_virtualenv}
executionEnvironment={summary_fields?.execution_environment}
/>
<Detail label={i18n._(t`Source Control Branch`)} value={scm_branch} />
<Detail label={i18n._(t`Playbook`)} value={playbook} />
<Detail label={i18n._(t`Forks`)} value={forks || '0'} />
Expand Down
10 changes: 6 additions & 4 deletions awx/ui_next/src/components/PromptDetail/PromptProjectDetail.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { Config } from '../../contexts/Config';
import { Detail, DeletedDetail } from '../DetailList';
import CredentialChip from '../CredentialChip';
import { toTitleCase } from '../../util/strings';
import ExecutionEnvironmentDetail from '../ExecutionEnvironmentDetail';

function PromptProjectDetail({ i18n, resource }) {
const {
Expand Down Expand Up @@ -64,6 +65,11 @@ function PromptProjectDetail({ i18n, resource }) {
) : (
<DeletedDetail label={i18n._(t`Organization`)} />
)}
<ExecutionEnvironmentDetail
virtualEnvironment={custom_virtualenv}
executionEnvironment={summary_fields?.default_environment}
isDefaultEnvironment
/>
<Detail
label={i18n._(t`Source Control Type`)}
value={scm_type === '' ? i18n._(t`Manual`) : toTitleCase(scm_type)}
Expand All @@ -88,10 +94,6 @@ function PromptProjectDetail({ i18n, resource }) {
label={i18n._(t`Cache Timeout`)}
value={`${scm_update_cache_timeout} ${i18n._(t`Seconds`)}`}
/>
<Detail
label={i18n._(t`Ansible Environment`)}
value={custom_virtualenv}
/>
<Config>
{({ project_base_dir }) => (
<Detail
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,17 @@ describe('PromptProjectDetail', () => {
assertDetail(wrapper, 'Source Control Branch', 'foo');
assertDetail(wrapper, 'Source Control Refspec', 'refs/');
assertDetail(wrapper, 'Cache Timeout', '3 Seconds');
assertDetail(wrapper, 'Ansible Environment', 'mock virtual env');
assertDetail(wrapper, 'Project Base Path', 'dir/foo/bar');
assertDetail(wrapper, 'Playbook Directory', '_6__demo_project');
assertDetail(wrapper, 'Source Control Credential', 'Scm: mock scm');
const executionEnvironment = wrapper.find('ExecutionEnvironmentDetail');
expect(executionEnvironment).toHaveLength(1);
expect(executionEnvironment.find('dt').text()).toEqual(
'Default Execution Environment'
);
expect(executionEnvironment.find('dd').text()).toEqual(
mockProject.summary_fields.default_environment.name
);
expect(
wrapper
.find('Detail[label="Options"]')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@
"organization_id": 1,
"kind": ""
},
"execution_environment": {
"id": 1,
"name": "Default EE",
"description": "",
"image": "quay.io/ansible/awx-ee"
},
"project": {
"id": 6,
"name": "Mock Project",
Expand Down Expand Up @@ -192,5 +198,6 @@
"custom_virtualenv": null,
"job_slice_count": 1,
"webhook_service": "github",
"webhook_credential": 8
"webhook_credential": 8,
"execution_environment": 1
}
9 changes: 8 additions & 1 deletion awx/ui_next/src/components/PromptDetail/data.project.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@
"name":"Default",
"description":""
},
"default_environment": {
"id": 1,
"name": "Default EE",
"description": "",
"image": "quay.io/ansible/awx-ee"
},
"credential": {
"id": 9,
"name": "mock scm",
Expand Down Expand Up @@ -103,5 +109,6 @@
"allow_override":true,
"custom_virtualenv": "mock virtual env",
"last_update_failed":false,
"last_updated":"2020-03-11T20:18:14Z"
"last_updated":"2020-03-11T20:18:14Z",
"default_environment": 1
}
24 changes: 24 additions & 0 deletions awx/ui_next/src/components/TemplateList/TemplateListItem.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import {
ProjectDiagramIcon,
RocketIcon,
} from '@patternfly/react-icons';
import styled from 'styled-components';

import { ActionsTd, ActionItem } from '../PaginatedTable';
import { DetailList, Detail, DeletedDetail } from '../DetailList';
import ChipGroup from '../ChipGroup';
Expand All @@ -23,6 +25,11 @@ import Sparkline from '../Sparkline';
import { toTitleCase } from '../../util/strings';
import CopyButton from '../CopyButton';

const ExclamationTriangleIconWarning = styled(ExclamationTriangleIcon)`
color: var(--pf-global--warning-color--100);
margin-left: 18px;
`;

function TemplateListItem({
i18n,
template,
Expand Down Expand Up @@ -67,6 +74,11 @@ function TemplateListItem({
(!summaryFields.project ||
(!summaryFields.inventory && !askInventoryOnLaunch));

const missingExecutionEnvironment =
template.type === 'job_template' &&
template.custom_virtualenv &&
!template.execution_environment;

const inventoryValue = (kind, id) => {
const inventorykind = kind === 'smart' ? 'smart_inventory' : 'inventory';

Expand Down Expand Up @@ -125,6 +137,18 @@ function TemplateListItem({
</Tooltip>
</span>
)}
{missingExecutionEnvironment && (
<span>
<Tooltip
content={i18n._(
t`Job template is missing an execution environment.`
)}
position="right"
>
<ExclamationTriangleIconWarning />
</Tooltip>
</span>
)}
</Td>
<Td dataLabel={i18n._(t`Type`)}>{toTitleCase(template.type)}</Td>
<Td dataLabel={i18n._(t`Last Ran`)}>{lastRun}</Td>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,23 +74,17 @@ describe('<InventorySourceAdd />', () => {
});

test('new form displays primary form fields', async () => {
const config = {
custom_virtualenvs: ['venv/foo', 'venv/bar'],
};
await act(async () => {
wrapper = mountWithContexts(
<InventorySourceAdd inventory={mockInventory} />,
{
context: { config },
}
<InventorySourceAdd inventory={mockInventory} />
);
});
await waitForElement(wrapper, 'ContentLoading', el => el.length === 0);
expect(wrapper.find('FormGroup[label="Name"]')).toHaveLength(1);
expect(wrapper.find('FormGroup[label="Description"]')).toHaveLength(1);
expect(wrapper.find('FormGroup[label="Source"]')).toHaveLength(1);
expect(wrapper.find('FormGroup[label="Ansible Environment"]')).toHaveLength(
1
0
);
});

Expand Down
Loading

0 comments on commit 99c7beb

Please sign in to comment.