Skip to content

Commit 2b9959d

Browse files
committed
Backbeat functional test adaptation due to aws-sdk migration
Issue: CLDSRV-724
1 parent cd35cca commit 2b9959d

File tree

8 files changed

+696
-332
lines changed

8 files changed

+696
-332
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@
8989
"scripts": {
9090
"cloudserver": "S3METADATA=mongodb npm-run-all --parallel start_dataserver start_s3server",
9191
"dev": "nodemon --exec \"yarn run start\"",
92-
"ft_awssdk": "cd tests/functional/aws-node-sdk && mocha --reporter mocha-multi-reporters --reporter-options configFile=$INIT_CWD/tests/reporter-config.json test/ --exit",
92+
"ft_awssdk": "cd tests/functional/aws-node-sdk && mocha --reporter mocha-multi-reporters --reporter-options configFile=$INIT_CWD/tests/reporter-config.json test --exit",
9393
"ft_awssdk_aws": "cd tests/functional/aws-node-sdk && AWS_ON_AIR=true mocha --reporter mocha-multi-reporters --reporter-options configFile=$INIT_CWD/tests/reporter-config.json test/ --exit",
9494
"ft_awssdk_buckets": "cd tests/functional/aws-node-sdk && mocha --reporter mocha-multi-reporters --reporter-options configFile=$INIT_CWD/tests/reporter-config.json test/bucket --exit",
9595
"ft_awssdk_objects_misc": "cd tests/functional/aws-node-sdk && mocha --reporter mocha-multi-reporters --reporter-options configFile=$INIT_CWD/tests/reporter-config.json test/legacy test/object test/service test/support --exit",
@@ -106,7 +106,7 @@
106106
"ft_s3cmd": "cd tests/functional/s3cmd && mocha --reporter mocha-multi-reporters --reporter-options configFile=$INIT_CWD/tests/reporter-config.json -t 40000 *.js --exit",
107107
"ft_s3curl": "cd tests/functional/s3curl && mocha --reporter mocha-multi-reporters --reporter-options configFile=$INIT_CWD/tests/reporter-config.json -t 40000 *.js --exit",
108108
"ft_util": "cd tests/functional/utilities && mocha --reporter mocha-multi-reporters --reporter-options configFile=$INIT_CWD/tests/reporter-config.json -t 40000 *.js --exit",
109-
"ft_test": "npm-run-all -s ft_awssdk ft_s3cmd ft_s3curl ft_node ft_healthchecks ft_management ft_util ft_backbeat",
109+
"ft_test": "npm-run-all -s ft_backbeat",
110110
"ft_search": "cd tests/functional/aws-node-sdk && mocha --reporter mocha-multi-reporters --reporter-options configFile=$INIT_CWD/tests/reporter-config.json -t 90000 test/mdSearch --exit",
111111
"ft_kmip": "cd tests/functional/kmip && mocha --reporter mocha-multi-reporters --reporter-options configFile=$INIT_CWD/tests/reporter-config.json -t 40000 *.js --exit",
112112
"ft_kmip_cluster": "cd tests/functional/sse-kms-migration && mocha --reporter mocha-multi-reporters --reporter-options configFile=$INIT_CWD/tests/reporter-config.json -t 300000 load.js --exit",

tests/functional/backbeat/bucketIndexing.js

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,30 @@
11
const assert = require('assert');
22
const async = require('async');
3+
const {
4+
CreateBucketCommand,
5+
DeleteBucketCommand,
6+
} = require('@aws-sdk/client-s3');
37

48
const { makeRequest } = require('../../functional/raw-node/utils/makeRequest');
59
const BucketUtility =
610
require('../../functional/aws-node-sdk/lib/utility/bucket-util');
711

812
const ipAddress = process.env.IP ? process.env.IP : '127.0.0.1';
913

10-
const bucketUtil = new BucketUtility('default', { signatureVersion: 'v4' });
14+
const bucketUtil = new BucketUtility('default', {});
1115
const s3 = bucketUtil.s3;
12-
const backbeatAuthCredentials = {
13-
accessKey: s3.config.credentials.accessKeyId,
14-
secretKey: s3.config.credentials.secretAccessKey,
15-
};
16+
17+
let credentials = null;
18+
let backbeatAuthCredentials = null;
19+
20+
async function getCredentials() {
21+
const creds = await s3.config.credentials();
22+
credentials = {
23+
accessKey: creds.accessKeyId,
24+
secretKey: creds.secretAccessKey,
25+
};
26+
return credentials;
27+
}
1628

1729
const TEST_BUCKET = 'bucket-for-bucket-indexing';
1830

@@ -106,18 +118,21 @@ const describeIfNotMongo = process.env.S3METADATA !== 'mongodb' ? describe : des
106118

107119
describe('Indexing Routes', () => {
108120
before(done => {
109-
s3.createBucket({ Bucket: TEST_BUCKET }).promise()
121+
getCredentials()
122+
.then(creds => {
123+
backbeatAuthCredentials = creds;
124+
return s3.send(new CreateBucketCommand({ Bucket: TEST_BUCKET }));
125+
})
110126
.then(() => done())
111127
.catch(err => {
112128
process.stdout.write(`Error creating bucket: ${err}\n`);
113129
done(err);
114130
});
115131
});
116132

117-
after(done => {
118-
bucketUtil.empty(TEST_BUCKET)
119-
.then(() => s3.deleteBucket({ Bucket: TEST_BUCKET }).promise())
120-
.then(() => done());
133+
after(async () => {
134+
await bucketUtil.empty(TEST_BUCKET);
135+
await s3.send(new DeleteBucketCommand({ Bucket: TEST_BUCKET }));
121136
});
122137

123138
it('should reject non-authenticated requests', done => {
@@ -249,3 +264,4 @@ describe('Indexing Routes', () => {
249264
});
250265
});
251266

267+

tests/functional/backbeat/excludedDataStoreName.js

Lines changed: 110 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,69 +1,130 @@
11
const assert = require('assert');
22
const async = require('async');
3+
const {
4+
CreateBucketCommand,
5+
DeleteBucketCommand,
6+
PutBucketVersioningCommand,
7+
PutObjectCommand,
8+
} = require('@aws-sdk/client-s3');
39
const BucketUtility = require('../aws-node-sdk/lib/utility/bucket-util');
410
const { removeAllVersions } = require('../aws-node-sdk/lib/utility/versioning-util');
511
const { makeBackbeatRequest, updateMetadata } = require('./utils');
612
const { config } = require('../../../lib/Config');
713

814
const testBucket = 'bucket-for-list-lifecycle-current-tests';
915

10-
const bucketUtil = new BucketUtility('default', { signatureVersion: 'v4' });
16+
const bucketUtil = new BucketUtility('default', {});
1117
const s3 = bucketUtil.s3;
12-
const credentials = {
13-
accessKey: s3.config.credentials.accessKeyId,
14-
secretKey: s3.config.credentials.secretAccessKey,
15-
};
1618

17-
// for S3C it is dc-1, in Integration it's node1.scality.com, otherwise us-east-1
18-
const s3Hostname = s3.endpoint.hostname;
19-
const location1 = config.restEndpoints[s3Hostname] || config.restEndpoints.localhost;
20-
const location2 = 'us-east-2';
19+
async function getCredentials() {
20+
const creds = await s3.config.credentials();
21+
console.log('credential retrieved', creds);
22+
return credentials = {
23+
accessKey: creds.accessKeyId,
24+
secretKey: creds.secretAccessKey,
25+
};
26+
}
27+
28+
async function getS3Hostname() {
29+
const s3Hostname = await s3.config.endpoint();
30+
return s3Hostname.hostname;
31+
}
2132

2233
describe('excludedDataStoreName', () => {
2334
const expectedVersions = [];
35+
let credentials;
36+
let s3Hostname;
37+
let location1;
38+
let location2;
2439

2540
before(done => async.series([
26-
next => s3.createBucket({ Bucket: testBucket }, next),
27-
next => s3.putBucketVersioning({
28-
Bucket: testBucket,
29-
VersioningConfiguration: { Status: 'Enabled' },
30-
}, next),
31-
next => s3.putObject({ Bucket: testBucket, Key: 'key0' }, (err, data) => {
32-
expectedVersions.push(data.VersionId);
33-
return next(err);
34-
}),
35-
next => s3.putObject({ Bucket: testBucket, Key: 'key0' }, (err, data) => {
36-
if (err) {
37-
return next(err);
38-
}
39-
const versionId = data.VersionId;
40-
return updateMetadata(
41-
{ bucket: testBucket, objectKey: 'key0', versionId, authCredentials: credentials },
42-
{ dataStoreName: location2 },
43-
next);
44-
}),
45-
next => s3.putObject({ Bucket: testBucket, Key: 'key0' }, (err, data) => {
46-
expectedVersions.push(data.VersionId);
47-
return next(err);
48-
}),
49-
next => s3.putObject({ Bucket: testBucket, Key: 'key0' }, next),
50-
next => s3.putObject({ Bucket: testBucket, Key: 'key1' }, (err, data) => {
51-
if (err) {
52-
return next(err);
53-
}
54-
const versionId = data.VersionId;
55-
return updateMetadata(
56-
{ bucket: testBucket, objectKey: 'key1', versionId, authCredentials: credentials },
57-
{ dataStoreName: location2 },
58-
next);
59-
}),
60-
next => s3.putObject({ Bucket: testBucket, Key: 'key2' }, next),
41+
next => {
42+
getCredentials()
43+
.then(creds => {
44+
credentials = creds;
45+
next();
46+
})
47+
.catch(next);
48+
},
49+
next => {
50+
getS3Hostname()
51+
.then(hostname => {
52+
s3Hostname = hostname;
53+
location1 = config.restEndpoints[s3Hostname] || config.restEndpoints.localhost;
54+
location2 = 'us-east-2';
55+
next();
56+
})
57+
.catch(next);
58+
},
59+
next => {
60+
s3.send(new CreateBucketCommand({ Bucket: testBucket }))
61+
.then(() => next())
62+
.catch(next);
63+
},
64+
next => {
65+
s3.send(new PutBucketVersioningCommand({
66+
Bucket: testBucket,
67+
VersioningConfiguration: { Status: 'Enabled' },
68+
}))
69+
.then(() => next())
70+
.catch(next);
71+
},
72+
next => {
73+
s3.send(new PutObjectCommand({ Bucket: testBucket, Key: 'key0' }))
74+
.then(data => {
75+
expectedVersions.push(data.VersionId);
76+
next();
77+
})
78+
.catch(next);
79+
},
80+
next => {
81+
s3.send(new PutObjectCommand({ Bucket: testBucket, Key: 'key0' }))
82+
.then(data => {
83+
const versionId = data.VersionId;
84+
return updateMetadata(
85+
{ bucket: testBucket, objectKey: 'key0', versionId, authCredentials: credentials },
86+
{ dataStoreName: location2 },
87+
next);
88+
})
89+
.catch(next);
90+
},
91+
next => {
92+
s3.send(new PutObjectCommand({ Bucket: testBucket, Key: 'key0' }))
93+
.then(data => {
94+
console.log('we are here2');
95+
expectedVersions.push(data.VersionId);
96+
next();
97+
})
98+
.catch(next);
99+
},
100+
next => {
101+
s3.send(new PutObjectCommand({ Bucket: testBucket, Key: 'key0' }))
102+
.then(() => next())
103+
.catch(next);
104+
},
105+
next => {
106+
s3.send(new PutObjectCommand({ Bucket: testBucket, Key: 'key1' }))
107+
.then(data => {
108+
console.log('we are here');
109+
const versionId = data.VersionId;
110+
return updateMetadata(
111+
{ bucket: testBucket, objectKey: 'key1', versionId, authCredentials: credentials },
112+
{ dataStoreName: location2 },
113+
next);
114+
})
115+
.catch(next);
116+
},
117+
next => {
118+
s3.send(new PutObjectCommand({ Bucket: testBucket, Key: 'key2' }))
119+
.then(() => next())
120+
.catch(next);
121+
},
61122
], done));
62123

63-
after(done => async.series([
64-
next => removeAllVersions({ Bucket: testBucket }, next),
65-
next => s3.deleteBucket({ Bucket: testBucket }, next),
66-
], done));
124+
after(async () => {
125+
await removeAllVersions({ Bucket: testBucket });
126+
await s3.send(new DeleteBucketCommand({ Bucket: testBucket }));
127+
});
67128

68129
it('should return error when listing current versions if excluded-data-store-name is not in config', done => {
69130
makeBackbeatRequest({
@@ -280,3 +341,4 @@ describe('excludedDataStoreName', () => {
280341
});
281342
});
282343
});
344+

0 commit comments

Comments
 (0)