Bug 1291710 - Use taskcluster environment to identify repo for Android mozharness; r=Callek
authorGeoff Brown <gbrown@mozilla.com>
Thu, 04 Aug 2016 07:14:23 -0600
changeset 308239 45bff034255d83e32ebe2207aa549f7ae4b0da3d
parent 308238 4e8a67e61102cb05b004fb4b9557ebb41812b9d0
child 308240 b614ddc26ff9a10fc4fa3ee2b6edaf8e5021e243
push id31092
push usercbook@mozilla.com
push dateFri, 05 Aug 2016 10:16:59 +0000
treeherderautoland@b97dd7dd3cb9 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersCallek
bugs1291710
milestone51.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1291710 - Use taskcluster environment to identify repo for Android mozharness; r=Callek
testing/mozharness/scripts/android_emulator_unittest.py
testing/mozharness/scripts/androidx86_emulator_unittest.py
--- a/testing/mozharness/scripts/android_emulator_unittest.py
+++ b/testing/mozharness/scripts/android_emulator_unittest.py
@@ -521,16 +521,43 @@ class AndroidEmulatorTest(BlobUploadMixi
         cmd.extend(try_options)
         cmd.extend(self.query_tests_args(
             self.config["suite_definitions"][self.test_suite].get("tests"),
             None,
             try_tests))
 
         return cmd
 
+    def _get_repo_url(self, path):
+        """
+           Return a url for a file (typically a tooltool manifest) in this hg repo
+           and using this revision (or mozilla-central/default if repo/rev cannot
+           be determined).
+
+           :param path specifies the directory path to the file of interest.
+        """
+        if 'GECKO_HEAD_REPOSITORY' in os.environ and 'GECKO_HEAD_REV' in os.environ:
+            # probably taskcluster
+            repo = os.environ['GECKO_HEAD_REPOSITORY']
+            revision = os.environ['GECKO_HEAD_REV']
+        elif self.buildbot_config and 'properties' in self.buildbot_config:
+            # probably buildbot
+            repo = 'https://hg.mozilla.org/%s' % self.buildbot_config['properties']['repo_path']
+            revision = self.buildbot_config['properties']['revision']
+        else:
+            # something unexpected!
+            repo = 'https://hg.mozilla.org/mozilla-central'
+            revision = 'default'
+            self.warning('Unable to find repo/revision for manifest; using mozilla-central/default')
+        url = '%s/raw-file/%s/%s' % (
+            repo,
+            revision,
+            path)
+        return url
+
     def _tooltool_fetch(self, url, dir):
         c = self.config
 
         manifest_path = self.download_file(
             url,
             file_name='releng.manifest',
             parent_dir=dir
         )
@@ -556,30 +583,18 @@ class AndroidEmulatorTest(BlobUploadMixi
         dirs = self.query_abs_dirs()
 
         # FIXME
         # Clobbering and re-unpacking would not be needed if we had a way to
         # check whether the unpacked content already present match the
         # contents of the tar ball
         self.rmtree(dirs['abs_avds_dir'])
         self.mkdir_p(dirs['abs_avds_dir'])
-        if not self.buildbot_config:
-            # XXX until we figure out how to determine the repo_path, revision
-            url = 'https://hg.mozilla.org/%s/raw-file/%s/%s' % (
-                "try", "default", c["tooltool_manifest_path"])
-            self._tooltool_fetch(url, dirs['abs_avds_dir'])
-        elif self.buildbot_config and 'properties' in self.buildbot_config:
-            url = 'https://hg.mozilla.org/%s/raw-file/%s/%s' % (
-                self.buildbot_config['properties']['repo_path'],
-                self.buildbot_config['properties']['revision'],
-                c["tooltool_manifest_path"])
-            self._tooltool_fetch(url, dirs['abs_avds_dir'])
-        else:
-            self.fatal("properties in self.buildbot_config are required to "
-                       "retrieve tooltool manifest to be used for avds setup")
+        url = self._get_repo_url(c["tooltool_manifest_path"])
+        self._tooltool_fetch(url, dirs['abs_avds_dir'])
 
         avd_home_dir = self.abs_dirs['abs_avds_dir']
         if avd_home_dir != "/home/cltbld/.android":
             # Modify the downloaded avds to point to the right directory.
             cmd = [
                 'bash', '-c',
                 'sed -i "s|/home/cltbld/.android|%s|" %s/test-*.ini' %
                 (avd_home_dir, os.path.join(avd_home_dir, 'avd'))
@@ -656,18 +671,17 @@ class AndroidEmulatorTest(BlobUploadMixi
         dirs = self.query_abs_dirs()
         if self.test_suite.startswith('robocop'):
             robocop_url = self.installer_url[:self.installer_url.rfind('/')] + '/robocop.apk'
             self.info("Downloading robocop...")
             self.download_file(robocop_url, 'robocop.apk', dirs['abs_work_dir'], error_level=FATAL)
         self.rmtree(dirs['abs_xre_dir'])
         self.mkdir_p(dirs['abs_xre_dir'])
         if self.config["hostutils_manifest_path"]:
-            url = 'https://hg.mozilla.org/%s/raw-file/%s/%s' % (
-                "try", "default", self.config["hostutils_manifest_path"])
+            url = self._get_repo_url(self.config["hostutils_manifest_path"])
             self._tooltool_fetch(url, dirs['abs_xre_dir'])
             for p in glob.glob(os.path.join(dirs['abs_xre_dir'], 'host-utils-*')):
                 if os.path.isdir(p) and os.path.isfile(os.path.join(p, 'xpcshell')):
                     self.xre_path = p
             if not self.xre_path:
                 self.fatal("xre path not found in %s" % dirs['abs_xre_dir'])
         else:
             self.fatal("configure hostutils_manifest_path!")
--- a/testing/mozharness/scripts/androidx86_emulator_unittest.py
+++ b/testing/mozharness/scripts/androidx86_emulator_unittest.py
@@ -498,16 +498,43 @@ class AndroidEmulatorTest(BlobUploadMixi
         return {
             "process": subprocess.Popen(cmd, cwd=cwd, stdout=tmp_stdout, stderr=tmp_stdout, env=env),
             "tmp_file": tmp_file,
             "tmp_stdout": tmp_stdout,
             "suite_name": suite_name,
             "emulator_index": emulator_index
         }
 
+    def _get_repo_url(self, path):
+        """
+           Return a url for a file (typically a tooltool manifest) in this hg repo
+           and using this revision (or mozilla-central/default if repo/rev cannot
+           be determined).
+
+           :param path specifies the directory path to the file of interest.
+        """
+        if 'GECKO_HEAD_REPOSITORY' in os.environ and 'GECKO_HEAD_REV' in os.environ:
+            # probably taskcluster
+            repo = os.environ['GECKO_HEAD_REPOSITORY']
+            revision = os.environ['GECKO_HEAD_REV']
+        elif self.buildbot_config and 'properties' in self.buildbot_config:
+            # probably buildbot
+            repo = 'https://hg.mozilla.org/%s' % self.buildbot_config['properties']['repo_path']
+            revision = self.buildbot_config['properties']['revision']
+        else:
+            # something unexpected!
+            repo = 'https://hg.mozilla.org/mozilla-central'
+            revision = 'default'
+            self.warning('Unable to find repo/revision for manifest; using mozilla-central/default')
+        url = '%s/raw-file/%s/%s' % (
+            repo,
+            revision,
+            path)
+        return url
+
     def _tooltool_fetch(self, url, dir):
         c = self.config
 
         manifest_path = self.download_file(
             url,
             file_name='releng.manifest',
             parent_dir=dir
         )
@@ -533,30 +560,18 @@ class AndroidEmulatorTest(BlobUploadMixi
         dirs = self.query_abs_dirs()
 
         # FIXME
         # Clobbering and re-unpacking would not be needed if we had a way to
         # check whether the unpacked content already present match the
         # contents of the tar ball
         self.rmtree(dirs['abs_avds_dir'])
         self.mkdir_p(dirs['abs_avds_dir'])
-        if not self.buildbot_config:
-            # XXX until we figure out how to determine the repo_path, revision
-            url = 'https://hg.mozilla.org/%s/raw-file/%s/%s' % (
-                "try", "default", c["tooltool_manifest_path"])
-            self._tooltool_fetch(url, dirs['abs_avds_dir'])
-        elif self.buildbot_config and 'properties' in self.buildbot_config:
-            url = 'https://hg.mozilla.org/%s/raw-file/%s/%s' % (
-                self.buildbot_config['properties']['repo_path'],
-                self.buildbot_config['properties']['revision'],
-                c["tooltool_manifest_path"])
-            self._tooltool_fetch(url, dirs['abs_avds_dir'])
-        else:
-            self.fatal("properties in self.buildbot_config are required to "
-                       "retrieve tooltool manifest to be used for avds setup")
+        url = self._get_repo_url(c["tooltool_manifest_path"])
+        self._tooltool_fetch(url, dirs['abs_avds_dir'])
 
         avd_home_dir = self.abs_dirs['abs_avds_dir']
         if avd_home_dir != "/home/cltbld/.android":
             # Modify the downloaded avds to point to the right directory.
             cmd = [
                 'bash', '-c',
                 'sed -i "s|/home/cltbld/.android|%s|" %s/test-*.ini' %
                 (avd_home_dir, os.path.join(avd_home_dir, 'avd'))
@@ -677,18 +692,17 @@ class AndroidEmulatorTest(BlobUploadMixi
         for suite_name in self.test_suites:
             if suite_name.startswith('robocop'):
                 self._download_robocop_apk()
                 break
 
         self.rmtree(dirs['abs_xre_dir'])
         self.mkdir_p(dirs['abs_xre_dir'])
         if self.config["hostutils_manifest_path"]:
-            url = 'https://hg.mozilla.org/%s/raw-file/%s/%s' % (
-                "try", "default", self.config["hostutils_manifest_path"])
+            url = self._get_repo_url(self.config["hostutils_manifest_path"])
             self._tooltool_fetch(url, dirs['abs_xre_dir'])
             for p in glob.glob(os.path.join(dirs['abs_xre_dir'], 'host-utils-*')):
                 if os.path.isdir(p) and os.path.isfile(os.path.join(p, 'xpcshell')):
                     self.xre_path = p
             if not self.xre_path:
                 self.fatal("xre path not found in %s" % dirs['abs_xre_dir'])
         else:
             self.fatal("configure hostutils_manifest_path!")