Skip to content

Commit

Permalink
Add tests for template provider and support
Browse files Browse the repository at this point in the history
  • Loading branch information
rawagner committed Feb 3, 2021
1 parent 7103849 commit 5ef0624
Show file tree
Hide file tree
Showing 13 changed files with 217 additions and 42 deletions.
Expand Up @@ -4,7 +4,7 @@ export class ProvisionSource extends ObjectEnum<string> {
static readonly URL = new ProvisionSource(
'URL',
'Import via URL (creates PVC)',
'https://download.fedoraproject.org/pub/fedora/linux/releases/33/Cloud/x86_64/images/Fedora-Cloud-Base-33-1.2.x86_64.raw.xz',
'http://download.cirros-cloud.net/0.5.1/cirros-0.5.1-x86_64-disk.imgz',
);

static readonly REGISTRY = new ProvisionSource(
Expand Down
Expand Up @@ -21,15 +21,6 @@ Cypress.Commands.add('deleteResource', (resource, ignoreNotFound = true) => {
);
});

Cypress.Commands.add('debugSource', () => {
cy.exec('kubectl get datavolume rhel6 -n kubevirt-os-images', { failOnNonZeroExit: false }).then(
(res) => {
cy.log(res?.stdout);
cy.log(res?.stderr);
},
);
});

Cypress.Commands.add('createResource', (resource) => {
cy.exec(`echo '${JSON.stringify(resource)}' | kubectl create -f -`);
});
Expand Down
Expand Up @@ -27,10 +27,6 @@ describe('test vm template source image', () => {
});
});

afterEach(() => {
cy.debugSource();
});

it('ID(CNV-5652) add Container image and delete', () => {
virtualization.templates.addSource(TEMPLATE);
addSource.addBootSource(ProvisionSource.REGISTRY);
Expand Down Expand Up @@ -77,3 +73,14 @@ describe('test vm template source image', () => {
virtualization.templates.testSource(TEMPLATE, 'Add source');
});
});

describe('test vm template source image provider', () => {
it('Vm Template list shows source provider', () => {
virtualization.templates.addSource(TEMPLATE);
addSource.addBootSource(ProvisionSource.REGISTRY, undefined, 'fooProvider');
virtualization.templates.testSource(TEMPLATE, 'Importing');
virtualization.templates.testSource(TEMPLATE, 'fooProvider');
virtualization.templates.deleteSource(TEMPLATE);
virtualization.templates.testSource(TEMPLATE, 'Add source');
});
});
@@ -0,0 +1,126 @@
import { virtualization } from '../../view/virtualization';
import { testName } from '../../support';
import { wizard } from '../../view/wizard';

const TEMPLATE_NAME = 'foo';
const TEMPLATE_NO_SUPPORT_NAME = 'foo-no-support';

