Skip to content

Commit c32f8d9

Browse files
authored
Merge pull request #3761 from boegel/fix_sanity_check_only
don't make changes to software installation directory when using --sanity-check-only
2 parents 8e0a02f + 7de5403 commit c32f8d9

File tree

2 files changed

+55
-37
lines changed

2 files changed

+55
-37
lines changed

easybuild/framework/easyblock.py

Lines changed: 31 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3700,6 +3700,11 @@ def build_and_install_one(ecdict, init_env):
37003700
new_log_dir = os.path.join(app.builddir, config.log_path(ec=app.cfg))
37013701
else:
37023702
new_log_dir = os.path.dirname(app.logfile)
3703+
3704+
# if we're only running the sanity check, we should not copy anything new to the installation directory
3705+
elif build_option('sanity_check_only'):
3706+
_log.info("Only running sanity check, so skipping build stats, easyconfigs archive, reprod files...")
3707+
37033708
else:
37043709
new_log_dir = os.path.join(app.installdir, config.log_path(ec=app.cfg))
37053710
if build_option('read_only_installdir'):
@@ -3749,30 +3754,35 @@ def build_and_install_one(ecdict, init_env):
37493754

37503755
# cleanup logs
37513756
app.close_log()
3752-
log_fn = os.path.basename(get_log_filename(app.name, app.version))
3753-
try:
3754-
application_log = os.path.join(new_log_dir, log_fn)
3755-
move_logs(app.logfile, application_log)
37563757

3757-
newspec = os.path.join(new_log_dir, app.cfg.filename())
3758-
copy_file(spec, newspec)
3759-
_log.debug("Copied easyconfig file %s to %s", spec, newspec)
3758+
if build_option('sanity_check_only'):
3759+
_log.info("Only running sanity check, so not copying anything to software install directory...")
3760+
else:
3761+
log_fn = os.path.basename(get_log_filename(app.name, app.version))
3762+
try:
3763+
application_log = os.path.join(new_log_dir, log_fn)
3764+
move_logs(app.logfile, application_log)
37603765

3761-
# copy patches
3762-
for patch in app.patches:
3763-
target = os.path.join(new_log_dir, os.path.basename(patch['path']))
3764-
copy_file(patch['path'], target)
3765-
_log.debug("Copied patch %s to %s", patch['path'], target)
3766+
newspec = os.path.join(new_log_dir, app.cfg.filename())
3767+
copy_file(spec, newspec)
3768+
_log.debug("Copied easyconfig file %s to %s", spec, newspec)
37663769

3767-
if build_option('read_only_installdir'):
3768-
# take away user write permissions (again)
3769-
adjust_permissions(new_log_dir, stat.S_IWUSR | stat.S_IWGRP | stat.S_IWOTH, add=False, recursive=True)
3770-
except EasyBuildError as error:
3771-
if build_option('module_only'):
3772-
application_log = None
3773-
_log.debug("Using --module-only so can recover from error: %s", error)
3774-
else:
3775-
raise error
3770+
# copy patches
3771+
for patch in app.patches:
3772+
target = os.path.join(new_log_dir, os.path.basename(patch['path']))
3773+
copy_file(patch['path'], target)
3774+
_log.debug("Copied patch %s to %s", patch['path'], target)
3775+
3776+
if build_option('read_only_installdir'):
3777+
# take away user write permissions (again)
3778+
perms = stat.S_IWUSR | stat.S_IWGRP | stat.S_IWOTH
3779+
adjust_permissions(new_log_dir, perms, add=False, recursive=True)
3780+
except EasyBuildError as error:
3781+
if build_option('module_only'):
3782+
application_log = None
3783+
_log.debug("Using --module-only so can recover from error: %s", error)
3784+
else:
3785+
raise error
37763786

37773787
end_timestamp = datetime.now()
37783788

