2018-06-15 09:49:14 -04:00
|
|
|
/*
|
|
|
|
* Licensed to Elasticsearch under one or more contributor
|
|
|
|
* license agreements. See the NOTICE file distributed with
|
|
|
|
* this work for additional information regarding copyright
|
|
|
|
* ownership. Elasticsearch licenses this file to you under
|
|
|
|
* the Apache License, Version 2.0 (the "License"); you may
|
|
|
|
* not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing,
|
|
|
|
* software distributed under the License is distributed on an
|
|
|
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
|
|
* KIND, either express or implied. See the License for the
|
|
|
|
* specific language governing permissions and limitations
|
|
|
|
* under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
import org.elasticsearch.gradle.MavenFilteringHack
|
2019-11-01 14:33:11 -04:00
|
|
|
import org.elasticsearch.gradle.info.BuildParams
|
2018-06-15 09:49:14 -04:00
|
|
|
import org.elasticsearch.gradle.test.AntFixture
|
2019-05-08 03:26:37 -04:00
|
|
|
import org.elasticsearch.gradle.test.RestIntegTestTask
|
2020-07-29 12:20:19 -04:00
|
|
|
import org.elasticsearch.gradle.test.rest.YamlRestTestPlugin
|
2018-06-15 09:49:14 -04:00
|
|
|
|
2019-07-10 18:42:28 -04:00
|
|
|
import static org.elasticsearch.gradle.PropertyNormalization.IGNORE_VALUE
|
|
|
|
|
2020-07-29 12:20:19 -04:00
|
|
|
apply plugin: 'elasticsearch.yaml-rest-test'
|
2018-06-15 09:49:14 -04:00
|
|
|
|
|
|
|
dependencies {
|
2020-07-29 12:20:19 -04:00
|
|
|
yamlRestTestImplementation project(':plugins:discovery-ec2')
|
2018-06-15 09:49:14 -04:00
|
|
|
}
|
|
|
|
|
2020-03-19 13:28:59 -04:00
|
|
|
restResources {
|
|
|
|
restApi {
|
|
|
|
includeCore '_common', 'cluster', 'nodes'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-15 09:49:14 -04:00
|
|
|
final int ec2NumberOfNodes = 3
|
|
|
|
|
|
|
|
Map<String, Object> expansions = [
|
2019-11-14 06:01:23 -05:00
|
|
|
'expected_nodes': ec2NumberOfNodes
|
2018-06-15 09:49:14 -04:00
|
|
|
]
|
|
|
|
|
2020-07-29 12:20:19 -04:00
|
|
|
processYamlRestTestResources {
|
2019-11-14 06:01:23 -05:00
|
|
|
inputs.properties(expansions)
|
|
|
|
MavenFilteringHack.filter(it, expansions)
|
2018-06-15 09:49:14 -04:00
|
|
|
}
|
|
|
|
|
2020-07-29 12:20:19 -04:00
|
|
|
// disable default yamlRestTest task, use spezialized ones below
|
|
|
|
yamlRestTest.enabled = false
|
2019-05-08 03:26:37 -04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* 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 ->
|
2019-11-14 06:01:23 -05:00
|
|
|
AntFixture fixture = tasks.create(name: "ec2Fixture${action}", type: AntFixture) {
|
2020-07-29 12:20:19 -04:00
|
|
|
dependsOn project.sourceSets.yamlRestTest.runtimeClasspath
|
|
|
|
env 'CLASSPATH', "${-> project.sourceSets.yamlRestTest.runtimeClasspath.asPath}"
|
2019-11-14 06:01:23 -05:00
|
|
|
executable = "${BuildParams.runtimeJavaHome}/bin/java"
|
2020-07-29 12:20:19 -04:00
|
|
|
args 'org.elasticsearch.discovery.ec2.AmazonEC2Fixture', baseDir, "${buildDir}/testclusters/yamlRestTest${action}-1/config/unicast_hosts.txt"
|
2019-11-14 06:01:23 -05:00
|
|
|
}
|
2019-05-08 03:26:37 -04:00
|
|
|
|
2020-07-29 12:20:19 -04:00
|
|
|
tasks.create(name: "yamlRestTest${action}", type: RestIntegTestTask) {
|
2020-09-03 22:26:44 -04:00
|
|
|
dependsOn fixture
|
2019-11-14 06:01:23 -05:00
|
|
|
}
|
2020-07-29 12:20:19 -04:00
|
|
|
SourceSetContainer sourceSets = project.getExtensions().getByType(SourceSetContainer.class);
|
|
|
|
SourceSet yamlRestTestSourceSet = sourceSets.getByName(YamlRestTestPlugin.SOURCE_SET_NAME)
|
|
|
|
"yamlRestTest${action}" {
|
2020-08-04 08:46:32 -04:00
|
|
|
setTestClassesDirs(yamlRestTestSourceSet.getOutput().getClassesDirs())
|
|
|
|
setClasspath(yamlRestTestSourceSet.getRuntimeClasspath())
|
2020-07-29 12:20:19 -04:00
|
|
|
}
|
|
|
|
check.dependsOn("yamlRestTest${action}")
|
2019-05-08 03:26:37 -04:00
|
|
|
|
2020-07-29 12:20:19 -04:00
|
|
|
testClusters."yamlRestTest${action}" {
|
2019-11-14 06:01:23 -05:00
|
|
|
numberOfNodes = ec2NumberOfNodes
|
2020-09-03 22:26:44 -04:00
|
|
|
plugin ':plugins:discovery-ec2'
|
2019-04-26 11:34:03 -04:00
|
|
|
|
2019-11-14 06:01:23 -05:00
|
|
|
setting 'discovery.seed_providers', 'ec2'
|
|
|
|
setting 'network.host', '_ec2_'
|
|
|
|
setting 'discovery.ec2.endpoint', { "http://${-> fixture.addressAndPort}" }, IGNORE_VALUE
|
2019-04-26 11:34:03 -04:00
|
|
|
|
2019-11-14 06:01:23 -05:00
|
|
|
systemProperty "com.amazonaws.sdk.ec2MetadataServiceEndpointOverride", { "http://${-> fixture.addressAndPort}" }, IGNORE_VALUE
|
|
|
|
}
|
2019-05-08 03:26:37 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Extra config for KeyStore
|
2020-07-29 12:20:19 -04:00
|
|
|
testClusters.yamlRestTestKeyStore {
|
2019-11-14 06:01:23 -05:00
|
|
|
keystore 'discovery.ec2.access_key', 'ec2_integration_test_access_key'
|
|
|
|
keystore 'discovery.ec2.secret_key', 'ec2_integration_test_secret_key'
|
2018-06-15 09:49:14 -04:00
|
|
|
}
|
2019-05-08 03:26:37 -04:00
|
|
|
|
|
|
|
// Extra config for EnvVariables
|
2020-07-29 12:20:19 -04:00
|
|
|
testClusters.yamlRestTestEnvVariables {
|
2019-11-14 06:01:23 -05:00
|
|
|
environment 'AWS_ACCESS_KEY_ID', 'ec2_integration_test_access_key'
|
|
|
|
environment 'AWS_SECRET_ACCESS_KEY', 'ec2_integration_test_secret_key'
|
2019-05-08 03:26:37 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Extra config for SystemProperties
|
2020-07-29 12:20:19 -04:00
|
|
|
testClusters.yamlRestTestSystemProperties {
|
2019-11-14 06:01:23 -05:00
|
|
|
systemProperty 'aws.accessKeyId', 'ec2_integration_test_access_key'
|
|
|
|
systemProperty 'aws.secretKey', 'ec2_integration_test_secret_key'
|
2019-05-08 03:26:37 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Extra config for ContainerCredentials
|
|
|
|
ec2FixtureContainerCredentials.env 'ACTIVATE_CONTAINER_CREDENTIALS', true
|
|
|
|
|
2020-07-29 12:20:19 -04:00
|
|
|
testClusters.yamlRestTestContainerCredentials {
|
2019-11-14 06:01:23 -05:00
|
|
|
environment 'AWS_CONTAINER_CREDENTIALS_FULL_URI',
|
|
|
|
{ "http://${-> tasks.findByName("ec2FixtureContainerCredentials").addressAndPort}/ecs_credentials_endpoint" }, IGNORE_VALUE
|
2019-05-08 03:26:37 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Extra config for InstanceProfile
|
|
|
|
ec2FixtureInstanceProfile.env 'ACTIVATE_INSTANCE_PROFILE', true
|