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

Add test for rbd pvc expansion #6154

Merged
merged 1 commit into from Jul 30, 2020
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
Expand Up @@ -52,10 +52,69 @@ export const testDeployment = {
},
};

export const testDeploymentRbd = {
apiVersion: 'apps/v1',
kind: 'Deployment',
metadata: {
name: 'example2',
namespace: testName,
},
spec: {
selector: {
matchLabels: {
app: 'hello-openshift',
},
},
replicas: 1,
template: {
metadata: {
labels: {
app: 'hello-openshift',
},
},
spec: {
volumes: [
{
name: `${testName}-rbdpvc`,
persistentVolumeClaim: {
claimName: `${testName}-rbdpvc`,
},
},
],
containers: [
{
name: 'my-container',
image: 'nginx',
securityContext: {
capabilities: {
add: ['SYS_ADMIN'],
},
},
volumeDevices: [
{
name: `${testName}-rbdpvc`,
devicePath: '/dev/rbdblock',
},
],
},
],
},
},
},
};

export const testPVC = {
name: `${testName}-pvc`,
namespace: testName,
size: '5',
sizeUnits: SIZE_UNITS.MI,
storageClass: STORAGE_CLASS_PATTERNS.FS,
};

export const testRbdPVC = {
name: `${testName}-rbdpvc`,
namespace: testName,
size: '5',
sizeUnits: SIZE_UNITS.MI,
storageClass: STORAGE_CLASS_PATTERNS.RBD,
};
Expand Up @@ -3,7 +3,12 @@ import { browser } from 'protractor';
import { clickKebabAction } from '@console/internal-integration-tests/views/crud.view';
import { click } from '@console/shared/src/test-utils/utils';
import { testName } from '@console/internal-integration-tests/protractor.conf';
import { testPVC, testDeployment } from '../../mocks/expand-test-mocks';
import {
testPVC,
testRbdPVC,
testDeployment,
testDeploymentRbd,
} from '../../mocks/expand-test-mocks';
import {
goToPersistentVolumeClaims,
expandButton,
Expand All @@ -13,25 +18,26 @@ import {
inputPVCSize,
} from '../../views/pvc.view';
import { SECOND, SIZE_UNITS } from '../../utils/consts';
import { sendKeys } from '../../utils/helpers';
import { createObjectFromJson, sendKeys } from '../../utils/helpers';

const expandValue = String(Number(testPVC.size) + 1);

const createDeployment = () =>
execSync(`echo '${JSON.stringify(testDeployment)}' | kubectl create -f -`);

const expandPVC = async (value: string, sizeUnit: SIZE_UNITS) => {
await clickKebabAction(testPVC.name, 'Expand PVC');
const expandPVC = async (pvcName: string, value: string, sizeUnit: SIZE_UNITS) => {
await goToPersistentVolumeClaims();
await clickKebabAction(pvcName, 'Expand PVC');
await browser.sleep(2 * SECOND);
await sendKeys(inputPVCSize, value);
await click(capacityUnitDropdown);
await click(expandSizeOption(sizeUnit));
await click(expandButton);
};

const getPVCRequestedStorage = () => {
const getPVCRequestedStorage = (pvcName: string) => {
const pvcJSON = JSON.parse(
execSync(`kubectl get pvc ${testPVC.name} -n ${testName} -o json`).toString(),
execSync(`kubectl get pvc ${pvcName} -n ${testName} -o json`).toString(),
);
return pvcJSON.spec.resources.requests.storage;
};
Expand All @@ -41,27 +47,34 @@ describe('Tests Expand flow for PVC', () => {
await createNewPersistentVolumeClaim(testPVC, true, createDeployment);
});

beforeEach(async () => {
await goToPersistentVolumeClaims();
});
it('Test PVC can be expanded (In MiBs)', async () => {
await expandPVC(expandValue, SIZE_UNITS.MI);
await expandPVC(testPVC.name, expandValue, SIZE_UNITS.MI);
await browser.sleep(5 * SECOND);
const requestedStorage = getPVCRequestedStorage();
const requestedStorage = getPVCRequestedStorage(testPVC.name);
expect(requestedStorage.trim()).toEqual(`${expandValue}${SIZE_UNITS.MI}`);
});

it('Test PVC can be expanded (In GiBs)', async () => {
await expandPVC(expandValue, SIZE_UNITS.GI);
await expandPVC(testPVC.name, expandValue, SIZE_UNITS.GI);
await browser.sleep(5 * SECOND);
const requestedStorage = getPVCRequestedStorage();
const requestedStorage = getPVCRequestedStorage(testPVC.name);
expect(requestedStorage.trim()).toEqual(`${expandValue}${SIZE_UNITS.GI}`);
});

it('Test PVC can be expanded (In TiBs)', async () => {
await expandPVC('1', SIZE_UNITS.TI);
await expandPVC(testPVC.name, '1', SIZE_UNITS.TI);
await browser.sleep(5 * SECOND);
const requestedStorage = getPVCRequestedStorage();
const requestedStorage = getPVCRequestedStorage(testPVC.name);
expect(requestedStorage.trim()).toEqual(`1${SIZE_UNITS.TI}`);
});

it('Test RBD PVC can be expanded (In MiBs)', async () => {
await createNewPersistentVolumeClaim(testRbdPVC, true);
await createObjectFromJson(testDeploymentRbd);
await browser.sleep(5 * SECOND);
await expandPVC(testRbdPVC.name, expandValue, SIZE_UNITS.MI);
await browser.sleep(5 * SECOND);
const requestedStorage = getPVCRequestedStorage(testRbdPVC.name);
expect(requestedStorage.trim()).toEqual(`${expandValue}${SIZE_UNITS.MI}`);
});
});
Expand Up @@ -173,6 +173,9 @@ export const hasOCSTaint = (node) => {
return taints.some((taint) => _.isEqual(taint, ocsTaint));
};

export const createObjectFromJson = (objectJson) =>
execSync(`echo '${JSON.stringify(objectJson)}' | kubectl create -f -`);

export type NodeType = {
id: number;
name: string;
Expand Down