Bug 902711 - Make marionette_transport its own package, r=ato

This commit is contained in:
Jonathan Griffin 2013-10-14 17:58:40 -07:00
parent 76ceab79f9
commit bf6caebb23
11 changed files with 84 additions and 16 deletions

View File

@ -1,2 +1,3 @@
-r mozbase_requirements.txt
../marionette/transport
../marionette

View File

@ -12,20 +12,20 @@ import types
import weakref
from b2ginstance import B2GInstance
from client import MarionetteClient
from errors import InvalidResponseException
from marionette import Marionette
from marionette_test import MarionetteTestCase
from marionette_transport import MarionetteTransport
from runtests import MarionetteTestRunner, cli
class B2GUpdateMarionetteClient(MarionetteClient):
class B2GUpdateMarionetteClient(MarionetteTransport):
RETRY_TIMEOUT = 5
CONNECT_TIMEOUT = 30
SEND_TIMEOUT = 60 * 5
MAX_RETRIES = 24
def __init__(self, addr, port, runner):
MarionetteClient.__init__(self, addr, port)
super(B2GUpdateMarionetteClient, self).__init__(addr, port)
self.runner = runner
def connect(self):
@ -36,7 +36,7 @@ class B2GUpdateMarionetteClient(MarionetteClient):
"""
for i in range(self.MAX_RETRIES):
try:
MarionetteClient.connect(self, timeout=self.CONNECT_TIMEOUT)
MarionetteTransport.connect(self, timeout=self.CONNECT_TIMEOUT)
break
except:
if i == self.MAX_RETRIES - 1:

View File

@ -293,7 +293,7 @@ waitFor(
# older emulators. 45s *should* be enough of a delay
# to allow telephony API's to work.
pass
except InvalidResponseException:
except (InvalidResponseException, IOError):
self.check_for_minidumps()
raise
print '...done'

View File

@ -11,12 +11,12 @@ import time
import traceback
from application_cache import ApplicationCache
from client import MarionetteClient
from decorators import do_crash_check
from emulator import Emulator
from emulator_screen import EmulatorScreen
from errors import *
from keys import Keys
from marionette_transport import MarionetteTransport
import geckoinstance
@ -511,7 +511,7 @@ class Marionette(object):
self.port = self.emulator.setup_port_forwarding(self.port)
assert(self.emulator.wait_for_port()), "Timed out waiting for port!"
self.client = MarionetteClient(self.host, self.port)
self.client = MarionetteTransport(self.host, self.port)
if emulator:
self.emulator.setup(self,
@ -522,7 +522,7 @@ class Marionette(object):
if self.session:
try:
self.delete_session()
except (MarionetteException, socket.error):
except (MarionetteException, socket.error, IOError):
# These exceptions get thrown if the Marionette server
# hit an exception/died or the connection died. We can
# do no further server-side cleanup in this case.

View File

@ -1,3 +1,4 @@
./transport
manifestdestiny
mozhttpd >= 0.5
mozinfo >= 0.7

View File

@ -1,5 +1,6 @@
import os
from setuptools import setup, find_packages
import sys
version = '0.7.6'
@ -14,6 +15,23 @@ except (OSError, IOError):
with open('requirements.txt') as f:
deps = f.read().splitlines()
# Requirements.txt contains a pointer to the local copy of marionette_transport;
# if we're installing using setup.py, handle this locally or replace with a valid
# pypi package reference.
deps = [x for x in deps if 'transport' not in x]
transport_dir = os.path.join(os.path.dirname(__file__), os.path.pardir, 'transport')
method = [x for x in sys.argv if x in ('develop', 'install')]
if os.path.exists(transport_dir) and method:
cmd = [sys.executable, 'setup.py', method[0]]
import subprocess
try:
subprocess.check_call(cmd, cwd=transport_dir)
except subprocess.CalledProcessError:
print "Error running setup.py in %s" % directory
raise
else:
deps += ['marionette-transport == 0.1']
setup(name='marionette_client',
version=version,
description="Marionette test automation client",

View File

@ -0,0 +1,14 @@
<!-- This Source Code Form is subject to the terms of the Mozilla Public
- License, v. 2.0. If a copy of the MPL was not distributed with this
- file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
# Marionette Transport Layer
[Marionette](https://developer.mozilla.org/en/Marionette) is a
Mozilla project to enable remote automation in Gecko-based projects,
including desktop Firefox, mobile Firefox, and Firefox OS. It's inspired
by [Selenium Webdriver](http://www.seleniumhq.org/projects/webdriver/).
This package defines the transport layer used by a Marionette client to
communicate with the Marionette server embedded in Gecko. It has no entry
points; rather it's designed to be used by Marionette client implementations.

View File

@ -0,0 +1 @@
from transport import MarionetteTransport

View File

@ -6,10 +6,8 @@ import errno
import json
import socket
from errors import InvalidResponseException, ErrorCodes
class MarionetteClient(object):
class MarionetteTransport(object):
""" The Marionette socket client. This speaks the same protocol
as the remote debugger inside Gecko, in which messages are
always preceded by the message length and a colon, e.g.,
@ -18,6 +16,7 @@ class MarionetteClient(object):
"""
max_packet_length = 4096
connection_lost_msg = "Connection to Marionette server is lost. Check gecko.log (desktop firefox) or logcat (b2g) for errors."
def __init__(self, addr, port):
self.addr = addr
@ -53,9 +52,7 @@ class MarionetteClient(object):
response += self._recv_n_bytes(int(length) + 1 + len(length) - 10)
return json.loads(response)
else:
raise InvalidResponseException("Could not communicate with Marionette server. "
"Is the Gecko process still running?",
status=ErrorCodes.INVALID_RESPONSE)
raise IOError(self.connection_lost_msg)
def connect(self, timeout=360.0):
""" Connect to the server and process the hello message we expect
@ -94,7 +91,7 @@ class MarionetteClient(object):
self.sock.send(packet)
except IOError as e:
if e.errno == errno.EPIPE:
raise IOError("%s: Connection to Marionette server is lost. Check gecko.log (desktop firefox) or logcat (b2g) for errors." % str(e))
raise IOError("%s: %s" % (str(e)), self.connection_lost_msg)
else:
raise e

