Bug 1296354 - Use actual content hash to compare fiels if ETags are different. r=nthomas a=release DONTBUILD draft
authorRail Aliiev <rail@mozilla.com>
Fri, 26 Aug 2016 10:06:21 -0400
changeset 406114 59d5faa2dec5f3ef7eddc06e1b2f7c07e0e14ec4
parent 406113 ac16b2ccd7a11e81b8d2fcb84146c6460a188256
child 529584 28851850d745d23bd4e77cfe1b7c4cc14a339b61
push id27647
push userbmo:rail@mozilla.com
push dateFri, 26 Aug 2016 14:06:49 +0000
reviewersnthomas, release
bugs1296354
milestone51.0a1
Bug 1296354 - Use actual content hash to compare fiels if ETags are different. r=nthomas a=release DONTBUILD MozReview-Commit-ID: vovlfndXrK
testing/mozharness/mozharness/base/script.py
testing/mozharness/scripts/release/push-candidate-to-releases.py
--- a/testing/mozharness/mozharness/base/script.py
+++ b/testing/mozharness/mozharness/base/script.py
@@ -2025,16 +2025,21 @@ class BaseScript(ScriptMixin, LogMixin, 
         hasher = hashlib.sha512()
         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()
 
+    def get_content_hash(self, content, hash_type="sha512"):
+        h = hashlib.new(hash_type)
+        h.update(content)
+        return h.hexdigest()
+
     @property
     def return_code(self):
         return self._return_code
 
     @return_code.setter
     def return_code(self, code):
         old_return_code, self._return_code = self._return_code, code
         if old_return_code != code:
--- a/testing/mozharness/scripts/release/push-candidate-to-releases.py
+++ b/testing/mozharness/scripts/release/push-candidate-to-releases.py
@@ -166,19 +166,29 @@ class ReleasePusher(BaseScript, Virtuale
                     self.info("Copying {} to {}".format(source, destination))
                     bucket.copy_key(destination, self.config["bucket_name"],
                                     source)
                 elif source_md5 == dest_md5:
                     self.warning(
                         "{} already exists with the same content ({}), skipping copy".format(
                             destination, dest_md5))
                 else:
-                    self.fatal(
-                        "{} already exists with the different content (src ETag: {}, dest ETag: {}), aborting".format(
+                    self.warn(
+                        "{} already exists with the different content (src ETag: {}, dest ETag: {}), comparing content...".format(
                             destination, source_key.etag, dest_key.etag))
+                    source_hash = self.get_content_hash(source_key.get_contents_as_string())
+                    dest_hash = self.get_content_hash(dest_key.get_contents_as_string())
+                    if source_hash == dest_hash:
+                        self.warning(
+                            "{} already exists with the same content ({}), skipping copy".format(
+                                destination, dest_hash))
+                    else:
+                        self.fatal(
+                            "{} already exists with the different content (src ETag: {}, dest ETag: {}), aborting".format(
+                                destination, source_key.etag, dest_key.etag))
 
             return retry(copy_key, sleeptime=5, max_sleeptime=60,
                          retry_exceptions=(S3CopyError, S3ResponseError))
 
         def find_release_files():
             candidates_prefix = self._get_candidates_prefix()
             release_prefix = self._get_releases_prefix()
             self.info("Getting key names from candidates")