test/framework/options.py

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import os
3232
import re
3333
import shutil
34+
import stat
3435
import sys
3536
import tempfile
3637
from distutils.version import LooseVersion
@@ -50,9 +51,9 @@
5051
from easybuild.tools.config import DEFAULT_MODULECLASSES
5152
from easybuild.tools.config import find_last_log, get_build_log_path, get_module_syntax, module_classes
5253
from easybuild.tools.environment import modify_env
53-
from easybuild.tools.filetools import change_dir, copy_dir, copy_file, download_file, is_patch_file, mkdir
54-
from easybuild.tools.filetools import parse_http_header_fields_urlpat, read_file, remove_dir, remove_file
55-
from easybuild.tools.filetools import which, write_file
54+
from easybuild.tools.filetools import adjust_permissions, change_dir, copy_dir, copy_file, download_file
55+
from easybuild.tools.filetools import is_patch_file, mkdir, move_file, parse_http_header_fields_urlpat
56+
from easybuild.tools.filetools import read_file, remove_dir, remove_file, which, write_file
5657
from easybuild.tools.github import GITHUB_RAW, GITHUB_EB_MAIN, GITHUB_EASYCONFIGS_REPO
5758
from easybuild.tools.github import URL_SEPARATOR, fetch_github_token
5859
from easybuild.tools.modules import Lmod
@@ -1105,11 +1106,14 @@ def test_show_ec(self):
11051106
regex = re.compile(pattern, re.M)
11061107
self.assertTrue(regex.search(stdout), "Pattern '%s' found in: %s" % (regex.pattern, stdout))
11071108

1108-
def mocked_main(self, args):
1109+
def mocked_main(self, args, **kwargs):
11091110
"""Run eb_main with mocked stdout/stderr."""
1111+
if not kwargs:
1112+
kwargs = {'raise_error': True}
1113+
11101114
self.mock_stderr(True)
11111115
self.mock_stdout(True)
1112-
self.eb_main(args, raise_error=True)
1116+
self.eb_main(args, **kwargs)
11131117
stderr, stdout = self.get_stderr(), self.get_stdout()
11141118
self.mock_stderr(False)
11151119
self.mock_stdout(False)
@@ -5867,15 +5871,8 @@ def test_sanity_check_only(self):
58675871

58685872
args = [test_ec, '--sanity-check-only']
58695873

5870-
self.mock_stdout(True)
5871-
self.mock_stderr(True)
5872-
self.eb_main(args + ['--trace'], do_build=True, raise_error=True, testing=False)
5873-
stdout = self.get_stdout().strip()
5874-
stderr = self.get_stderr().strip()
5875-
self.mock_stdout(False)
5876-
self.mock_stderr(False)
5874+
stdout = self.mocked_main(args + ['--trace'], do_build=True, raise_error=True, testing=False)
58775875

5878-
self.assertFalse(stderr)
58795876
skipped = [
58805877
"fetching files",
58815878
"creating build dir, resetting environment",
@@ -5910,10 +5907,12 @@ def test_sanity_check_only(self):
59105907
for msg in msgs:
59115908
self.assertTrue(msg in stdout, "'%s' found in: %s" % (msg, stdout))
59125909

5910+
ebroottoy = os.path.join(self.test_installpath, 'software', 'toy', '0.0')
5911+
59135912
# check if sanity check for extension fails if a file provided by that extension,
5914-
# which is checked by the sanity check for that extension, is removed
5915-
libbarbar = os.path.join(self.test_installpath, 'software', 'toy', '0.0', 'lib', 'libbarbar.a')
5916-
remove_file(libbarbar)
5913+
# which is checked by the sanity check for that extension, is no longer there
5914+
libbarbar = os.path.join(ebroottoy, 'lib', 'libbarbar.a')
5915+
move_file(libbarbar, libbarbar + '.moved')
59175916

59185917
outtxt, error_thrown = self.eb_main(args + ['--debug'], do_build=True, return_error=True)
59195918
error_msg = str(error_thrown)
@@ -5929,6 +5928,15 @@ def test_sanity_check_only(self):
59295928
outtxt = self.eb_main(args + ['--skip-extensions'], do_build=True, raise_error=True)
59305929
self.assertTrue("Sanity check for toy successful" in outtxt)
59315930

5931+
# restore fail, we want a passing sanity check for the next check
5932+
move_file(libbarbar + '.moved', libbarbar)
5933+
5934+
# check use of --sanity-check-only when installation directory is read-only;
5935+
# cfr. https://github.com/easybuilders/easybuild-framework/issues/3757
5936+
adjust_permissions(ebroottoy, stat.S_IWUSR | stat.S_IWGRP | stat.S_IWOTH, add=False, recursive=True)
5937+
5938+
stdout = self.mocked_main(args + ['--trace'], do_build=True, raise_error=True, testing=False)
5939+
59325940
def test_skip_extensions(self):
59335941
"""Test use of --skip-extensions."""
59345942
topdir = os.path.abspath(os.path.dirname(__file__))

0 commit comments

Comments
 (0)