View File

@ -0,0 +1,34 @@
import os
from setuptools import setup, find_packages
version = '0.1'
# get documentation from the README
try:
here = os.path.dirname(os.path.abspath(__file__))
description = file(os.path.join(here, 'README.md')).read()
except (OSError, IOError):
description = ''
# dependencies
deps = []
setup(name='marionette-transport',
version=version,
description="Transport layer for Marionette client",
long_description=description,
classifiers=[], # Get strings from http://pypi.python.org/pypi?%3Aaction=list_classifiers
keywords='mozilla',
author='Mozilla Automation and Tools Team',
author_email='tools@lists.mozilla.org',
url='https://developer.mozilla.org/en-US/docs/Marionette',
license='MPL',
packages=find_packages(exclude=['ez_setup', 'examples', 'tests']),
package_data={},
include_package_data=False,
zip_safe=False,
entry_points="""
""",
install_requires=deps,
)

View File

@ -529,7 +529,9 @@ stage-steeplechase: make-stage-dir
MARIONETTE_DIR=$(PKG_STAGE)/marionette
stage-marionette: make-stage-dir
$(NSINSTALL) -D $(MARIONETTE_DIR)/tests
@(cd $(topsrcdir)/testing/marionette/client && tar --exclude marionette/tests $(TAR_CREATE_FLAGS) - *) | (cd $(MARIONETTE_DIR) && tar -xf -)
$(NSINSTALL) -D $(MARIONETTE_DIR)/transport
@(cd $(topsrcdir)/testing/marionette/client && tar --exclude marionette/tests $(TAR_CREATE_FLAGS) - *) | (cd $(MARIONETTE_DIR)/ && tar -xf -)
@(cd $(topsrcdir)/testing/marionette/transport && tar $(TAR_CREATE_FLAGS) - *) | (cd $(MARIONETTE_DIR)/transport && tar -xf -)
$(PYTHON) $(topsrcdir)/testing/marionette/client/marionette/tests/print-manifest-dirs.py \
$(topsrcdir) \
$(topsrcdir)/testing/marionette/client/marionette/tests/unit-tests.ini \