Skip to content

Commit 62f4af3

Browse files
authored
Merge pull request #4526 from branfosj/checksums
deprecate old checksum options (incl. md5)
2 parents 98a13fc + d905f02 commit 62f4af3

File tree

16 files changed

+127
-91
lines changed

16 files changed

+127
-91
lines changed

easybuild/framework/easyblock.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@
7777
from easybuild.tools.config import build_option, build_path, get_log_filename, get_repository, get_repositorypath
7878
from easybuild.tools.config import install_path, log_path, package_path, source_paths
7979
from easybuild.tools.environment import restore_env, sanitize_env
80-
from easybuild.tools.filetools import CHECKSUM_TYPE_MD5, CHECKSUM_TYPE_SHA256
80+
from easybuild.tools.filetools import CHECKSUM_TYPE_SHA256
8181
from easybuild.tools.filetools import adjust_permissions, apply_patch, back_up_file, change_dir, check_lock
8282
from easybuild.tools.filetools import compute_checksum, convert_name, copy_file, create_lock, create_patch_info
8383
from easybuild.tools.filetools import derive_alt_pypi_url, diff_files, dir_contains_files, download_file
@@ -666,8 +666,7 @@ def collect_exts_file_info(self, fetch_files=True, verify_checksums=True):
666666
src_path = ext_src['src']
667667
src_fn = os.path.basename(src_path)
668668

669-
# report both MD5 and SHA256 checksums, since both are valid default checksum types
670-
for checksum_type in (CHECKSUM_TYPE_MD5, CHECKSUM_TYPE_SHA256):
669+
for checksum_type in [CHECKSUM_TYPE_SHA256]:
671670
src_checksum = compute_checksum(src_path, checksum_type=checksum_type)
672671
self.log.info("%s checksum for %s: %s", checksum_type, src_path, src_checksum)
673672

@@ -695,9 +694,7 @@ def collect_exts_file_info(self, fetch_files=True, verify_checksums=True):
695694
if verify_checksums:
696695
for patch in ext_patches:
697696
patch = patch['path']
698-
# report both MD5 and SHA256 checksums,
699-
# since both are valid default checksum types
700-
for checksum_type in (CHECKSUM_TYPE_MD5, CHECKSUM_TYPE_SHA256):
697+
for checksum_type in [CHECKSUM_TYPE_SHA256]:
701698
checksum = compute_checksum(patch, checksum_type=checksum_type)
702699
self.log.info("%s checksum for %s: %s", checksum_type, patch, checksum)
703700

@@ -2410,8 +2407,7 @@ def fetch_step(self, skip_checksums=False):
24102407
# compute checksums for all source and patch files
24112408
if not (skip_checksums or self.dry_run):
24122409
for fil in self.src + self.patches:
2413-
# report both MD5 and SHA256 checksums, since both are valid default checksum types
2414-
for checksum_type in [CHECKSUM_TYPE_MD5, CHECKSUM_TYPE_SHA256]:
2410+
for checksum_type in [CHECKSUM_TYPE_SHA256]:
24152411
fil[checksum_type] = compute_checksum(fil['path'], checksum_type=checksum_type)
24162412
self.log.info("%s checksum for %s: %s", checksum_type, fil['path'], fil[checksum_type])
24172413

easybuild/framework/easyconfig/types.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -516,7 +516,7 @@ def to_checksums(checksums):
516516
for checksum in checksums:
517517
# each list entry can be:
518518
# * None (indicates no checksum)
519-
# * a string (MD5 or SHA256 checksum)
519+
# * a string (SHA256 checksum)
520520
# * a tuple with 2 elements: checksum type + checksum value
521521
# * a list of checksums (i.e. multiple checksums for a single file)
522522
# * a dict (filename to checksum mapping)

