Skip to content

Commit 068bad1

Browse files
committed
Make logdir writable also when --stop/--fetch is given
1 parent 20808ff commit 068bad1

File tree

2 files changed

+34
-10
lines changed

2 files changed

+34
-10
lines changed

easybuild/framework/easyblock.py

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3690,15 +3690,21 @@ def build_and_install_one(ecdict, init_env):
36903690

36913691
if os.path.exists(app.installdir) and build_option('read_only_installdir') and (
36923692
build_option('rebuild') or build_option('force')):
3693+
enabled_write_permissions = True
36933694
# re-enable write permissions so we can install additional modules
36943695
adjust_permissions(app.installdir, stat.S_IWUSR, add=True, recursive=True)
3696+
else:
3697+
enabled_write_permissions = False
36953698

36963699
result = app.run_all_steps(run_test_cases=run_test_cases)
36973700

36983701
if not dry_run:
36993702
# also add any extension easyblocks used during the build for reproducibility
37003703
if app.ext_instances:
37013704
copy_easyblocks_for_reprod(app.ext_instances, reprod_dir)
3705+
# If not already done remove the granted write permissions if we did so
3706+
if enabled_write_permissions and os.lstat(app.installdir)[stat.ST_MODE] & stat.S_IWUSR:
3707+
adjust_permissions(app.installdir, stat.S_IWUSR, add=False, recursive=True)
37023708

37033709
except EasyBuildError as err:
37043710
first_n = 300
@@ -3715,28 +3721,37 @@ def build_and_install_one(ecdict, init_env):
37153721

37163722
# successful (non-dry-run) build
37173723
if result and not dry_run:
3724+
def ensure_writable_log_dir(log_dir):
3725+
"""Make sure we can write into the log dir"""
3726+
if build_option('read_only_installdir'):
3727+
# temporarily re-enable write permissions for copying log/easyconfig to install dir
3728+
if os.path.exists(log_dir):
3729+
adjust_permissions(log_dir, stat.S_IWUSR, add=True, recursive=True)
3730+
else:
3731+
parent_dir = os.path.dirname(log_dir)
3732+
if os.path.exists(parent_dir):
3733+
adjust_permissions(parent_dir, stat.S_IWUSR, add=True, recursive=False)
3734+
mkdir(log_dir, parents=True)
3735+
adjust_permissions(parent_dir, stat.S_IWUSR, add=False, recursive=False)
3736+
else:
3737+
mkdir(log_dir, parents=True)
3738+
adjust_permissions(log_dir, stat.S_IWUSR, add=True, recursive=True)
37183739

37193740
if app.cfg['stop']:
37203741
ended = 'STOPPED'
37213742
if app.builddir is not None:
37223743
new_log_dir = os.path.join(app.builddir, config.log_path(ec=app.cfg))
37233744
else:
37243745
new_log_dir = os.path.dirname(app.logfile)
3746+
ensure_writable_log_dir(new_log_dir)
37253747

37263748
# if we're only running the sanity check, we should not copy anything new to the installation directory
37273749
elif build_option('sanity_check_only'):
37283750
_log.info("Only running sanity check, so skipping build stats, easyconfigs archive, reprod files...")
37293751

37303752
else:
37313753
new_log_dir = os.path.join(app.installdir, config.log_path(ec=app.cfg))
3732-
if build_option('read_only_installdir'):
3733-
# temporarily re-enable write permissions for copying log/easyconfig to install dir
3734-
if os.path.exists(new_log_dir):
3735-
adjust_permissions(new_log_dir, stat.S_IWUSR, add=True, recursive=True)
3736-
else:
3737-
adjust_permissions(app.installdir, stat.S_IWUSR, add=True, recursive=False)
3738-
mkdir(new_log_dir, parents=True)
3739-
adjust_permissions(app.installdir, stat.S_IWUSR, add=False, recursive=False)
3754+
ensure_writable_log_dir(new_log_dir)
37403755

37413756
# collect build stats
37423757
_log.info("Collecting build stats...")

test/framework/toy_build.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ def check_toy(self, installpath, outtxt, version='0.0', versionprefix='', versio
112112
full_version = ''.join([versionprefix, version, versionsuffix])
113113

114114
# check for success
115-
success = re.compile(r"COMPLETED: Installation ended successfully \(took .* secs?\)")
115+
success = re.compile(r"COMPLETED: Installation (ended|STOPPED) successfully \(took .* secs?\)")
116116
self.assertTrue(success.search(outtxt), "COMPLETED message found in '%s" % outtxt)
117117

118118
# if the module exists, it should be fine
@@ -615,7 +615,16 @@ def test_toy_permissions_installdir(self):
615615
# 2. Existing build with --rebuild -> Reinstall and set read-only
616616
# 3. Existing build with --force -> Reinstall and set read-only
617617
# 4-5: Same as 2-3 but with --skip
618-
for extra_args in ([], ['--rebuild'], ['--force'], ['--skip', '--rebuild'], ['--skip', '--force']):
618+
# 6. Existing build with --fetch -> Test that logs can be written
619+
test_cases = (
620+
[],
621+
['--rebuild'],
622+
['--force'],
623+
['--skip', '--rebuild'],
624+
['--skip', '--force'],
625+
['--rebuild', '--fetch'],
626+
)
627+
for extra_args in test_cases:
619628
self.mock_stdout(True)
620629
self.test_toy_build(ec_file=test_ec, extra_args=['--read-only-installdir'] + extra_args, force=False)
621630
self.mock_stdout(False)

0 commit comments

Comments
 (0)