diff options
author | Harald Musum <musum@yahoo-inc.com> | 2016-12-02 09:38:12 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-12-02 09:38:12 +0100 |
commit | b118c2ddaa61500694644983e2f2a532ea3ff7e8 (patch) | |
tree | 31a02d18ece677b7c0d83f3079a4b53ca50d9377 /node-admin | |
parent | 88ebccfb70f5e6c8ceef2e074610a83821326471 (diff) | |
parent | 7a6f6a9452b970b16614b6f1d8111a7e9ec6d9d2 (diff) |
Merge pull request #1229 from yahoo/freva/run-systemtests-improvements
RunSystemTests improvements
Diffstat (limited to 'node-admin')
-rw-r--r-- | node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/docker/LocalZoneUtils.java | 10 | ||||
-rw-r--r-- | node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/docker/RunVespaLocal.java | 49 |
2 files changed, 32 insertions, 27 deletions
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..58dd64f48bc 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; @@ -36,6 +36,7 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; /** + * <pre> * Requires docker daemon, see {@link com.yahoo.vespa.hosted.dockerapi.DockerTestUtils} for more details. * * To get started: @@ -44,32 +45,43 @@ 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 * + * Example usage: + DockerImage vespaDockerBase = new DockerImage("docker-registry.ops.yahoo.com:4443/vespa/ci:6.52.35"); + Path pathToAppToDeploy = Paths.get("/home/valerijf/dev/basic-search/target/application.zip"); + RunVespaLocal runVespaLocal = new RunVespaLocal(vespaDockerBase, pathToAppToDeploy); + runVespaLocal.runVespaLocalTest(); * * Issues: * 1. If you cannot make Docker Toolbox start, try starting Virtualbox and turn off the "default" machine * 2. If the above is not enough try "sudo ifconfig vboxnet0 down && sudo ifconfig vboxnet0 up" (see https://github.com/docker/kitematic/issues/1193) + * </pre> * * @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 +94,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 +120,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 +146,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(); - } - } } |