easybuild/tools/filetools.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1192,12 +1192,16 @@ def compute_checksum(path, checksum_type=DEFAULT_CHECKSUM):
11921192
Compute checksum of specified file.
11931193
11941194
:param path: Path of file to compute checksum for
1195-
:param checksum_type: type(s) of checksum ('adler32', 'crc32', 'md5' (default), 'sha1', 'sha256', 'sha512', 'size')
1195+
:param checksum_type: type(s) of checksum ('adler32', 'crc32', 'md5', 'sha1', 'sha256', 'sha512', 'size')
11961196
"""
11971197
if checksum_type not in CHECKSUM_FUNCTIONS:
11981198
raise EasyBuildError("Unknown checksum type (%s), supported types are: %s",
11991199
checksum_type, CHECKSUM_FUNCTIONS.keys())
12001200

1201+
if checksum_type in ['adler32', 'crc32', 'md5', 'sha1', 'size']:
1202+
_log.deprecated("Checksum type %s is deprecated. Use sha256 (default) or sha512 instead" % checksum_type,
1203+
'6.0')
1204+
12011205
try:
12021206
checksum = CHECKSUM_FUNCTIONS[checksum_type](path)
12031207
except IOError as err:
@@ -1235,7 +1239,7 @@ def verify_checksum(path, checksums):
12351239
Verify checksum of specified file.
12361240
12371241
:param path: path of file to verify checksum of
1238-
:param checksums: checksum values (and type, optionally, default is MD5), e.g., 'af314', ('sha', '5ec1b')
1242+
:param checksums: checksum values (and type, optionally, default is sha256), e.g., 'af314', ('sha', '5ec1b')
12391243
"""
12401244

