Skip to content

Commit

Permalink
finished adapting pertinent singularity tests to barebones tests
Browse files Browse the repository at this point in the history
  • Loading branch information
FrederickDeny committed Mar 12, 2024
1 parent ec76332 commit f69b93a
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 36 deletions.
3 changes: 2 additions & 1 deletion e4s_cl/cf/containers/barebones.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,9 @@ def _prepare(self, command: List[str], overload: bool = True) -> List[str]:
nvidia_flag = ['--nv'] if self._has_nvidia() else []

return [
*self._additional_options('exec'),
*self._additional_options(),
*command,
*self._additional_options('exec'),
]

def bind_file(self,
Expand Down
18 changes: 18 additions & 0 deletions e4s_cl/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,24 @@ def __str__(self):
"Options to pass to the shifter executable",
),
}),
ConfigurationGroup(
"barebones",
{
ConfigurationField(
"options",
list,
lambda: [],
"Options to pass before the execution script",
),
ConfigurationField(
"exec_options",
list,
lambda: [],
"Options to pass after the execution script",
),
},
"Barebones backend configuration",
),
}),
})

Expand Down
40 changes: 5 additions & 35 deletions tests/test_containers_barebones.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
TEST_CONFIGURATION = config.Configuration.create_from_string(f"""
backends:
barebones:
options: ['--nocolor', '-s']
exec_options: ['--hostname', 'XxmycoolcontainerxX']
""")

Expand All @@ -27,19 +28,6 @@ def test_create(self):
self.assertFalse(type(container) == Container)
self.assertTrue(isinstance(container, Container))

def test_run_image(self):
container = Container(name='barebones', image='imagenametest')
command = ['']
container_cmd = container._prepare(command)
self.assertIn('imagenametest', ' '.join(map(str, container_cmd)))

def test_run_pwd(self):
container = Container(name='barebones')
command = ['']
container_cmd = container._prepare(command)
pwd = getcwd()
self.assertIn(pwd, ' '.join(map(str, container_cmd)))

def test_run_mpirun(self):
container = Container(name='barebones', image='dummyimagename')
command = ['mpirun -n 2 ls']
Expand All @@ -64,22 +52,6 @@ def test_bind_file(self):
self.assertIn('tmp2',
[Path(path).name for path in list_directory_files(Path(BAREBONES_LIBRARY_DIR))])

def test_bind_relative(self):
container = Container(name='barebones')

target = Path('/tmp/../proc/meminfo')

ref = Path('/tmp')
file_ex = Path('/proc/meminfo')
home = Path.home()
paths = {ref, file_ex, home}

container.bind_file(target)
files = set(map(lambda x: x.origin, container.bound))

for item in paths:
self.assertIn(item, files)

def test_additional_options_config(self):
container = Container(name='barebones')
command = ['']
Expand All @@ -93,7 +65,6 @@ def test_additional_options_config(self):
self.assertContainsInOrder([
'--nocolor',
'-s',
'exec',
'--hostname',
'XxmycoolcontainerxX',
], barebones_command)
Expand All @@ -111,20 +82,19 @@ def test_additional_options_environment(self):
for option in {'--nocolor', '-s', '--hostname', 'XxmycoolcontainerxX'}:
self.assertNotIn(option, barebones_command)

environ['E4S_CL_barebones_OPTIONS'] = "--nocolor -s"
environ['E4S_CL_BAREBONES_OPTIONS'] = "--nocolor -s"
environ[
'E4S_CL_barebones_EXEC_OPTIONS'] = "--hostname XxmycoolcontainerxX"
'E4S_CL_BAREBONES_EXEC_OPTIONS'] = "--hostname XxmycoolcontainerxX"
barebones_command = container._prepare(command)
self.assertContainsInOrder([
'--nocolor',
'-s',
'exec',
'--hostname',
'XxmycoolcontainerxX',
], barebones_command)

del environ['E4S_CL_barebones_OPTIONS']
del environ['E4S_CL_barebones_EXEC_OPTIONS']
del environ['E4S_CL_BAREBONES_OPTIONS']
del environ['E4S_CL_BAREBONES_EXEC_OPTIONS']
barebones_command = container._prepare(command)
for option in {'--nocolor', '-s', '--hostname', 'XxmycoolcontainerxX'}:
self.assertNotIn(option, barebones_command)

0 comments on commit f69b93a

Please sign in to comment.