Skip to content

Commit 2d30f8a

Browse files
pvanheusmr-c
authored andcommitted
Added fix for detecting with singularity --userns is broken (#771)
1 parent 01ea0a1 commit 2d30f8a

File tree

6 files changed

+45
-10
lines changed

6 files changed

+45
-10
lines changed

.travis.yml

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,17 @@
1+
dist: trusty
12
sudo: true
23
services:
34
- docker
5+
6+
env:
7+
- SINGVER=2.5.1
8+
9+
before_install:
10+
- wget -O- http://neuro.debian.net/lists/trusty.us-nh.full | sudo tee /etc/apt/sources.list.d/neurodebian.sources.list
11+
- sudo apt-key adv --recv-keys --keyserver hkp://pool.sks-keyservers.net:80 0xA5D32F012649A5A9
12+
- sudo apt-get update
13+
- sudo apt-get install -y singularity-container
14+
415
language: python
516
cache: pip
617
python:
@@ -15,7 +26,7 @@ install:
1526
jobs:
1627
include:
1728
- stage: release-test
18-
script: RELEASE_SKIP=head ./release-test.sh
29+
script: RELEASE_SKIP=head ${TRAVIS_BUILD_DIR}/release-test.sh
1930
script: tox
2031
branches:
2132
only:

cwltool/hello.simg

4.03 KB
Binary file not shown.

cwltool/singularity.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,23 @@
22
from __future__ import absolute_import
33
import logging
44
import os
5+
import os.path
56
import re
67
import shutil
78
import sys
89
from io import open # pylint: disable=redefined-builtin
9-
from typing import (Dict, List, Text, Optional, MutableMapping)
10+
from typing import (Dict, List, Text, Optional, # pylint: disable=unused-import
11+
MutableMapping)
12+
from schema_salad.sourceline import SourceLine
1013
from .errors import WorkflowException
1114
from .job import ContainerCommandLineJob
12-
from .pathmapper import PathMapper, ensure_writable
15+
from .pathmapper import PathMapper, ensure_writable # pylint: disable=unused-import
1316
from .process import (UnsupportedRequirement)
1417
from .utils import docker_windows_path_adjust
15-
from schema_salad.sourceline import SourceLine
1618
if os.name == 'posix':
17-
from subprocess32 import (check_call, check_output, # pylint: disable=import-error
18-
CalledProcessError, DEVNULL, PIPE, Popen,
19-
TimeoutExpired)
19+
from subprocess32 import ( # pylint: disable=import-error,no-name-in-module
20+
check_call, check_output, CalledProcessError, DEVNULL, PIPE, Popen,
21+
TimeoutExpired)
2022
else: # we're not on Unix, so none of this matters
2123
pass
2224

@@ -27,8 +29,9 @@ def _singularity_supports_userns(): # type: ()->bool
2729
global _USERNS # pylint: disable=global-statement
2830
if _USERNS is None:
2931
try:
32+
hello_image = os.path.join(os.path.dirname(__file__), 'hello.simg')
3033
result = Popen(
31-
[u"singularity", u"exec", u"--userns", u"/etc", u"true"],
34+
[u"singularity", u"exec", u"--userns", hello_image, u"true"],
3235
stderr=PIPE, stdout=DEVNULL,
3336
universal_newlines=True).communicate(timeout=60)[1]
3437
_USERNS = "No valid /bin/sh" in result

setup.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@
4545
'schemas/v1.1.0-dev1/salad/schema_salad/metaschema/*.md',
4646
'cwlNodeEngine.js',
4747
'cwlNodeEngineJSConsole.js',
48-
'extensions.yml']},
48+
'extensions.yml',
49+
'hello.simg']},
4950
include_package_data=True,
5051
install_requires=[
5152
'setuptools',

tests/test_examples.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
from cwltool.main import main
2828
from cwltool.utils import onWindows, subprocess
2929

30-
from .util import (get_data, needs_docker, get_windows_safe_factory,
30+
from .util import (get_data, needs_docker, needs_singularity, get_windows_safe_factory,
3131
windows_needs_docker)
3232

3333

@@ -702,5 +702,21 @@ def test_no_compute_checksum(self):
702702
self.assertNotIn("checksum", stdout)
703703

704704

705+
@needs_singularity
706+
class TestChecksumSingularity(TestCmdLine):
707+
708+
def setUp(self):
709+
self.cache_dir = tempfile.mkdtemp("cwltool_cache")
710+
711+
def tearDown(self):
712+
shutil.rmtree(self.cache_dir)
713+
714+
def test_singularity_workflow(self):
715+
error_code, stdout, stderr = self.get_main_output(
716+
['--singularity', '--default-container', 'debian',
717+
get_data("tests/wf/hello-workflow.cwl"), "--usermessage", "hello"])
718+
self.assertIn("completed success", stderr)
719+
self.assertEquals(error_code, 0)
720+
705721
if __name__ == '__main__':
706722
unittest.main()

tests/util.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ def get_data(filename):
4444
reason="Requires the docker executable on the "
4545
"system path.")
4646

47+
needs_singularity = pytest.mark.skipif(not bool(distutils.spawn.find_executable('singularity')),
48+
reason="Requires the singularity executable on the "
49+
"system path.")
50+
4751
windows_needs_docker = pytest.mark.skipif(
4852
onWindows() and not bool(distutils.spawn.find_executable('docker')),
4953
reason="Running this test on MS Windows requires the docker executable "

0 commit comments

Comments
 (0)