From cf777ca6374794fedca5675ee235414b43a39087 Mon Sep 17 00:00:00 2001 From: Francois Ferrand Date: Wed, 13 Nov 2024 19:53:58 +0100 Subject: [PATCH] Add test for archive object replacement Add replacement with MPU or copyObject. Issue: ZENKO-4928 --- tests/ctst/common/common.ts | 23 +++++++++- tests/ctst/features/dmf.feature | 41 +++++++++++++++++ tests/ctst/steps/utils/utils.ts | 80 +++++++++++++++++++++++++++++++++ 3 files changed, 142 insertions(+), 2 deletions(-) diff --git a/tests/ctst/common/common.ts b/tests/ctst/common/common.ts index 78926f1ae8..52d09afa71 100644 --- a/tests/ctst/common/common.ts +++ b/tests/ctst/common/common.ts @@ -7,6 +7,8 @@ import assert from 'assert'; import { Admin, Kafka } from 'kafkajs'; import { createBucketWithConfiguration, + putMpuObject, + copyObject, putObject, runActionAgainstBucket, getObjectNameWithBackendFlakiness, @@ -62,7 +64,7 @@ export async function cleanS3Bucket( } async function addMultipleObjects(this: Zenko, numberObjects: number, - objectName: string, sizeBytes: number, userMD?: string) { + objectName: string, sizeBytes: number, userMD?: string, parts?: number) { let lastResult = null; for (let i = 1; i <= numberObjects; i++) { this.resetCommand(); @@ -74,7 +76,9 @@ async function addMultipleObjects(this: Zenko, numberObjects: number, if (userMD) { this.addToSaved('userMetadata', userMD); } - lastResult = await putObject(this, objectNameFinal); + lastResult = parts === undefined + ? await putObject(this, objectNameFinal) + : await putMpuObject(this, parts, objectNameFinal); } return lastResult; } @@ -147,6 +151,16 @@ Given('{int} objects {string} of size {int} bytes', await addMultipleObjects.call(this, numberObjects, objectName, sizeBytes); }); +Given('{int} mpu objects {string} of size {int} bytes', + async function (this: Zenko, numberObjects: number, objectName: string, sizeBytes: number) { + await addMultipleObjects.call(this, numberObjects, objectName, sizeBytes, undefined, 3); + }); + +Given('{string} is copied to {string}', + async function (this: Zenko, sourceObject: string, destinationObject: string) { + await copyObject(this, sourceObject, destinationObject); + }); + Given('{int} objects {string} of size {int} bytes on {string} site', async function (this: Zenko, numberObjects: number, objectName: string, sizeBytes: number, site: string) { this.resetCommand(); @@ -164,6 +178,11 @@ Given('{int} objects {string} of size {int} bytes with user metadata {string}', await addMultipleObjects.call(this, numberObjects, objectName, sizeBytes, userMD); }); +Given('{int} mpu objects {string} of size {int} bytes with user metadata {string}', + async function (this: Zenko, numberObjects: number, objectName: string, sizeBytes: number, userMD: string) { + await addMultipleObjects.call(this, numberObjects, objectName, sizeBytes, userMD); + }); + Given('a tag on object {string} with key {string} and value {string}', async function (this: Zenko, objectName: string, tagKey: string, tagValue: string) { this.resetCommand(); diff --git a/tests/ctst/features/dmf.feature b/tests/ctst/features/dmf.feature index 175553e87b..09b36a5f77 100644 --- a/tests/ctst/features/dmf.feature +++ b/tests/ctst/features/dmf.feature @@ -92,3 +92,44 @@ Feature: DMF | versioningConfiguration | objectCount | objectSize | | Non versioned | 1 | 100 | | Suspended | 1 | 100 | + + @2.7.0 + @PreMerge + @Dmf + @ColdStorage + Scenario Outline: Overwriting of a cold mpu object + Given a "" bucket + And a transition workflow to "e2e-cold" location + And objects "obj" of size bytes + Then object "obj-1" should be "transitioned" and have the storage class "e2e-cold" + And dmf volume should contain objects + Given mpu objects "obj" of size bytes + Then object "obj-1" should be "transitioned" and have the storage class "e2e-cold" + And dmf volume should contain 1 objects + + Examples: + | versioningConfiguration | objectCount | objectSize | + | Non versioned | 1 | 100 | + | Suspended | 1 | 100 | + + @2.7.0 + @PreMerge + @Dmf + @ColdStorage + Scenario Outline: Overwriting of a cold object with copyObject + Given a "" bucket + And a transition workflow to "e2e-cold" location + And 2 objects "obj" of size bytes + Then object "obj-1" should be "transitioned" and have the storage class "e2e-cold" + And object "obj-2" should be "transitioned" and have the storage class "e2e-cold" + And dmf volume should contain 2 objects + When i restore object "obj-1" for 5 days + Then object "obj-1" should be "restored" and have the storage class "e2e-cold" + Given "obj-1" is copied to "obj-2" + Then object "obj-2" should be "transitioned" and have the storage class "e2e-cold" + And dmf volume should contain 2 objects + + Examples: + | versioningConfiguration | objectSize | + | Non versioned | 100 | + | Suspended | 100 | diff --git a/tests/ctst/steps/utils/utils.ts b/tests/ctst/steps/utils/utils.ts index dd1745bc25..67c3c95c95 100644 --- a/tests/ctst/steps/utils/utils.ts +++ b/tests/ctst/steps/utils/utils.ts @@ -199,6 +199,84 @@ async function createBucketWithConfiguration( } } +async function putMpuObject(world: Zenko, parts: number = 2, objectName: string, content?: string) { + const key = objectName || `${Utils.randomString()}`; + const bucket = world.getSaved('bucketName'); + + world.resetCommand(); + world.addToSaved('objectName', objectName); + world.logger.debug('Adding mpu object', { objectName }); + world.addCommandParameter({ key }); + world.addCommandParameter({ bucket }); + const userMetadata = world.getSaved('userMetadata'); + if (userMetadata) { + world.addCommandParameter({ metadata: JSON.stringify(userMetadata) }); + } + + const initiateMPUResult = await S3.createMultipartUpload(world.getCommandParameters()); + assert.ifError(initiateMPUResult.stderr || initiateMPUResult.err); + const uploadId = extractPropertyFromResults(initiateMPUResult, 'UploadId'); + + await uploadSetup(world, 'UploadPart', content); + const body = world.getSaved('tempFileName'); + + const uploadedParts = []; + for (let i = 0; i < parts; i++) { + world.resetCommand(); + world.addCommandParameter({ key }); + world.addCommandParameter({ bucket }); + world.addCommandParameter({ partNumber: i+1 }); + world.addCommandParameter({ uploadId }); + if (body) { + world.addCommandParameter({ body }); + } + + const uploadPartResult = await S3.uploadPart(world.getCommandParameters()); + assert.ifError(uploadPartResult.stderr || uploadPartResult.err); + + uploadedParts.push({ + ETag: extractPropertyFromResults(uploadPartResult, 'ETag'), + PartNumber: (i+1).toString(), + }); + } + + await uploadTeardown(world, 'UploadPart'); + + world.resetCommand(); + world.addCommandParameter({ key }); + world.addCommandParameter({ bucket }); + world.addCommandParameter({ uploadId }); + world.addCommandParameter({ multipartUpload: JSON.stringify({ Parts: uploadedParts }) }); + + const result = await S3.completeMultipartUpload(world.getCommandParameters()); + const versionId = extractPropertyFromResults(result, 'VersionId'); + world.saveCreatedObject(objectName, versionId || ''); + world.setResult(result); + return result; +} + +async function copyObject(world: Zenko, srcObjectName?: string, dstObjectName?: string) { + const bucket = world.getSaved('bucketName'); + const key = dstObjectName || world.getSaved('objectName'); + const copySource = `${bucket}/${srcObjectName || world.getSaved('objectName')}`; + + world.resetCommand(); + world.addCommandParameter({ copySource }); + world.addCommandParameter({ bucket }); + world.addCommandParameter({ key }); + + const userMetadata = world.getSaved('userMetadata'); + if (userMetadata) { + world.addCommandParameter({ metadata: JSON.stringify(userMetadata) }); + } + + const result = await S3.copyObject(world.getCommandParameters()); + const versionId = extractPropertyFromResults(result, 'VersionId'); + world.saveCreatedObject(key, versionId || ''); + world.setResult(result); + return result; +} + async function putObject(world: Zenko, objectName?: string, content?: string) { world.resetCommand(); let finalObjectName = objectName; @@ -394,6 +472,8 @@ export { runActionAgainstBucket, createBucketWithConfiguration, getAuthorizationConfiguration, + putMpuObject, + copyObject, putObject, emptyNonVersionedBucket, emptyVersionedBucket,