Skip to content

Commit 2397e60

Browse files
author
ocaisa
authored
Merge pull request #3153 from boegel/fix_check_checksums
take into account that a checksum value may be a tuple of valid checksum in EasyBlock.check_checksums
2 parents 114625c + 2b13d4b commit 2397e60

File tree

3 files changed

+54
-6
lines changed

3 files changed

+54
-6
lines changed

easybuild/framework/easyblock.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1829,7 +1829,7 @@ def checksum_step(self):
18291829

18301830
def check_checksums_for(self, ent, sub='', source_cnt=None):
18311831
"""
1832-
Utility method: check whether checksums for all sources/patches are available, for given entity
1832+
Utility method: check whether SHA256 checksums for all sources/patches are available, for given entity
18331833
"""
18341834
ec_fn = os.path.basename(self.cfg.path)
18351835
checksum_issues = []
@@ -1856,8 +1856,19 @@ def check_checksums_for(self, ent, sub='', source_cnt=None):
18561856
if isinstance(checksum, dict):
18571857
checksum = checksum.get(fn)
18581858

1859-
if not is_sha256_checksum(checksum):
1860-
msg = "Non-SHA256 checksum found for %s: %s" % (fn, checksum)
1859+
# take into account that we may encounter a tuple of valid SHA256 checksums
1860+
# (see https://github.com/easybuilders/easybuild-framework/pull/2958)
1861+
if isinstance(checksum, tuple):
1862+
# 1st tuple item may indicate checksum type, must be SHA256 or else it's blatently ignored here
1863+
if len(checksum) == 2 and checksum[0] == CHECKSUM_TYPE_SHA256:
1864+
valid_checksums = (checksum[1],)
1865+
else:
1866+
valid_checksums = checksum
1867+
else:
1868+
valid_checksums = (checksum,)
1869+
1870+
if not all(is_sha256_checksum(c) for c in valid_checksums):
1871+
msg = "Non-SHA256 checksum(s) found for %s: %s" % (fn, valid_checksums)
18611872
checksum_issues.append(msg)
18621873

18631874
return checksum_issues

test/framework/easyblock.py

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1690,7 +1690,7 @@ def run_checks():
16901690
expected = "Checksums missing for one or more sources/patches in toy-0.0-gompi-2018a-test.eb: "
16911691
expected += "found 1 sources + 1 patches vs 1 checksums"
16921692
self.assertEqual(res[0], expected)
1693-
self.assertTrue(res[1].startswith("Non-SHA256 checksum found for toy-0.0.tar.gz:"))
1693+
self.assertTrue(res[1].startswith("Non-SHA256 checksum(s) found for toy-0.0.tar.gz:"))
16941694

16951695
# check for main sources/patches should reveal two issues with checksums
16961696
res = eb.check_checksums_for(eb.cfg)
@@ -1708,6 +1708,43 @@ def run_checks():
17081708
self.assertTrue(res[idx].startswith(expected))
17091709
idx += 1
17101710

1711+
# check whether tuple of alternative SHA256 checksums is correctly recognized
1712+
toy_ec = os.path.join(testdir, 'easyconfigs', 'test_ecs', 't', 'toy', 'toy-0.0.eb')
1713+
1714+
ec = process_easyconfig(toy_ec)[0]
1715+
eb = get_easyblock_instance(ec)
1716+
1717+
# single SHA256 checksum per source/patch: OK
1718+
eb.cfg['checksums'] = [
1719+
'44332000aa33b99ad1e00cbd1a7da769220d74647060a10e807b916d73ea27bc', # toy-0.0.tar.gz
1720+
'45b5e3f9f495366830e1869bb2b8f4e7c28022739ce48d9f9ebb159b439823c5', # toy-*.patch
1721+
'4196b56771140d8e2468fb77f0240bc48ddbf5dabafe0713d612df7fafb1e458', # toy-extra.txt]
1722+
]
1723+
# no checksum issues
1724+
self.assertEqual(eb.check_checksums(), [])
1725+
1726+
# SHA256 checksum with type specifier: OK
1727+
eb.cfg['checksums'] = [
1728+
('sha256', '44332000aa33b99ad1e00cbd1a7da769220d74647060a10e807b916d73ea27bc'), # toy-0.0.tar.gz
1729+
'45b5e3f9f495366830e1869bb2b8f4e7c28022739ce48d9f9ebb159b439823c5', # toy-*.patch
1730+
('sha256', '4196b56771140d8e2468fb77f0240bc48ddbf5dabafe0713d612df7fafb1e458'), # toy-extra.txt]
1731+
]
1732+
# no checksum issues
1733+
self.assertEqual(eb.check_checksums(), [])
1734+
1735+
# tuple of two alternate SHA256 checksums: OK
1736+
eb.cfg['checksums'] = [
1737+
(
1738+
# two alternate checksums for toy-0.0.tar.gz
1739+
'a2848f34fcd5d6cf47def00461fcb528a0484d8edef8208d6d2e2909dc61d9cd',
1740+
'44332000aa33b99ad1e00cbd1a7da769220d74647060a10e807b916d73ea27bc',
1741+
),
1742+
'45b5e3f9f495366830e1869bb2b8f4e7c28022739ce48d9f9ebb159b439823c5', # toy-*.patch
1743+
'4196b56771140d8e2468fb77f0240bc48ddbf5dabafe0713d612df7fafb1e458', # toy-extra.txt
1744+
]
1745+
# no checksum issues
1746+
self.assertEqual(eb.check_checksums(), [])
1747+
17111748
def test_this_is_easybuild(self):
17121749
"""Test 'this_is_easybuild' function (and get_git_revision function used by it)."""
17131750
# make sure both return a non-Unicode string

test/framework/easyconfig.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3028,7 +3028,7 @@ def test_check_sha256_checksums(self):
30283028

30293029
res = check_sha256_checksums(ecs)
30303030
self.assertTrue(res)
3031-
self.assertTrue(res[-1].startswith("Non-SHA256 checksum found for toy-0.0.tar.gz"))
3031+
self.assertTrue(res[-1].startswith("Non-SHA256 checksum(s) found for toy-0.0.tar.gz"))
30323032

30333033
# re-test with right checksum in place
30343034
toy_sha256 = '44332000aa33b99ad1e00cbd1a7da769220d74647060a10e807b916d73ea27bc'
@@ -3052,7 +3052,7 @@ def test_check_sha256_checksums(self):
30523052
res = check_sha256_checksums(ecs)
30533053
self.assertTrue(res)
30543054
# multiple checksums listed for source tarball, while exactly one (SHA256) checksum is expected
3055-
self.assertTrue(res[1].startswith("Non-SHA256 checksum found for toy-0.0.tar.gz: "))
3055+
self.assertTrue(res[1].startswith("Non-SHA256 checksum(s) found for toy-0.0.tar.gz: "))
30563056

30573057
def test_deprecated(self):
30583058
"""Test use of 'deprecated' easyconfig parameter."""

0 commit comments

Comments
 (0)