summaryrefslogtreecommitdiffstats
path: root/docker-api
diff options
context:
space:
mode:
authorfreva <valerijf@yahoo-inc.com>2016-11-29 12:57:49 +0100
committerfreva <valerijf@yahoo-inc.com>2016-11-29 12:57:49 +0100
commiteea20988aaf4dd40b5f06c643c752f521bce7128 (patch)
tree80b66a1aa3164b4d8a1a4dcb234e40b189826759 /docker-api
parentdc142fc1c35c6e9cf0d3199434925afc8b43050b (diff)
Build test image and run systemtest from IDE
Diffstat (limited to 'docker-api')
-rw-r--r--docker-api/src/main/java/com/yahoo/vespa/hosted/dockerapi/DockerTestUtils.java4
-rw-r--r--docker-api/src/test/java/com/yahoo/vespa/hosted/dockerapi/RunSystemTests.java112
2 files changed, 85 insertions, 31 deletions
diff --git a/docker-api/src/main/java/com/yahoo/vespa/hosted/dockerapi/DockerTestUtils.java b/docker-api/src/main/java/com/yahoo/vespa/hosted/dockerapi/DockerTestUtils.java
index cf8d37f59ad..d2281f7e800 100644
--- a/docker-api/src/main/java/com/yahoo/vespa/hosted/dockerapi/DockerTestUtils.java
+++ b/docker-api/src/main/java/com/yahoo/vespa/hosted/dockerapi/DockerTestUtils.java
@@ -69,7 +69,9 @@ public class DockerTestUtils {
public static void createDockerTestNetworkIfNeeded(DockerImpl docker) {
if (! docker.dockerClient.listNetworksCmd().withNameFilter(DockerImpl.DOCKER_CUSTOM_MACVLAN_NETWORK_NAME).exec().isEmpty()) return;
- Network.Ipam ipam = new Network.Ipam().withConfig(new Network.Ipam.Config().withSubnet("172.18.0.0/16"));
+ Network.Ipam ipam = new Network.Ipam().withConfig(new Network.Ipam.Config()
+ .withSubnet("172.18.0.0/16")
+ .withGateway("172.18.0.1"));
docker.dockerClient.createNetworkCmd()
.withName(DockerImpl.DOCKER_CUSTOM_MACVLAN_NETWORK_NAME).withDriver("bridge").withIpam(ipam).exec();
}
diff --git a/docker-api/src/test/java/com/yahoo/vespa/hosted/dockerapi/RunSystemTests.java b/docker-api/src/test/java/com/yahoo/vespa/hosted/dockerapi/RunSystemTests.java
index d48470d1f9d..efad444329a 100644
--- a/docker-api/src/test/java/com/yahoo/vespa/hosted/dockerapi/RunSystemTests.java
+++ b/docker-api/src/test/java/com/yahoo/vespa/hosted/dockerapi/RunSystemTests.java
@@ -1,55 +1,107 @@
// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.hosted.dockerapi;
+import com.github.dockerjava.api.command.ExecCreateCmdResponse;
+import com.github.dockerjava.api.command.ExecStartCmd;
+import com.github.dockerjava.api.command.InspectExecResponse;
+import com.github.dockerjava.core.command.ExecStartResultCallback;
import org.junit.Test;
+import java.io.IOException;
import java.net.InetAddress;
import java.net.UnknownHostException;
+import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
+import java.util.Optional;
+import java.util.logging.Logger;
+
+import static org.junit.Assert.assertEquals;
/**
- * Systemtests image must be manually built because docker-java does not support --ulimit argument for docker build
- * yet (Novemeber 2016). To build, run:
- * $ sudo docker build --tag vespa-systest:latest --ulimit nofile=16384 --ulimit nproc=409600 --ulimit core=-1 docker-api/src/test/resources/systest/
- * from the root of this project.
+ * Requires docker daemon, see {@link com.yahoo.vespa.hosted.dockerapi.DockerTestUtils} for more details.
+ *
+ * To get started:
+ * 1. Add system test host hostnames to /etc/hosts:
+ * $ sudo ./vespa/node-admin/scripts/etc-hosts.sh
+ * 2. Set environmental variable in shell or e.g. ~/.bashrc:
+ * VESPA_DOCKER_REGISTRY="<registry hostname>:<port>"
*
* @author freva
*/
public class RunSystemTests {
- private static final ContainerName SYSTEM_TESTS_CONTAINER_NAME = new ContainerName("systest");
+ private static final DockerImage VESPA_BASE_IMAGE = new DockerImage(
+ System.getenv("VESPA_DOCKER_REGISTRY") + "/vespa/ci:6.50.111");
private static final DockerImage SYSTEM_TEST_DOCKER_IMAGE = new DockerImage("vespa-systest:latest");
+ private static final Path PATH_TO_SYSTEM_TESTS_IN_CONTAINER = Paths.get("/systemtests");
+ private final Logger logger = Logger.getLogger("RunVespaLocal");
- public void runBasicSearch() {
- Docker docker = DockerTestUtils.getDocker();
+// @Test
+ public void runBasicSearch() throws IOException, InterruptedException {
+ DockerImpl docker = DockerTestUtils.getDocker();
+ ContainerName systemTestContainerName = new ContainerName("stest-1");
+ Path testToRunPath = PATH_TO_SYSTEM_TESTS_IN_CONTAINER.resolve("tests/search/basicsearch/basic_search.rb");
+ logger.info("Building " + SYSTEM_TEST_DOCKER_IMAGE.asString());
+ buildVespaSystestDockerImage(docker, VESPA_BASE_IMAGE);
+
+ logger.info("Starting systemtests host");
Path pathToSystemsTestsRepo = Paths.get("/home/valerijf/dev/systemtests/");
- startSystemTestNode(docker, "cnode-20", pathToSystemsTestsRepo);
+ startSystemTestNodeIfNeeded(docker, systemTestContainerName, pathToSystemsTestsRepo);
+
+ logger.info("Running test " + testToRunPath);
+ Integer testExitCode = executeTestInHost(docker, testToRunPath, systemTestContainerName);
+ assertEquals("Test did not finish with exit code 0", Integer.valueOf(0), testExitCode);
+ }
+
+ private Integer executeTestInHost(DockerImpl docker, Path pathToTest, ContainerName hostToExecuteTest) throws InterruptedException {
+ ExecCreateCmdResponse response = docker.dockerClient.execCreateCmd(hostToExecuteTest.asString())
+ .withCmd(PATH_TO_SYSTEM_TESTS_IN_CONTAINER.resolve("bin/run_test.rb").toString(), pathToTest.toString())
+ .withAttachStdout(true)
+ .withAttachStderr(true)
+ .exec();
+
+ ExecStartCmd execStartCmd = docker.dockerClient.execStartCmd(response.getId());
+ execStartCmd.exec(new ExecStartResultCallback(System.out, System.err)).awaitCompletion();
+
+ InspectExecResponse state = docker.dockerClient.inspectExecCmd(execStartCmd.getExecId()).exec();
+ return state.getExitCode();
}
- private static void startSystemTestNode(Docker docker, String hostname, Path pathToSystemsTestsRepo) {
- try {
- InetAddress nodeInetAddress = InetAddress.getByName(hostname);
-
- docker.createContainerCommand(
- SYSTEM_TEST_DOCKER_IMAGE,
- SYSTEM_TESTS_CONTAINER_NAME,
- hostname)
- .withNetworkMode(DockerImpl.DOCKER_CUSTOM_MACVLAN_NETWORK_NAME)
- .withIpAddress(nodeInetAddress)
- .withEnvironment("USER", "root")
- .withUlimit("nofile", 16384, 16384)
- .withUlimit("nproc", 409600, 409600)
- .withUlimit("core", -1, -1)
- .withVolume("/etc/hosts", "/etc/hosts")
- .withVolume(pathToSystemsTestsRepo.toString(), "/systemtests")
- .create();
-
- docker.startContainer(SYSTEM_TESTS_CONTAINER_NAME);
- docker.executeInContainer(SYSTEM_TESTS_CONTAINER_NAME, "nohup", "/systemtests/bin/node_server.rb", "&");
- } catch (UnknownHostException e) {
- throw new RuntimeException("Failed to create container " + SYSTEM_TESTS_CONTAINER_NAME.asString(), e);
+ private void startSystemTestNodeIfNeeded(Docker docker, ContainerName containerName, Path pathToSystemsTestsRepo) throws UnknownHostException {
+ Optional<Container> container = docker.getContainer(containerName.asString());
+ if (container.isPresent()) {
+ if (container.get().isRunning) return;
+ else docker.deleteContainer(containerName);
}
+
+ InetAddress nodeInetAddress = InetAddress.getByName(containerName.asString());
+ docker.createContainerCommand(
+ SYSTEM_TEST_DOCKER_IMAGE,
+ containerName,
+ containerName.asString())
+ .withNetworkMode(DockerImpl.DOCKER_CUSTOM_MACVLAN_NETWORK_NAME)
+ .withIpAddress(nodeInetAddress)
+ .withEnvironment("USER", "root")
+ .withUlimit("nofile", 16384, 16384)
+ .withUlimit("nproc", 409600, 409600)
+ .withUlimit("core", -1, -1)
+ .withVolume("/etc/hosts", "/etc/hosts")
+ .withVolume(pathToSystemsTestsRepo.toString(), PATH_TO_SYSTEM_TESTS_IN_CONTAINER.toString())
+ .create();
+
+ docker.startContainer(containerName);
+ }
+
+ private void buildVespaSystestDockerImage(Docker docker, DockerImage vespaBaseImage) throws IOException {
+ Path systestBuildDirectory = Paths.get("src/test/resources/systest/");
+ Path systestDockerfile = systestBuildDirectory.resolve("Dockerfile");
+
+ String dockerfileTemplate = new String(Files.readAllBytes(systestBuildDirectory.resolve("Dockerfile.template")))
+ .replaceAll("\\$VESPA_BASE_IMAGE", vespaBaseImage.asString());
+ Files.write(systestDockerfile, dockerfileTemplate.getBytes());
+
+ docker.buildImage(systestDockerfile.toFile(), SYSTEM_TEST_DOCKER_IMAGE);
}
}