Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions reframe/core/containers.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ class ContainerPlatform(abc.ABC):
mount_points = fields.TypedField('mount_points',
typ.List[typ.Tuple[str, str]])

#: Additional options to be passed to the container runtime when executed.
#:
#: :type: :class:`list[str]`
#: :default: ``[]``
options = fields.TypedField('options', typ.List[str])

#: The working directory of ReFrame inside the container.
#:
#: This is the directory where the test's stage directory is mounted inside
Expand All @@ -48,6 +54,7 @@ def __init__(self):
self.image = None
self.commands = []
self.mount_points = []
self.options = []
self.workdir = '/rfm_workdir'

@abc.abstractmethod
Expand Down Expand Up @@ -93,6 +100,7 @@ def emit_prepare_commands(self):
def launch_command(self):
super().launch_command()
run_opts = ['-v "%s":"%s"' % mp for mp in self.mount_points]
run_opts += self.options
run_cmd = 'docker run --rm %s %s bash -c ' % (' '.join(run_opts),
self.image)
return run_cmd + "'" + '; '.join(
Expand Down Expand Up @@ -124,6 +132,7 @@ def launch_command(self):
if self.with_mpi:
run_opts.append('--mpi')

run_opts += self.options
run_cmd = self._command + ' run %s %s bash -c ' % (' '.join(run_opts),
self.image)
return run_cmd + "'" + '; '.join(
Expand Down Expand Up @@ -158,11 +167,12 @@ def emit_prepare_commands(self):

def launch_command(self):
super().launch_command()
exec_opts = ['-B"%s:%s"' % mp for mp in self.mount_points]
run_opts = ['-B"%s:%s"' % mp for mp in self.mount_points]
if self.with_cuda:
exec_opts.append('--nv')
run_opts.append('--nv')

run_cmd = 'singularity exec %s %s bash -c ' % (' '.join(exec_opts),
run_opts += self.options
run_cmd = 'singularity exec %s %s bash -c ' % (' '.join(run_opts),
self.image)
return run_cmd + "'" + '; '.join(
['cd ' + self.workdir] + self.commands) + "'"
Expand Down
15 changes: 8 additions & 7 deletions unittests/test_containers.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ def test_run_opts(self):
self.container_platform.commands = ['cmd']
self.container_platform.mount_points = [('/path/one', '/one')]
self.container_platform.workdir = '/stagedir'
self.container_platform.options = ['--foo', '--bar']
assert (self.expected_cmd_with_run_opts ==
self.container_platform.launch_command())

Expand All @@ -77,7 +78,7 @@ def expected_cmd_prepare(self):

@property
def expected_cmd_with_run_opts(self):
return ('docker run --rm -v "/path/one":"/one" '
return ('docker run --rm -v "/path/one":"/one" --foo --bar '
"name:tag bash -c 'cd /stagedir; cmd'")


Expand All @@ -100,7 +101,7 @@ def expected_cmd_prepare(self):
def expected_cmd_with_run_opts(self):
return ('shifter run '
'--mount=type=bind,source="/path/one",destination="/one" '
"name:tag bash -c 'cd /stagedir; cmd'")
"--foo --bar name:tag bash -c 'cd /stagedir; cmd'")


class TestShifterNGWithMPI(TestShifterNG):
Expand All @@ -120,7 +121,7 @@ def expected_cmd_mount_points(self):
def expected_cmd_with_run_opts(self):
return ('shifter run '
'--mount=type=bind,source="/path/one",destination="/one" '
"--mpi name:tag bash -c 'cd /stagedir; cmd'")
"--mpi --foo --bar name:tag bash -c 'cd /stagedir; cmd'")


class TestSarus(_ContainerPlatformTest, unittest.TestCase):
Expand All @@ -142,7 +143,7 @@ def expected_cmd_prepare(self):
def expected_cmd_with_run_opts(self):
return ('sarus run '
'--mount=type=bind,source="/path/one",destination="/one" '
"name:tag bash -c 'cd /stagedir; cmd'")
"--foo --bar name:tag bash -c 'cd /stagedir; cmd'")


class TestSarusWithMPI(TestSarus):
Expand All @@ -163,7 +164,7 @@ def expected_cmd_with_run_opts(self):
self.container_platform.with_mpi = True
return ('sarus run '
'--mount=type=bind,source="/path/one",destination="/one" '
"--mpi name:tag bash -c 'cd /stagedir; cmd'")
"--mpi --foo --bar name:tag bash -c 'cd /stagedir; cmd'")


class TestSingularity(_ContainerPlatformTest, unittest.TestCase):
Expand All @@ -182,7 +183,7 @@ def expected_cmd_prepare(self):
@property
def expected_cmd_with_run_opts(self):
return ('singularity exec -B"/path/one:/one" '
"name:tag bash -c 'cd /stagedir; cmd'")
"--foo --bar name:tag bash -c 'cd /stagedir; cmd'")


class TestSingularityWithCuda(TestSingularity):
Expand All @@ -204,4 +205,4 @@ def expected_cmd_prepare(self):
def expected_cmd_with_run_opts(self):
self.container_platform.with_cuda = True
return ('singularity exec -B"/path/one:/one" '
"--nv name:tag bash -c 'cd /stagedir; cmd'")
"--nv --foo --bar name:tag bash -c 'cd /stagedir; cmd'")