describe('test VM template support', () => {
before(() => {
cy.visit('');
cy.createProject(testName);
});

beforeEach(() => {
virtualization.templates.visit();
});

afterEach(() => {
cy.deleteResource({
kind: 'Template',
metadata: {
name: TEMPLATE_NAME,
namespace: testName,
},
});
cy.deleteResource({
kind: 'Template',
metadata: {
name: TEMPLATE_NO_SUPPORT_NAME,
namespace: testName,
},
});
});

it('details show user supported template', () => {
wizard.template.open();
wizard.template.createTemplate(TEMPLATE_NAME, 'bar', true);
virtualization.templates.testProvider(TEMPLATE_NAME, 'bar');
virtualization.templates.testSource(TEMPLATE_NAME, 'bar');
virtualization.templates.testSupport(
TEMPLATE_NAME,
'bar',
Cypress.env('DOWNSTREAM') ? 'Red Hat' : undefined,
);

wizard.template.open();
wizard.template.createTemplate(TEMPLATE_NO_SUPPORT_NAME, 'bar', false);
virtualization.templates.testProvider(TEMPLATE_NO_SUPPORT_NAME, 'bar');
virtualization.templates.testSource(TEMPLATE_NO_SUPPORT_NAME, 'bar');
virtualization.templates.testSupport(
TEMPLATE_NO_SUPPORT_NAME,
undefined,
Cypress.env('DOWNSTREAM') ? 'Red Hat' : undefined,
);
});

if (Cypress.env('DOWNSTREAM')) {
it('shows support modal for community supported template', () => {
virtualization.templates.testSupport('CentOS 7.0+ VM');
virtualization.templates.clickCreate('CentOS 7.0+ VM');
cy.get('.ReactModal__Overlay').within(() => {
cy.get('a').should('have.attr', 'href', 'https://www.centos.org');
cy.byLegacyTestID('modal-cancel-action').click();
});
});

it('shows no support modal for user supported template based on community supported one', () => {
wizard.template.open();
wizard.template.createTemplate(TEMPLATE_NAME, 'bar', true, 'CentOS 7 or higher');
virtualization.templates.testProvider(TEMPLATE_NAME, 'bar');
virtualization.templates.testSource(TEMPLATE_NAME, 'bar');
virtualization.templates.testSupport(TEMPLATE_NAME, 'bar');
virtualization.templates.clickCreate(TEMPLATE_NAME);
cy.get('.ReactModal__Overlay').should('not.exist');
});

it('shows support modal for user template based on community supported one', () => {
wizard.template.open();
wizard.template.createTemplate(TEMPLATE_NAME, 'bar', false, 'CentOS 7 or higher');
virtualization.templates.testProvider(TEMPLATE_NAME, 'bar');
virtualization.templates.testSource(TEMPLATE_NAME, 'bar');
virtualization.templates.testSupport(TEMPLATE_NAME);
virtualization.templates.clickCreate(TEMPLATE_NAME);
cy.get('.ReactModal__Overlay').within(() => {
cy.get('a').should('have.attr', 'href', 'https://www.centos.org');
cy.byLegacyTestID('modal-cancel-action').click();
});
});

it('shows no support modal for supported template', () => {
virtualization.templates.testSupport('Red Hat Enterprise Linux 8.0+ VM', 'Red Hat');
virtualization.templates.clickCreate('Red Hat Enterprise Linux 8.0+ VM');
cy.get('.ReactModal__Overlay').should('not.exist');
});

it('shows no support modal for user supported template', () => {
wizard.template.open();
wizard.template.createTemplate(
TEMPLATE_NAME,
'bar',
true,
'Red Hat Enterprise Linux 8.0 or higher',
);
virtualization.templates.testProvider(TEMPLATE_NAME, 'bar');
virtualization.templates.testSource(TEMPLATE_NAME, 'bar');
virtualization.templates.testSupport(TEMPLATE_NAME, 'bar', 'Red Hat');
virtualization.templates.clickCreate(TEMPLATE_NAME);
cy.get('.ReactModal__Overlay').should('not.exist');
});

it('shows support modal for user template with no support', () => {
wizard.template.open();
wizard.template.createTemplate(TEMPLATE_NAME, 'bar', false, 'CentOS 7 or higher');
virtualization.templates.testProvider(TEMPLATE_NAME, 'bar');
virtualization.templates.testSource(TEMPLATE_NAME, 'bar');
cy.exec(
`kubectl patch template -n ${testName} ${TEMPLATE_NAME} --type=json -p'[{"op": "remove", "path": "/metadata/annotations/template.kubevirt.ui~1parent-support-level"}, {"op": "remove", "path": "/metadata/annotations/template.kubevirt.ui~1parent-provider-url"}]'`,
);
virtualization.templates.testSupport(TEMPLATE_NAME);
virtualization.templates.clickCreate(TEMPLATE_NAME);
cy.get('.ReactModal__Overlay').within(() => {
cy.byTestID('no-support-description').should('exist');
});
});
}
});
Expand Up @@ -11,7 +11,7 @@ type DiskSourceOpts = {
};

