diff options
Diffstat (limited to 'docker-api/src/test')
6 files changed, 0 insertions, 335 deletions
diff --git a/docker-api/src/test/java/com/yahoo/vespa/hosted/dockerapi/DockerImplTest.java b/docker-api/src/test/java/com/yahoo/vespa/hosted/dockerapi/DockerImplTest.java index 12e52dde494..654b5df3f3b 100644 --- a/docker-api/src/test/java/com/yahoo/vespa/hosted/dockerapi/DockerImplTest.java +++ b/docker-api/src/test/java/com/yahoo/vespa/hosted/dockerapi/DockerImplTest.java @@ -12,7 +12,6 @@ import com.github.dockerjava.api.command.InspectImageCmd; import com.github.dockerjava.api.command.InspectImageResponse; import com.github.dockerjava.api.command.PullImageCmd; import com.github.dockerjava.api.exception.NotFoundException; -import com.github.dockerjava.core.DefaultDockerClientConfig; import com.github.dockerjava.core.command.ExecStartResultCallback; import com.yahoo.metrics.simple.MetricReceiver; import com.yahoo.vespa.hosted.dockerapi.metrics.MetricReceiverWrapper; @@ -20,12 +19,6 @@ import org.junit.Test; import org.mockito.ArgumentCaptor; import org.mockito.Matchers; -import java.io.IOException; -import java.security.KeyManagementException; -import java.security.KeyStoreException; -import java.security.NoSuchAlgorithmException; -import java.security.UnrecoverableKeyException; - import static org.hamcrest.CoreMatchers.is; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertThat; @@ -39,60 +32,6 @@ import static org.mockito.Mockito.when; * @author tonytv */ public class DockerImplTest { - @Test - public void testDockerConfigWithUnixPath() throws UnrecoverableKeyException, NoSuchAlgorithmException, KeyStoreException, KeyManagementException { - String dockerUri = "unix:///var/run/docker.sock"; - DockerConfig config = createConfig(dockerUri, null, null, null); - DefaultDockerClientConfig clientConfig = DockerImpl.buildDockerClientConfig(config).build(); - - assertTrue("Docker uri incorrectly set", clientConfig.getDockerHost().toString().equals(dockerUri)); - assertTrue("SSL config was set when using socket", clientConfig.getSSLConfig() == null); - } - - @Test - public void testDockerConfigWithTcpPathWithoutSSL() { - String dockerUri = "tcp://127.0.0.1:2376"; - DockerConfig config = createConfig(dockerUri, null, null, null); - DefaultDockerClientConfig clientConfig = DockerImpl.buildDockerClientConfig(config).build(); - - assertTrue("Docker uri incorrectly set", clientConfig.getDockerHost().toString().equals(dockerUri)); - assertTrue("SSL config was set", clientConfig.getSSLConfig() == null); - } - - @Test - public void testDockerConfigWithTcpPathWithSslConfig() throws IOException, UnrecoverableKeyException, NoSuchAlgorithmException, KeyStoreException, KeyManagementException { - String dockerUri = "tcp://127.0.0.1:2376"; - DockerConfig config = createConfig(dockerUri, "/some/path/ca", "/some/path/cert", "/some/path/key"); - DefaultDockerClientConfig clientConfig = DockerImpl.buildDockerClientConfig(config).build(); - - assertTrue("Docker uri incorrectly set", clientConfig.getDockerHost().toString().equals(dockerUri)); - assertTrue("SSL config was not set", clientConfig.getSSLConfig() != null); - } - - @Test(expected=RuntimeException.class) - public void testDockerConfigWithTcpPathWithInvalidSslConfig() throws IOException, UnrecoverableKeyException, NoSuchAlgorithmException, KeyStoreException, KeyManagementException { - String dockerUri = "tcp://127.0.0.1:2376"; - DockerConfig config = createConfig(dockerUri, "/some/path/ca", "/some/path/cert", "/some/path/key"); - DefaultDockerClientConfig clientConfig = DockerImpl.buildDockerClientConfig(config).build(); - - assertTrue("Docker uri incorrectly set", clientConfig.getDockerHost().toString().equals(dockerUri)); - assertTrue("SSL config was not set", clientConfig.getSSLConfig() != null); - - // SSL certificates are read during the getSSLContext(), the invalid paths should cause a RuntimeException - clientConfig.getSSLConfig().getSSLContext(); - } - - private static DockerConfig createConfig(String uri, String caCertPath, String clientCertPath, String clientKeyPath) { - DockerConfig.Builder configBuilder = new DockerConfig.Builder(); - - if (uri != null) configBuilder.uri(uri); - if (caCertPath != null) configBuilder.caCertPath(caCertPath); - if (clientCertPath != null) configBuilder.clientCertPath(clientCertPath); - if (clientKeyPath != null) configBuilder.clientKeyPath(clientKeyPath); - - return new DockerConfig(configBuilder); - } - @Test public void testExecuteCompletes() throws Exception { diff --git a/docker-api/src/test/java/com/yahoo/vespa/hosted/dockerapi/DockerTest.java b/docker-api/src/test/java/com/yahoo/vespa/hosted/dockerapi/DockerTest.java deleted file mode 100644 index 18f87e5ae17..00000000000 --- a/docker-api/src/test/java/com/yahoo/vespa/hosted/dockerapi/DockerTest.java +++ /dev/null @@ -1,197 +0,0 @@ -// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -package com.yahoo.vespa.hosted.dockerapi; - -import org.apache.commons.io.IOUtils; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; - -import java.io.IOException; -import java.net.InetAddress; -import java.net.URL; -import java.util.Optional; -import java.util.concurrent.ExecutionException; - -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.assertTrue; -import static org.junit.Assume.assumeTrue; - -/** - * Requires docker daemon, see {@link com.yahoo.vespa.hosted.dockerapi.DockerTestUtils} for more details. - * - * @author freva - * @author dybdahl - */ -public class DockerTest { - private DockerImpl docker; - private static final DockerImage dockerImage = new DockerImage("simple-ipv6-server:Dockerfile"); - private static final String MANAGER_NAME = "docker-test"; - - // Ignored because the test is very slow (several minutes) when swap is enabled, to disable: (Linux) - // $ sudo swapoff -a - @Ignore - @Test - public void testOutOfMemoryDoesNotAffectOtherContainers() throws InterruptedException, ExecutionException, IOException { - String hostName1 = "docker10.test.yahoo.com"; - String hostName2 = "docker11.test.yahoo.com"; - ContainerName containerName1 = new ContainerName("docker-test-1"); - ContainerName containerName2 = new ContainerName("docker-test-2"); - InetAddress inetAddress1 = InetAddress.getByName("172.18.10.10"); - InetAddress inetAddress2 = InetAddress.getByName("172.18.10.11"); - - docker.createContainerCommand(dockerImage, ContainerResources.from(0, 0.1), containerName1, hostName1) - .withManagedBy(MANAGER_NAME) - .withNetworkMode(DockerImpl.DOCKER_CUSTOM_MACVLAN_NETWORK_NAME) - .withIpAddress(inetAddress1) - .create(); - docker.startContainer(containerName1); - - docker.createContainerCommand(dockerImage, ContainerResources.from(0, 0.1), containerName2, hostName2) - .withManagedBy(MANAGER_NAME) - .withNetworkMode(DockerImpl.DOCKER_CUSTOM_MACVLAN_NETWORK_NAME) - .withIpAddress(inetAddress2) - .create(); - docker.startContainer(containerName2); - - // 137 = 128 + 9 = kill -9 (SIGKILL), doesn't need to be run as "root", but "yahoo" does not exist in this basic image - assertThat(docker.executeInContainerAsRoot(containerName2, "python", "/pysrc/fillmem.py", "90").getExitStatus(), is(137)); - - // Verify that both HTTP servers are still up - testReachabilityFromHost("http://" + inetAddress1.getHostAddress() + "/ping"); - testReachabilityFromHost("http://" + inetAddress2.getHostAddress() + "/ping"); - - docker.stopContainer(containerName1); - docker.deleteContainer(containerName1); - - docker.stopContainer(containerName2); - docker.deleteContainer(containerName2); - } - - @Test - public void testContainerCycle() throws IOException, InterruptedException, ExecutionException { - final ContainerName containerName = new ContainerName("docker-test-foo"); - final String containerHostname = "hostName1"; - - docker.createContainerCommand(dockerImage, ContainerResources.UNLIMITED, containerName, containerHostname) - .withManagedBy(MANAGER_NAME).create(); - Optional<Container> container = docker.getContainer(containerName); - assertTrue(container.isPresent()); - assertEquals(container.get().state, Container.State.CREATED); - - docker.startContainer(containerName); - container = docker.getContainer(containerName); - assertTrue(container.isPresent()); - assertEquals(container.get().state, Container.State.RUNNING); - - docker.dockerClient.pauseContainerCmd(containerName.asString()).exec(); - container = docker.getContainer(containerName); - assertTrue(container.isPresent()); - assertEquals(container.get().state, Container.State.PAUSED); - - docker.dockerClient.unpauseContainerCmd(containerName.asString()).exec(); - docker.stopContainer(containerName); - container = docker.getContainer(containerName); - assertTrue(container.isPresent()); - assertEquals(container.get().state, Container.State.EXITED); - - docker.deleteContainer(containerName); - assertThat(docker.listAllContainersManagedBy(MANAGER_NAME).isEmpty(), is(true)); - } - - /** - * Test the expected behavior for exec when it times out - it should throw an exception when it times out, - * and before the process completes. - * - * The test timeout value is set quite high to avoid noise if screwdriver is slow but lower than the process time. - */ - @Test(expected = DockerExecTimeoutException.class, timeout = 2000) - public void testContainerExecHounorsTimeout() throws IOException, InterruptedException, ExecutionException { - final ContainerName containerName = new ContainerName("docker-test-foo"); - final String containerHostname = "hostName1"; - - docker.createContainerCommand(dockerImage, ContainerResources.UNLIMITED, containerName, containerHostname) - .withManagedBy(MANAGER_NAME).create(); - docker.startContainer(containerName); - docker.executeInContainerAsRoot(containerName, 1L, "sh", "-c", "sleep 5"); - } - - /** - * Test the expected behavior for exec that completes before specified timeout - it should return when the process finishes and not - * wait for the timeout. Some previous tests indicated that this was not behaving correctly. - * - * No timeout implies infinite timeout. - * - * The test timeout value is set quite high to avoid noise if screwdriver is slow - */ - @Test(timeout = 4000) - public void testContainerExecDoesNotBlockUntilTimeoutWhenCommandFinishesBeforeTimeout() throws IOException, InterruptedException, ExecutionException { - final ContainerName containerName = new ContainerName("docker-test-foo"); - final String containerHostname = "hostName1"; - - docker.createContainerCommand(dockerImage, ContainerResources.UNLIMITED, containerName, containerHostname) - .withManagedBy(MANAGER_NAME).create(); - docker.startContainer(containerName); - docker.executeInContainerAsRoot(containerName, 2L, "sh", "-c", "echo hei"); - - // Also test that this is the behavoir when not specifying timeout - docker.executeInContainerAsRoot(containerName,"sh", "-c", "echo hei"); - } - - @Test - public void testDockerNetworking() throws InterruptedException, ExecutionException, IOException { - String hostName1 = "docker10.test.yahoo.com"; - String hostName2 = "docker11.test.yahoo.com"; - ContainerName containerName1 = new ContainerName("docker-test-1"); - ContainerName containerName2 = new ContainerName("docker-test-2"); - InetAddress inetAddress1 = InetAddress.getByName("172.18.10.10"); - InetAddress inetAddress2 = InetAddress.getByName("172.18.10.11"); - - docker.createContainerCommand(dockerImage, ContainerResources.UNLIMITED, containerName1, hostName1) - .withManagedBy(MANAGER_NAME) - .withNetworkMode(DockerImpl.DOCKER_CUSTOM_MACVLAN_NETWORK_NAME).withIpAddress(inetAddress1).create(); - docker.startContainer(containerName1); - - docker.createContainerCommand(dockerImage, ContainerResources.UNLIMITED, containerName2, hostName2) - .withManagedBy(MANAGER_NAME) - .withNetworkMode(DockerImpl.DOCKER_CUSTOM_MACVLAN_NETWORK_NAME).withIpAddress(inetAddress2).create(); - docker.startContainer(containerName2); - - testReachabilityFromHost("http://" + inetAddress1.getHostAddress() + "/ping"); - testReachabilityFromHost("http://" + inetAddress2.getHostAddress() + "/ping"); - - String[] curlFromNodeToNode = new String[]{"curl", "-g", "http://" + inetAddress2.getHostAddress() + "/ping"}; - ProcessResult result = docker.executeInContainerAsRoot(containerName1, curlFromNodeToNode); - assertThat("Could not reach " + containerName2.asString() + " from " + containerName1.asString(), - result.getOutput(), is("pong\n")); - - docker.stopContainer(containerName1); - docker.deleteContainer(containerName1); - - docker.stopContainer(containerName2); - docker.deleteContainer(containerName2); - } - - @Before - public void setup() throws InterruptedException, ExecutionException, IOException { - if (docker == null) { - assumeTrue(DockerTestUtils.dockerDaemonIsPresent()); - - docker = DockerTestUtils.getDocker(); - DockerTestUtils.buildSimpleHttpServerDockerImage(docker, dockerImage); - } - - // Clean up any non deleted containers from previous tests - docker.getAllContainersManagedBy(MANAGER_NAME).forEach(container -> { - if (container.state.isRunning()) docker.stopContainer(container.name); - docker.deleteContainer(container.name); - }); - } - - private void testReachabilityFromHost(String target) throws IOException, InterruptedException { - URL url = new URL(target); - String containerServer = IOUtils.toString(url.openStream()); - assertThat(containerServer, is("pong\n")); - } -} diff --git a/docker-api/src/test/resources/simple-ipv6-server/Dockerfile b/docker-api/src/test/resources/simple-ipv6-server/Dockerfile deleted file mode 100644 index ee33894dbeb..00000000000 --- a/docker-api/src/test/resources/simple-ipv6-server/Dockerfile +++ /dev/null @@ -1,13 +0,0 @@ -# Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. - -FROM gliderlabs/alpine:3.4 - -# Install python and curl -RUN apk-install python curl - -# Copy source -ADD src/ pysrc - -# Run http server on port 80 -EXPOSE 80 -CMD ["python", "/pysrc/server.py"] diff --git a/docker-api/src/test/resources/simple-ipv6-server/README b/docker-api/src/test/resources/simple-ipv6-server/README deleted file mode 100644 index 0cb96035c42..00000000000 --- a/docker-api/src/test/resources/simple-ipv6-server/README +++ /dev/null @@ -1,10 +0,0 @@ -Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. - -This is the source for a basic docker image that runs a python HTTP server listening at IPv6 port 80. -The server serves two basic paths: - /ip - returns IP address of the requester - /ping - returns string "pong" - - -To build the image run: -$ sudo docker build -t "simple-ipv6-server:Dockerfile" <path to this directory> diff --git a/docker-api/src/test/resources/simple-ipv6-server/src/fillmem.py b/docker-api/src/test/resources/simple-ipv6-server/src/fillmem.py deleted file mode 100644 index b3990bea859..00000000000 --- a/docker-api/src/test/resources/simple-ipv6-server/src/fillmem.py +++ /dev/null @@ -1,11 +0,0 @@ -# Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. - -import sys -import time - -megabyte = [0] * (1024 * 1024 / 8) -data = megabyte * int(sys.argv[1]) - -while True: - time.sleep(1) - data.extend(megabyte) diff --git a/docker-api/src/test/resources/simple-ipv6-server/src/server.py b/docker-api/src/test/resources/simple-ipv6-server/src/server.py deleted file mode 100644 index 9b4d543d4ed..00000000000 --- a/docker-api/src/test/resources/simple-ipv6-server/src/server.py +++ /dev/null @@ -1,43 +0,0 @@ -# Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -import socket -from BaseHTTPServer import HTTPServer -from SimpleHTTPServer import SimpleHTTPRequestHandler - - -class MyHandler(SimpleHTTPRequestHandler): - def do_GET(self): - if self.path == '/ip': - self.send_response(200) - self.send_header('Content-type', 'text/html') - self.end_headers() - self.wfile.write('Your IP address is %s\n' % self.client_address[0]) - return - - elif self.path == '/ping': - self.send_response(200) - self.send_header('Content-type', 'text/html') - self.end_headers() - self.wfile.write('pong\n') - return - - else: - self.send_response(404) - self.send_header('Content-type', 'text/html') - self.end_headers() - self.wfile.write('Could not find ' + self.path + '! Try /ping or /ip.\n') - return - - -class DualHTTPServer(HTTPServer): - def __init__(self, address, handler): - self.address_family = socket.AF_INET6 if (':' in address[0]) else socket.AF_INET - HTTPServer.__init__(self, address, handler) - - -def main(ipv6): - server = DualHTTPServer(('::' if ipv6 else '', 80), MyHandler) - server.serve_forever() - - -if __name__ == '__main__': - main(False) |