Bug 1338232 - add sha256 hash in checksums automation. r=rail a=release DONTBUILD
authorMihai Tabara <mtabara@mozilla.com>
Fri, 17 Feb 2017 21:16:20 +0200
changeset 376308 b21ecf4c9ef5d8206e358581483d03ae37e8a59d
parent 376307 d57841320b5495f190734e16e3f5eb25a008379a
child 376309 53189303b53dbf20ca068c9081232b7ae7ec01d4
push id6996
push userjlorenzo@mozilla.com
push dateMon, 06 Mar 2017 20:48:21 +0000
treeherdermozilla-beta@d89512dab048 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersrail, release
bugs1338232
milestone53.0a2
Bug 1338232 - add sha256 hash in checksums automation. r=rail a=release DONTBUILD MozReview-Commit-ID: C0tahX0pG55
testing/mozharness/mozharness/base/script.py
testing/mozharness/scripts/release/beet_mover.py
testing/mozharness/scripts/release/generate-checksums.py
--- a/testing/mozharness/mozharness/base/script.py
+++ b/testing/mozharness/mozharness/base/script.py
@@ -2236,19 +2236,19 @@ class BaseScript(ScriptMixin, LogMixin, 
                     return -1
         self.copyfile(target, dest, log_level=log_level, compress=compress)
         if os.path.exists(dest):
             return dest
         else:
             self.log("%s doesn't exist after copy!" % dest, level=error_level)
             return None
 
-    def file_sha512sum(self, file_path):
+    def get_hash_for_file(self, file_path, hash_type="sha512"):
         bs = 65536
-        hasher = hashlib.sha512()
+        hasher = hashlib.new(hash_type)
         with open(file_path, 'rb') as fh:
             buf = fh.read(bs)
             while len(buf) > 0:
                 hasher.update(buf)
                 buf = fh.read(bs)
         return hasher.hexdigest()
 
     @property
--- a/testing/mozharness/scripts/release/beet_mover.py
+++ b/testing/mozharness/scripts/release/beet_mover.py
@@ -115,16 +115,18 @@ MIME_MAP = {
     '.bundle': 'application/octet-stream',
     '.bz2': 'application/octet-stream',
     '.checksums': 'text/plain',
     '.dmg': 'application/x-iso9660-image',
     '.mar': 'application/octet-stream',
     '.xpi': 'application/x-xpinstall'
 }
 
+HASH_FORMATS = ["sha512", "sha256"]
+
 
 class BeetMover(BaseScript, VirtualenvMixin, object):
     def __init__(self, aws_creds):
         beetmover_kwargs = {
             'config_options': CONFIG_OPTIONS,
             'all_actions': [
                 # 'clobber',
                 'create-virtualenv',
@@ -286,20 +288,23 @@ class BeetMover(BaseScript, VirtualenvMi
                 downloaded_file = os.path.join(dirs['abs_work_dir'], self.get_filename_from_url(source))
                 # generate checksums for every uploaded file
                 beet_file_name = '{}.beet'.format(downloaded_file)
                 # upload checksums to a separate subdirectory
                 beet_dest = '{prefix}beetmover-checksums/{f}.beet'.format(
                     prefix=self._get_template_vars()["s3_prefix"],
                     f=self._strip_prefix(s3_key)
                 )
-                beet_contents = '{hash} sha512 {size} {name}\n'.format(
-                    hash=self.file_sha512sum(downloaded_file),
-                    size=os.path.getsize(downloaded_file),
-                    name=self._strip_prefix(s3_key))
+                beet_contents = '\n'.join([
+                    '{hash} {fmt} {size} {name}'.format(
+                        hash=self.get_hash_for_file(downloaded_file, hash_type=algo),
+                        fmt=fmt,
+                        size=os.path.getsize(downloaded_file),
+                        name=self._strip_prefix(s3_key)) for fmt in HASH_FORMATS
+                ])
                 self.write_to_file(beet_file_name, beet_contents)
                 self.upload_bit(source=downloaded_file, s3_key=s3_key,
                                 bucket=bucket)
                 self.upload_bit(source=beet_file_name, s3_key=beet_dest,
                                 bucket=bucket)
         self.log('Success!')
 
 
--- a/testing/mozharness/scripts/release/generate-checksums.py
+++ b/testing/mozharness/scripts/release/generate-checksums.py
@@ -114,17 +114,17 @@ class ChecksumsGenerator(BaseScript, Vir
         for prop in ['version', 'build_number']:
             if props.get(prop):
                 self.info("Overriding %s with %s" % (prop, props[prop]))
                 self.config[prop] = props.get(prop)
 
         # These defaults are set here rather in the config because default
         # lists cannot be completely overidden, only appended to.
         if not self.config.get("formats"):
-            self.config["formats"] = ["sha512"]
+            self.config["formats"] = ["sha512", "sha256"]
 
         if not self.config.get("includes"):
             self.config["includes"] = [
                 r"^.*\.tar\.bz2$",
                 r"^.*\.tar\.xz$",
                 r"^.*\.dmg$",
                 r"^.*\.bundle$",
                 r"^.*\.mar$",