/** * Starts given docker machine. * * @param cliPathExec * location of docker-machine or null if it is on PATH. * @param machineName * to be started. */ public void startDockerMachine(String cliPathExec, String machineName) { commandLineExecutor.execCommand(createDockerMachineCommand(cliPathExec), "start", machineName); this.manuallyStarted = true; }
@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")); }
/** * Starts given docker machine. * * @param cliPathExec * location of docker-machine or null if it is on PATH. * @param machineName * to be started. */ public void startDockerMachine(String cliPathExec, String machineName) { commandLineExecutor.execCommand(createDockerMachineCommand(cliPathExec), "start", machineName); this.manuallyStarted = true; }
public void stopDockerMachine(String cliPathExec, String machineName) { commandLineExecutor.execCommand(createDockerMachineCommand(cliPathExec), "stop", machineName); this.manuallyStarted = false; }
public void stopDockerMachine(String cliPathExec, String machineName) { commandLineExecutor.execCommand(createDockerMachineCommand(cliPathExec), "stop", machineName); this.manuallyStarted = false; }
/** * Checks if Docker Machine is installed by running docker-machine and inspect the result. * * @param cliPathExec * location of docker-machine or null if it is on PATH. * * @return true if it is installed, false otherwise. */ public boolean isDockerMachineInstalled(String cliPathExec) { try { commandLineExecutor.execCommand(createDockerMachineCommand(cliPathExec)); return true; } catch (Exception e) { return false; } }
private String getIp(String cliPathExec) { String output = commandLineExecutor.execCommand(getCommandArguments(cliPathExec)); Matcher m = getIpPattern().matcher(output); if (m.find()) { String ip = m.group(); return ip; } else { String errorMessage = String.format( "Cli Internet address resolver executed %s command and does not return a valid ip. It returned %s.", Arrays.toString(getCommandArguments(cliPathExec)), output); log.log(Level.SEVERE, errorMessage); throw new IllegalArgumentException(errorMessage); } }
private String getIp(String cliPathExec) { String output = commandLineExecutor.execCommand(getCommandArguments(cliPathExec)); Matcher m = getIpPattern().matcher(output); if (m.find()) { String ip = m.group(); return ip; } else { String errorMessage = String.format( "Cli Internet address resolver executed %s command and does not return a valid ip. It returned %s.", Arrays.toString(getCommandArguments(cliPathExec)), output); log.log(Level.SEVERE, errorMessage); throw new IllegalArgumentException(errorMessage); } }
@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 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(expected = ExecutionException.class) public void shouldThrowAnIllegalArgumentExceptionWhenCommandNotFound() { CommandLineExecutor commandLineExecutor = new CommandLineExecutor(); commandLineExecutor.execCommand("commandNotFound.sh"); } }
@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 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 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 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 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 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 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 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())); }
@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())); }