Skip to content

Commit 31aa094

Browse files
mb1069mr-c
authored andcommitted
Added conditional removal of cidfile_path from runtime arguments of D… (#1007)
* Added conditional removal of cidfile_path from runtime arguments of DockerCommandLineJob * Added test to verify udocker usage does not generate cid files
1 parent 4635090 commit 31aa094

File tree

2 files changed

+54
-19
lines changed

2 files changed

+54
-19
lines changed

cwltool/docker.py

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -342,27 +342,28 @@ def create_runtime(self,
342342
runtime.append(u"--env=HOME=%s" % self.builder.outdir)
343343

344344
# add parameters to docker to write a container ID file
345+
if runtimeContext.user_space_docker_cmd is None:
346+
if runtimeContext.cidfile_dir:
347+
cidfile_dir = runtimeContext.cidfile_dir
348+
if not os.path.exists(str(cidfile_dir)):
349+
_logger.error("--cidfile-dir %s error:\n%s", cidfile_dir,
350+
"directory doesn't exist, please create it first")
351+
exit(2)
352+
if not os.path.isdir(cidfile_dir):
353+
_logger.error("--cidfile-dir %s error:\n%s", cidfile_dir,
354+
cidfile_dir + " is not a directory, "
355+
"please check it first")
356+
exit(2)
357+
else:
358+
cidfile_dir = tempfile.mkdtemp(dir=runtimeContext.tmpdir_prefix)
345359

346-
if runtimeContext.cidfile_dir:
347-
cidfile_dir = runtimeContext.cidfile_dir
348-
if not os.path.exists(str(cidfile_dir)):
349-
_logger.error("--cidfile-dir %s error:\n%s", cidfile_dir,
350-
"directory doesn't exist, please create it first")
351-
exit(2)
352-
if not os.path.isdir(cidfile_dir):
353-
_logger.error("--cidfile-dir %s error:\n%s", cidfile_dir,
354-
cidfile_dir + " is not a directory, "
355-
"please check it first")
356-
exit(2)
360+
cidfile_name = datetime.datetime.now().strftime("%Y%m%d%H%M%S-%f") + ".cid"
361+
if runtimeContext.cidfile_prefix is not None:
362+
cidfile_name = str(runtimeContext.cidfile_prefix + "-" + cidfile_name)
363+
cidfile_path = os.path.join(cidfile_dir, cidfile_name)
364+
runtime.append(u"--cidfile=%s" % cidfile_path)
357365
else:
358-
cidfile_dir = tempfile.mkdtemp(dir=runtimeContext.tmpdir_prefix)
359-
360-
cidfile_name = datetime.datetime.now().strftime("%Y%m%d%H%M%S-%f") + ".cid"
361-
if runtimeContext.cidfile_prefix is not None:
362-
cidfile_name = str(runtimeContext.cidfile_prefix + "-" + cidfile_name)
363-
cidfile_path = os.path.join(cidfile_dir, cidfile_name)
364-
runtime.append(u"--cidfile=%s" % cidfile_path)
365-
366+
cidfile_path = None
366367
for key, value in self.environment.items():
367368
runtime.append(u"--env=%s=%s" % (key, value))
368369

tests/test_udocker.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import pytest
2+
import sys
3+
import os
4+
import subprocess
5+
from .util import get_data, get_main_output
6+
7+
LINUX = sys.platform in ('linux', 'linux2')
8+
9+
10+
@pytest.mark.skipif(not LINUX, reason="LINUX only")
11+
def test_udocker_usage_should_not_write_cid_file(tmpdir):
12+
cwd = tmpdir.chdir()
13+
install_cmds = [
14+
"curl https://raw.githubusercontent.com/indigo-dc/udocker/master/udocker.py -o ./udocker",
15+
"chmod u+rx ./udocker",
16+
"./udocker install"]
17+
os.environ['UDOCKER_DIR'] = os.path.join(str(tmpdir), ".udocker")
18+
19+
assert sum([subprocess.call(cmd.split()) for cmd in install_cmds]) == 0
20+
21+
docker_path = os.path.join(str(tmpdir), 'udocker')
22+
23+
test_file = "tests/wf/wc-tool.cwl"
24+
job_file = "tests/wf/wc-job.json"
25+
error_code, stdout, stderr = get_main_output(
26+
["--debug", "--default-container", "debian", "--user-space-docker-cmd=" + docker_path,
27+
get_data(test_file), get_data(job_file)])
28+
cwd.chdir()
29+
cidfiles_count = sum(1 for _ in tmpdir.visit(fil="*.cid"))
30+
31+
tmpdir.remove(ignore_errors=True)
32+
33+
assert "completed success" in stderr
34+
assert cidfiles_count == 0

0 commit comments

Comments
 (0)