Skip to content

Commit

Permalink
Adds Internal Mode Installation Test to Cypress
Browse files Browse the repository at this point in the history
Adds Storage cluster expansion Test to Cypress
Add tests for PVC Expansion
Add tests for OCS Persistent Storage Dashboard
  • Loading branch information
bipuladh committed Dec 10, 2020
1 parent d617b52 commit 0a759d6
Show file tree
Hide file tree
Showing 23 changed files with 547 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"reporterOptions": {
"configFile": "reporter-config.json"
},
"supportFile": "../../integration-tests-cypress/support/index.ts",
"supportFile": "./support/index.ts",
"pluginsFile": "../../integration-tests-cypress/plugins/index.js",
"fixturesFolder": false,
"defaultCommandTimeout": 30000,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './installation';
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import * as _ from 'lodash';

export const SIZE_MAP = {
'512Gi': 0.5,
'2Ti': 2,
'4Ti': 4,
};

export const getPodName = (pod) => pod.metadata.name;

export const getPodRestartCount = (pod) => pod.status.containerStatuses[0].restartCount;

export const getPresentPod = (pods, podName: string) =>
pods.items.find((pod) => getPodName(pod) === podName);

export const getIds = (nodes, type: string): number[] =>
nodes.filter((node) => node.type === type).map((node) => node.id);

export const getNewOSDIds = (nodes, osds: number[]): number[] =>
nodes
.filter((node) => node.type === 'osd' && osds.indexOf(node.id) === -1)
.map((node) => node.id);

export const createOSDTreeMap = (nodes) =>
nodes.reduce((acc, curr) => Object.assign(acc, { [curr.id]: curr }), {});

export const verifyZoneOSDMapping = (zones: number[], osds: number[], osdtree): boolean => {
let filteredOsds = [...osds];
zones.forEach((zone) => {
const hostId = osdtree[zone].children[0];
const len = osdtree[hostId].children.length;
filteredOsds = filteredOsds.filter((osd) => osd !== osdtree[hostId].children[len - 1]);
});

return filteredOsds.length === 0;
};

export const verifyNodeOSDMapping = (nodes: number[], osds: number[], osdtree): boolean => {
let filteredOsds = [...osds];
nodes.forEach((node) => {
const len = osdtree[node].children.length;
filteredOsds = filteredOsds.filter((osd) => osd !== osdtree[node].children[len - 1]);
});

return filteredOsds.length === 0;
};

export const isNodeReady = (node): boolean => {
const conditions = _.get(node, 'status.conditions', []);
const readyState: any = _.find(conditions, { type: 'Ready' });

return readyState && readyState.status === 'True';
};