12411245
filename = os.path.basename(path)
@@ -1287,7 +1291,7 @@ def verify_checksum(path, checksums):
12871291
# no matching checksums
12881292
return False
12891293
else:
1290-
raise EasyBuildError("Invalid checksum spec '%s': should be a string (MD5 or SHA256), "
1294+
raise EasyBuildError("Invalid checksum spec '%s': should be a string (SHA256), "
12911295
"2-tuple (type, value), or tuple of alternative checksum specs.",
12921296
checksum)
12931297

test/framework/easyblock.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1536,9 +1536,8 @@ def test_fetch_sources(self):
15361536
self.assertTrue(os.path.samefile(eb.src[0]['path'], toy_source))
15371537
self.assertEqual(eb.src[0]['name'], 'toy-0.0.tar.gz')
15381538
self.assertEqual(eb.src[0]['cmd'], None)
1539-
self.assertEqual(len(eb.src[0]['checksum']), 7)
1540-
self.assertEqual(eb.src[0]['checksum'][0], 'be662daa971a640e40be5c804d9d7d10')
1541-
self.assertEqual(eb.src[0]['checksum'][1], '44332000aa33b99ad1e00cbd1a7da769220d74647060a10e807b916d73ea27bc')
1539+
self.assertEqual(len(eb.src[0]['checksum']), 2)
1540+
self.assertEqual(eb.src[0]['checksum'][0], '44332000aa33b99ad1e00cbd1a7da769220d74647060a10e807b916d73ea27bc')
15421541

15431542
# reconfigure EasyBuild so we can check 'downloaded' sources
15441543
os.environ['EASYBUILD_SOURCEPATH'] = self.test_prefix
@@ -2573,8 +2572,8 @@ def test_checksum_step(self):
25732572
copy_file(toy_ec, self.test_prefix)
25742573
toy_ec = os.path.join(self.test_prefix, os.path.basename(toy_ec))
25752574
ectxt = read_file(toy_ec)
2576-
# replace MD5 checksum for toy-0.0.tar.gz
2577-
ectxt = ectxt.replace('be662daa971a640e40be5c804d9d7d10', '00112233445566778899aabbccddeeff')
2575+
# replace SHA256 checksum for toy-0.0.tar.gz
2576+
ectxt = ectxt.replace('44332000aa33b99ad1e00cbd1a7da769220d74647060a10e807b916d73ea27bc', '76543210' * 8)
25782577
# replace SHA256 checksums for source of bar extension
25792578
ectxt = ectxt.replace('f3676716b610545a4e8035087f5be0a0248adee0abb3930d3edb76d498ae91e7', '01234567' * 8)
25802579
write_file(toy_ec, ectxt)
@@ -2664,7 +2663,8 @@ def test_checksum_step(self):
26642663
self.mock_stderr(False)
26652664
self.mock_stdout(False)
26662665
self.assertEqual(stdout, '')
2667-
self.assertEqual(stderr.strip(), "WARNING: Ignoring failing checksum verification for bar-0.0.tar.gz")
2666+
self.assertEqual(stderr.strip(), "WARNING: Ignoring failing checksum verification for bar-0.0.tar.gz\n\n\n"
2667+
"WARNING: Ignoring failing checksum verification for toy-0.0.tar.gz")
26682668

26692669
def test_check_checksums(self):
26702670
"""Test for check_checksums_for and check_checksums methods."""

test/framework/easyconfig.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,7 @@ def test_exts_list(self):
485485
# SHA256 checksum for source (gzip-1.4.eb)
486486
"6a5abcab719cefa95dca4af0db0d2a9d205d68f775a33b452ec0f2b75b6a3a45",
487487
# SHA256 checksum for 'patch' (toy-0.0.eb)
488-
"2d964e0e8f05a7cce0dd83a3e68c9737da14b87b61b8b8b0291d58d4c8d1031c",
488+
"177b34bcdfa1abde96f30354848a01894ebc9c24913bc5145306cd30f78fc8ad",
489489
],
490490
}),
491491
# Can use templates in name and version
@@ -509,7 +509,7 @@ def test_exts_list(self):
509509
self.assertEqual(exts_sources[1]['version'], '2.0')
510510
self.assertEqual(exts_sources[1]['options'], {
511511
'checksums': ['6a5abcab719cefa95dca4af0db0d2a9d205d68f775a33b452ec0f2b75b6a3a45',
512-
'2d964e0e8f05a7cce0dd83a3e68c9737da14b87b61b8b8b0291d58d4c8d1031c'],
512+
'177b34bcdfa1abde96f30354848a01894ebc9c24913bc5145306cd30f78fc8ad'],
513513
'patches': [('toy-0.0.eb', '.')],
514514
'source_tmpl': 'gzip-1.4.eb',
515515
'source_urls': [('http://example.com', 'suffix')],

test/framework/easyconfigs/test_ecs/t/toy/toy-0.0-deps.eb

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,10 @@ toolchain = SYSTEM
99

1010
sources = [SOURCE_TAR_GZ]
1111
checksums = [[
12-
'be662daa971a640e40be5c804d9d7d10', # default (MD5)
1312
'44332000aa33b99ad1e00cbd1a7da769220d74647060a10e807b916d73ea27bc', # default (SHA256)
14-
('adler32', '0x998410035'),
15-
('crc32', '0x1553842328'),
16-
('md5', 'be662daa971a640e40be5c804d9d7d10'),
17-
('sha1', 'f618096c52244539d0e89867405f573fdb0b55b0'),
18-
('size', 273),
13+
('sha512',
14+
'3c9dc629e1f2fd01a15c68f9f2a328b5da045c2ec1a189dc72d7195642f32e0'
15+
'ff59275aba5fa2a78e84417c7645d0ca5d06aff39e688a8936061ed5c4c600708'),
1916
]]
2017
patches = ['toy-0.0_fix-silly-typo-in-printf-statement.patch']
2118

test/framework/easyconfigs/test_ecs/t/toy/toy-0.0-gompi-2018a-test.eb

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,10 @@ toolchainopts = {'pic': True, 'opt': True, 'optarch': True}
1010

1111
sources = [SOURCE_TAR_GZ]
1212
checksums = [[
13-
'be662daa971a640e40be5c804d9d7d10', # default (MD5)
1413
'44332000aa33b99ad1e00cbd1a7da769220d74647060a10e807b916d73ea27bc', # default (SHA256)
15-
('adler32', '0x998410035'),
16-
('crc32', '0x1553842328'),
17-
('md5', 'be662daa971a640e40be5c804d9d7d10'),
18-
('sha1', 'f618096c52244539d0e89867405f573fdb0b55b0'),
19-
('size', 273),
14+
('sha512',
15+
'3c9dc629e1f2fd01a15c68f9f2a328b5da045c2ec1a189dc72d7195642f32e0'
16+
'ff59275aba5fa2a78e84417c7645d0ca5d06aff39e688a8936061ed5c4c600708'),
2017
{SOURCE_TAR_GZ: '44332000aa33b99ad1e00cbd1a7da769220d74647060a10e807b916d73ea27bc',
2118
'bar.tgz': '33ac60685a3e29538db5094259ea85c15906cbd0f74368733f4111eab6187c8f'},
2219
]]

test/framework/easyconfigs/test_ecs/t/toy/toy-0.0-gompi-2018a.eb

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,10 @@ toolchainopts = {'pic': True, 'opt': True, 'optarch': True}
99

1010
sources = [SOURCE_TAR_GZ]
1111
checksums = [[
12-
'be662daa971a640e40be5c804d9d7d10', # default (MD5)
1312
'44332000aa33b99ad1e00cbd1a7da769220d74647060a10e807b916d73ea27bc', # default (SHA256)
14-
('adler32', '0x998410035'),
15-
('crc32', '0x1553842328'),
16-
('md5', 'be662daa971a640e40be5c804d9d7d10'),
17-
('sha1', 'f618096c52244539d0e89867405f573fdb0b55b0'),
18-
('size', 273),
13+
('sha512',
14+
'3c9dc629e1f2fd01a15c68f9f2a328b5da045c2ec1a189dc72d7195642f32e0'
15+
'ff59275aba5fa2a78e84417c7645d0ca5d06aff39e688a8936061ed5c4c600708'),
1916
]]
2017
patches = [
2118
'toy-0.0_fix-silly-typo-in-printf-statement.patch',

test/framework/easyconfigs/test_ecs/t/toy/toy-0.0-multiple.eb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ toolchain = SYSTEM
1111
sources = [SOURCE_TAR_GZ]
1212
patches = ['toy-0.0_fix-silly-typo-in-printf-statement.patch']
1313
checksums = [
14-
('adler32', '0x998410035'),
15-
'a99f2a72cee1689a2f7e3ace0356efb1',
14+
'44332000aa33b99ad1e00cbd1a7da769220d74647060a10e807b916d73ea27bc',
15+
'81a3accc894592152f81814fbf133d39afad52885ab52c25018722c7bda92487',
1616
]
1717

1818
moduleclass = 'tools'

test/framework/easyconfigs/test_ecs/t/toy/toy-0.0-test.eb

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,10 @@ toolchain = SYSTEM
99

1010
sources = [SOURCE_TAR_GZ]
1111
checksums = [[
12-
'be662daa971a640e40be5c804d9d7d10', # default (MD5)
1312
'44332000aa33b99ad1e00cbd1a7da769220d74647060a10e807b916d73ea27bc', # default (SHA256)
14-
('adler32', '0x998410035'),
15-
('crc32', '0x1553842328'),
16-
('md5', 'be662daa971a640e40be5c804d9d7d10'),
17-
('sha1', 'f618096c52244539d0e89867405f573fdb0b55b0'),
18-
('size', 273),
13+
('sha512',
14+
'3c9dc629e1f2fd01a15c68f9f2a328b5da045c2ec1a189dc72d7195642f32e0'
15+
'ff59275aba5fa2a78e84417c7645d0ca5d06aff39e688a8936061ed5c4c600708'),
1916
]]
2017
patches = [
2118
'toy-0.0_fix-silly-typo-in-printf-statement.patch',

0 commit comments

Comments
 (0)