Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug 1798581: Add tests for pvc creation with different options #3708

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -0,0 +1,105 @@
import { browser } from 'protractor';
import { appHost } from '@console/internal-integration-tests/protractor.conf';
import { resourceRowsPresent } from '@console/internal-integration-tests/views/crud.view';
import {
createNewPersistentVolumeClaim,
deletePersistentVolumeClaim,
goToPersistentVolumeClaims,
pvcStatus,
pvcSize,
} from '../../views/pvc.view';
import {
NS,
PVC_STATUS,
SIZE_UNITS,
STORAGE_CLASS_PATTERNS,
VOLUME_ACCESS_MODES,
} from '../../utils/consts';

describe('Test PVC creation with options.', () => {
beforeAll(async () => {
await browser.get(`${appHost}/`);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be a bit safer to await isLoaded() here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isLoaded() function doesn't work here, because the page being loaded as default is Overview Dashboard, so I'd need dashboardIsLoaded()
But actually I wouldn't want the test to wait for the dashboard to be loaded, it might fail on https://bugzilla.redhat.com/show_bug.cgi?id=1753666 or just make the test run longer unnecessarily.
I do check that Persistent Volume Claims page is loaded at the beginning of each test as part of PVC creation function.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ack

});

it('Test RBD PVC is created and gets bound', async () => {
const testPvc = {
name: 'rbdpvc',
namespace: NS,
size: '5',
sizeUnits: SIZE_UNITS.GI,
storageClass: STORAGE_CLASS_PATTERNS.RBD,
accessMode: VOLUME_ACCESS_MODES.RWO,
};
await createNewPersistentVolumeClaim(testPvc, true);
expect(pvcStatus.getText()).toEqual(PVC_STATUS.BOUND);
await goToPersistentVolumeClaims();
await resourceRowsPresent();
await deletePersistentVolumeClaim('rbdpvc', NS);
});

it('Test PVC size is rounded', async () => {
// PVC size of 1.5 should be rounded to 2
// https://bugzilla.redhat.com/show_bug.cgi?id=1746156
const testPvc = {
name: 'rbdpvc',
namespace: NS,
size: '1.5',
sizeUnits: SIZE_UNITS.GI,
storageClass: STORAGE_CLASS_PATTERNS.RBD,
accessMode: VOLUME_ACCESS_MODES.RWO,
};
await createNewPersistentVolumeClaim(testPvc, true);
expect(pvcSize.getText()).toEqual('2Gi');
await goToPersistentVolumeClaims();
await resourceRowsPresent();
await deletePersistentVolumeClaim('rbdpvc', NS);
});

it('Test cephFS PVC is created and gets bound', async () => {
const testPvc = {
name: 'cephfspvc',
namespace: NS,
size: '1',
sizeUnits: SIZE_UNITS.TI,
storageClass: STORAGE_CLASS_PATTERNS.FS,
accessMode: VOLUME_ACCESS_MODES.RWO,
};
await createNewPersistentVolumeClaim(testPvc, true);
expect(pvcStatus.getText()).toEqual(PVC_STATUS.BOUND);
await goToPersistentVolumeClaims();
await resourceRowsPresent();
await deletePersistentVolumeClaim('cephfspvc', NS);
});

it('Test RWX RBD PVC is created and gets bound', async () => {
const testPvc = {
name: 'rwxrbdpvc',
namespace: NS,
size: '512',
sizeUnits: SIZE_UNITS.MI,
storageClass: STORAGE_CLASS_PATTERNS.RBD,
accessMode: VOLUME_ACCESS_MODES.RWX,
};
await createNewPersistentVolumeClaim(testPvc, true);
expect(pvcStatus.getText()).toEqual(PVC_STATUS.BOUND);
await goToPersistentVolumeClaims();
await resourceRowsPresent();
await deletePersistentVolumeClaim('rwxrbdpvc', NS);
});

it('Test RWX CephFS PVC is created and gets bound', async () => {
const testPvc = {
name: 'rwxcephfspvc',
namespace: NS,
size: '5',
sizeUnits: SIZE_UNITS.GI,
storageClass: STORAGE_CLASS_PATTERNS.FS,
accessMode: VOLUME_ACCESS_MODES.RWX,
};
await createNewPersistentVolumeClaim(testPvc, true);
expect(pvcStatus.getText()).toEqual(PVC_STATUS.BOUND);
await goToPersistentVolumeClaims();
await resourceRowsPresent();
await deletePersistentVolumeClaim('rwxcephfspvc', NS);
});
});
Expand Up @@ -43,3 +43,20 @@ export const OCS_OPERATOR_NAME = 'ocs-operator';
export const HOST = 'host';
export const ZONE = 'zone';
export const OSD = 'osd';

export enum VOLUME_ACCESS_MODES {
RWO = 'ReadWriteOnce',
RWX = 'ReadWriteMany',
ROX = 'ReadOnlyMany',
}

export enum SIZE_UNITS {
MI = 'Mi',
GI = 'Gi',
TI = 'Ti',
}

