Skip to content

Commit 494851e

Browse files
committed
Add docker-compose fixtures for S3 integration tests (elastic#49107)
Similarly to what has been done for Azure (elastic#48636) and GCS (elastic#48762), this committ removes the existing Ant fixture that emulates a S3 storage service in favor of multiple docker-compose based fixtures. The goals here are multiple: be able to reuse a s3-fixture outside of the repository-s3 plugin; allow parallel execution of integration tests; removes the existing AmazonS3Fixture that has evolved in a weird beast in dedicated, more maintainable fixtures. The server side logic that emulates S3 mostly comes from the latest HttpHandler made for S3 blob store repository tests, with additional features extracted from the (now removed) AmazonS3Fixture: authentication checks, session token checks and improved response errors. Chunked upload request support for S3 object has been added too. The server side logic of all tests now reside in a single S3HttpHandler class. Whereas AmazonS3Fixture contained logic for basic tests, session token tests, EC2 tests or ECS tests, the S3 fixtures are now dedicated to each kind of test. Fixtures are inheriting from each other, making things easier to maintain.
1 parent 8fd1eaa commit 494851e

File tree

12 files changed

+820
-854
lines changed

12 files changed

+820
-854
lines changed

plugins/repository-s3/build.gradle

+32-62
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import org.elasticsearch.gradle.MavenFilteringHack
2-
import org.elasticsearch.gradle.test.AntFixture
32
import org.elasticsearch.gradle.test.RestIntegTestTask
43

54
import static org.elasticsearch.gradle.PropertyNormalization.IGNORE_VALUE
@@ -22,6 +21,7 @@ import static org.elasticsearch.gradle.PropertyNormalization.IGNORE_VALUE
2221
* specific language governing permissions and limitations
2322
* under the License.
2423
*/
24+
apply plugin: 'elasticsearch.test.fixtures'
2525

2626
esplugin {
2727
description 'The S3 repository plugin adds S3 repositories'
@@ -48,10 +48,10 @@ dependencies {
4848
compile "joda-time:joda-time:${versions.joda}"
4949

5050
// HACK: javax.xml.bind was removed from default modules in java 9, so we pull the api in here,
51-
// and whitelist this hack in JarHell
51+
// and whitelist this hack in JarHell
5252
compile 'javax.xml.bind:jaxb-api:2.2.2'
5353

54-
testCompile project(':test:fixtures:minio-fixture')
54+
testCompile project(':test:fixtures:s3-fixture')
5555
}
5656

5757
dependencyLicenses {
@@ -110,7 +110,7 @@ if (!s3PermanentAccessKey && !s3PermanentSecretKey && !s3PermanentBucket && !s3P
110110
s3PermanentAccessKey = 'access_key'
111111
s3PermanentSecretKey = 'secret_key'
112112
s3PermanentBucket = 'bucket'
113-
s3PermanentBasePath = ''
113+
s3PermanentBasePath = 'base_path'
114114

115115
useFixture = true
116116

@@ -119,21 +119,21 @@ if (!s3PermanentAccessKey && !s3PermanentSecretKey && !s3PermanentBucket && !s3P
119119
}
120120

121121
if (!s3TemporaryAccessKey && !s3TemporarySecretKey && !s3TemporaryBucket && !s3TemporaryBasePath && !s3TemporarySessionToken) {
122-
s3TemporaryAccessKey = 's3_integration_test_temporary_access_key'
123-
s3TemporarySecretKey = 's3_integration_test_temporary_secret_key'
124-
s3TemporaryBucket = 'temporary-bucket-test'
125-
s3TemporaryBasePath = 'integration_test'
126-
s3TemporarySessionToken = 's3_integration_test_temporary_session_token'
122+
s3TemporaryAccessKey = 'session_token_access_key'
123+
s3TemporarySecretKey = 'session_token_secret_key'
124+
s3TemporaryBucket = 'session_token_bucket'
125+
s3TemporaryBasePath = 'session_token_base_path'
126+
s3TemporarySessionToken = 'session_token'
127127

128128
} else if (!s3TemporaryAccessKey || !s3TemporarySecretKey || !s3TemporaryBucket || !s3TemporaryBasePath || !s3TemporarySessionToken) {
129129
throw new IllegalArgumentException("not all options specified to run against external S3 service as temporary credentials are present")
130130
}
131131

132132
if (!s3EC2Bucket && !s3EC2BasePath && !s3ECSBucket && !s3ECSBasePath) {
133-
s3EC2Bucket = 'ec2-bucket-test'
134-
s3EC2BasePath = 'integration_test'
135-
s3ECSBucket = 'ecs-bucket-test'
136-
s3ECSBasePath = 'integration_test'
133+
s3EC2Bucket = 'ec2_bucket'
134+
s3EC2BasePath = 'ec2_base_path'
135+
s3ECSBucket = 'ecs_bucket'
136+
s3ECSBasePath = 'ecs_base_path'
137137
} else if (!s3EC2Bucket || !s3EC2BasePath || !s3ECSBucket || !s3ECSBasePath) {
138138
throw new IllegalArgumentException("not all options specified to run EC2/ECS tests are present")
139139
}
@@ -147,8 +147,6 @@ task thirdPartyTest(type: Test) {
147147
}
148148

149149
if (useFixture) {
150-
apply plugin: 'elasticsearch.test.fixtures'
151-
152150
testFixtures.useFixture(':test:fixtures:minio-fixture')
153151

154152
def minioAddress = {
@@ -206,39 +204,6 @@ if (useFixture) {
206204

207205
check.dependsOn(thirdPartyTest)
208206

209-
File parentFixtures = new File(project.buildDir, "fixtures")
210-
File s3FixtureFile = new File(parentFixtures, 's3Fixture.properties')
211-
212-
task s3FixtureProperties {
213-
outputs.file(s3FixtureFile)
214-
def s3FixtureOptions = [
215-
"tests.seed" : project.testSeed,
216-
"s3Fixture.permanent_bucket_name" : s3PermanentBucket,
217-
"s3Fixture.permanent_key" : s3PermanentAccessKey,
218-
"s3Fixture.temporary_bucket_name" : s3TemporaryBucket,
219-
"s3Fixture.temporary_key" : s3TemporaryAccessKey,
220-
"s3Fixture.temporary_session_token": s3TemporarySessionToken,
221-
"s3Fixture.ec2_bucket_name" : s3EC2Bucket,
222-
"s3Fixture.ecs_bucket_name" : s3ECSBucket,
223-
"s3Fixture.disableChunkedEncoding" : s3DisableChunkedEncoding
224-
]
225-
226-
doLast {
227-
file(s3FixtureFile).text = s3FixtureOptions.collect { k, v -> "$k = $v" }.join("\n")
228-
}
229-
}
230-
231-
/** A task to start the AmazonS3Fixture which emulates an S3 service **/
232-
task s3Fixture(type: AntFixture) {
233-
dependsOn testClasses
234-
dependsOn s3FixtureProperties
235-
inputs.file(s3FixtureFile)
236-
237-
env 'CLASSPATH', "${ -> project.sourceSets.test.runtimeClasspath.asPath }"
238-
executable = new File(project.runtimeJavaHome, 'bin/java')
239-
args 'org.elasticsearch.repositories.s3.AmazonS3Fixture', baseDir, s3FixtureFile.getAbsolutePath()
240-
}
241-
242207
processTestResources {
243208
Map<String, Object> expansions = [
244209
'permanent_bucket': s3PermanentBucket,
@@ -255,8 +220,13 @@ processTestResources {
255220
MavenFilteringHack.filter(it, expansions)
256221
}
257222

258-
integTest {
259-
dependsOn s3Fixture
223+
testFixtures.useFixture(':test:fixtures:s3-fixture')
224+
225+
def fixtureAddress = { fixture ->
226+
assert useFixture: 'closure should not be used without a fixture'
227+
int ephemeralPort = project(':test:fixtures:s3-fixture').postProcessFixture.ext."test.fixtures.${fixture}.tcp.80"
228+
assert ephemeralPort > 0
229+
'http://127.0.0.1:' + ephemeralPort
260230
}
261231

262232
testClusters.integTest {
@@ -268,12 +238,12 @@ testClusters.integTest {
268238
keystore 's3.client.integration_test_temporary.session_token', s3TemporarySessionToken
269239

270240
if (useFixture) {
271-
setting 's3.client.integration_test_permanent.endpoint', { "http://${s3Fixture.addressAndPort}" }, IGNORE_VALUE
272-
setting 's3.client.integration_test_temporary.endpoint', { "http://${s3Fixture.addressAndPort}" }, IGNORE_VALUE
273-
setting 's3.client.integration_test_ec2.endpoint', { "http://${s3Fixture.addressAndPort}" }, IGNORE_VALUE
241+
setting 's3.client.integration_test_permanent.endpoint', { "${-> fixtureAddress('s3-fixture')}" }, IGNORE_VALUE
242+
setting 's3.client.integration_test_temporary.endpoint', { "${-> fixtureAddress('s3-fixture-with-session-token')}" }, IGNORE_VALUE
243+
setting 's3.client.integration_test_ec2.endpoint', { "${-> fixtureAddress('s3-fixture-with-ec2')}" }, IGNORE_VALUE
274244
275245
// to redirect InstanceProfileCredentialsProvider to custom auth point
276-
systemProperty "com.amazonaws.sdk.ec2MetadataServiceEndpointOverride", { "http://${s3Fixture.addressAndPort}" }, IGNORE_VALUE
246+
systemProperty "com.amazonaws.sdk.ec2MetadataServiceEndpointOverride", { "${-> fixtureAddress('s3-fixture-with-ec2')}" }, IGNORE_VALUE
277247
} else {
278248
println "Using an external service to test the repository-s3 plugin"
279249
}
@@ -286,7 +256,7 @@ task s3ThirdPartyTests {
286256
if (useFixture) {
287257
task integTestECS(type: RestIntegTestTask.class) {
288258
description = "Runs tests using the ECS repository."
289-
dependsOn(project.s3Fixture)
259+
dependsOn('bundlePlugin')
290260
runner {
291261
systemProperty 'tests.rest.blacklist', [
292262
'repository_s3/10_basic/*',
@@ -299,9 +269,9 @@ if (useFixture) {
299269
check.dependsOn(integTestECS)
300270
301271
testClusters.integTestECS {
302-
setting 's3.client.integration_test_ecs.endpoint', { "http://${s3Fixture.addressAndPort}" }, IGNORE_VALUE
272+
setting 's3.client.integration_test_ecs.endpoint', { "${-> fixtureAddress('s3-fixture-with-ecs')}" }, IGNORE_VALUE
303273
plugin file(tasks.bundlePlugin.archiveFile)
304-
environment 'AWS_CONTAINER_CREDENTIALS_FULL_URI', { "http://${s3Fixture.addressAndPort}/ecs_credentials_endpoint" }, IGNORE_VALUE
274+
environment 'AWS_CONTAINER_CREDENTIALS_FULL_URI', { "${-> fixtureAddress('s3-fixture-with-ecs')}/ecs_credentials_endpoint" }, IGNORE_VALUE
305275
}
306276
307277
gradle.taskGraph.whenReady {
@@ -314,10 +284,10 @@ if (useFixture) {
314284
315285
thirdPartyAudit.ignoreMissingClasses (
316286
// classes are missing
317-
'javax.servlet.ServletContextEvent',
318-
'javax.servlet.ServletContextListener',
319-
'org.apache.avalon.framework.logger.Logger',
320-
'org.apache.log.Hierarchy',
287+
'javax.servlet.ServletContextEvent',
288+
'javax.servlet.ServletContextListener',
289+
'org.apache.avalon.framework.logger.Logger',
290+
'org.apache.log.Hierarchy',
321291
'org.apache.log.Logger',
322292
'software.amazon.ion.IonReader',
323293
'software.amazon.ion.IonSystem',
@@ -328,7 +298,7 @@ thirdPartyAudit.ignoreMissingClasses (
328298
'software.amazon.ion.system.IonSystemBuilder',
329299
'software.amazon.ion.system.IonTextWriterBuilder',
330300
'software.amazon.ion.system.IonWriterBuilder',
331-
// We don't use the kms dependency
301+
// We don't use the kms dependency
332302
'com.amazonaws.services.kms.AWSKMS',
333303
'com.amazonaws.services.kms.AWSKMSClient',
334304
'com.amazonaws.services.kms.model.DecryptRequest',

0 commit comments

Comments
 (0)