Skip to content

Commit

Permalink
Add easier way to support selectors for multiple versions in OCS Tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bipuladh committed Apr 28, 2020
1 parent 94ec5cb commit 70482cc
Show file tree
Hide file tree
Showing 7 changed files with 248 additions and 315 deletions.
Expand Up @@ -3,19 +3,20 @@ import { browser } from 'protractor';
import * as crudView from '@console/internal-integration-tests/views/crud.view';
import {
MINUTE,
NS,
OCS_NODE_LABEL,
POD_NAME_PATTERNS,
STORAGE_CLASS_PATTERNS,
STORAGE_CLUSTER_NAME,
SECOND,
SUCCESS,
NS as OCS_NS,
} from '../../utils/consts';
import {
InstallCluster,
filterInput,
goToStorageClasses,
ocsOperatorStatus,
currentSelectors,
TEST_PLATFORM,
} from '../../views/installFlow.view';
import {
checkIfClusterIsReady,
Expand All @@ -28,19 +29,23 @@ import {
verifyNodeLabels,
} from '../../utils/helpers';

const Installer = new InstallCluster(NS);
const Installer = new InstallCluster(OCS_NS);

describe('Testing OCS Subscription', () => {
beforeAll(async () => {
await Installer.createNamespace();
expect(browser.getCurrentUrl()).toContain(NS);
}, 2 * MINUTE);
/**
* - Tests the namespace creation (Remove this)
* - Installs OCS Operator from Operator Hub
* - Tests for various resources associated with OCS Operator to be in acceptable state
* - Creates Storage Cluster
* - Tests for resources associated with Storage Cluster to be in acceptable state
*/

describe('Testing OCS Subscription', () => {
it(
'tests subscription flow for ocs operator',
'tests subscription flow for OCS Operator',
async () => {
await Installer.subscribeToOperator();
const text = await ocsOperatorStatus.getText();
const text = await currentSelectors.ocsOperatorStatus.getText();
// Operator is installed successfully
expect(text.includes(SUCCESS)).toBe(true);
},
3 * MINUTE,
Expand All @@ -66,101 +71,117 @@ describe('Test creation of Storage Cluster', () => {
it(
'creates a storage cluster',
async () => {
const nodes = await Installer.createStorageCluster();
const { selectedNodes: nodes } = await Installer.createStorageCluster();
browser.sleep(2 * SECOND);
const text = await crudView.resourceTitle.getText();
expect(text).toEqual(STORAGE_CLUSTER_NAME);
// Verify all the nodes have the required labels
// Wait for 5 seconds for label to apply
await browser.sleep(5 * SECOND);
nodes.forEach((node) => {
expect(verifyNodeLabels(node, OCS_NODE_LABEL)).toBe(true);
});
// Wait for cluster to come to ready state
await checkIfClusterIsReady();
nodes.forEach((node) => expect(verifyNodeLabels(node, OCS_NODE_LABEL)).toBeTruthy());
const storageCR = JSON.parse(
execSync(
`kubectl get storageclusters ${STORAGE_CLUSTER_NAME} -n ${OCS_NS} -o json`,
).toString(),
);
const scFromCR =
storageCR?.spec?.storageDeviceSets?.[0]?.dataPVCTemplate?.spec?.storageClassName;
const size =
storageCR?.spec?.storageDeviceSets?.[0]?.dataPVCTemplate?.spec?.resources?.requests
?.storage;
const defaultSC = execSync(`kubectl get storageclasses | grep -Po '\\w+(?=.*default)'`)
.toString()
.trim();
expect(size).toEqual('512Gi');
expect(defaultSC).toEqual(scFromCR);
},
16 * MINUTE,
);
});

describe('Tests for pods and storage classes', () => {
let pods = null;

beforeAll(() => {
const podList = JSON.parse(
execSync('kubectl get po -n openshift-storage -o json').toString('utf-8'),
);
pods = podList.items;
});
if (TEST_PLATFORM === 'OCS') {
describe('Tests for pods and storage classes', () => {
let pods = null;

it('tests if ocs-operator is running', () => {
const pod = getPodData(pods, POD_NAME_PATTERNS.OCS);
testPodIsRunning(getPodPhase(pod));
});
beforeAll(async () => {
// Wait for cluster to come to ready state
await checkIfClusterIsReady();
const podList = JSON.parse(
execSync('kubectl get po -n openshift-storage -o json').toString('utf-8'),
);
pods = podList.items;
});

it('tests if rook-ceph-operator is running', () => {
const pod = getPodData(pods, POD_NAME_PATTERNS.ROOK);
testPodIsRunning(getPodPhase(pod));
});
it('tests if ocs-operator is running', () => {
const pod = getPodData(pods, POD_NAME_PATTERNS.OCS);
testPodIsRunning(getPodPhase(pod));
});

it('tests if noobaa-operator is running', () => {
const pod = getPodData(pods, POD_NAME_PATTERNS.NOOBA_OPERATOR);
testPodIsRunning(getPodPhase(pod));
});
it('tests if rook-ceph-operator is running', () => {
const pod = getPodData(pods, POD_NAME_PATTERNS.ROOK);
testPodIsRunning(getPodPhase(pod));
});

it('tests if noobaa-core is running', () => {
const pod = getPodData(pods, POD_NAME_PATTERNS.NOOBAA_CORE);
testPodIsRunning(getPodPhase(pod));
});
it('tests if noobaa-operator is running', () => {
const pod = getPodData(pods, POD_NAME_PATTERNS.NOOBA_OPERATOR);
testPodIsRunning(getPodPhase(pod));
});

it("tests if 3 rook-ceph-mon's are running", () => {
const podList = getPodData(pods, POD_NAME_PATTERNS.ROOK_CEPH_MON);
expect(podList.length).toBe(3);
podList.forEach((pod) => {
it('tests if noobaa-core is running', () => {
const pod = getPodData(pods, POD_NAME_PATTERNS.NOOBAA_CORE);
testPodIsRunning(getPodPhase(pod));
});
});

it('tests if rook-ceph-mgr is running', () => {
const pod = getPodData(pods, POD_NAME_PATTERNS.ROOK_CEPH_MGR);
testPodIsRunning(getPodPhase(pod));
});
it("tests if 3 rook-ceph-mon's are running", () => {
const podList = getPodData(pods, POD_NAME_PATTERNS.ROOK_CEPH_MON);
expect(podList.length).toBe(3);
podList.forEach((pod) => {
testPodIsRunning(getPodPhase(pod));
});
});

// 3 cephfsplugin-* 2 csi-cephfsplugin-provisioner-*
it('tests if 5 csi-cephfsplugin are running', () => {
const podList = getPodData(pods, POD_NAME_PATTERNS.CSI_CEPHFS);
expect(podList.length).toBe(5);
podList.forEach((pod) => {
it('tests if rook-ceph-mgr is running', () => {
const pod = getPodData(pods, POD_NAME_PATTERNS.ROOK_CEPH_MGR);
testPodIsRunning(getPodPhase(pod));
});
});

// 2 csi-rbdplugin-provisioner-* 3 csi-rbd-plugin-*
it('tests if 5 csi-rbdplugin are running', () => {
const podList = getPodData(pods, POD_NAME_PATTERNS.CSI_RBD);
expect(podList.length).toBe(5);
podList.forEach((pod) => {
testPodIsRunning(getPodPhase(pod));
// 3 cephfsplugin-* 2 csi-cephfsplugin-provisioner-*
it('tests if 5 csi-cephfsplugin are running', () => {
const podList = getPodData(pods, POD_NAME_PATTERNS.CSI_CEPHFS);
expect(podList.length).toBe(5);
podList.forEach((pod) => {
testPodIsRunning(getPodPhase(pod));
});
});
});

it('tests if 2 rook-ceph-mds-ocs-storagecluster-cephfilesystem pods are running', () => {
const podList = getPodData(pods, POD_NAME_PATTERNS.ROOK_CEPH_MDS);
expect(podList.length).toBe(2);
podList.forEach((pod) => {
testPodIsRunning(getPodPhase(pod));
// 2 csi-rbdplugin-provisioner-* 3 csi-rbd-plugin-*
it('tests if 5 csi-rbdplugin are running', () => {
const podList = getPodData(pods, POD_NAME_PATTERNS.CSI_RBD);
expect(podList.length).toBe(5);
podList.forEach((pod) => {
testPodIsRunning(getPodPhase(pod));
});
});
});

it('tests if all ceph-rbd, cephfs, noobaa storage classes are shown', async () => {
await goToStorageClasses();
await sendKeys(filterInput, STORAGE_CLASS_PATTERNS.RBD);
const rdbClass = await getDataFromRowAndCol(0, 1, podNameFilter);
expect(rdbClass.includes(STORAGE_CLASS_PATTERNS.RBD)).toBe(true);
await sendKeys(filterInput, STORAGE_CLASS_PATTERNS.FS);
const fsClass = await getDataFromRowAndCol(0, 1, podNameFilter);
expect(fsClass.includes(STORAGE_CLASS_PATTERNS.FS)).toBe(true);
await sendKeys(filterInput, STORAGE_CLASS_PATTERNS.NOOBAA);
const noobaaClass = await getDataFromRowAndCol(0, 1, podNameFilter);
expect(noobaaClass.includes(STORAGE_CLASS_PATTERNS.NOOBAA)).toBe(true);
it('tests if 2 rook-ceph-mds-ocs-storagecluster-cephfilesystem pods are running', () => {
const podList = getPodData(pods, POD_NAME_PATTERNS.ROOK_CEPH_MDS);
expect(podList.length).toBe(2);
podList.forEach((pod) => {
testPodIsRunning(getPodPhase(pod));
});
});

it('tests if all ceph-rbd, cephfs, noobaa storage classes are shown', async () => {
await goToStorageClasses();
await sendKeys(filterInput, STORAGE_CLASS_PATTERNS.RBD);
const rdbClass = await getDataFromRowAndCol(0, 1, podNameFilter);
expect(rdbClass.includes(STORAGE_CLASS_PATTERNS.RBD)).toBe(true);
await sendKeys(filterInput, STORAGE_CLASS_PATTERNS.FS);
const fsClass = await getDataFromRowAndCol(0, 1, podNameFilter);
expect(fsClass.includes(STORAGE_CLASS_PATTERNS.FS)).toBe(true);
await sendKeys(filterInput, STORAGE_CLASS_PATTERNS.NOOBAA);
const noobaaClass = await getDataFromRowAndCol(0, 1, podNameFilter);
expect(noobaaClass.includes(STORAGE_CLASS_PATTERNS.NOOBAA)).toBe(true);
});
});
});
}
Expand Up @@ -12,7 +12,6 @@ import {
ocsOp,
storageClusterRow,
verifyFields,
getStorageClusterLink,
} from '../../views/add-capacity.view';
import {
CLUSTER_STATUS,
Expand Down Expand Up @@ -42,6 +41,7 @@ import {
verifyNodeOSDMapping,
verifyZoneOSDMapping,
} from '../../utils/helpers';
import { currentSelectors } from '../../views/installFlow.view';

const storageCluster = JSON.parse(execSync(`kubectl get -o json -n ${NS} ${KIND}`).toString());
const cephValue = JSON.parse(execSync(`kubectl get cephCluster -n ${NS} -o json`).toString());
Expand Down Expand Up @@ -110,7 +110,7 @@ if (clusterStatus && cephHealth) {

await goToInstalledOperators();
await click(ocsOp);
const storageClusterLink = await getStorageClusterLink();
const storageClusterLink = await currentSelectors.getStorageClusterLink();
await click(storageClusterLink);

await clickKebabAction(uid, 'Add Capacity');
Expand Down

This file was deleted.

Expand Up @@ -18,6 +18,15 @@ export const checkIfClusterIsReady = async () => {
}
};

export const waitUntil = async (functor, expected, count = 1) => {
const value = await functor();
if (value < expected) {
await browser.sleep(2 * SECOND);
await waitUntil(functor, expected, count - 1);
}
return true;
};

export const waitFor = async (element, text, count = 1) => {
let rowNumber = 0;
while (rowNumber !== count) {
Expand Down
@@ -1,16 +1,12 @@
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, getOperatorHubCardIndex } from '@console/shared/src/test-utils/utils';
import { click } from '@console/shared/src/test-utils/utils';
import { CAPACITY_UNIT, CAPACITY_VALUE, OCS_OP } from '../utils/consts';
import { namespaceDropdown, openshiftStorageItem } from './installFlow.view';
import { currentSelectors } from './installFlow.view';

export const ocsOp = $(`a[data-test-operator-row='${OCS_OP}']`);
export const getStorageClusterLink = async () => {
const index = await getOperatorHubCardIndex('Storage Cluster');
const link = $(`article:nth-child(${index + 1}) a`);
return link;
};

export const actionForLabel = (label: string) => $(`button[data-test-action='${label}']`);
export const confirmButton = $('#confirm-action');
export const storageClusterRow = (uid) => $(`tr[data-id='${uid}']`);
Expand All @@ -37,7 +33,7 @@ export const goToInstalledOperators = async () => {
await browser.wait(until.and(crudView.untilNoLoadersPresent));
await sideNavView.clickNavLink(['Operators', 'Installed Operators']);
await browser.wait(until.and(crudView.untilNoLoadersPresent));
await click(namespaceDropdown);
await click(openshiftStorageItem);
await click(currentSelectors.namespaceDropdown);
await click(currentSelectors.openshiftStorageItem);
await browser.wait(until.and(crudView.untilNoLoadersPresent));
};

0 comments on commit 70482cc

Please sign in to comment.