Exemplo n.º 1
0
def test_docker_exec_signal_handling() -> None:
    def run_catch(exe: LocalContainer, catch_signal_stash: Stash) -> None:
        exe.unstash(catch_signal_stash)
        exe.sh("python3 -u tests/catch_signals.py")

    with concurrent.futures.ThreadPoolExecutor(1) as e:
        with Local() as local_exe:
            catch_signal_stash = local_exe.stash("tests/catch_signals.py")

            with LocalContainer("python") as exe:
                f = e.submit(run_catch, exe, catch_signal_stash)

                # Wait until process is running and file exists
                for _ in range(30):
                    try:
                        time.sleep(1)
                        local_exe.sh(
                            f"docker exec {exe.container_name} cat is_sleeping"
                        )
                        break
                    except:
                        pass

                global_kill_signal.set()
                print("global_kill_signal set")
                try:
                    f.result()
                except ProcessError as e:
                    assert e.exit_code == 101
                else:
                    raise Exception("Expected exception")
            print("killed container")
    global_kill_signal.clear()
Exemplo n.º 2
0
def test_stash() -> None:
    with Local() as exe:
        source = exe.stash(".")
        ls = exe.sh("ls -l --time-style=+%s Dockerfile").decode()

    with LocalContainer("debian", path="/root") as exe2:
        exe2.unstash(source, "./Dockerfile")
        ls2 = exe2.sh("ls -l --time-style=+%s Dockerfile").decode()
        normalized1 = " ".join(ls.split()[:2] + ls.split()[4:])
        normalized2 = " ".join(ls2.split()[:2] + ls2.split()[4:])
        print(normalized1)
        print(normalized2)
        assert normalized1 == normalized2
Exemplo n.º 3
0
 def run(self) -> None:
     with LocalContainer(image_name, temp_path=True) as exe:
         exe.unstash(source)
         exe.sh("make check")
Exemplo n.º 4
0
 def run(self) -> None:
     with LocalContainer(image_name, temp_path=True,
                         mount_docker=True) as exe:
         exe.unstash(source)
         exe.sh("make test")
Exemplo n.º 5
0
 def run_catch(exe: LocalContainer, catch_signal_stash: Stash) -> None:
     exe.unstash(catch_signal_stash)
     exe.sh("python3 -u tests/catch_signals.py")
Exemplo n.º 6
0
def test_temp_path() -> None:
    with LocalContainer("debian", temp_path=True) as exe:
        assert exe.sh("pwd").decode().strip().startswith("/tmp/")
Exemplo n.º 7
0
def test_docker_in_docker() -> None:
    with Local() as exe:
        exe.sh("docker build . -t test")
    with LocalContainer("test", temp_path=True, mount_docker=True) as exe2:
        exe2.sh("docker ps")
Exemplo n.º 8
0
 def run(self) -> None:
     with LocalContainer(self.state.image) as exe:
         lines, failed = run_and_capture_lines(exe, "make typecheck")
         checks.conclude(self.state.ctx, "mypy", from_lines=lines)
         assert not failed
Exemplo n.º 9
0
 def run(self) -> None:
     with LocalContainer(self.state.image) as exe:
         lines, _ = run_and_capture_lines(exe, "make lint")
         checks.conclude(self.state.ctx, "pylint", from_lines=lines)