Skip to content

Commit

Permalink
Merge pull request #4261 from PetrKralCZ/20230519152245_new_pr_ptbySP…
Browse files Browse the repository at this point in the history
…kCbt

avoid error being logged when checksums.json is not found
  • Loading branch information
boegel authored Sep 9, 2023
2 parents 02ed943 + 0981458 commit f1cd377
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 8 deletions.
32 changes: 24 additions & 8 deletions easybuild/framework/easyblock.py
Original file line number Diff line number Diff line change
Expand Up @@ -395,13 +395,13 @@ def get_checksums_from_json(self, always_read=False):
:param always_read: always read the checksums.json file, even if it has been read before
"""
if always_read or self.json_checksums is None:
try:
path = self.obtain_file("checksums.json", no_download=True)
path = self.obtain_file("checksums.json", no_download=True, warning_only=True)
if path is not None:
self.log.info("Loading checksums from file %s", path)
json_txt = read_file(path)
self.json_checksums = json.loads(json_txt)
# if the file can't be found, return an empty dict
except EasyBuildError:
else:
# if the file can't be found, return an empty dict
self.json_checksums = {}

return self.json_checksums
Expand Down Expand Up @@ -736,7 +736,8 @@ def collect_exts_file_info(self, fetch_files=True, verify_checksums=True):
return exts_sources

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

except IOError as err:
raise EasyBuildError("Downloading file %s from url %s to %s failed: %s", filename, url, fullpath, err)
if not warning_only:
raise EasyBuildError("Downloading file %s "
"from url %s to %s failed: %s", filename, url, fullpath, err)
else:
self.log.warning("Downloading file %s "
"from url %s to %s failed: %s", filename, url, fullpath, err)
return None

else:
# try and find file in various locations
Expand Down Expand Up @@ -866,8 +873,13 @@ def obtain_file(self, filename, extension=False, urls=None, download_filename=No
self.dry_run_msg(" * %s (MISSING)", filename)
return filename
else:
raise EasyBuildError("Couldn't find file %s anywhere, and downloading it is disabled... "
if not warning_only:
raise EasyBuildError("Couldn't find file %s anywhere, and downloading it is disabled... "
"Paths attempted (in order): %s ", filename, ', '.join(failedpaths))
else:
self.log.warning("Couldn't find file %s anywhere, and downloading it is disabled... "
"Paths attempted (in order): %s ", filename, ', '.join(failedpaths))
return None
elif git_config:
return get_source_tarball_from_git(filename, targetdir, git_config)
else:
Expand Down Expand Up @@ -959,7 +971,11 @@ def obtain_file(self, filename, extension=False, urls=None, download_filename=No
error_msg += "and downloading it didn't work either... "
error_msg += "Paths attempted (in order): %s " % failedpaths_msg

raise EasyBuildError(error_msg, filename)
if not warning_only:
raise EasyBuildError(error_msg, filename)
else:
self.log.warning(error_msg, filename)
return None

#
# GETTER/SETTER UTILITY FUNCTIONS
Expand Down
25 changes: 25 additions & 0 deletions test/framework/easyblock.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
from unittest import TextTestRunner

import easybuild.tools.systemtools as st
from easybuild.base import fancylogger
from easybuild.framework.easyblock import EasyBlock, get_easyblock_instance
from easybuild.framework.easyconfig import CUSTOM
from easybuild.framework.easyconfig.easyconfig import EasyConfig
Expand Down Expand Up @@ -2424,6 +2425,30 @@ def test_checksum_step(self):
eb.fetch_sources()
eb.checksum_step()

with self.mocked_stdout_stderr() as (stdout, stderr):

# using checksum-less test easyconfig in location that does not provide checksums.json
test_ec = os.path.join(self.test_prefix, 'test-no-checksums.eb')
copy_file(toy_ec, test_ec)
write_file(test_ec, 'checksums = []', append=True)
ec = process_easyconfig(test_ec)[0]

# enable logging to screen, so we can check whether error is logged when checksums.json is not found
fancylogger.logToScreen(enable=True, stdout=True)

eb = get_easyblock_instance(ec)
eb.fetch_sources()
eb.checksum_step()

fancylogger.logToScreen(enable=False, stdout=True)
stdout = self.get_stdout()

# make sure there's no error logged for not finding checksums.json,
# see also https://github.com/easybuilders/easybuild-framework/issues/4301
regex = re.compile("ERROR .*Couldn't find file checksums.json anywhere", re.M)
regex.search(stdout)
self.assertFalse(regex.search(stdout), "Pattern '%s' should not be found in log" % regex.pattern)

# fiddle with checksum to check whether faulty checksum is catched
copy_file(toy_ec, self.test_prefix)
toy_ec = os.path.join(self.test_prefix, os.path.basename(toy_ec))
Expand Down

0 comments on commit f1cd377

Please sign in to comment.