summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorfreva <valerijf@yahoo-inc.com>2016-12-01 16:29:18 +0100
committerfreva <valerijf@yahoo-inc.com>2016-12-01 16:29:18 +0100
commitef0fbf630f1685b22afbb8884974bf9473cd4001 (patch)
treeedfc02d57bb95c294b7f67d2d9c23ac268509930
parent0da1046ce54cd7b301bbf618d40e6cee9533cb66 (diff)
RunVespaLocal and RunSystemTests no longer regular tests
-rw-r--r--.gitignore3
-rw-r--r--docker-api/src/test/java/com/yahoo/vespa/hosted/dockerapi/RunSystemTests.java127
-rw-r--r--node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/docker/LocalZoneUtils.java10
-rw-r--r--node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/docker/RunVespaLocal.java42
4 files changed, 94 insertions, 88 deletions
diff --git a/.gitignore b/.gitignore
index f66ef979ab6..610eda0fd67 100644
--- a/.gitignore
+++ b/.gitignore
@@ -36,5 +36,4 @@ Testing
/.ninja_log
/build.ninja
/rules.ninja
-*_test_app
-*/target_container/* \ No newline at end of file
+*_test_app \ No newline at end of file
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 7aebd091654..504c9494414 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
@@ -5,16 +5,15 @@ 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.nio.file.StandardCopyOption;
import java.util.Optional;
+import java.util.concurrent.ExecutionException;
import java.util.logging.Logger;
import static org.junit.Assert.assertEquals;
@@ -26,92 +25,96 @@ import static org.junit.Assert.assertEquals;
* 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="docker.registry.hostname.com:1234"
- * SYSTEMTESTS_PATH="/path/to/git/repo/systemtests/"
- *
- *
- * To run systemtests with SNAPSHOT Vespa:
- * 1. Add "--vespa-version=6-SNAPSHOT" argument to {@link #runTest(DockerImpl, ContainerName, Path, String... arguments)}
- * 2. List all the modules that need to be built and added to local repository in order in
- * {@link #mavenInstallModules(DockerImpl, ContainerName, String... listOfModules)}
- * 3. Copy jars from {@code PATH_TO_VESPA_REPO_IN_CONTAINER.resolve(module).resolve(CONTAINER_TARGET_DIRECTORY).resolve(module.jar}
*
*</pre>
* @author freva
*/
public class RunSystemTests {
- private static final DockerImage VESPA_BASE_IMAGE = new DockerImage(
- System.getenv("VESPA_DOCKER_REGISTRY") + "/vespa/ci:6.50.111");
private static final DockerImage SYSTEMTESTS_DOCKER_IMAGE = new DockerImage("vespa-systest:latest");
- private static final String CONTAINER_TARGET_DIRECTORY = "target_container";
- private final Path PATH_TO_SYSTEMTESTS_IN_HOST = Paths.get(System.getenv("SYSTEMTESTS_PATH"));
- private final Path PATH_TO_SYSTEMTESTS_IN_CONTAINER = Paths.get("/systemtests");
- private final Path PATH_TO_VESPA_REPO_IN_HOST = Paths.get("").toAbsolutePath().getParent();
- private final Path PATH_TO_VESPA_REPO_IN_CONTAINER = Paths.get("/vespa");
- private final Path PATH_TO_TEST_RUNNER = PATH_TO_SYSTEMTESTS_IN_CONTAINER.resolve("bin/run_test.rb");
+ private final DockerImpl docker;
+ private final DockerImage vespaBaseImage;
+ private final Path pathToSystemtestsInHost;
+ private final Path pathToSystemtestsInContainer = Paths.get("/systemtests");
+ private final Path pathToVespaRepoInHost = Paths.get("").toAbsolutePath();
+ private final Path pathToVespaRepoInContainer = Paths.get("/vespa");
+ private final Path pathToTestRunner = pathToSystemtestsInContainer.resolve("bin/run_test.rb");
+ private final Path pathToLibJars = Paths.get("/home/y/lib/jars");
private final Logger logger = Logger.getLogger("systemtest");
- @Test
- public void runBasicSearch() throws IOException, InterruptedException {
- DockerImpl docker = DockerTestUtils.getDocker();
- ContainerName systemTestContainerName = new ContainerName("stest-1");
- Path testToRunPath = PATH_TO_SYSTEMTESTS_IN_CONTAINER.resolve("tests/search/basicsearch/basic_search.rb");
-
- logger.info("Building " + SYSTEMTESTS_DOCKER_IMAGE.asString());
- buildVespaSystestDockerImage(docker, VESPA_BASE_IMAGE);
+ public RunSystemTests(DockerImage vespaBaseImage, Path pathToSystemtestsInHost) {
+ this.docker = DockerTestUtils.getDocker();
+ this.vespaBaseImage = vespaBaseImage;
+ this.pathToSystemtestsInHost = pathToSystemtestsInHost;
+ }
- logger.info("Starting systemtests host");
- startSystemTestNodeIfNeeded(docker, systemTestContainerName);
+ /**
+ * @param systemtestHost name of the container that will execute the test, if it does not exist, a new
+ * one will be started.
+ * @param systemtestToRun relative path from the root of systemtests to the test to run, f.ex.
+ * tests/search/basicsearch/basic_search.rb
+ */
+ void runSystemTest(ContainerName systemtestHost, Path systemtestToRun, String... arguments) throws InterruptedException, ExecutionException, IOException {
+ startSystemTestNodeIfNeeded(systemtestHost);
-// mavenInstallModules(docker, systemTestContainerName, "docproc", "container-dev");
-// executeInContainer(docker, systemTestContainerName, "cp",
-// PATH_TO_VESPA_REPO_IN_CONTAINER.resolve("docproc").resolve(CONTAINER_TARGET_DIRECTORY).resolve("docproc.jar").toString(),
-// "/home/y/lib/jars/");
+ Path pathToSystetestToRun = pathToSystemtestsInContainer.resolve(systemtestToRun);
- logger.info("Running test " + testToRunPath);
- Integer testExitCode = runTest(docker, systemTestContainerName, testToRunPath);
+ logger.info("Running test " + pathToSystetestToRun);
+ Integer testExitCode = runTest(systemtestHost, pathToSystetestToRun, arguments);
assertEquals("Test did not finish with exit code 0", Integer.valueOf(0), testExitCode);
}
/**
- * This method runs mvn install inside container to update container's local repository, but because it runs as
- * root we have to move around the target/ otherwise mvn will fail on host next time you run it.
+ * This method runs mvn install inside container to update container's local repository, then copies any
+ * existing and updated file from target to /home/y/lib/jars.
+ *
+ * Because it runs as root we have to temporarly move around the target/ otherwise mvn will overwrite it and
+ * as root, making mvn on host fail next time it runs.
+ *
+ * @param containerName name of the container to install modules in, if it does not exist, a new
+ * one will be started.
+ * @param modules list of modules to install in order
*/
- private void mavenInstallModules(DockerImpl docker, ContainerName containerName, String... modules) throws InterruptedException, IOException {
+ void mavenInstallModules(ContainerName containerName, String... modules) throws InterruptedException, IOException, ExecutionException {
+ startSystemTestNodeIfNeeded(containerName);
+
for (String module : modules) {
- Path pathToModule = PATH_TO_VESPA_REPO_IN_CONTAINER.resolve(module);
- Path pathToTarget = PATH_TO_VESPA_REPO_IN_HOST.resolve(module).resolve("target");
- Path pathToTargetBackup = PATH_TO_VESPA_REPO_IN_HOST.resolve(module).resolve("target_bcp");
+ Path pathToModule = pathToVespaRepoInContainer.resolve(module);
+ Path pathToTargetInHost = pathToVespaRepoInHost.resolve(module).resolve("target");
+ Path pathToTargetBackupInHost = pathToVespaRepoInHost.resolve(module).resolve("target_bcp");
- if (Files.exists(pathToTarget)) {
- Files.move(pathToTarget, pathToTargetBackup, StandardCopyOption.REPLACE_EXISTING);
+ if (Files.exists(pathToTargetInHost)) {
+ Files.move(pathToTargetInHost, pathToTargetBackupInHost, StandardCopyOption.REPLACE_EXISTING);
}
try {
- assert 0 == executeInContainer(docker, containerName, "mvn", "-DskipTests", "-e",
+ executeInContainer(containerName, "mvn", "-DskipTests", "-e",
"-f=" + pathToModule.resolve("pom.xml"), "install");
+
+ executeInContainer(containerName, "rsync", "--archive", "--existing", "--update",
+ pathToModule.resolve("target").toString() + "/", pathToLibJars.toString() + "/");
} finally {
- executeInContainer(docker, containerName, "mv",
- PATH_TO_VESPA_REPO_IN_CONTAINER.resolve(module).resolve("target").toString(),
- PATH_TO_VESPA_REPO_IN_CONTAINER.resolve(module).resolve(CONTAINER_TARGET_DIRECTORY).toString());
+ executeInContainer(containerName, "rm", "-rf", pathToModule.resolve("target").toString());
- if (Files.exists(pathToTargetBackup)) {
- Files.move(pathToTargetBackup, pathToTarget);
+ if (Files.exists(pathToTargetBackupInHost)) {
+ Files.move(pathToTargetBackupInHost, pathToTargetInHost);
}
}
}
}
- private void startSystemTestNodeIfNeeded(Docker docker, ContainerName containerName) throws UnknownHostException, InterruptedException {
+ private void startSystemTestNodeIfNeeded(ContainerName containerName) throws IOException, InterruptedException, ExecutionException {
+ logger.info("Building " + SYSTEMTESTS_DOCKER_IMAGE.asString());
+ buildVespaSystestDockerImage(docker, vespaBaseImage);
+
Optional<Container> container = docker.getContainer(containerName.asString());
if (container.isPresent()) {
if (container.get().isRunning) return;
else docker.deleteContainer(containerName);
}
+ logger.info("Starting systemtests host");
InetAddress nodeInetAddress = InetAddress.getByName(containerName.asString());
docker.createContainerCommand(
SYSTEMTESTS_DOCKER_IMAGE,
@@ -125,8 +128,8 @@ public class RunSystemTests {
.withUlimit("core", -1, -1)
.withVolume(Paths.get(System.getProperty("user.home")).resolve(".m2/settings.xml").toString(), "/root/.m2/settings.xml")
.withVolume("/etc/hosts", "/etc/hosts")
- .withVolume(PATH_TO_SYSTEMTESTS_IN_HOST.toString(), PATH_TO_SYSTEMTESTS_IN_CONTAINER.toString())
- .withVolume(PATH_TO_VESPA_REPO_IN_HOST.toString(), PATH_TO_VESPA_REPO_IN_CONTAINER.toString())
+ .withVolume(pathToSystemtestsInHost.toString(), pathToSystemtestsInContainer.toString())
+ .withVolume(pathToVespaRepoInHost.toString(), pathToVespaRepoInContainer.toString())
.create();
docker.startContainer(containerName);
@@ -134,8 +137,13 @@ public class RunSystemTests {
Thread.sleep(1000);
}
- private void buildVespaSystestDockerImage(Docker docker, DockerImage vespaBaseImage) throws IOException {
- Path systestBuildDirectory = Paths.get("src/test/resources/systest/");
+ private void buildVespaSystestDockerImage(Docker docker, DockerImage vespaBaseImage) throws IOException, ExecutionException, InterruptedException {
+ if (!docker.imageIsDownloaded(vespaBaseImage)) {
+ logger.info("Pulling " + vespaBaseImage.asString() + " (This may take a while)");
+ docker.pullImageAsync(vespaBaseImage).get();
+ }
+
+ Path systestBuildDirectory = pathToVespaRepoInHost.resolve("docker-api/src/test/resources/systest/");
Path systestDockerfile = systestBuildDirectory.resolve("Dockerfile");
String dockerfileTemplate = new String(Files.readAllBytes(systestBuildDirectory.resolve("Dockerfile.template")))
@@ -145,7 +153,8 @@ public class RunSystemTests {
docker.buildImage(systestDockerfile.toFile(), SYSTEMTESTS_DOCKER_IMAGE);
}
- private static Integer executeInContainer(DockerImpl docker, ContainerName containerName, String... args) throws InterruptedException {
+ private Integer executeInContainer(ContainerName containerName, String... args) throws InterruptedException {
+ logger.info("Executing in container: " + String.join(" ", args));
ExecCreateCmdResponse response = docker.dockerClient.execCreateCmd(containerName.asString())
.withCmd(args)
.withAttachStdout(true)
@@ -159,12 +168,12 @@ public class RunSystemTests {
return state.getExitCode();
}
- private Integer runTest(DockerImpl docker, ContainerName containerName, Path testToRun, String... args) throws InterruptedException {
+ private Integer runTest(ContainerName containerName, Path testToRun, String... args) throws InterruptedException {
String[] combinedArgs = new String[args.length + 2];
- combinedArgs[0] = PATH_TO_TEST_RUNNER.toString();
+ combinedArgs[0] = pathToTestRunner.toString();
combinedArgs[1] = testToRun.toString();
System.arraycopy(args, 0, combinedArgs, 2, args.length);
- return executeInContainer(docker, containerName, combinedArgs);
+ return executeInContainer(containerName, combinedArgs);
}
}
diff --git a/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/docker/LocalZoneUtils.java b/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/docker/LocalZoneUtils.java
index a27f38c6955..0f86c9e753f 100644
--- a/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/docker/LocalZoneUtils.java
+++ b/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/docker/LocalZoneUtils.java
@@ -43,6 +43,7 @@ public class LocalZoneUtils {
private static final String APP_HOSTNAME_PREFIX = "cnode-";
private static final String TENANT_NAME = "localtenant";
private static final String APPLICATION_NAME = "default";
+ private static final Path PROJECT_ROOT = Paths.get("").toAbsolutePath();
public static boolean startConfigServerIfNeeded(Docker docker, Environment environment) throws UnknownHostException {
Optional<Container> container = docker.getContainer(CONFIG_SERVER_HOSTNAME);
@@ -83,7 +84,7 @@ public class LocalZoneUtils {
}
public static void buildVespaLocalDockerImage(Docker docker, DockerImage vespaBaseImage) throws IOException {
- Path dockerfileTemplatePath = Paths.get("Dockerfile.template");
+ Path dockerfileTemplatePath = Paths.get("node-admin/Dockerfile.template");
String dockerfileTemplate = new String(Files.readAllBytes(dockerfileTemplatePath))
.replaceAll("\\$NODE_ADMIN_FROM_IMAGE", vespaBaseImage.asString())
@@ -97,12 +98,11 @@ public class LocalZoneUtils {
*
* Therefore, copy docker-api jar to node-admin/target and used node-admin as build root instead of vespa/
*/
- Path projectRoot = Paths.get("").toAbsolutePath().getParent();
- Files.copy(projectRoot.resolve("docker-api/target/docker-api-jar-with-dependencies.jar"),
- projectRoot.resolve("node-admin/target/docker-api-jar-with-dependencies.jar"),
+ Files.copy(PROJECT_ROOT.resolve("docker-api/target/docker-api-jar-with-dependencies.jar"),
+ PROJECT_ROOT.resolve("node-admin/target/docker-api-jar-with-dependencies.jar"),
StandardCopyOption.REPLACE_EXISTING);
- Path dockerfilePath = Paths.get("Dockerfile").toAbsolutePath();
+ Path dockerfilePath = PROJECT_ROOT.resolve("node-admin/Dockerfile");
Files.write(dockerfilePath, dockerfileTemplate.getBytes());
docker.buildImage(dockerfilePath.getParent().toFile(), VESPA_LOCAL_IMAGE);
diff --git a/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/docker/RunVespaLocal.java b/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/docker/RunVespaLocal.java
index 16c2d58df7e..0c87544a700 100644
--- a/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/docker/RunVespaLocal.java
+++ b/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/docker/RunVespaLocal.java
@@ -17,11 +17,11 @@ import com.yahoo.vespa.hosted.node.admin.util.InetAddressResolver;
import com.yahoo.vespa.hosted.node.maintenance.Maintainer;
import com.yahoo.vespa.hosted.provision.Node;
import org.junit.Before;
-import org.junit.Test;
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.URL;
+import java.nio.file.Path;
import java.nio.file.Paths;
import java.time.Instant;
import java.util.Collections;
@@ -44,8 +44,6 @@ import static org.mockito.Mockito.when;
* 2. Set environmental variables in shell or e.g. ~/.bashrc:
* VESPA_HOME="/home/y"
* VESPA_WEB_SERVICE_PORT="4080"
- * VESPA_DOCKER_REGISTRY="<registry hostname>:<port>"
- * VESPA_PATH_TO_APP="<path to vespa app to deploy>.zip"
*
* Linux only:
* 1. Create /home/docker/container-storage with read/write permissions
@@ -58,18 +56,25 @@ import static org.mockito.Mockito.when;
* @author freva
*/
public class RunVespaLocal {
- private static final DockerImage VESPA_BASE_IMAGE = new DockerImage(
- System.getenv("VESPA_DOCKER_REGISTRY") + "/vespa/ci:6.50.111");
private static final Environment environment = new Environment(
Collections.singleton(LocalZoneUtils.CONFIG_SERVER_HOSTNAME), "prod", "vespa-local",
HostName.getLocalhost(), new InetAddressResolver());
private static final Maintainer maintainer = mock(Maintainer.class);
- private static final String PATH_TO_APP_TO_DEPLOY = System.getenv("VESPA_PATH_TO_APP");
+
+ private final Docker docker;
+ private final DockerImage vespaBaseImage;
+ private final Path pathToAppToDeploy;
+
private final Logger logger = Logger.getLogger("RunVespaLocal");
- @Test
- public void runVespaLocalTest() throws IOException, InterruptedException {
+ RunVespaLocal(DockerImage vespaBaseImage, Path pathToAppToDeploy) {
+ this.docker = DockerTestUtils.getDocker();
+ this.vespaBaseImage = vespaBaseImage;
+ this.pathToAppToDeploy = pathToAppToDeploy;
+ }
+
+ void runVespaLocalTest() throws IOException, InterruptedException, ExecutionException {
DockerTestUtils.OS operatingSystem = DockerTestUtils.getSystemOS();
if (operatingSystem == DockerTestUtils.OS.Mac_OS_X) {
when(maintainer.pathInHostFromPathInNode(any(), any())).thenReturn(Paths.get("/tmp/"));
@@ -82,9 +87,13 @@ public class RunVespaLocal {
return maintainer.pathInHostFromPathInNode((ContainerName) args[0], (String) args[1]);
});
- Docker docker = DockerTestUtils.getDocker();
+ if (!docker.imageIsDownloaded(vespaBaseImage)) {
+ logger.info("Pulling " + vespaBaseImage.asString() + " (This may take a while)");
+ docker.pullImageAsync(vespaBaseImage).get();
+ }
+
logger.info("Building " + LocalZoneUtils.VESPA_LOCAL_IMAGE.asString());
- LocalZoneUtils.buildVespaLocalDockerImage(docker, VESPA_BASE_IMAGE);
+ LocalZoneUtils.buildVespaLocalDockerImage(docker, vespaBaseImage);
logger.info("Starting config-server");
assertTrue("Could not start config server", LocalZoneUtils.startConfigServerIfNeeded(docker, environment));
@@ -104,7 +113,7 @@ public class RunVespaLocal {
}
logger.info("Deploying application");
- LocalZoneUtils.deployApp(docker, Paths.get(PATH_TO_APP_TO_DEPLOY));
+ LocalZoneUtils.deployApp(docker, pathToAppToDeploy);
logger.info("Starting node-admin");
NodeAdminStateUpdater nodeAdminStateUpdater = new ComponentsProviderImpl(docker,
@@ -130,15 +139,4 @@ public class RunVespaLocal {
LocalZoneUtils.deleteApplication();
nodeAdminStateUpdater.deconstruct();
}
-
- @Before
- public void before() throws ExecutionException, InterruptedException {
- assumeTrue(DockerTestUtils.dockerDaemonIsPresent());
- Docker docker = DockerTestUtils.getDocker();
-
- if (!docker.imageIsDownloaded(VESPA_BASE_IMAGE)) {
- logger.info("Pulling " + VESPA_BASE_IMAGE.asString() + " (This may take a while)");
- docker.pullImageAsync(VESPA_BASE_IMAGE).get();
- }
- }
}