From 3d11730ba34ceb1528d046b41802a84ef8f86181 Mon Sep 17 00:00:00 2001 From: Vasileios Karakasis Date: Fri, 22 Nov 2019 19:13:38 -0700 Subject: [PATCH] Allow passing arbitrary options to a container platform --- reframe/core/containers.py | 16 +++++++++++++--- unittests/test_containers.py | 15 ++++++++------- 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/reframe/core/containers.py b/reframe/core/containers.py index fe1fb7be3a..e8a0d94868 100644 --- a/reframe/core/containers.py +++ b/reframe/core/containers.py @@ -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 @@ -48,6 +54,7 @@ def __init__(self): self.image = None self.commands = [] self.mount_points = [] + self.options = [] self.workdir = '/rfm_workdir' @abc.abstractmethod @@ -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( @@ -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( @@ -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) + "'" diff --git a/unittests/test_containers.py b/unittests/test_containers.py index ae616e6687..8432d6cbdb 100644 --- a/unittests/test_containers.py +++ b/unittests/test_containers.py @@ -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()) @@ -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'") @@ -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): @@ -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): @@ -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): @@ -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): @@ -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): @@ -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'")