Skip to content

Commit d21467f

Browse files
authored
Merge pull request #4723 from lexming/sanity_tmp
run sanity checks commands from an empty temporary directory (rather than the software install directory)
2 parents a470089 + 2389fc6 commit d21467f

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

easybuild/framework/easyblock.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3739,16 +3739,16 @@ def xs2str(xs):
37393739
if self.toolchain.mpi_family() and self.toolchain.mpi_family() in toolchain.OPENMPI:
37403740
env.setvar('OMPI_MCA_rmaps_base_oversubscribe', '1')
37413741

3742-
# change to install directory (better environment for running tests)
3743-
if os.path.isdir(self.installdir):
3744-
change_dir(self.installdir)
3742+
# run sanity checks from an empty temp directory
3743+
# using the build or installation directory can produce false positives and polute them with files
3744+
sanity_check_work_dir = tempfile.mkdtemp(prefix='eb-sanity-check-')
37453745

37463746
# run sanity check commands
37473747
for cmd in commands:
37483748

37493749
trace_msg(f"running command '{cmd}' ...")
37503750

3751-
res = run_shell_cmd(cmd, fail_on_error=False, hidden=True)
3751+
res = run_shell_cmd(cmd, work_dir=sanity_check_work_dir, fail_on_error=False, hidden=True)
37523752
if res.exit_code != EasyBuildExit.SUCCESS:
37533753
fail_msg = f"sanity check command {cmd} failed with exit code {res.exit_code} (output: {res.output})"
37543754
self.sanity_check_fail_msgs.append(fail_msg)
@@ -3802,8 +3802,8 @@ def xs2str(xs):
38023802
"Sanity check failed: " + '\n'.join(self.sanity_check_fail_msgs),
38033803
exit_code=EasyBuildExit.FAIL_SANITY_CHECK,
38043804
)
3805-
else:
3806-
self.log.debug("Sanity check passed!")
3805+
3806+
self.log.debug("Sanity check passed!")
38073807

38083808
def _set_module_as_default(self, fake=False):
38093809
"""

test/framework/toy_build.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2373,6 +2373,8 @@ def test_toy_sanity_check_commands(self):
23732373
test_easyconfigs = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'easyconfigs', 'test_ecs')
23742374
toy_ec_txt = read_file(os.path.join(test_easyconfigs, 't', 'toy', 'toy-0.0.eb'))
23752375

2376+
out_file = os.path.join(self.test_prefix, 'out.txt')
2377+
23762378
toy_ec_txt = '\n'.join([
23772379
toy_ec_txt,
23782380
"toolchain = {'name': 'foss', 'version': '2018a'}",
@@ -2388,6 +2390,8 @@ def test_toy_sanity_check_commands(self):
23882390
" True,",
23892391
# test command to make sure that '-h' is not passed to commands specified as string ('env -h' fails)
23902392
" 'env',"
2393+
# print current working directory, should *not* be software install directory, but empty dir
2394+
f" '(pwd && ls | wc -l) > {out_file}',",
23912395
"]",
23922396
])
23932397

@@ -2412,6 +2416,13 @@ def test_toy_sanity_check_commands(self):
24122416

24132417
self.assertExists(toy_modfile)
24142418

2419+
# check contents of output file created by sanity check commands
2420+
self.assertExists(out_file)
2421+
out_txt = read_file(out_file)
2422+
# working dir for sanity check command should be an empty custom temporary directory
2423+
regex = re.compile('^.*/eb-[^/]+/eb-sanity-check-[^/]+\n[ ]*0$')
2424+
self.assertTrue(regex.match(out_txt), f"Pattern '{regex.pattern}' should match in: {out_txt}")
2425+
24152426
def test_sanity_check_paths_lib64(self):
24162427
"""Test whether fallback in sanity check for lib64/ equivalents of library files works."""
24172428
test_ecs_dir = os.path.join(os.path.abspath(os.path.dirname(__file__)), 'easyconfigs')

0 commit comments

Comments
 (0)