public void configure(@Observes(precedence = 100) ManagerStarted managerStarted) { topInstanceProducer.set(new Top()); } }
private Map<String, String> resolveDockerInsideDocker(Map<String, String> cubeConfiguration) { // if DIND_RESOLUTION property is not set, since by default is enabled, we need to go inside code. if (!cubeConfiguration.containsKey(CubeDockerConfiguration.DIND_RESOLUTION) || Boolean.parseBoolean( cubeConfiguration.get(CubeDockerConfiguration.DIND_RESOLUTION))) { if (top.isSpinning()) { log.fine(String.format( "Your Cube tests are going to run inside a running Docker container. %s property is replaced to %s", CubeDockerConfiguration.DOCKER_URI, OperatingSystemFamily.DIND.getServerUri())); String serverUri = OperatingSystemFamily.DIND.getServerUri(); cubeConfiguration.put(CubeDockerConfiguration.DOCKER_URI, serverUri); } } return cubeConfiguration; }
@Test public void shouldNotStopSpinningIfRunningInsideDocker() throws IOException { temporaryFolder.newFile(Top.DOCKERENV); temporaryFolder.newFile(Top.DOCKERINIT); Top top = new Top(temporaryFolder.getRoot().getAbsolutePath(), temporaryFolder.getRoot().getAbsolutePath()); assertThat(top.isSpinning(), is(false)); } }
@Test public void shouldStopSpinningIfRunningInsideDocker() throws IOException { temporaryFolder.newFile(Top.DOCKER_SOCK); temporaryFolder.newFile(Top.DOCKERENV); temporaryFolder.newFile(Top.DOCKERINIT); Top top = new Top(temporaryFolder.getRoot().getAbsolutePath(), temporaryFolder.getRoot().getAbsolutePath()); assertThat(top.isSpinning(), is(true)); }
public void configure(@Observes(precedence = 100) ManagerStarted managerStarted) { topInstanceProducer.set(new Top()); } }
private Map<String, String> resolveDockerInsideDocker(Map<String, String> cubeConfiguration) { // if DIND_RESOLUTION property is not set, since by default is enabled, we need to go inside code. if (!cubeConfiguration.containsKey(CubeDockerConfiguration.DIND_RESOLUTION) || Boolean.parseBoolean( cubeConfiguration.get(CubeDockerConfiguration.DIND_RESOLUTION))) { if (top.isSpinning()) { log.fine(String.format( "Your Cube tests are going to run inside a running Docker container. %s property is replaced to %s", CubeDockerConfiguration.DOCKER_URI, OperatingSystemFamily.DIND.getServerUri())); String serverUri = OperatingSystemFamily.DIND.getServerUri(); cubeConfiguration.put(CubeDockerConfiguration.DOCKER_URI, serverUri); } } return cubeConfiguration; }
public DockerRequirement() { this.commandLineExecutor = new CommandLineExecutor(); this.resolver = new CubeDockerConfigurationResolver(new Top(), new DockerMachine(commandLineExecutor), new Boot2Docker(commandLineExecutor), new DefaultDocker(), new OperatingSystemResolver().currentOperatingSystem() ); }
@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())); }
public DockerRequirement() { this.commandLineExecutor = new CommandLineExecutor(); this.resolver = new CubeDockerConfigurationResolver(new Top(), new DockerMachine(commandLineExecutor), new Boot2Docker(commandLineExecutor), new DefaultDocker(), new OperatingSystemResolver().currentOperatingSystem() ); }
@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 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)); }
@Before public void setup() { bind(ApplicationScoped.class, Boot2Docker.class, new Boot2Docker(commandLineExecutor)); bind(ApplicationScoped.class, DockerMachine.class, new DockerMachine(commandLineExecutor)); bind(ApplicationScoped.class, ArquillianDescriptor.class, arquillianDescriptor); bind(ApplicationScoped.class, Top.class, top); when(top.isSpinning()).thenReturn(false); }
@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())); } }
@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 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())); }
public static DockerClientExecutor initialize() { Injector injector = new Injector() { @Override public <T> T inject(T t) { return t; } }; CubeDockerConfigurationResolver resolver = new CubeDockerConfigurationResolver(new Top(), new DockerMachine(new CommandLineExecutor()), new Boot2Docker(new CommandLineExecutor()), new DefaultDocker(), new OperatingSystemResolver().currentOperatingSystem()); final Map<String, String> config = resolver.resolve(new HashMap<>()); final CubeDockerConfiguration cubeDockerConfiguration = CubeDockerConfiguration.fromMap(config, injector); return new DockerClientExecutor(cubeDockerConfiguration); }