Bug 1548574 [mozproxy] mitmproxy failing to start when using both 2.x and 4.x in same test job r=tarek
authorFlorin Strugariu <fstrugariu@mozilla.com>
Tue, 07 May 2019 13:36:37 +0000
changeset 531711 26561f2b9384185befb5ed88fd947032a1a35960
parent 531710 d3125bd46f54e6127e168dd2ccdada6046e847b4
child 531712 83d3bb582acd0f20cb6d84d660654e6183af053c
push id11265
push userffxbld-merge
push dateMon, 13 May 2019 10:53:39 +0000
treeherdermozilla-beta@77e0fe8dbdd3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstarek
bugs1548574
milestone68.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 1548574 [mozproxy] mitmproxy failing to start when using both 2.x and 4.x in same test job r=tarek Differential Revision: https://phabricator.services.mozilla.com/D29996
testing/mozbase/mozproxy/mozproxy/backends/mitm.py
--- a/testing/mozbase/mozproxy/mozproxy/backends/mitm.py
+++ b/testing/mozbase/mozproxy/mozproxy/backends/mitm.py
@@ -77,16 +77,24 @@ class Mitmproxy(Playback):
         self.mitmproxy_proc = None
         self.mitmdump_path = None
         self.browser_path = config.get("binary")
         self.policies_dir = None
         self.ignore_mitmdump_exit_failure = config.get(
             "ignore_mitmdump_exit_failure", False
         )
 
+        if self.config.get("playback_version") is None:
+            LOG.info("mitmproxy was not provided with a 'playback_version' "
+                     "getting 'playback_version' from 'playback_binary_manifest'")
+            if "4.0.4" in self.config["playback_binary_manifest"]:
+                self.config["playback_version"] = "4.0.4"
+            else:
+                self.config["playback_version"] = "2.0.2"
+
         # mozproxy_dir is where we will download all mitmproxy required files
         # when running locally it comes from obj_path via mozharness/mach
         if self.config.get("obj_path") is not None:
             self.mozproxy_dir = self.config.get("obj_path")
         else:
             # in production it is ../tasks/task_N/build/, in production that dir
             # is not available as an envvar, however MOZ_UPLOAD_DIR is set as
             # ../tasks/task_N/build/blobber_upload_dir so take that and go up 1 level
@@ -105,37 +113,51 @@ class Mitmproxy(Playback):
         # where to get the data
         os.environ["MOZPROXY_DIR"] = self.mozproxy_dir
 
     def start(self):
         # go ahead and download and setup mitmproxy
         self.download()
 
         # mitmproxy must be started before setup, so that the CA cert is available
-        self.mitmdump_path = os.path.join(self.mozproxy_dir, "mitmdump")
         self.start_mitmproxy_playback(self.mitmdump_path, self.browser_path)
 
         # In case the setup fails, we want to stop the process before raising.
         try:
             self.setup()
         except Exception:
             self.stop()
             raise
 
     def download(self):
         """Download and unpack mitmproxy binary and pageset using tooltool"""
         if not os.path.exists(self.mozproxy_dir):
             os.makedirs(self.mozproxy_dir)
 
-        LOG.info("downloading mitmproxy binary")
         _manifest = os.path.join(here, self.config["playback_binary_manifest"])
         transformed_manifest = transform_platform(_manifest, self.config["platform"])
-        tooltool_download(
-            transformed_manifest, self.config["run_local"], self.mozproxy_dir
-        )
+
+        # generate the mitmdump_path
+        self.mitmdump_path = os.path.join(self.mozproxy_dir, "mitmdump-%s" %
+                                          self.config["playback_version"], "mitmdump")
+
+        # Check if mitmproxy bin exists
+        if os.path.exists(self.mitmdump_path):
+            LOG.info("mitmproxy binary already exists. Skipping download")
+        else:
+            # Download and unpack mitmproxy binary
+            download_path = os.path.dirname(self.mitmdump_path)
+            LOG.info("create mitmproxy %s dir" % self.config["playback_version"])
+            if not os.path.exists(download_path):
+                os.makedirs(download_path)
+
+            LOG.info("downloading mitmproxy binary")
+            tooltool_download(
+                transformed_manifest, self.config["run_local"],
+                download_path)
 
         if "playback_pageset_manifest" in self.config:
             # we use one pageset for all platforms
             LOG.info("downloading mitmproxy pageset")
             _manifest = self.config["playback_pageset_manifest"]
             transformed_manifest = transform_platform(
                 _manifest, self.config["platform"]
             )