Skip to content

Commit

Permalink
Run some REST tests against a cluster running in docker containers (e…
Browse files Browse the repository at this point in the history
…lastic#39515)

* Run REST tests against a cluster running on docker

Closes elastic#38053
  • Loading branch information
alpar-t authored Jul 11, 2019
1 parent fea50c2 commit 5310dbf
Show file tree
Hide file tree
Showing 8 changed files with 474 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public void apply(Project project) {

extension.fixtures
.matching(fixtureProject -> fixtureProject.equals(project) == false)
.all(fixtureProject -> project.evaluationDependsOn(fixtureProject.getPath()));
.all(fixtureProject -> project.evaluationDependsOn(fixtureProject.getPath()));

conditionTaskByType(tasks, extension, Test.class);
conditionTaskByType(tasks, extension, getTaskClass("org.elasticsearch.gradle.test.RestIntegTestTask"));
Expand Down
59 changes: 53 additions & 6 deletions distribution/docker/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,20 @@ import org.elasticsearch.gradle.MavenFilteringHack
import org.elasticsearch.gradle.VersionProperties
import org.elasticsearch.gradle.testfixtures.TestFixturesPlugin

apply plugin: 'base'
apply plugin: 'elasticsearch.standalone-rest-test'
apply plugin: 'elasticsearch.test.fixtures'

configurations {
dockerPlugins
dockerSource
ossDockerSource
restSpec
}

dependencies {
dockerSource project(path: ":distribution:archives:linux-tar")
ossDockerSource project(path: ":distribution:archives:oss-linux-tar")
restSpec project(':rest-api-spec')
}

ext.expansions = { oss, local ->
Expand Down Expand Up @@ -77,20 +79,65 @@ void addCopyDockerContextTask(final boolean oss) {
}
}

def createAndSetWritable (Object... locations) {
locations.each { location ->
File file = file(location)
file.mkdirs()
file.setWritable(true, false)
}
}

task copyKeystore(type: Sync) {
from project(':x-pack:plugin:core')
.file('src/test/resources/org/elasticsearch/xpack/security/transport/ssl/certs/simple/testnode.jks')
into "${buildDir}/certs"
doLast {
file("${buildDir}/certs").setReadable(true, false)
file("${buildDir}/certs/testnode.jks").setReadable(true, false)
}
}

preProcessFixture {
if (TestFixturesPlugin.dockerComposeSupported()) {
dependsOn assemble
}
dependsOn copyKeystore
doLast {
// tests expect to have an empty repo
project.delete(
"${buildDir}/repo",
"${buildDir}/oss-repo"
)
createAndSetWritable(
"${buildDir}/repo",
"${buildDir}/oss-repo",
"${buildDir}/logs/default-1",
"${buildDir}/logs/default-2",
"${buildDir}/logs/oss-1",
"${buildDir}/logs/oss-2"
)
}
}

processTestResources {
from ({ zipTree(configurations.restSpec.singleFile) }) {
include 'rest-api-spec/api/**'
}
from project(':x-pack:plugin:core')
.file('src/test/resources/org/elasticsearch/xpack/security/transport/ssl/certs/simple/testnode.jks')
dependsOn configurations.restSpec
// don't add the tasks to build the docker images if we have no way of testing them
if (TestFixturesPlugin.dockerComposeSupported()) {
dependsOn assemble
}
}

postProcessFixture.doLast {
println "docker default distro is on port: ${ext."test.fixtures.elasticsearch-default.tcp.9200"}, " +
"oss is on: ${ext."test.fixtures.elasticsearch-oss.tcp.9200"}"
task integTest(type: Test) {
maxParallelForks = '1'
include '**/*IT.class'
}

// TODO: Add some actual tests, this will just check that the TPC port in the container is up
check.dependsOn postProcessFixture
check.dependsOn integTest

void addBuildDockerImage(final boolean oss) {
final Task buildDockerImageTask = task(taskName("build", oss, "DockerImage"), type: LoggedExec) {
Expand Down
126 changes: 121 additions & 5 deletions distribution/docker/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,133 @@
# Only used for testing the docker images
version: '3'
services:
elasticsearch-default:
elasticsearch-default-1:
image: elasticsearch:test
environment:
- node.name=elasticsearch-default-1
- cluster.initial_master_nodes=elasticsearch-default-1,elasticsearch-default-2
- discovery.seed_hosts=elasticsearch-default-2:9300
- cluster.name=elasticsearch-default
- discovery.type=single-node
- bootstrap.memory_lock=true
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
- path.repo=/tmp/es-repo
- node.attr.testattr=test
- cluster.routing.allocation.disk.watermark.low=1b
- cluster.routing.allocation.disk.watermark.high=1b
- cluster.routing.allocation.disk.watermark.flood_stage=1b
- script.max_compilations_rate=2048/1m
- node.store.allow_mmap=false
- xpack.security.enabled=true
- xpack.security.transport.ssl.enabled=true
- xpack.security.http.ssl.enabled=true
- xpack.security.authc.token.enabled=true
- xpack.security.audit.enabled=true
- xpack.security.authc.realms.file.file1.order=0
- xpack.security.authc.realms.native.native1.order=1
- xpack.security.transport.ssl.keystore.path=/usr/share/elasticsearch/config/testnode.jks
- xpack.security.http.ssl.keystore.path=/usr/share/elasticsearch/config/testnode.jks
- xpack.http.ssl.verification_mode=certificate
- xpack.security.transport.ssl.verification_mode=certificate
- xpack.license.self_generated.type=trial
volumes:
- ./build/repo:/tmp/es-repo
- ./build/certs/testnode.jks:/usr/share/elasticsearch/config/testnode.jks
- ./build/logs/default-1:/usr/share/elasticsearch/logs
- ./docker-test-entrypoint.sh:/docker-test-entrypoint.sh
ports:
- "9200"
elasticsearch-oss:
image: elasticsearch-oss:test
ulimits:
memlock:
soft: -1
hard: -1
entrypoint: /docker-test-entrypoint.sh
elasticsearch-default-2:
image: elasticsearch:test
environment:
- node.name=elasticsearch-default-2
- cluster.initial_master_nodes=elasticsearch-default-1,elasticsearch-default-2
- discovery.seed_hosts=elasticsearch-default-1:9300
- cluster.name=elasticsearch-default
- bootstrap.memory_lock=true
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
- path.repo=/tmp/es-repo
- node.attr.testattr=test
- cluster.routing.allocation.disk.watermark.low=1b
- cluster.routing.allocation.disk.watermark.high=1b
- cluster.routing.allocation.disk.watermark.flood_stage=1b
- script.max_compilations_rate=2048/1m
- node.store.allow_mmap=false
- xpack.security.enabled=true
- xpack.security.transport.ssl.enabled=true
- xpack.security.http.ssl.enabled=true
- xpack.security.authc.token.enabled=true
- xpack.security.audit.enabled=true
- xpack.security.authc.realms.file.file1.order=0
- xpack.security.authc.realms.native.native1.order=1
- xpack.security.transport.ssl.keystore.path=/usr/share/elasticsearch/config/testnode.jks
- xpack.security.http.ssl.keystore.path=/usr/share/elasticsearch/config/testnode.jks
- xpack.http.ssl.verification_mode=certificate
- xpack.security.transport.ssl.verification_mode=certificate
- xpack.license.self_generated.type=trial
volumes:
- ./build/repo:/tmp/es-repo
- ./build/certs/testnode.jks:/usr/share/elasticsearch/config/testnode.jks
- ./build/logs/default-2:/usr/share/elasticsearch/logs
- ./docker-test-entrypoint.sh:/docker-test-entrypoint.sh
ports:
- "9200"
ulimits:
memlock:
soft: -1
hard: -1
entrypoint: /docker-test-entrypoint.sh
elasticsearch-oss-1:
image: elasticsearch:test
environment:
- node.name=elasticsearch-oss-1
- cluster.initial_master_nodes=elasticsearch-oss-1,elasticsearch-oss-2
- discovery.seed_hosts=elasticsearch-oss-2:9300
- cluster.name=elasticsearch-oss
- bootstrap.memory_lock=true
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
- path.repo=/tmp/es-repo
- node.attr.testattr=test
- cluster.routing.allocation.disk.watermark.low=1b
- cluster.routing.allocation.disk.watermark.high=1b
- cluster.routing.allocation.disk.watermark.flood_stage=1b
- script.max_compilations_rate=2048/1m
- node.store.allow_mmap=false
volumes:
- ./build/oss-repo:/tmp/es-repo
- ./build/logs/oss-1:/usr/share/elasticsearch/logs
ports:
- "9200"
ulimits:
memlock:
soft: -1
hard: -1
elasticsearch-oss-2:
image: elasticsearch:test
environment:
- node.name=elasticsearch-oss-2
- cluster.initial_master_nodes=elasticsearch-oss-1,elasticsearch-oss-2
- discovery.seed_hosts=elasticsearch-oss-1:9300
- cluster.name=elasticsearch-oss
- discovery.type=single-node
- bootstrap.memory_lock=true
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
- path.repo=/tmp/es-repo
- node.attr.testattr=test
- cluster.routing.allocation.disk.watermark.low=1b
- cluster.routing.allocation.disk.watermark.high=1b
- cluster.routing.allocation.disk.watermark.flood_stage=1b
- script.max_compilations_rate=2048/1m
- node.store.allow_mmap=false
volumes:
- ./build/oss-repo:/tmp/es-repo
- ./build/logs/oss-2:/usr/share/elasticsearch/logs
ports:
- "9200"
ulimits:
memlock:
soft: -1
hard: -1
7 changes: 7 additions & 0 deletions distribution/docker/docker-test-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash
cd /usr/share/elasticsearch/bin/
./elasticsearch-users useradd x_pack_rest_user -p x-pack-test-password -r superuser || true
echo "testnode" > /tmp/password
cat /tmp/password | ./elasticsearch-keystore add -x -f -v 'xpack.security.transport.ssl.keystore.secure_password'
cat /tmp/password | ./elasticsearch-keystore add -x -f -v 'xpack.security.http.ssl.keystore.secure_password'
/usr/local/bin/docker-entrypoint.sh | tee > /usr/share/elasticsearch/logs/console.log
Loading

0 comments on commit 5310dbf

Please sign in to comment.