comparison env/lib/python3.9/site-packages/cwltool/tests/test_udocker.py @ 0:4f3585e2f14b draft default tip

"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
author shellac
date Mon, 22 Mar 2021 18:12:50 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:4f3585e2f14b
1 """Test optional udocker feature."""
2 import copy
3 import os
4 import subprocess
5 import sys
6 from pathlib import Path
7
8 import pytest
9 from _pytest.tmpdir import TempPathFactory
10
11 from .util import get_data, get_main_output
12
13 LINUX = sys.platform in ("linux", "linux2")
14
15
16 @pytest.fixture(scope="session")
17 def udocker(tmp_path_factory: TempPathFactory) -> str:
18 """Udocker fixture, returns the path to the udocker script."""
19 test_cwd = os.getcwd()
20 test_environ = copy.copy(os.environ)
21 docker_install_dir = str(tmp_path_factory.mktemp("udocker"))
22 os.chdir(docker_install_dir)
23
24 url = "https://raw.githubusercontent.com/jorge-lip/udocker-builds/master/tarballs/udocker-1.1.4.tar.gz"
25 install_cmds = [
26 ["curl", url, "-o", "./udocker-tarball.tgz"],
27 ["tar", "xzvf", "udocker-tarball.tgz", "udocker"],
28 [
29 "bash",
30 "-c",
31 "UDOCKER_TARBALL={}/udocker-tarball.tgz ./udocker install".format(
32 docker_install_dir
33 ),
34 ],
35 ]
36
37 test_environ["UDOCKER_DIR"] = os.path.join(docker_install_dir, ".udocker")
38 test_environ["HOME"] = docker_install_dir
39
40 results = []
41 for _ in range(3):
42 results = [subprocess.call(cmds, env=test_environ) for cmds in install_cmds]
43 if sum(results) == 0:
44 break
45 subprocess.call(["rm", "./udocker"])
46
47 assert sum(results) == 0
48
49 udocker_path = os.path.join(docker_install_dir, "udocker")
50 os.chdir(test_cwd)
51 return udocker_path
52
53
54 @pytest.mark.skipif(not LINUX, reason="LINUX only")
55 def test_udocker_usage_should_not_write_cid_file(udocker: str, tmp_path: Path) -> None:
56 """Confirm that no cidfile is made when udocker is used."""
57 cwd = Path.cwd()
58 os.chdir(tmp_path)
59
60 test_file = "tests/wf/wc-tool.cwl"
61 job_file = "tests/wf/wc-job.json"
62 error_code, stdout, stderr = get_main_output(
63 [
64 "--debug",
65 "--default-container",
66 "debian",
67 "--user-space-docker-cmd=" + udocker,
68 get_data(test_file),
69 get_data(job_file),
70 ]
71 )
72
73 cidfiles_count = sum(1 for _ in tmp_path.glob("*.cid"))
74 os.chdir(cwd)
75
76 assert "completed success" in stderr, stderr
77 assert cidfiles_count == 0
78
79
80 @pytest.mark.skipif(
81 not LINUX or "GITHUB" in os.environ,
82 reason="Linux only",
83 )
84 def test_udocker_should_display_memory_usage(udocker: str, tmp_path: Path) -> None:
85 """Confirm that memory ussage is logged even with udocker."""
86 cwd = Path.cwd()
87 os.chdir(tmp_path)
88 error_code, stdout, stderr = get_main_output(
89 [
90 "--enable-ext",
91 "--default-container=debian",
92 "--user-space-docker-cmd=" + udocker,
93 get_data("tests/wf/timelimit.cwl"),
94 "--sleep_time",
95 "10",
96 ]
97 )
98 os.chdir(cwd)
99
100 assert "completed success" in stderr, stderr
101 assert "Max memory" in stderr, stderr