export const addSource = {
addBootSource: (provisionSource: ProvisionSource, opts?: DiskSourceOpts) => {
addBootSource: (provisionSource: ProvisionSource, opts?: DiskSourceOpts, provider?: string) => {
cy.get('#image-source-type-dropdown').click();
cy.get('.pf-c-select__menu')
.contains(provisionSource.getDescription())
Expand All @@ -35,6 +35,9 @@ export const addSource = {
.clear()
.type('5');
}
if (provider) {
cy.get('#form-ds-provider-input').type(provider);
}
if (Cypress.env('STORAGE_CLASS')) {
cy.byTestID('advanced-section').within(() =>
cy
Expand Down
Expand Up @@ -27,6 +27,23 @@ export const virtualization = {
.should('have.text', 'Add source')
.click(),
),
testProvider: (templateName: string, provider: string) =>
getRow(templateName, () => cy.byTestID('template-provider').should('have.text', provider)),
testSupport: (templateName: string, support?: string, parentSupport?: string) => {
getRow(templateName, () => cy.byTestID('template-details').click());
if (support) {
cy.byTestID('template-support').should('exist');
cy.byTestID('template-support').should('have.text', support);
} else {
cy.byTestID('template-support').should('not.exist');
}
if (parentSupport) {
cy.byTestID('template-support-parent').should('exist');
cy.byTestID('template-support-parent').should('have.text', parentSupport);
} else {
cy.byTestID('template-support-parent').should('not.exist');
}
},
testSource: (templateName: string, sourceStatus: string, timeout = 600000) =>
getRow(templateName, () =>
cy.byTestID('template-source', { timeout }).should('have.text', sourceStatus),
Expand All @@ -38,5 +55,7 @@ export const virtualization = {
cy.byTestID('delete-template-source').click();
cy.byTestID('confirm-action').click();
},
clickCreate: (templateName: string) =>
getRow(templateName, () => cy.byTestID('create-from-template').click()),
},
};
@@ -0,0 +1,37 @@
import { ProvisionSource } from '../enums/provisionSource';

export const wizard = {
template: {
open: () => {
cy.byLegacyTestID('details-actions').click();
cy.byLegacyTestID('template-wizard').click();
},
createTemplate: (
name: string,
provider: string,
supported: boolean,
baseOS = 'Red Hat Enterprise Linux 6.0 or higher',
) => {
cy.get('#vm-name').type(name);
cy.get('#template-provider').type(provider);
if (supported) {
cy.get('#template-supported').click();
cy.get('button')
.contains('Support by template provider')
.click();
}
cy.get('#operating-system-dropdown').click();
cy.get('button')
.contains(baseOS)
.click({ force: true });
cy.get('#image-source-type-dropdown').click();
cy.get('.pf-c-select__menu')
.contains(ProvisionSource.REGISTRY.getDescription())
.click();
cy.get('input[id="provision-source-container"]').type(ProvisionSource.REGISTRY.getSource());
cy.get('#create-vm-wizard-reviewandcreate-btn').click();
cy.get('#create-vm-wizard-submit-btn').click();
cy.byTestID('success-list').click();
},
},
};
Expand Up @@ -58,6 +58,7 @@ export const SuccessResultsComponent: React.FC<SuccessResultsProps> = ({
history.push(modelListPath);
onClick && onClick();
}}
data-test="success-list"
>
{t('kubevirt-plugin~Go to list')}
</Button>
Expand Down
Expand Up @@ -48,7 +48,7 @@ const SupportModal: React.FC<SupportModalProps> = ({ onConfirm, close, community
</>
) : (
<>
<StackItem>
<StackItem data-test="no-support-description">
{t(
'kubevirt-plugin~The support level is not defined in the template yaml. To mark this template as supported, add these two annotations in the template details:',
)}
Expand Down
Expand Up @@ -27,14 +27,18 @@ export const VMTemplateLabel: React.FC<VMTemplateLabelProps> = ({ template, clas
<Tooltip
content={t('kubevirt-plugin~{{provider}} supported', { provider: parentProvider })}
>
<Label isTruncated color="green">
<Label data-test="template-support-parent" isTruncated color="green">
{parentProvider}
</Label>
</Tooltip>
)}
{templateSupport.provider === 'Full' && provider && (
<Tooltip content={t('kubevirt-plugin~{{provider}} supported', { provider })}>
<Label color={isCommonTemplate(template) ? 'green' : 'blue'} isTruncated>
<Label
data-test="template-support"
color={isCommonTemplate(template) ? 'green' : 'blue'}
isTruncated
>
{provider}
</Label>
</Tooltip>
Expand Down
Expand Up @@ -202,7 +202,9 @@ const VMTemplateTableRow: RowFunction<TemplateItem, VMTemplateTableRowProps> = (
</Link>
{pinned && <PinnedIcon />}
</TableData>
<TableData className={dimensify()}>{getTemplateProvider(t, template)}</TableData>
<TableData data-test="template-provider" className={dimensify()}>
{getTemplateProvider(t, template)}
</TableData>
<TableData className={dimensify()}>
<ResourceLink
kind={NamespaceModel.kind}
Expand All @@ -225,11 +227,16 @@ const VMTemplateTableRow: RowFunction<TemplateItem, VMTemplateTableRowProps> = (
headerContent={t('kubevirt-plugin~Template details')}
bodyContent={<VMTemplateDetailsBody template={template} sourceStatus={sourceStatus} />}
>
<Button variant="link" className="kubevirt-vm-template-details">
<Button
variant="link"
className="kubevirt-vm-template-details"
data-test="template-details"
>
{t('kubevirt-plugin~Details')}
</Button>
</Popover>
<Button
data-test="create-from-template"
onClick={() => withSupportModal(obj, () => createVMAction(obj, sourceStatus, namespace))}
variant="secondary"
className="kubevirt-vm-template-details"
Expand Down
Expand Up @@ -26,7 +26,6 @@ import {
import { VMWrapper } from '../../../wrapper/vm/vm-wrapper';
import { VMTemplateWrapper } from '../../../wrapper/vm/vm-template-wrapper';
import { isCustomFlavor } from '../../../../selectors/vm-like/flavor';
import { isCommonTemplate } from '../../../../selectors/vm-template/basic';
import { TemplateSupport } from '../../../../constants/vm-templates/support';

export const initializeCommonMetadata = (
Expand Down Expand Up @@ -129,20 +128,9 @@ export const initializeCommonTemplateMetadata = (
const iconClass = annotations?.[ANNOTATION_ICON];
iconClass && entity.addAnotation(ANNOTATION_ICON, iconClass);

let provider = annotations?.[TEMPLATE_PROVIDER_ANNOTATION];
let supportLevel = annotations?.[TEMPLATE_SUPPORT_LEVEL];
const provider = annotations?.[TEMPLATE_PROVIDER_ANNOTATION];
const supportLevel = annotations?.[TEMPLATE_SUPPORT_LEVEL];

const isUpstream = window.SERVER_FLAGS.branding === 'okd';
if (
!provider &&
!supportLevel &&
!isUpstream &&
isCommonTemplate(template) &&
(template.metadata.name.startsWith('win') || template.metadata.name.startsWith('rhel'))
) {
provider = 'Red Hat';
supportLevel = 'Full';
}
if (provider && supportLevel) {
entity.addAnotation(TEMPLATE_PARENT_SUPPORT_LEVEL, supportLevel);
entity.addAnotation(TEMPLATE_PARENT_PROVIDER_ANNOTATION, provider);
Expand Down
Expand Up @@ -43,14 +43,6 @@ export const getTemplateSupport = (
return support;
}

if (
!support.provider &&
isCommonTemplate(template) &&
(template.metadata.name.startsWith('win') || template.metadata.name.startsWith('rhel'))
) {
support.provider = 'Full';
}

support.parent = getAnnotation(template, TEMPLATE_PARENT_SUPPORT_LEVEL);
support.parentURL = getAnnotation(template, TEMPLATE_PARENT_PROVIDER_URL);
return support;
Expand Down

0 comments on commit 5ef0624

Please sign in to comment.