export enum PVC_STATUS {
PENDING = 'Pending',
BOUND = 'Bound',
}
Expand Up @@ -178,3 +178,12 @@ export type NodeType = {
export type FormattedOsdTreeType = {
[key: string]: NodeType;
};

export type PvcType = {
name: string;
namespace: string;
size: string;
sizeUnits: string;
storageClass: string;
accessMode: string;
};
@@ -0,0 +1,66 @@
import { $, $$, browser, ExpectedConditions as until } from 'protractor';
import * as crudView from '@console/internal-integration-tests/views/crud.view';
import * as sideNavView from '@console/internal-integration-tests/views/sidenav.view';
import { click } from '@console/shared/src/test-utils/utils';
import { PVC_STATUS } from '../utils/consts';
import { PvcType } from '../utils/helpers';

export const selectItemFromDropdown = async (item, dropdownElement) => {
await click(dropdownElement);
await click($(`#${item}-link`));
};

// create pvc
export const namespaceDropdown = $$('[class="pf-c-dropdown__toggle pf-m-plain"]').get(0);
export const storageclassDropdown = $('#storageclass-dropdown');
export const inputPVCName = $('#pvc-name');
export const selectAccessMode = (accessMode) => $(`input[value=${accessMode}]`);
export const inputPVCSize = $('[name=requestSizeValue]');
export const sizeUnitsDropdown = $('[data-test-id=dropdown-button]');

// pvc details
export const pvcName = $('[data-test-id=pvc-name]');
export const pvcStatus = $('[data-test-id=pvc-status]');
export const pvcSize = $('[data-test-id=pvc-capacity]');
export const pvcAccessMode = $('[data-test-id=pvc-access-mode]');
export const pvcVolumeMode = $('[data-test-id=pvc-volume-mode]');
export const pvcStorageClass = $('[data-test-id=pvc-storageclass]');
export const pvcPersistentVolume = $('[data-test-id=persistent-volume]');
export const actionsButton = $('[data-test-id=actions-menu-button]');
export const deletePvc = $('[data-test-action="Delete Persistent Volume Claim"]');

// list of PVCs
export const nameInTable = (name) => $(`a[data-test-id=${name}]`);

export const goToPersistentVolumeClaims = async () => {
await sideNavView.clickNavLink(['Storage', 'Persistent Volume Claims']);
await crudView.isLoaded();
};

export const createNewPersistentVolumeClaim = async (pvc: PvcType, waitForBinding: boolean) => {
await goToPersistentVolumeClaims();
await selectItemFromDropdown(pvc.namespace, namespaceDropdown);
await click(crudView.createYAMLButton);
await browser.wait(
until.textToBePresentInElement($('.co-m-pane__heading'), 'Create Persistent Volume Claim'),
);
await browser.wait(until.and(crudView.untilNoLoadersPresent));
await selectItemFromDropdown(pvc.storageClass, storageclassDropdown);
await inputPVCName.sendKeys(pvc.name);
await click(selectAccessMode(pvc.accessMode));
await inputPVCSize.sendKeys(pvc.size);
// Units should be Mi, Gi or Ti
await selectItemFromDropdown(pvc.sizeUnits, sizeUnitsDropdown);
await click(crudView.saveChangesBtn);
if (waitForBinding === true)
await browser.wait(until.textToBePresentInElement(pvcStatus, PVC_STATUS.BOUND));
};

export const deletePersistentVolumeClaim = async (name: string, namespace: string) => {
await goToPersistentVolumeClaims();
await selectItemFromDropdown(namespace, namespaceDropdown);
await crudView.resourceRowsPresent();
await crudView.filterForName(name);
await crudView.isLoaded();
await crudView.deleteRow('PersistentVolumeClaim')(name);
ebondare marked this conversation as resolved.
Show resolved Hide resolved
};
14 changes: 7 additions & 7 deletions frontend/public/components/persistent-volume-claim.jsx
Expand Up @@ -140,33 +140,33 @@ const Details_ = ({ flags, obj: pvc }) => {
<div className="col-sm-6">
<ResourceSummary resource={pvc}>
<dt>Label Selector</dt>
<dd>
<dd data-test-id="pvc-name">
<Selector selector={labelSelector} kind="PersistentVolume" />
</dd>
</ResourceSummary>
</div>
<div className="col-sm-6">
<dl>
<dt>Status</dt>
<dd>
<dd data-test-id="pvc-status">
<PVCStatus pvc={pvc} />
</dd>
{storage && (
<>
<dt>Capacity</dt>
<dd>{storage}</dd>
<dd data-test-id="pvc-capacity">{storage}</dd>
</>
)}
{!_.isEmpty(accessModes) && (
<>
<dt>Access Modes</dt>
<dd>{accessModes.join(', ')}</dd>
<dd data-test-id="pvc-access-mode">{accessModes.join(', ')}</dd>
</>
)}
<dt>Volume Mode</dt>
<dd>{volumeMode || 'Filesystem'}</dd>
<dd data-test-id="pvc-volume-mode">{volumeMode || 'Filesystem'}</dd>
<dt>Storage Class</dt>
<dd>
<dd data-test-id="pvc-storageclass">
{storageClassName ? (
<ResourceLink kind="StorageClass" name={storageClassName} />
) : (
Expand All @@ -176,7 +176,7 @@ const Details_ = ({ flags, obj: pvc }) => {
{volumeName && canListPV && (
<>
<dt>Persistent Volume</dt>
<dd>
<dd data-test-id="persistent-volume">
<ResourceLink kind="PersistentVolume" name={volumeName} />
</dd>
</>
Expand Down