Skip to content

Commit

Permalink
Write e2e tests for Compression
Browse files Browse the repository at this point in the history
Signed-off-by: Bipul Adhikari <[email protected]>
  • Loading branch information
bipuladh committed Oct 11, 2022
1 parent 63558e4 commit f661102
Show file tree
Hide file tree
Showing 5 changed files with 222 additions and 4 deletions.
137 changes: 137 additions & 0 deletions cypress/mocks/compression.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
export const compressionPool = {
apiVersion: 'ceph.rook.io/v1',
kind: 'CephBlockPool',
metadata: { name: 'plasma-reactor-pool', namespace: 'openshift-storage' },
spec: {
compressionMode: 'aggressive',
deviceClass: 'ssd',
failureDomain: 'zone',
parameters: { compression_mode: 'aggressive' },
replicated: { size: 2 },
},
};

export const compressionStorageClass = {
kind: 'StorageClass',
apiVersion: 'storage.k8s.io/v1',
metadata: {
name: 'compression-class',
},
provisioner: 'openshift-storage.rbd.csi.ceph.com',
parameters: {
'csi.storage.k8s.io/fstype': 'ext4',
'csi.storage.k8s.io/provisioner-secret-namespace': 'openshift-storage',
'csi.storage.k8s.io/provisioner-secret-name': 'rook-csi-rbd-provisioner',
'csi.storage.k8s.io/node-stage-secret-name': 'rook-csi-rbd-node',
'csi.storage.k8s.io/controller-expand-secret-name':
'rook-csi-rbd-provisioner',
imageFormat: '2',
clusterID: 'openshift-storage',
imageFeatures: 'layering,deep-flatten,exclusive-lock,object-map,fast-diff',
'csi.storage.k8s.io/controller-expand-secret-namespace':
'openshift-storage',
pool: 'plasma-reactor-pool',
'csi.storage.k8s.io/node-stage-secret-namespace': 'openshift-storage',
},
reclaimPolicy: 'Delete',
allowVolumeExpansion: true,
volumeBindingMode: 'Immediate',
};

export const fioPVC = {
kind: 'PersistentVolumeClaim',
apiVersion: 'v1',
metadata: {
name: 'fio-claim',
},
spec: {
storageClassName: 'compression-class',
accessModes: ['ReadWriteOnce'],
volumeMode: 'Filesystem',
resources: {
requests: {
storage: '5Gi',
},
},
},
};

export const fioConfig = `kind: ConfigMap
apiVersion: v1
metadata:
name: fio-job-config
data:
fio.job: |-
[global]
ioengine=psync
direct=1
buffered=0
size=1G
iodepth=1000
numjobs=2
group_reporting
refill_buffers
rwmixread=80
norandommap
randrepeat=0
percentage_random=0
bs=512K
buffer_compress_percentage=50
rw=read
[testjob]
`;

export const fioJob = {
apiVersion: 'batch/v1',
kind: 'Job',
metadata: {
name: 'fio',
labels: {
app: 'fio',
},
},
spec: {
template: {
spec: {
containers: [
{
name: 'fio',
image: 'quay.io/badhikar/fio:latest',
command: ['sh'],
args: [
'-c',
// eslint-disable-next-line no-template-curly-in-string
'echo ${HOSTNAME} && mkdir -p /scratch/${HOSTNAME} && fio /configs/fio.job --eta=never --directory=/scratch/${HOSTNAME}',
],
volumeMounts: [
{
name: 'fio-config-vol',
mountPath: '/configs',
},
{
name: 'fio-data',
mountPath: '/scratch',
},
],
imagePullPolicy: 'Always',
},
],
restartPolicy: 'OnFailure',
volumes: [
{
name: 'fio-config-vol',
configMap: {
name: 'fio-job-config',
},
},
{
name: 'fio-data',
persistentVolumeClaim: {
claimName: 'fio-claim',
},
},
],
},
},
},
};
20 changes: 20 additions & 0 deletions cypress/support.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
import { CLUSTER_NAMESPACE, STORAGE_SYSTEM_NAME, OCS_SC_STATE } from './consts';
import './support/selectors';
import './support/login';
import { commandPoll } from './views/common';

declare global {
namespace Cypress {
interface Chainable<Subject> {
install(encrypted?: boolean): Chainable<Element>;
enableToolboxPod(): void;
}
}
}
Expand Down Expand Up @@ -87,3 +89,21 @@ Cypress.Commands.add('install', () => {
}
});
});

