Skip to content

Commit

Permalink
Fixed test
Browse files Browse the repository at this point in the history
  • Loading branch information
ckunki committed Oct 20, 2023
1 parent 07a67e0 commit 23e3ca0
Showing 1 changed file with 35 additions and 36 deletions.
71 changes: 35 additions & 36 deletions test/integration/test_install_dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,48 +29,47 @@
)

@pytest.fixture(scope="session")
def dockerfile(tmp_path):
dockerfile = tmp_path / "test_container" / "Dockerfile"
dockerfile.parent.mkdir()
def dockerfile(tmpdir_factory):
dockerfile = tmpdir_factory.mktemp("test_container") / "Dockerfile"
with dockerfile.open("w") as f:
print(DOCKERFILE_CONTENT, file = f)
yield dockerfile


@pytest.fixture(scope="session")
def docker_test_container(test_config, dockerfile, tmp_path):
# with tempfile.TemporaryDirectory() as tmp_path:
docker_env = docker.from_env()
# p = Path(__file__).parent / "test_container"
docker_env.images.build(
path=str(dockerfile.parent),
tag=TEST_CONTAINER_IMAGE_TAG
)
socket_mount = Mount("/var/run/docker.sock", "/var/run/docker.sock", type="bind")
tmp_mount = Mount(tmp_path, tmp_path, type="bind")
mapped_ports = {'8888/tcp': 8888}
test_container = docker_env.containers.create(image=TEST_CONTAINER_IMAGE_TAG,
name=TEST_CONTAINER_NAME, mounts=[socket_mount, tmp_mount],
command="sleep infinity", detach=True, ports=mapped_ports)
test_container.start()
repos = default_repositories + (AnsibleResourceRepository(test.ansible),)
ansible_run_context = \
AnsibleRunContext(playbook="slc_setup_test.yml",
extra_vars={"test_docker_container": test_container.name,
"slc_dest_folder": f"{tmp_path}/script-languages-release"})
try:
run_install_dependencies(AnsibleAccess(), configuration=test_config,
host_infos=tuple(), ansible_run_context=ansible_run_context,
ansible_repositories=repos)
yield test_container, tmp_path
# Note: script-languages-release will be cloned by ansible within the docker container.
# Because the docker container runs as root, the repository will be owned by root.
# For simplicity, we delete the folder from within the Docker container (as root).
# Otherwise, we get a permission problem when tmp_path tries to clean-up itself.
finally:
test_container.exec_run(f"rm -rf {tmp_path}/script-languages-release")
test_container.stop()
test_container.remove()
def docker_test_container(test_config, dockerfile):
with tempfile.TemporaryDirectory() as tmp_path:
docker_env = docker.from_env()
# p = Path(__file__).parent / "test_container"
docker_env.images.build(
path=str(dockerfile.parent),
tag=TEST_CONTAINER_IMAGE_TAG
)
socket_mount = Mount("/var/run/docker.sock", "/var/run/docker.sock", type="bind")
tmp_mount = Mount(tmp_path, tmp_path, type="bind")
mapped_ports = {'8888/tcp': 8888}
test_container = docker_env.containers.create(image=TEST_CONTAINER_IMAGE_TAG,
name=TEST_CONTAINER_NAME, mounts=[socket_mount, tmp_mount],
command="sleep infinity", detach=True, ports=mapped_ports)
test_container.start()
repos = default_repositories + (AnsibleResourceRepository(test.ansible),)
ansible_run_context = \
AnsibleRunContext(playbook="slc_setup_test.yml",
extra_vars={"test_docker_container": test_container.name,
"slc_dest_folder": f"{tmp_path}/script-languages-release"})
try:
run_install_dependencies(AnsibleAccess(), configuration=test_config,
host_infos=tuple(), ansible_run_context=ansible_run_context,
ansible_repositories=repos)
yield test_container, tmp_path
# Note: script-languages-release will be cloned by ansible within the docker container.
# Because the docker container runs as root, the repository will be owned by root.
# For simplicity, we delete the folder from within the Docker container (as root).
# Otherwise, we get a permission problem when tmp_path tries to clean-up itself.
finally:
test_container.exec_run(f"rm -rf {tmp_path}/script-languages-release")
test_container.stop()
test_container.remove()


def test_install_dependencies_jupyterlab(docker_test_container):
Expand Down

0 comments on commit 23e3ca0

Please sign in to comment.