|
|
@@ -20,6 +20,7 @@
|
|
|
|
|
|
import org.elasticsearch.gradle.MavenFilteringHack
|
|
|
import org.elasticsearch.gradle.test.AntFixture
|
|
|
+import org.elasticsearch.gradle.test.RestIntegTestTask
|
|
|
|
|
|
apply plugin: 'elasticsearch.standalone-rest-test'
|
|
|
apply plugin: 'elasticsearch.rest-test'
|
|
|
@@ -30,14 +31,6 @@ dependencies {
|
|
|
|
|
|
final int ec2NumberOfNodes = 3
|
|
|
|
|
|
-/** A task to start the AmazonEC2Fixture which emulates an EC2 service **/
|
|
|
-task ec2Fixture(type: AntFixture) {
|
|
|
- dependsOn compileTestJava
|
|
|
- env 'CLASSPATH', "${ -> project.sourceSets.test.runtimeClasspath.asPath }"
|
|
|
- executable = new File(project.runtimeJavaHome, 'bin/java')
|
|
|
- args 'org.elasticsearch.discovery.ec2.AmazonEC2Fixture', baseDir, "${buildDir}/testclusters/integTest-1/config/unicast_hosts.txt"
|
|
|
-}
|
|
|
-
|
|
|
Map<String, Object> expansions = [
|
|
|
'expected_nodes': ec2NumberOfNodes
|
|
|
]
|
|
|
@@ -47,20 +40,71 @@ processTestResources {
|
|
|
MavenFilteringHack.filter(it, expansions)
|
|
|
}
|
|
|
|
|
|
-integTest {
|
|
|
- dependsOn ec2Fixture, project(':plugins:discovery-ec2').bundlePlugin
|
|
|
-}
|
|
|
+// disable default test task, use spezialized ones below
|
|
|
+integTest.enabled = false
|
|
|
+
|
|
|
+/*
|
|
|
+ * Test using various credential providers (see also https://docs.aws.amazon.com/sdk-for-java/v2/developer-guide/credentials.html):
|
|
|
+ * - Elasticsearch Keystore (secure settings discovery.ec2.access_key and discovery.ec2.secret_key)
|
|
|
+ * - Java system properties (aws.accessKeyId and aws.secretAccessKey)
|
|
|
+ * - Environment variables (AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY)
|
|
|
+ * - ECS container credentials (loaded from ECS if the environment variable AWS_CONTAINER_CREDENTIALS_RELATIVE_URI is set)
|
|
|
+ * - Instance profile credentials (delivered through the EC2 metadata service)
|
|
|
+ *
|
|
|
+ * Notably missing is a test for the default credential profiles file, which is located at ~/.aws/credentials and would at least require a
|
|
|
+ * custom Java security policy to work.
|
|
|
+ */
|
|
|
+['KeyStore', 'EnvVariables', 'SystemProperties', 'ContainerCredentials', 'InstanceProfile'].forEach { action ->
|
|
|
+ AntFixture fixture = tasks.create(name: "ec2Fixture${action}", type: AntFixture) {
|
|
|
+ dependsOn compileTestJava
|
|
|
+ env 'CLASSPATH', "${ -> project.sourceSets.test.runtimeClasspath.asPath }"
|
|
|
+ executable = new File(project.runtimeJavaHome, 'bin/java')
|
|
|
+ args 'org.elasticsearch.discovery.ec2.AmazonEC2Fixture', baseDir, "${buildDir}/testclusters/integTest${action}-1/config/unicast_hosts.txt"
|
|
|
+ }
|
|
|
+
|
|
|
+ tasks.create(name: "integTest${action}", type: RestIntegTestTask) {
|
|
|
+ dependsOn fixture, project(':plugins:discovery-ec2').bundlePlugin
|
|
|
+ }
|
|
|
+
|
|
|
+ check.dependsOn("integTest${action}")
|
|
|
+
|
|
|
+ testClusters."integTest${action}" {
|
|
|
+ numberOfNodes = ec2NumberOfNodes
|
|
|
+ plugin file(project(':plugins:discovery-ec2').bundlePlugin.archiveFile)
|
|
|
|
|
|
-testClusters.integTest {
|
|
|
- numberOfNodes = ec2NumberOfNodes
|
|
|
- plugin file(project(':plugins:discovery-ec2').bundlePlugin.archiveFile)
|
|
|
+ setting 'discovery.seed_providers', 'ec2'
|
|
|
+ setting 'network.host', '_ec2_'
|
|
|
+ setting 'discovery.ec2.endpoint', { "http://${-> fixture.addressAndPort}" }
|
|
|
|
|
|
+ systemProperty "com.amazonaws.sdk.ec2MetadataServiceEndpointOverride", { "http://${-> fixture.addressAndPort}" }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+// Extra config for KeyStore
|
|
|
+testClusters.integTestKeyStore {
|
|
|
keystore 'discovery.ec2.access_key', 'ec2_integration_test_access_key'
|
|
|
keystore 'discovery.ec2.secret_key', 'ec2_integration_test_secret_key'
|
|
|
-
|
|
|
- setting 'discovery.seed_providers', 'ec2'
|
|
|
- setting 'network.host', '_ec2_'
|
|
|
- setting 'discovery.ec2.endpoint', { "http://${ec2Fixture.addressAndPort}" }
|
|
|
-
|
|
|
- systemProperty "com.amazonaws.sdk.ec2MetadataServiceEndpointOverride", { "http://${ec2Fixture.addressAndPort}" }
|
|
|
}
|
|
|
+
|
|
|
+// Extra config for EnvVariables
|
|
|
+testClusters.integTestEnvVariables {
|
|
|
+ environment 'AWS_ACCESS_KEY_ID', 'ec2_integration_test_access_key'
|
|
|
+ environment 'AWS_SECRET_ACCESS_KEY', 'ec2_integration_test_secret_key'
|
|
|
+}
|
|
|
+
|
|
|
+// Extra config for SystemProperties
|
|
|
+testClusters.integTestSystemProperties {
|
|
|
+ systemProperty 'aws.accessKeyId', 'ec2_integration_test_access_key'
|
|
|
+ systemProperty 'aws.secretKey', 'ec2_integration_test_secret_key'
|
|
|
+}
|
|
|
+
|
|
|
+// Extra config for ContainerCredentials
|
|
|
+ec2FixtureContainerCredentials.env 'ACTIVATE_CONTAINER_CREDENTIALS', true
|
|
|
+
|
|
|
+testClusters.integTestContainerCredentials {
|
|
|
+ environment 'AWS_CONTAINER_CREDENTIALS_FULL_URI',
|
|
|
+ { "http://${-> tasks.findByName("ec2FixtureContainerCredentials").addressAndPort}/ecs_credentials_endpoint" }
|
|
|
+}
|
|
|
+
|
|
|
+// Extra config for InstanceProfile
|
|
|
+ec2FixtureInstanceProfile.env 'ACTIVATE_INSTANCE_PROFILE', true
|