Skip to content

Commit

Permalink
Add Internal Mode Installation Test to Cypress
Browse files Browse the repository at this point in the history
Add Add Capcity for Storage Cluster Test to Cypress
  • Loading branch information
bipuladh committed Nov 19, 2020
1 parent 87ed788 commit 6ac80b3
Show file tree
Hide file tree
Showing 11 changed files with 354 additions and 48 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,67 @@
import * as _ from 'lodash';

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

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

export const isPodPresent = (pods, podName) => {
const podObj = pods.items.find((pod) => getPodName(pod) === podName);
return podObj || '';
};

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);

// created dictionary for faster acess O(1)
export const createOSDTreeMap = (nodes) => {
const tree = {};
nodes.forEach((node) => {
tree[node.id] = node;
});
return tree;
};

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 SIZE_MAP = {
'512Gi': 0.5,
'2Ti': 2,
'4Ti': 4,
};

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,96 @@
import * as _ from 'lodash';
import '../../../integration-tests-cypress/support/index.ts';

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

Cypress.Commands.add('install', (mode: 'Internal' | 'Attached' = 'Internal', encrypted = false) => {
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('enable-monitoring').click();
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`);
cy.clickNavLink(['Installed Operators']);
cy.byLegacyTestID('item-filter').type('ocs-operator');
cy.byTestOperatorRow('OpenShift Container Storage').click();
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
cy.get('input[name=check-all]').check();
cy.get('input[name=check-all').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();
cy.get('.pf-c-button.pf-m-primary')
.contains('Next')
.click();

// Step 2
if (encrypted) {
cy.log('Enabling Encryption');
cy.byTestID('encryption-checkbox').click();
}
cy.get('.pf-c-button.pf-m-primary')
.contains('Next')
.click();

// Final Step
cy.get('.pf-c-button.pf-m-primary')
.contains('Create')
.click();

// Check worker nodes for labels
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 });
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@
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,
getPodName,
getPodRestartCount,
isNodeReady,
isPodPresent,
SIZE_MAP,
verifyNodeOSDMapping,
verifyZoneOSDMapping,
} from '../helpers';

describe('OCS Operator Basic Tests', () => {
before(() => {
cy.login();
cy.visit('/');

cy.install();
});

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

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

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

it.only('Add 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 and after 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);

cy.clickNavLink(['Operators', 'Installed Operators']);
cy.byLegacyTestID('item-filter').type('ocs-operator');
cy.byTestOperatorRow('OpenShift Container Storage').click();
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`,
);
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 = isPodPresent(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 availability zones/failure domains');
const zones = getIds(osdTree.nodes, 'zone');
expect(verifyZoneOSDMapping(zones, newOSDIds, formattedOSDTree)).toBeTruthy();

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();
});
});
});

This file was deleted.

0 comments on commit 6ac80b3

Please sign in to comment.