Bug 1241061 - [firefox-ui-tests] Workaround for bug 1237706 to use ZipFile if unzip command is not available. r=maja_zf DONTBUILD
authorHenrik Skupin <mail@hskupin.info>
Thu, 21 Jan 2016 11:57:08 +0100
changeset 281111 c345486a8f5149db8ab622926c93dbc23f89e1b3
parent 281110 485b9de85b9d11c8db952e5ca4926efef1d38b04
child 281112 fa5e60f6adaa4e82e1f3d993108c67654c2fcc25
push id19403
push usercbook@mozilla.com
push dateFri, 22 Jan 2016 13:51:28 +0000
treeherderb2g-inbound@233069cc7590 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmaja_zf
bugs1241061, 1237706
milestone46.0a1
Bug 1241061 - [firefox-ui-tests] Workaround for bug 1237706 to use ZipFile if unzip command is not available. r=maja_zf DONTBUILD
testing/mozharness/mozharness/mozilla/testing/firefox_ui_tests.py
--- a/testing/mozharness/mozharness/mozilla/testing/firefox_ui_tests.py
+++ b/testing/mozharness/mozharness/mozilla/testing/firefox_ui_tests.py
@@ -178,25 +178,31 @@ class FirefoxUITests(TestingMixin, VCSTo
         """Delete the working directory"""
         super(FirefoxUITests, self).clobber()
 
         # Also ensure to delete the reports directory to get rid of old files
         dirs = self.query_abs_dirs()
         self.rmtree(dirs['abs_reports_dir'], error_level=FATAL)
 
     def download_and_extract(self):
-        """Overriding method from TestingMixin until firefox-ui-tests are in tree and
-        supported across all branches.
+        """Overriding method from TestingMixin for more specific behavior.
 
         We use the test_packages_url command line argument to check where to get the
         harness, puppeteer, and tests from and how to set them up.
 
         """
         if self.test_packages_url or self.test_url:
-            super(FirefoxUITests, self).download_and_extract()
+            target_unzip_dirs = ['config/*',
+                                 'firefox-ui/*',
+                                 'marionette/*',
+                                 'mozbase/*',
+                                 'puppeteer/*',
+                                 'tools/wptserve/*',
+                                 ]
+            super(FirefoxUITests, self).download_and_extract(target_unzip_dirs=target_unzip_dirs)
 
         else:
             self.checkout()
             self._download_installer()
 
             if self.config.get('download_symbols'):
                 self._download_and_extract_symbols()
 
@@ -343,16 +349,61 @@ class FirefoxUITests(TestingMixin, VCSTo
 
     def run_tests(self):
         """Run all the tests"""
         return self.run_test(
             binary_path=self.binary_path,
             env=self.query_env(),
         )
 
+    def download_unzip(self, url, parent_dir, target_unzip_dirs=None, halt_on_failure=True):
+        """Overwritten method from BaseScript until bug 1237706 is fixed.
+
+        The downloaded file will always be saved to the working directory and is not getting
+        deleted after extracting.
+
+        Args:
+            url (str): URL where the file to be downloaded is located.
+            parent_dir (str): directory where the downloaded file will
+                              be extracted to.
+            target_unzip_dirs (list, optional): directories inside the zip file to extract.
+                                                Defaults to `None`.
+            halt_on_failure (bool, optional): whether or not to redefine the
+                                              log level as `FATAL` on errors. Defaults to True.
+
+        """
+        import fnmatch
+        import itertools
+        import functools
+        import zipfile
+
+        def _filter_entries(namelist):
+            """Filter entries of the archive based on the specified list of extract_dirs."""
+            filter_partial = functools.partial(fnmatch.filter, namelist)
+            for entry in itertools.chain(*map(filter_partial, target_unzip_dirs or ['*'])):
+                yield entry
+
+        dirs = self.query_abs_dirs()
+        zip = self.download_file(url, parent_dir=dirs['abs_work_dir'],
+                                 error_level=FATAL)
+
+        try:
+            self.info('Using ZipFile to extract {} to {}'.format(zip, parent_dir))
+            with zipfile.ZipFile(zip) as bundle:
+                for entry in _filter_entries(bundle.namelist()):
+                    bundle.extract(entry, path=parent_dir)
+
+                    # ZipFile doesn't preserve permissions: http://bugs.python.org/issue15795
+                    fname = os.path.realpath(os.path.join(parent_dir, entry))
+                    mode = bundle.getinfo(entry).external_attr >> 16 & 0x1FF
+                    os.chmod(fname, mode)
+        except zipfile.BadZipfile as e:
+            self.log('%s (%s)' % (e.message, zip),
+                     level=FATAL, exit_code=2)
+
 
 class FirefoxUIFunctionalTests(FirefoxUITests):
 
     cli_script = 'cli_functional.py'
 
 
 class FirefoxUIUpdateTests(FirefoxUITests):