Bug 978333 - Try to use localhost for marionette webserver if possible. r=jgriffin
authorWilliam Lachance <wlachance@mozilla.com>
Mon, 17 Mar 2014 15:28:23 -0400
changeset 192461 8eac82c5e61691e6f7b2b4ee2b2728d4a235dc3c
parent 192460 d58e8a7d933d3a74ceebda987ea760320e6a7306
child 192462 c3431749b0acaf5f9c5154651cf8c185017a698e
push id3624
push userasasaki@mozilla.com
push dateMon, 09 Jun 2014 21:49:01 +0000
treeherdermozilla-beta@b1a5da15899a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjgriffin
bugs978333
milestone31.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 978333 - Try to use localhost for marionette webserver if possible. r=jgriffin
testing/marionette/client/marionette/runner/base.py
--- a/testing/marionette/client/marionette/runner/base.py
+++ b/testing/marionette/client/marionette/runner/base.py
@@ -529,17 +529,16 @@ class BaseMarionetteTestRunner(object):
         self.bin = bin
         self.profile = profile
         self.autolog = autolog
         self.testgroup = testgroup
         self.revision = revision
         self.logger = logger
         self.noWindow = noWindow
         self.httpd = None
-        self.baseurl = None
         self.marionette = None
         self.logcat_dir = logcat_dir
         self.xml_output = xml_output
         self.repeat = repeat
         self.gecko_path = gecko_path
         self.testvars = {}
         self.test_kwargs = kwargs
         self.tree = tree
@@ -615,76 +614,73 @@ class BaseMarionetteTestRunner(object):
         return self._appName
 
     def reset_test_stats(self):
         self.passed = 0
         self.failed = 0
         self.todo = 0
         self.failures = []
 
-    def start_httpd(self):
-        host = moznetwork.get_ip()
+    def start_httpd(self, need_external_ip):
+        host = "127.0.0.1"
+        if need_external_ip:
+            host = moznetwork.get_ip()
         self.httpd = MozHttpd(host=host,
                               port=0,
                               docroot=os.path.join(os.path.dirname(os.path.dirname(__file__)), 'www'))
         self.httpd.start()
-        self.baseurl = 'http://%s:%d/' % (host, self.httpd.httpd.server_port)
-        self.logger.info('running webserver on %s' % self.baseurl)
+        self.marionette.baseurl = 'http://%s:%d/' % (host, self.httpd.httpd.server_port)
+        self.logger.info('running webserver on %s' % self.marionette.baseurl)
 
     def start_marionette(self):
-        assert(self.baseurl is not None)
         if self.bin:
             if self.address:
                 host, port = self.address.split(':')
             else:
                 host = 'localhost'
                 port = 2828
             self.marionette = Marionette(host=host,
                                          port=int(port),
                                          app=self.app,
                                          app_args=self.app_args,
                                          bin=self.bin,
                                          profile=self.profile,
-                                         baseurl=self.baseurl,
                                          timeout=self.timeout,
                                          device_serial=self.device_serial)
         elif self.address:
             host, port = self.address.split(':')
             try:
                 #establish a socket connection so we can vertify the data come back
                 connection = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
                 connection.connect((host,int(port)))
                 connection.close()
             except Exception, e:
                 raise Exception("Connection attempt to %s:%s failed with error: %s" %(host,port,e))
             if self.emulator:
                 self.marionette = Marionette.getMarionetteOrExit(
                                              host=host, port=int(port),
                                              connectToRunningEmulator=True,
                                              homedir=self.homedir,
-                                             baseurl=self.baseurl,
                                              logcat_dir=self.logcat_dir,
                                              gecko_path=self.gecko_path,
                                              symbols_path=self.symbols_path,
                                              timeout=self.timeout,
                                              device_serial=self.device_serial)
             else:
                 self.marionette = Marionette(host=host,
                                              port=int(port),
-                                             baseurl=self.baseurl,
                                              timeout=self.timeout,
                                              device_serial=self.device_serial)
         elif self.emulator:
             self.marionette = Marionette.getMarionetteOrExit(
                                          emulator=self.emulator,
                                          emulatorBinary=self.emulatorBinary,
                                          emulatorImg=self.emulatorImg,
                                          emulator_res=self.emulator_res,
                                          homedir=self.homedir,
-                                         baseurl=self.baseurl,
                                          noWindow=self.noWindow,
                                          logcat_dir=self.logcat_dir,
                                          gecko_path=self.gecko_path,
                                          symbols_path=self.symbols_path,
                                          timeout=self.timeout,
                                          sdcard=self.sdcard,
                                          device_serial=self.device_serial)
         else:
@@ -733,27 +729,32 @@ class BaseMarionetteTestRunner(object):
                 testgroup.add_test_failure(test=f[0], text=f[1], status=f[2])
 
             testgroup.submit()
 
     def run_tests(self, tests):
         self.reset_test_stats()
         starttime = datetime.utcnow()
 
-        if not self.httpd:
-            print "starting httpd"
-            self.start_httpd()
-
+        need_external_ip = True
         if not self.marionette:
             self.start_marionette()
             if self.emulator:
                 self.marionette.emulator.wait_for_homescreen(self.marionette)
             # Retrieve capabilities for later use
             if not self._capabilities:
                 self.capabilities
+            # if we're working against a desktop version, we usually don't need
+            # an external ip
+            if self._capabilities['device'] == "desktop":
+                need_external_ip = False
+
+        if not self.httpd:
+            print "starting httpd"
+            self.start_httpd(need_external_ip)
 
         for test in tests:
             self.add_test(test)
 
         counter = self.repeat
         while counter >=0:
             round = self.repeat - counter
             if round > 0: