Skip to content

Commit f1cd377

Browse files
authored
Merge pull request #4261 from PetrKralCZ/20230519152245_new_pr_ptbySPkCbt
avoid error being logged when checksums.json is not found
2 parents 02ed943 + 0981458 commit f1cd377

File tree

2 files changed

+49
-8
lines changed

2 files changed

+49
-8
lines changed

easybuild/framework/easyblock.py

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -395,13 +395,13 @@ def get_checksums_from_json(self, always_read=False):
395395
:param always_read: always read the checksums.json file, even if it has been read before
396396
"""
397397
if always_read or self.json_checksums is None:
398-
try:
399-
path = self.obtain_file("checksums.json", no_download=True)
398+
path = self.obtain_file("checksums.json", no_download=True, warning_only=True)
399+
if path is not None:
400400
self.log.info("Loading checksums from file %s", path)
401401
json_txt = read_file(path)
402402
self.json_checksums = json.loads(json_txt)
403-
# if the file can't be found, return an empty dict
404-
except EasyBuildError:
403+
else:
404+
# if the file can't be found, return an empty dict
405405
self.json_checksums = {}
406406

407407
return self.json_checksums
@@ -736,7 +736,8 @@ def collect_exts_file_info(self, fetch_files=True, verify_checksums=True):
736736
return exts_sources
737737

738738
def obtain_file(self, filename, extension=False, urls=None, download_filename=None, force_download=False,
739-
git_config=None, no_download=False, download_instructions=None, alt_location=None):
739+
git_config=None, no_download=False, download_instructions=None, alt_location=None,
740+
warning_only=False):
740741
"""
741742
Locate the file with the given name
742743
- searches in different subdirectories of source path
@@ -789,7 +790,13 @@ def obtain_file(self, filename, extension=False, urls=None, download_filename=No
789790
return fullpath
790791

791792
except IOError as err:
792-
raise EasyBuildError("Downloading file %s from url %s to %s failed: %s", filename, url, fullpath, err)
793+
if not warning_only:
794+
raise EasyBuildError("Downloading file %s "
795+
"from url %s to %s failed: %s", filename, url, fullpath, err)
796+
else:
797+
self.log.warning("Downloading file %s "
798+
"from url %s to %s failed: %s", filename, url, fullpath, err)
799+
return None
793800

794801
else:
795802
# try and find file in various locations
@@ -866,8 +873,13 @@ def obtain_file(self, filename, extension=False, urls=None, download_filename=No
866873
self.dry_run_msg(" * %s (MISSING)", filename)
867874
return filename
868875
else:
869-
raise EasyBuildError("Couldn't find file %s anywhere, and downloading it is disabled... "
876+
if not warning_only:
877+
raise EasyBuildError("Couldn't find file %s anywhere, and downloading it is disabled... "
878+
"Paths attempted (in order): %s ", filename, ', '.join(failedpaths))
879+
else:
880+
self.log.warning("Couldn't find file %s anywhere, and downloading it is disabled... "
870881
"Paths attempted (in order): %s ", filename, ', '.join(failedpaths))
882+
return None
871883
elif git_config:
872884
return get_source_tarball_from_git(filename, targetdir, git_config)
873885
else:
@@ -959,7 +971,11 @@ def obtain_file(self, filename, extension=False, urls=None, download_filename=No
959971
error_msg += "and downloading it didn't work either... "
960972
error_msg += "Paths attempted (in order): %s " % failedpaths_msg
961973

962-
raise EasyBuildError(error_msg, filename)
974+
if not warning_only:
975+
raise EasyBuildError(error_msg, filename)
976+
else:
977+
self.log.warning(error_msg, filename)
978+
return None
963979

964980
#
965981
# GETTER/SETTER UTILITY FUNCTIONS

test/framework/easyblock.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
from unittest import TextTestRunner
4040

4141
import easybuild.tools.systemtools as st
42+
from easybuild.base import fancylogger
4243
from easybuild.framework.easyblock import EasyBlock, get_easyblock_instance
4344
from easybuild.framework.easyconfig import CUSTOM
4445
from easybuild.framework.easyconfig.easyconfig import EasyConfig
@@ -2424,6 +2425,30 @@ def test_checksum_step(self):
24242425
eb.fetch_sources()
24252426
eb.checksum_step()
24262427

2428+
with self.mocked_stdout_stderr() as (stdout, stderr):
2429+
2430+
# using checksum-less test easyconfig in location that does not provide checksums.json
2431+
test_ec = os.path.join(self.test_prefix, 'test-no-checksums.eb')
2432+
copy_file(toy_ec, test_ec)
2433+
write_file(test_ec, 'checksums = []', append=True)
2434+
ec = process_easyconfig(test_ec)[0]
2435+
2436+
# enable logging to screen, so we can check whether error is logged when checksums.json is not found
2437+
fancylogger.logToScreen(enable=True, stdout=True)
2438+
2439+
eb = get_easyblock_instance(ec)
2440+
eb.fetch_sources()
2441+
eb.checksum_step()
2442+
2443+
fancylogger.logToScreen(enable=False, stdout=True)
2444+
stdout = self.get_stdout()
2445+
2446+
# make sure there's no error logged for not finding checksums.json,
2447+
# see also https://github.com/easybuilders/easybuild-framework/issues/4301
2448+
regex = re.compile("ERROR .*Couldn't find file checksums.json anywhere", re.M)
2449+
regex.search(stdout)
2450+
self.assertFalse(regex.search(stdout), "Pattern '%s' should not be found in log" % regex.pattern)
2451+
24272452
# fiddle with checksum to check whether faulty checksum is catched
24282453
copy_file(toy_ec, self.test_prefix)
24292454
toy_ec = os.path.join(self.test_prefix, os.path.basename(toy_ec))

0 commit comments

Comments
 (0)