private Map<String, String> resolveServerUriByOperativeSystem(Map<String, String> cubeConfiguration) { if (!cubeConfiguration.containsKey(CubeDockerConfiguration.DOCKER_URI)) { if (isDockerMachineSet(cubeConfiguration)) { String serverUri = OperatingSystemFamily.MACHINE.getServerUri(); cubeConfiguration.put(CubeDockerConfiguration.DOCKER_URI, serverUri); } else { String serverUri = operatingSystem.getFamily().getServerUri(); cubeConfiguration.put(CubeDockerConfiguration.DOCKER_URI, serverUri); } } return cubeConfiguration; } }
private Map<String, String> resolveServerUriByOperativeSystem(Map<String, String> cubeConfiguration) { if (!cubeConfiguration.containsKey(CubeDockerConfiguration.DOCKER_URI)) { if (isDockerMachineSet(cubeConfiguration)) { String serverUri = OperatingSystemFamily.MACHINE.getServerUri(); cubeConfiguration.put(CubeDockerConfiguration.DOCKER_URI, serverUri); } else { String serverUri = operatingSystem.getFamily().getServerUri(); cubeConfiguration.put(CubeDockerConfiguration.DOCKER_URI, serverUri); } } return cubeConfiguration; } }
private static String convertToBind(Path hostPath, String containterPath, String mode) { boolean isWindows = new OperatingSystemResolver().currentOperatingSystem().getFamily() == OperatingSystemFamily.WINDOWS; Path absoluteHostPath = hostPath.toAbsolutePath(); if(isWindows) {
private static String convertToBind(Path hostPath, String containterPath, String mode) { boolean isWindows = new OperatingSystemResolver().currentOperatingSystem().getFamily() == OperatingSystemFamily.WINDOWS; Path absoluteHostPath = hostPath.toAbsolutePath(); if(isWindows) {
config.put(CubeDockerConfiguration.TLS_VERIFY, Boolean.toString(true)); if (operatingSystem.getFamily() == OperatingSystemFamily.LINUX) {
config.put(CubeDockerConfiguration.TLS_VERIFY, Boolean.toString(true)); if (operatingSystem.getFamily() == OperatingSystemFamily.LINUX) {
public static String resolveDistro() { OperatingSystemFamilyInterface currentOSFamily = new OperatingSystemResolver().currentOperatingSystem().getFamily(); for (DockerMachineDistro distro : values()) { for (OperatingSystemFamily osFamily : distro.osFamily) { if (osFamily == currentOSFamily) { return distro.distro; } } } return null; }
public static String resolveDistro() { OperatingSystemFamilyInterface currentOSFamily = new OperatingSystemResolver().currentOperatingSystem().getFamily(); for (DockerMachineDistro distro : values()) { for (OperatingSystemFamily osFamily : distro.osFamily) { if (osFamily == currentOSFamily) { return distro.distro; } } } return null; }
private void bindNonExistingDockerSocketOS() { when(operatingSystem.getDefaultFamily()).thenReturn(operatingSystemFamily); when(operatingSystem.getFamily()).thenReturn(OperatingSystemFamily.MAC); when(operatingSystemFamily.getServerUri()).thenReturn("non/existing/path"); bind(ApplicationScoped.class, OperatingSystemInterface.class, operatingSystem); }
@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 shouldDetectsValidDockerDefault() throws Exception { CubeDockerConfigurationResolver resolver = new CubeDockerConfigurationResolver(new Top(), new DockerMachine(null), new Boot2Docker(null), mockDefaultDocker(), operatingSystemInterface); when(info.getName()).thenReturn("docker-ce"); when(info.getServerVersion()).thenReturn("arquillian-test"); when(info.getKernelVersion()).thenReturn("0.0.0"); URL sockURL = this.getClass().getClassLoader().getResource("docker.sock"); String sockUri = "unix://" + sockURL; when(defaultOperatingSystemFamilyInterface.getServerUri()).thenReturn(sockUri); when(operatingSystemInterface.getDefaultFamily()).thenReturn(defaultOperatingSystemFamilyInterface); when(operatingSystemInterface.getFamily()).thenReturn(OperatingSystem.MAC_OSX.getFamily()); Map<String, String> config = new HashMap<>(); Map<String, String> resolvedConfig = resolver.resolve(config); assertThat(Boolean.valueOf(resolvedConfig.get(CubeDockerConfiguration.TLS_VERIFY)), is(false)); assertThat(resolvedConfig.get(CubeDockerConfiguration.CERT_PATH), is(nullValue())); assertThat(resolvedConfig.get(CubeDockerConfiguration.DOCKER_URI), is(sockUri)); }
@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())); }
@Test public void shouldNotSetTlsVerifyForTcpSchemeOnOSX() { CubeDockerConfigurationResolver resolver = new CubeDockerConfigurationResolver(new Top(), new DockerMachine(null), new Boot2Docker(null), mockDefaultDocker(), operatingSystemInterface); when(infoCmd.exec()).thenThrow(new ProcessingException("test exception")); String sockUri = "unix:///a/path-that/does/not/exist"; when(defaultOperatingSystemFamilyInterface.getServerUri()).thenReturn(sockUri); when(operatingSystemInterface.getDefaultFamily()).thenReturn(defaultOperatingSystemFamilyInterface); when(operatingSystemInterface.getFamily()).thenReturn(OperatingSystem.MAC_OSX.getFamily()); Map<String, String> config = new HashMap<>(); config.put(CubeDockerConfiguration.DOCKER_URI, "tcp://localhost:2376"); Map<String, String> resolvedConfig = resolver.resolve(config); assertThat(Boolean.valueOf(resolvedConfig.get(CubeDockerConfiguration.TLS_VERIFY)), is(false)); assertThat(resolvedConfig.get(CubeDockerConfiguration.CERT_PATH), is(nullValue())); }
@Test public void dockerUriConfigurationParameterShouldTakePrecedenceOverSystemEnv() { assumeThat(new OperatingSystemResolver().currentOperatingSystem().getFamily(), is(not(OperatingSystemFamily.LINUX))); String originalVar = System.getProperty(CubeDockerConfigurator.DOCKER_HOST); try { System.setProperty(CubeDockerConfigurator.DOCKER_HOST, "tcp://127.0.0.1:22222"); 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(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(CubeDockerConfiguration.DOCKER_SERVER_IP, "192.168.0.1")); } finally { if (originalVar != null) { System.setProperty(CubeDockerConfigurator.DOCKER_HOST, originalVar); } else { System.clearProperty(CubeDockerConfigurator.DOCKER_HOST); } } }
@Test public void shouldSkipsInvalidDockerDefault() throws Exception { CubeDockerConfigurationResolver resolver = new CubeDockerConfigurationResolver(new Top(), new DockerMachine(null), new Boot2Docker(boot2dockerCommandLineExecutor), mockDefaultDocker(), operatingSystemInterface); when(boot2dockerCommandLineExecutor.execCommand(Matchers.<String>anyVararg())).thenReturn("127.0.0.1"); String sockUri = "unix:///a/path-that/does/not/exist"; when(defaultOperatingSystemFamilyInterface.getServerUri()).thenReturn(sockUri); when(operatingSystemInterface.getDefaultFamily()).thenReturn(defaultOperatingSystemFamilyInterface); when(operatingSystemInterface.getFamily()).thenReturn(OperatingSystem.MAC_OSX.getFamily()); Map<String, String> config = new HashMap<>(); Map<String, String> resolvedConfig = resolver.resolve(config); assertThat(Boolean.valueOf(resolvedConfig.get(CubeDockerConfiguration.TLS_VERIFY)), is(true)); assertThat(resolvedConfig.get(CubeDockerConfiguration.DOCKER_URI), is("tcp://127.0.0.1:2376")); }
@Test public void shouldNotSetTlsVerifyForTcpSchemeOnLinux() { CubeDockerConfigurationResolver resolver = new CubeDockerConfigurationResolver(new Top(), new DockerMachine(null), new Boot2Docker(null), mockDefaultDocker(), operatingSystemInterface); when(infoCmd.exec()).thenThrow(new ProcessingException("test exception")); String sockUri = "unix:///a/path-that/does/not/exist"; when(defaultOperatingSystemFamilyInterface.getServerUri()).thenReturn(sockUri); when(operatingSystemInterface.getDefaultFamily()).thenReturn(defaultOperatingSystemFamilyInterface); when(operatingSystemInterface.getFamily()).thenReturn(OperatingSystem.LINUX_OS.getFamily()); Map<String, String> config = new HashMap<>(); config.put(CubeDockerConfiguration.DOCKER_URI, "tcp://localhost:2376"); Map<String, String> resolvedConfig = resolver.resolve(config); assertThat(Boolean.valueOf(resolvedConfig.get(CubeDockerConfiguration.TLS_VERIFY)), is(false)); assertThat(resolvedConfig.get(CubeDockerConfiguration.CERT_PATH), is(nullValue())); } }