public static CubeConfiguration fromMap(Map<String, String> map) { CubeConfiguration cubeConfiguration = new CubeConfiguration(); if (map.containsKey(CONNECTION_MODE)) { cubeConfiguration.connectionMode = ConnectionMode.valueOf(ConnectionMode.class, map.get(CONNECTION_MODE)); } return cubeConfiguration; }
public static CubeConfiguration fromMap(Map<String, String> map) { CubeConfiguration cubeConfiguration = new CubeConfiguration(); if (map.containsKey(CONNECTION_MODE)) { cubeConfiguration.connectionMode = ConnectionMode.valueOf(ConnectionMode.class, map.get(CONNECTION_MODE)); } return cubeConfiguration; }
@Test public void shouldNotChangeServerUriInCaseODockerInsideDockerIfItIsDisabled() { Map<String, String> config = new HashMap<>(); config.put(CubeDockerConfiguration.DOCKER_URI, "tcp://dockerHost:22222"); config.put(CubeDockerConfiguration.DIND_RESOLUTION, "false"); when(extensionDef.getExtensionProperties()).thenReturn(config); when(arquillianDescriptor.extension("docker")).thenReturn(extensionDef); when(commandLineExecutor.execCommand("boot2docker", "ip")).thenReturn("192.168.0.1"); when(commandLineExecutor.execCommand("docker-machine")).thenThrow(new RuntimeException()); when(top.isSpinning()).thenReturn(true); fire(new CubeConfiguration()); assertThat(config, hasEntry(CubeDockerConfiguration.DOCKER_URI, "tcp://192.168.0.1:22222")); }
@Test public void shouldChangeServerUriInCaseOfRunningDockerInsideDocker() { Map<String, String> config = new HashMap<>(); config.put(CubeDockerConfiguration.DOCKER_URI, "https://dockerHost:22222"); when(extensionDef.getExtensionProperties()).thenReturn(config); when(arquillianDescriptor.extension("docker")).thenReturn(extensionDef); when(commandLineExecutor.execCommand("boot2docker", "ip")).thenReturn("192.168.0.1"); when(commandLineExecutor.execCommand("docker-machine")).thenThrow(new RuntimeException()); when(top.isSpinning()).thenReturn(true); fire(new CubeConfiguration()); assertThat(config, hasEntry(CubeDockerConfiguration.DOCKER_URI, OperatingSystemFamily.DIND.getServerUri())); }
@Test public void shouldUseDockerMachineIfDockerHostIsSetOnServerURIAndMachineNameIsSet() { Map<String, String> config = new HashMap<>(); config.put(CubeDockerConfiguration.DOCKER_URI, "tcp://dockerHost:22222"); config.put(CubeDockerConfiguration.DOCKER_MACHINE_NAME, "dev"); when(extensionDef.getExtensionProperties()).thenReturn(config); when(arquillianDescriptor.extension("docker")).thenReturn(extensionDef); when(commandLineExecutor.execCommandAsArray("docker-machine", "ls")) .thenReturn(Arrays.asList( "NAME ACTIVE DRIVER STATE URL SWARM", "dev * virtualbox Running tcp://192.168.0.2:222222 ")); when(commandLineExecutor.execCommand("docker-machine", "ip", "dev")).thenReturn("192.168.0.2"); fire(new CubeConfiguration()); assertThat(config, hasEntry(CubeDockerConfiguration.DOCKER_URI, "tcp://192.168.0.2:22222")); }
@Test public void shouldDumpCubeConfiguration() throws Exception { Map<String, String> config = new HashMap<>(); config.put(CubeDockerConfiguration.DOCKER_URI, "https://dockerHost:22222"); when(extensionDef.getExtensionProperties()).thenReturn(config); when(arquillianDescriptor.extension("docker")).thenReturn(extensionDef); when(extensionDef.getExtensionProperties()).thenReturn(config); when(arquillianDescriptor.extension("docker")).thenReturn(extensionDef); when(commandLineExecutor.execCommand("boot2docker", "ip")).thenReturn("192.168.0.1"); when(commandLineExecutor.execCommand("docker-machine")).thenThrow(new RuntimeException()); PrintStream old = System.out; ByteArrayOutputStream baos = new ByteArrayOutputStream(); System.setOut(new PrintStream(baos)); CubeConfiguration cubeConfiguration = new CubeConfiguration(); fire(cubeConfiguration); System.out.flush(); System.setOut(old); assertThat(baos.toString(), containsString("CubeDockerConfiguration:")); }
@Test public void shouldStartDockerMachineIfItIsStoppedAndMachineNameIsSet() { Map<String, String> config = new HashMap<>(); config.put(CubeDockerConfiguration.DOCKER_URI, "tcp://dockerHost:22222"); config.put(CubeDockerConfiguration.DOCKER_MACHINE_NAME, "dev"); when(extensionDef.getExtensionProperties()).thenReturn(config); when(arquillianDescriptor.extension("docker")).thenReturn(extensionDef); when(commandLineExecutor.execCommandAsArray("docker-machine", "ls")) .thenReturn(Arrays.asList( "NAME ACTIVE DRIVER STATE URL SWARM", "dev * virtualbox Stopped tcp://192.168.0.2:222222 ")); when(commandLineExecutor.execCommand("docker-machine", "ip", "dev")).thenReturn("192.168.0.2"); fire(new CubeConfiguration()); assertThat(config, hasEntry(CubeDockerConfiguration.DOCKER_URI, "tcp://192.168.0.2:22222")); verify(commandLineExecutor, times(1)).execCommand("docker-machine", "start", "dev"); }
@Test public void shouldUseDefaultsInCaseOfNotHavingDockerMachineInstalledAndNoDockerUriNorMachineName() { Assume.assumeTrue(SystemUtils.IS_OS_MAC_OSX || SystemUtils.IS_OS_WINDOWS); Map<String, String> config = new HashMap<>(); when(extensionDef.getExtensionProperties()).thenReturn(config); when(arquillianDescriptor.extension("docker")).thenReturn(extensionDef); when(commandLineExecutor.execCommand("boot2docker", "ip")).thenReturn("192.168.0.1"); when(commandLineExecutor.execCommand("docker-machine")).thenThrow(new IllegalArgumentException()); bindNonExistingDockerSocketOS(); fire(new CubeConfiguration()); assertThat(config, hasEntry(CubeDockerConfiguration.DOCKER_URI, "tcp://192.168.0.1:2376")); }
@Test public void tlsVerifyShouldBeFalseInCaseOfSetToTrueAndHttpServerUri() { Map<String, String> config = new HashMap<>(); config.put(CubeDockerConfiguration.DOCKER_URI, "http://192.168.0.2:22222"); config.put(CubeDockerConfiguration.TLS_VERIFY, "true"); when(extensionDef.getExtensionProperties()).thenReturn(config); when(arquillianDescriptor.extension("docker")).thenReturn(extensionDef); when(commandLineExecutor.execCommand("docker-machine")).thenThrow(new RuntimeException()); fire(new CubeConfiguration()); assertThat(config, hasEntry(CubeDockerConfiguration.DOCKER_URI, "tcp://192.168.0.2:22222")); assertThat(config, hasEntry(CubeDockerConfiguration.TLS_VERIFY, "false")); assertThat(config, not(hasKey(CubeDockerConfiguration.CERT_PATH))); }
@Test public void tlsVerifyShouldBeFalseInCaseOfHttpServerUri() throws Exception { Map<String, String> config = new HashMap<>(); config.put(CubeDockerConfiguration.DOCKER_URI, "http://192.168.0.2:22222"); when(extensionDef.getExtensionProperties()).thenReturn(config); when(arquillianDescriptor.extension("docker")).thenReturn(extensionDef); when(commandLineExecutor.execCommand("docker-machine")).thenThrow(new RuntimeException()); fire(new CubeConfiguration()); assertThat(config, hasEntry(CubeDockerConfiguration.DOCKER_URI, "tcp://192.168.0.2:22222")); assertThat(config, hasEntry(CubeDockerConfiguration.TLS_VERIFY, "false")); assertThat(config, not(hasKey(CubeDockerConfiguration.CERT_PATH))); }
@Test public void tlsVerifyShouldBeTrueInCaseOfSetToFalseAndDockerHostTagNotPresent() { Map<String, String> config = new HashMap<>(); config.put(CubeDockerConfiguration.DOCKER_URI, "tcp://192.168.0.2:22222"); config.put(CubeDockerConfiguration.TLS_VERIFY, "false"); when(extensionDef.getExtensionProperties()).thenReturn(config); when(arquillianDescriptor.extension("docker")).thenReturn(extensionDef); when(commandLineExecutor.execCommand("docker-machine")).thenThrow(new RuntimeException()); fire(new CubeConfiguration()); assertThat(config, hasEntry(CubeDockerConfiguration.DOCKER_URI, "tcp://192.168.0.2:22222")); assertThat(config, hasEntry(CubeDockerConfiguration.TLS_VERIFY, "false")); assertThat(config, not(hasKey(CubeDockerConfiguration.CERT_PATH))); }
@Test public void tlsVerifyShouldBeTrueInCaseOfHttpsServerUri() { Map<String, String> config = new HashMap<>(); config.put(CubeDockerConfiguration.DOCKER_URI, "https://192.168.0.2:22222"); when(extensionDef.getExtensionProperties()).thenReturn(config); when(arquillianDescriptor.extension("docker")).thenReturn(extensionDef); when(commandLineExecutor.execCommand("docker-machine")).thenThrow(new RuntimeException()); fire(new CubeConfiguration()); assertThat(config, hasEntry(CubeDockerConfiguration.DOCKER_URI, "tcp://192.168.0.2:22222")); assertThat(config, hasEntry(CubeDockerConfiguration.TLS_VERIFY, "true")); assertThat(config, hasEntry(is(CubeDockerConfiguration.CERT_PATH), defaultBootToDockerCertPath())); }
@Test public void tlsVerifyShouldBeFalseInCaseOfSetToFalseAndDockerHostTagPresent() { Map<String, String> config = new HashMap<>(); config.put(CubeDockerConfiguration.DOCKER_URI, "tcp://dockerHost:22222"); config.put(CubeDockerConfiguration.TLS_VERIFY, "false"); when(extensionDef.getExtensionProperties()).thenReturn(config); when(arquillianDescriptor.extension("docker")).thenReturn(extensionDef); when(commandLineExecutor.execCommand("boot2docker", "ip")).thenReturn("192.168.0.2"); when(commandLineExecutor.execCommand("docker-machine")).thenThrow(new RuntimeException()); fire(new CubeConfiguration()); assertThat(config, hasEntry(CubeDockerConfiguration.DOCKER_URI, "tcp://192.168.0.2:22222")); assertThat(config, hasEntry(CubeDockerConfiguration.TLS_VERIFY, "false")); assertThat(config, not(hasKey(CubeDockerConfiguration.CERT_PATH))); }
@Test public void tlsVerifyShouldBeTrueInCaseOfSetToFalseAndHttpsServerUri() { Map<String, String> config = new HashMap<>(); config.put(CubeDockerConfiguration.DOCKER_URI, "https://192.168.0.2:22222"); config.put(CubeDockerConfiguration.TLS_VERIFY, "false"); when(extensionDef.getExtensionProperties()).thenReturn(config); when(arquillianDescriptor.extension("docker")).thenReturn(extensionDef); when(commandLineExecutor.execCommand("docker-machine")).thenThrow(new RuntimeException()); fire(new CubeConfiguration()); assertThat(config, hasEntry(CubeDockerConfiguration.DOCKER_URI, "tcp://192.168.0.2:22222")); assertThat(config, hasEntry(CubeDockerConfiguration.TLS_VERIFY, "true")); assertThat(config, hasEntry(is(CubeDockerConfiguration.CERT_PATH), defaultBootToDockerCertPath())); }
@Before @SuppressWarnings("unchecked") public void setup() { when(cube.getId()).thenReturn(CUBE_ID); when(container.getName()).thenReturn(CUBE_ID); when(container.getDeployableContainer()).thenReturn(deployableContainer); when(container.getContainerConfiguration()).thenReturn(containerDef); when(containerDef.getContainerProperties()).thenReturn(Collections.EMPTY_MAP); when(containerRegistry.getContainers()).thenReturn(Arrays.asList(container)); registry = new LocalCubeRegistry(); registry.addCube(cube); bind(ApplicationScoped.class, CubeRegistry.class, registry); bind(ApplicationScoped.class, ContainerRegistry.class, containerRegistry); bind(ApplicationScoped.class, CubeConfiguration.class, new CubeConfiguration()); }
@Test public void shouldSetServerIpWithLocalhostInCaseOfNativeLinuxInstallation() { String originalVar = System.getProperty(CubeDockerConfigurator.DOCKER_HOST); try { System.setProperty(CubeDockerConfigurator.DOCKER_HOST, "unix:///var/run/docker.sock"); Map<String, String> config = new HashMap<>(); when(extensionDef.getExtensionProperties()).thenReturn(config); when(arquillianDescriptor.extension("docker")).thenReturn(extensionDef); when(commandLineExecutor.execCommand("docker-machine")).thenThrow(new RuntimeException()); fire(new CubeConfiguration()); assertThat(config, hasEntry(CubeDockerConfiguration.DOCKER_URI, "unix:///var/run/docker.sock")); assertThat(config, hasEntry(CubeDockerConfiguration.DOCKER_SERVER_IP, "localhost")); } finally { if (originalVar != null) { System.setProperty(CubeDockerConfigurator.DOCKER_HOST, originalVar); } else { System.clearProperty(CubeDockerConfigurator.DOCKER_HOST); } } }
@Test public void shouldUseBoot2DockerIfDockerHostIsSetOnServerURIByDefault() { assumeThat(new OperatingSystemResolver().currentOperatingSystem().getFamily(), is(not(OperatingSystemFamily.LINUX))); Map<String, String> config = new HashMap<>(); config.put(CubeDockerConfiguration.DOCKER_URI, "tcp://dockerHost:22222"); when(extensionDef.getExtensionProperties()).thenReturn(config); when(arquillianDescriptor.extension("docker")).thenReturn(extensionDef); when(commandLineExecutor.execCommand("boot2docker", "ip")).thenReturn("192.168.0.1"); when(commandLineExecutor.execCommand("docker-machine")).thenThrow(new RuntimeException()); fire(new CubeConfiguration()); assertThat(config, hasEntry(CubeDockerConfiguration.DOCKER_URI, "tcp://192.168.0.1:22222")); assertThat(config, hasEntry(is(CubeDockerConfiguration.CERT_PATH), defaultBootToDockerCertPath())); }
@Test public void tlsVerifyShouldBeTrueInCaseOfDockerMachine() { Map<String, String> config = new HashMap<>(); config.put(CubeDockerConfiguration.DOCKER_URI, "https://dockerHost:22222"); config.put(CubeDockerConfiguration.DOCKER_MACHINE_NAME, "dev"); when(extensionDef.getExtensionProperties()).thenReturn(config); when(arquillianDescriptor.extension("docker")).thenReturn(extensionDef); when(commandLineExecutor.execCommand("docker-machine", "ip", "dev")).thenReturn("192.168.0.2"); when(commandLineExecutor.execCommandAsArray("docker-machine", "ls")) .thenReturn(Arrays.asList( "NAME ACTIVE DRIVER STATE URL SWARM", "dev * virtualbox Running tcp://192.168.0.2:222222 ")); fire(new CubeConfiguration()); assertThat(config, hasEntry(CubeDockerConfiguration.DOCKER_URI, "tcp://192.168.0.2:22222")); assertThat(config, hasEntry(CubeDockerConfiguration.TLS_VERIFY, "true")); assertThat(config, hasEntry(is(CubeDockerConfiguration.CERT_PATH), defaultDockerMachineCertPath())); }
@Test public void shouldNotUseDockerMachineIfDockerHostIsNotSetNotDockerMachineAndTwoMachineIsRunning() { Assume.assumeTrue(SystemUtils.IS_OS_MAC_OSX || SystemUtils.IS_OS_WINDOWS); Map<String, String> config = new HashMap<>(); when(extensionDef.getExtensionProperties()).thenReturn(config); when(arquillianDescriptor.extension("docker")).thenReturn(extensionDef); when(commandLineExecutor.execCommand("docker-machine", "ip", "dev")).thenReturn("192.168.99.100"); when(commandLineExecutor.execCommandAsArray("docker-machine", "ls")) .thenReturn(Arrays.asList( "NAME ACTIVE DRIVER STATE URL SWARM", "dev * virtualbox Running tcp://192.168.99.100:2376 ", "dev2 * virtualbox Running tcp://192.168.99.100:2376 ")); when(commandLineExecutor.execCommand("boot2docker", "ip")).thenReturn("192.168.0.1"); // Docker-Machine is installed when(commandLineExecutor.execCommand("docker-machine")) .thenReturn("Usage: docker-machine [OPTIONS] COMMAND [arg...]"); bindNonExistingDockerSocketOS(); fire(new CubeConfiguration()); assertThat(config, hasEntry(CubeDockerConfiguration.DOCKER_URI, "tcp://192.168.0.1:2376")); }
@Test public void tlsVerifyShouldBeTrueInCaseOfNotSetAndDockerHostTagPresent() { assumeThat(new OperatingSystemResolver().currentOperatingSystem().getFamily(), is(not(OperatingSystemFamily.LINUX))); Map<String, String> config = new HashMap<>(); config.put(CubeDockerConfiguration.DOCKER_URI, "tcp://dockerHost:22222"); when(extensionDef.getExtensionProperties()).thenReturn(config); when(arquillianDescriptor.extension("docker")).thenReturn(extensionDef); when(commandLineExecutor.execCommand("boot2docker", "ip")).thenReturn("192.168.0.2"); when(commandLineExecutor.execCommand("docker-machine")).thenThrow(new RuntimeException()); fire(new CubeConfiguration()); assertThat(config, hasEntry(CubeDockerConfiguration.DOCKER_URI, "tcp://192.168.0.2:22222")); assertThat(config, hasEntry(CubeDockerConfiguration.TLS_VERIFY, "true")); assertThat(config, hasEntry(is(CubeDockerConfiguration.CERT_PATH), defaultBootToDockerCertPath())); }