Bug 1439694 - Fix jsonschema import error when running talos locally; r=jmaher, a=test-only
authorRob Wood <rwood@mozilla.com>
Mon, 26 Feb 2018 16:43:09 -0500
changeset 463036 fb0f35c060ef3d8f435e01b30947e7079a27f11d
parent 463035 525f37e3a399becabd44b4c7cdb3f5b6424ced0e
child 463037 8f8a8dab2700e31e124060e1806e68d05a012bea
push id1683
push usersfraser@mozilla.com
push dateThu, 26 Apr 2018 16:43:40 +0000
treeherdermozilla-release@5af6cb21869d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjmaher, test-only
bugs1439694
milestone60.0
Bug 1439694 - Fix jsonschema import error when running talos locally; r=jmaher, a=test-only MozReview-Commit-ID: HK3wMVBzQXR
testing/mozharness/mozharness/mozilla/testing/talos.py
testing/talos/mach_commands.py
--- a/testing/mozharness/mozharness/mozilla/testing/talos.py
+++ b/testing/mozharness/mozharness/mozilla/testing/talos.py
@@ -579,16 +579,37 @@ class Talos(TestingMixin, MercurialScrip
         return super(Talos, self).download_and_extract(
             suite_categories=['common', 'talos']
         )
 
     def create_virtualenv(self, **kwargs):
         """VirtualenvMixin.create_virtualenv() assuemes we're using
         self.config['virtualenv_modules']. Since we are installing
         talos from its source, we have to wrap that method here."""
+        # if virtualenv already exists, just add to path and don't re-install, need it
+        # in path so can import jsonschema later when validating output for perfherder
+        _virtualenv_path = self.config.get("virtualenv_path")
+
+        if self.run_local and os.path.exists(_virtualenv_path):
+            self.info("Virtualenv already exists, skipping creation")
+            _python_interp = self.config.get('exes')['python']
+
+            if 'win' in self.platform_name():
+                _path = os.path.join(_virtualenv_path,
+                                     'Lib',
+                                     'site-packages')
+            else:
+                _path = os.path.join(_virtualenv_path,
+                                     'lib',
+                                     os.path.basename(_python_interp),
+                                     'site-packages')
+            sys.path.append(_path)
+            return
+
+        # virtualenv doesn't already exist so create it
         # install mozbase first, so we use in-tree versions
         if not self.run_local:
             mozbase_requirements = os.path.join(
                 self.query_abs_dirs()['abs_test_install_dir'],
                 'config',
                 'mozbase_requirements.txt'
             )
         else:
@@ -607,18 +628,16 @@ class Talos(TestingMixin, MercurialScrip
             modules=['pip>=1.5']
         )
         # talos in harness requires what else is
         # listed in talos requirements.txt file.
         self.install_module(
             requirements=[os.path.join(self.talos_path,
                                        'requirements.txt')]
         )
-        # install jsonschema for perfherder validation
-        self.install_module(module="jsonschema")
 
     def _validate_treeherder_data(self, parser):
         # late import is required, because install is done in create_virtualenv
         import jsonschema
 
         if len(parser.found_perf_data) != 1:
             self.critical("PERFHERDER_DATA was seen %d times, expected 1."
                           % len(parser.found_perf_data))
--- a/testing/talos/mach_commands.py
+++ b/testing/talos/mach_commands.py
@@ -44,19 +44,18 @@ class TalosRunner(MozbuildObject):
                                               'virtualenv', 'virtualenv.py')
         self.virtualenv_path = os.path.join(self._topobjdir, 'testing',
                                             'talos-venv')
         self.python_interp = sys.executable
         self.talos_args = talos_args
 
     def make_config(self):
         default_actions = ['populate-webroot']
-        if not os.path.exists(self.virtualenv_path):
-            default_actions.append('create-virtualenv')
         default_actions.extend([
+            'create-virtualenv',
             'setup-mitmproxy',
             'run-tests',
         ])
         self.config = {
             'run_local': True,
             'talos_json': self.talos_json,
             'binary_path': self.binary_path,
             'repo_path': self.topsrcdir,