public DockerMachineRequirement() { commandLineExecutor = new CommandLineExecutor(); }
/** * 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 String execCommand(String... arguments) { return execCommandAsArray(arguments).get(0); }
@Test(expected = ExecutionException.class) public void shouldThrowAnIllegalArgumentExceptionWhenCommandNotFound() { CommandLineExecutor commandLineExecutor = new CommandLineExecutor(); commandLineExecutor.execCommand("commandNotFound.sh"); } }
@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 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 DockerMachineRequirement() { commandLineExecutor = new CommandLineExecutor(); }
public String execCommand(String... arguments) { return execCommandAsArray(arguments).get(0); }
@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")); }
public void stopDockerMachine(String cliPathExec, String machineName) { commandLineExecutor.execCommand(createDockerMachineCommand(cliPathExec), "stop", machineName); this.manuallyStarted = false; }
public void configure(@Observes(precedence = 100) ManagerStarted managerStarted) { dockerMachineInstanceProducer.set(new DockerMachine(new CommandLineExecutor())); } }
public void createMachine(String machinePath, String machineDriver, String machineName) { List<String> create = commandLineExecutor.execCommandAsArray(machinePath, "create", "--driver", machineDriver, machineName); printOutput(create); }
@Test public void shouldUseDockerMachineIfDockerHostIsNotSetAndOnlyOneMachineIsRunning() { 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", "--filter", "state=Running")) .thenReturn(Arrays.asList( "NAME ACTIVE DRIVER STATE URL SWARM", "dev * virtualbox Running tcp://192.168.99.100:2376 ")); when(commandLineExecutor.execCommandAsArray("docker-machine", "ls")) .thenReturn(Arrays.asList( "NAME ACTIVE DRIVER STATE URL SWARM", "dev * virtualbox Running tcp://192.168.99.100:2376 ")); // 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.99.100:2376")); assertThat(config, hasEntry(CubeDockerConfiguration.DOCKER_MACHINE_NAME, "dev")); }
public void stopDockerMachine(String cliPathExec, String machineName) { commandLineExecutor.execCommand(createDockerMachineCommand(cliPathExec), "stop", machineName); this.manuallyStarted = false; }
public void configure(@Observes(precedence = 100) ManagerStarted managerStarted) { boot2DockerInstanceProducer.set(new Boot2Docker(new CommandLineExecutor())); } }
public void grantPermissionToDockerMachine(String machinePath) { List<String> chmod = commandLineExecutor.execCommandAsArray("chmod", "+x", machinePath); printOutput(chmod); }
@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())); }
/** * 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; } }
public void configure(@Observes(precedence = 100) ManagerStarted managerStarted) { dockerMachineInstanceProducer.set(new DockerMachine(new CommandLineExecutor())); } }