export const getDeviceCount = (storageCluster) => storageCluster?.spec?.storageDeviceSets[0].count;
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
export const getPVCJSON = (
name: string,
namespace: string,
storageClassName: string,
size: string = '5Gi',
volumeMode: string = 'Filesystem',
) => ({
apiVersion: 'v1',
kind: 'PersistentVolumeClaim',
metadata: {
name,
namespace,
},
spec: {
accessModes: ['ReadWriteOnce'],
resources: {
requests: {
storage: size,
},
},
storageClassName,
volumeMode,
},
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
import * as _ from 'lodash';
import '../../../integration-tests-cypress/support/index.ts';
import { wizard } from '../../../integration-tests-cypress/views/wizard';
import { commonFlows } from '../views/common';

declare global {
namespace Cypress {
interface Chainable<Subject> {
install(mode?: 'Internal' | 'Attached', encrypted?: boolean): Chainable<Element>;
}
}
}

Cypress.Commands.add('install', (mode: 'Internal' | 'Attached' = 'Internal', encrypted = false) => {
cy.exec('oc get storagecluster ocs-storagecluster -n openshift-storage', {
failOnNonZeroExit: false,
}).then(({ code }) => {
// Only run Installation if the Storage Cluster doesn't already exist
if (code !== 0) {
cy.log('Perform OCS Installation and cluster creation');
cy.log('Search in Operator Hub');
cy.clickNavLink(['Operators', 'OperatorHub']);
cy.byTestID('search-operatorhub').type('Openshift Container Storage');
cy.byTestID('ocs-operator-redhat-operators-openshift-marketplace').click();

cy.log('Subscribe to OCS Operator');
cy.byLegacyTestID('operator-install-btn').click({ force: true });
cy.byTestID('Operator recommended namespace:-radio-input').should('be.checked');
cy.byTestID('install-operator').click();
cy.byTestID('success-icon', { timeout: 180000 }).should('be.visible');
cy.exec('oc get project openshift-storage -o json').then((res) => {
const obj = JSON.parse(res.stdout);
expect(obj.metadata.labels?.['openshift.io/cluster-monitoring']).toEqual('true');
});

// Rook, Noobaa and OCS pod should come up after installation.
cy.exec('oc get po -n openshift-storage -o json').then((res) => {
const { items } = JSON.parse(res.stdout);
expect(
items.find((item) => _.startsWith(item.metadata.name, 'noobaa-operator')),
).toBeDefined();
expect(
items.find((item) => _.startsWith(item.metadata.name, 'ocs-operator')),
).toBeDefined();
expect(
items.find((item) => _.startsWith(item.metadata.name, 'rook-ceph-operator')),
).toBeDefined();
});

// Make changes to this once we add annotation
cy.log(`Install OCS in ${mode} Mode`);
commonFlows.navigateToOCS();
cy.byLegacyTestID('horizontal-link-Storage Cluster').click();
cy.byTestID('yaml-create').click();

cy.log(`Select ${mode}`);
cy.byTestID('Internal-radio-input').should('be.checked');

// Step 1
// Select all worker Nodes
commonFlows.checkAll.check();
commonFlows.checkAll.should('be.checked');
// Two dropdowns in the same page.
// (Todo: )make dropdown data-test-id be something that can be passed as a prop
cy.byLegacyTestID('dropdown-button')
.first()
.click();
cy.byTestDropDownMenu('512Gi').click();
wizard.next();

// Step 2
if (encrypted) {
cy.log('Enabling Encryption');
cy.byTestID('encryption-checkbox').click();
}

// Final Step
wizard.create();

cy.log('Verify all worker nodes are labelled');
cy.exec('oc get nodes -o json').then((res) => {
const { items } = JSON.parse(res.stdout);
items
.map((item) => item.metadata.labels)
.filter((item) => item.hasOwnProperty('node-role.kubernetes.io/worker'))
.forEach((item) =>
expect(item.hasOwnProperty('cluster.ocs.openshift.io/openshift-storage')).toBeTruthy(),
);
});

// Wait for the storage cluster to reach Ready
// Storage Cluster CR flickers so wait for 10 seconds
// Disablng until ocs-operator fixes above issue
// eslint-disable-next-line cypress/no-unnecessary-waiting
cy.wait(10000);
cy.byTestID('resource-status').contains('Ready', { timeout: 900000 });
}
cy.log('OCS Storage Cluster is already Installed. Proceeding without installation');
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
import * as _ from 'lodash';
import { checkErrors } from '../../../integration-tests-cypress/support';
import { modal } from '../../../integration-tests-cypress/views/modal';
import { CLUSTER_STATUS } from '../../integration-tests/utils/consts';
import {
createOSDTreeMap,
getDeviceCount,
getIds,
getNewOSDIds,
getPodRestartCount,
isNodeReady,
SIZE_MAP,
verifyNodeOSDMapping,
getPresentPod,
getPodName,
} from '../helpers';
import { commonFlows } from '../views/common';

describe('OCS Operator Expansion of Storage Class Test', () => {
before(() => {
cy.login();
cy.visit('/');
cy.install();
});

beforeEach(() => {
cy.visit('/');
});

afterEach(() => {
checkErrors();
});

after(() => {
cy.logout();
});

it.only('Add additional capacity to Storage Cluster', () => {
const initialState = {
storageCluster: null,
cephCluster: null,
osdTree: null,
pods: null,
formattedOSDTree: null,
osdIDs: null,
};

cy.exec('oc get storagecluster ocs-storagecluster -n openshift-storage -o json')
.then((res) => {
const storageCluster = JSON.parse(res.stdout);
_.set(initialState, 'storageCluster', storageCluster);

return cy.exec(
'oc get cephCluster ocs-storagecluster-cephcluster -n openshift-storage -o json',
);
})
.then((res) => {
const cephCluster = JSON.parse(res.stdout);
_.set(initialState, 'cephCluster', cephCluster);

cy.log('Check if ceph cluster is healthy before expansion');
expect(cephCluster.status.ceph.health).not.toBe(CLUSTER_STATUS.HEALTH_ERROR);

return cy.exec(
`oc -n openshift-storage rsh $(oc get po -n openshift-storage | grep ceph-operator | awk '{print$1}') ceph --conf=/var/lib/rook/openshift-storage/openshift-storage.config osd tree --format=json`,
{ timeout: 120000 },
);
})
.then((res) => {
const osdTree = JSON.parse(res.stdout);
_.set(initialState, 'osdTree', osdTree);

const formattedOSDTree = createOSDTreeMap(osdTree.nodes);
_.set(initialState, 'formattedOSDTree', formattedOSDTree);

const osdIDs = getIds(osdTree.nodes, 'osd');
_.set(initialState, 'osdIDs', osdIDs);

return cy.exec('oc get po -n openshift-storage -o json');
})
.then((res) => {
const pods = JSON.parse(res.stdout);
_.set(initialState, 'pods', pods);

commonFlows.navigateToOCS();

cy.byLegacyTestID('horizontal-link-Storage Cluster').click();
cy.byLegacyTestID('kebab-button').click();
cy.byTestActionID('Add Capacity').click();
modal.shouldBeOpened();

const initialCapcity =
SIZE_MAP[
initialState.storageCluster?.spec?.storageDeviceSets?.[0]?.dataPVCTemplate?.spec
?.resources?.requests?.storage
];
cy.byLegacyTestID('requestSize').should('have.value', String(initialCapcity));
cy.byTestID('provisioned-capacity').contains(
`${String((initialCapcity * 3).toFixed(2))} TiB`,
);
cy.byTestID('add-cap-sc-dropdown', { timeout: 10000 }).should('be.visible');
modal.submit();
modal.shouldBeClosed();

// Wait for the storage cluster to reach Ready
// Storage Cluster CR flickers so wait for 10 seconds
// Disablng until ocs-operator fixes above issue
// eslint-disable-next-line cypress/no-unnecessary-waiting
cy.wait(10000);
cy.byTestOperandLink('ocs-storagecluster').click();
cy.byTestID('resource-status').contains('Ready', { timeout: 900000 });

return cy.exec('oc get storagecluster ocs-storagecluster -n openshift-storage -o json');
})
.then((res) => {
const storageCluster = JSON.parse(res.stdout);
// Assertion of increment of device count
cy.log('Check cluster deivce set count has increased');
expect(getDeviceCount(initialState.storageCluster)).toEqual(
getDeviceCount(storageCluster) - 1,
);

return cy.exec(
'oc get cephCluster ocs-storagecluster-cephcluster -n openshift-storage -o json',
);
})
.then((res) => {
const cephCluster = JSON.parse(res.stdout);

cy.log('Check if ceph cluster is healthy after expansion');
expect(cephCluster.status.ceph.health).not.toBe(CLUSTER_STATUS.HEALTH_ERROR);

return cy.exec('oc get po -n openshift-storage -o json');
})
.then((res) => {
const pods = JSON.parse(res.stdout);

cy.log('Check Pods have not restarted unexpectedly');
initialState.pods.items.forEach((pod) => {
const initalRestarts = getPodRestartCount(pod);
const updatedPod = getPresentPod(pods, getPodName(pod));
if (updatedPod) {
const currentRestarts = getPodRestartCount(updatedPod);
expect(initalRestarts).toEqual(currentRestarts);
}
});

return cy.exec(
`oc -n openshift-storage rsh $(oc get po -n openshift-storage | grep ceph-operator | awk '{print$1}') ceph --conf=/var/lib/rook/openshift-storage/openshift-storage.config osd tree --format=json`,
{ timeout: 120000 },
);
})
.then((res) => {
const osdTree = JSON.parse(res.stdout);
const formattedOSDTree = createOSDTreeMap(osdTree.nodes);
const newOSDIds = getNewOSDIds(osdTree.nodes, initialState.osdIDs);

cy.log('New OSDs are added correctly to the right nodes', () => {
const nodes = getIds(osdTree.nodes, 'host');
expect(verifyNodeOSDMapping(nodes, newOSDIds, formattedOSDTree)).toBeTruthy();
});

return cy.exec('oc get nodes -o json');
})
.then((res) => {
const nodes = JSON.parse(res.stdout);
const allNodesReady = nodes.items.every(isNodeReady);

cy.log('No Nodes should go to Not Ready state');
expect(allNodesReady).toBeTruthy();
});
});
});

0 comments on commit 0a759d6

Please sign in to comment.