Cypress.Commands.add('enableToolboxPod', () => {
cy.exec(
`oc patch ocsinitialization ocsinit -n openshift-storage --type json --patch '[{ "op": "replace", "path": "/spec/enableCephTools", "value": true }]'`
);
// wait for the pod CR to be registered
// eslint-disable-next-line cypress/no-unnecessary-waiting
commandPoll(
'oc get pod -l "app=rook-ceph-tools" -n openshift-storage',
null,
false,
30,
0
);
cy.exec(
`oc wait --for=condition=ready pod -l "app=rook-ceph-tools" -n openshift-storage`
);
});
59 changes: 59 additions & 0 deletions cypress/tests/compression.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import {
compressionPool,
compressionStorageClass,
fioConfig,
fioJob,
fioPVC,
} from '../mocks/compression';
import { navigateToBlockPool } from '../views/block-pool';
import { commandPoll } from '../views/common';

describe('Test Pool Compression', () => {
before(() => {
cy.login();
cy.visit('/');
cy.install();
cy.enableToolboxPod();
cy.exec(`echo '${JSON.stringify(compressionPool)}' | oc apply -f -`);
cy.exec(
`echo '${JSON.stringify(compressionStorageClass)}' | oc apply -f -`
);
cy.exec(`echo '${fioConfig}' | oc apply -f -`);
cy.exec(`echo '${JSON.stringify(fioPVC)}' | oc apply -f -`);
cy.exec(`echo '${JSON.stringify(fioJob)}' | oc apply -f -`);
commandPoll('oc get job fio', null, false, 30, 0);
cy.exec(`oc wait --for=condition=complete job fio`, { timeout: 120000 });
});

after(() => {
cy.exec(`echo ${JSON.stringify(fioJob)} | oc delete -f -`);
cy.exec(`echo ${JSON.stringify(fioPVC)} | oc delete -f -`);
cy.exec(`echo ${JSON.stringify(fioConfig)} | oc delete -f -`);
cy.exec(`echo ${JSON.stringify(compressionPool)} | oc delete -f -`);
cy.exec(`echo ${JSON.stringify(compressionStorageClass)} | oc delete -f -`);
cy.logout();
});

it('Tests compression statistics are correct on the BlockPool list Page', () => {
navigateToBlockPool();
cy.byTestID('name-filter-input').type(compressionPool.metadata.name);
// TableData does not support data-test ids
// eslint-disable-next-line cypress/require-data-selectors
cy.get('#compressionStatus').should('have.text', 'Enabled');
cy.exec(
`oc exec -it $(oc get pods -n openshift-storage -l app=rook-ceph-tools -o name) -n openshift-storage -- /usr/bin/rados df -f json`
).then(({ stdout }) => {
const poolData = JSON.parse(stdout).pools;
const plasmaPool = poolData.find(
(pool) => pool.name === compressionPool.metadata.name
);
const compressionSavings = plasmaPool.compress_bytes_used;
// TableData does not support data-test ids
// eslint-disable-next-line cypress/require-data-selectors
cy.get('#compressionSavings').should(
'have.text',
(compressionSavings / 1024 ** 2).toFixed(2)
);
});
});
});
2 changes: 1 addition & 1 deletion cypress/views/block-pool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const poolMessage: {

export const navigateToBlockPool = () => {
ODFCommon.visitStorageDashboard();
cy.byLegacyTestID('horizontal-link-Storage Systems').click();
cy.byTestID('horizontal-link-Storage Systems').click();
cy.byLegacyTestID('item-filter').type('ocs-storagecluster-storagesystem');
cy.byTestRows('resource-row').get('td a').first().click();
cy.byLegacyTestID('horizontal-link-BlockPools').click();
Expand Down
8 changes: 5 additions & 3 deletions cypress/views/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,19 @@ export const commonFlows = {
cy.clickNavLink(['Storage', 'Data Foundation']);
//cy.byTestOperatorRow('OpenShift Data Foundation').click();
},
// eslint-disable-next-line cypress/require-data-selectors
checkAll: () => cy.get('input[name=check-all]'),
};

export const commandPoll = (
cmd: string,
expected: string,
failOnNonZeroExit: boolean = true,
retry: number = 300
retry: number = 300,
expectedCode?: number
) => {
cy.exec(cmd, { failOnNonZeroExit }).then((res) => {
if (res.stdout === expected) {
if (res.stdout === expected || expectedCode === res.code) {
assert(true);
return;
}
Expand All @@ -22,6 +24,6 @@ export const commandPoll = (
return;
}

commandPoll(cmd, expected, failOnNonZeroExit, retry - 1);
commandPoll(cmd, expected, failOnNonZeroExit, retry - 1, expectedCode);
});
};

0 comments on commit f661102

Please sign in to comment.