Bug 1236467 - [mozdevice] raise exception when missing devices access permissions. r=ahal draft
authorJulien Pagès <j.parkouss@gmail.com>
Mon, 04 Jan 2016 16:29:36 +0100
changeset 318861 a79be8684a51a529a6b163c9bac378a199ab6961
parent 318640 0771c5eab32f0cee4f7d12bc382298a81e0eabb2
child 512515 f4aae46bacbdae3577eb3a46b2f86860a804aeba
push id8943
push userj.parkouss@gmail.com
push dateTue, 05 Jan 2016 10:10:12 +0000
reviewersahal
bugs1236467
milestone46.0a1
Bug 1236467 - [mozdevice] raise exception when missing devices access permissions. r=ahal Also bump the version to 0.48.
testing/mozbase/mozdevice/mozdevice/adb.py
testing/mozbase/mozdevice/setup.py
--- a/testing/mozbase/mozdevice/mozdevice/adb.py
+++ b/testing/mozbase/mozdevice/mozdevice/adb.py
@@ -62,16 +62,26 @@ class ADBProcess(object):
 class ADBError(Exception):
     """ADBError is raised in situations where a command executed on a
     device either exited with a non-zero exitcode or when an
     unexpected error condition has occurred. Generally, ADBErrors can
     be handled and the device can continue to be used.
     """
     pass
 
+class ADBListDevicesError(ADBError):
+    """ADBListDevicesError is raised when errors are found listing the
+    devices, typically not any permissions.
+
+    The devices information is stocked with the *devices* member.
+    """
+    def __init__(self, msg, devices):
+        ADBError.__init__(self, msg)
+        self.devices = devices
+
 class ADBRootError(Exception):
     """ADBRootError is raised when a shell command is to be executed as
     root but the device does not support it. This error is fatal since
     there is no recovery possible by the script. You must either root
     your device or change your scripts to not require running as root.
     """
     pass
 
@@ -427,16 +437,17 @@ class ADBHost(ADBCommand):
         :param timeout: The maximum time in
             seconds for any spawned adb process to complete before
             throwing an ADBTimeoutError.  This timeout is per adb call. The
             total time spent may exceed this value. If it is not
             specified, the value set in the ADBHost constructor is used.
         :type timeout: integer or None
         :returns: an object contain
         :raises: * ADBTimeoutError
+                 * ADBListDevicesError
                  * ADBError
 
         The output of adb devices -l ::
 
             $ adb devices -l
             List of devices attached
             b313b945               device usb:1-7 product:d2vzw model:SCH_I535 device:d2vzw
 
@@ -463,16 +474,24 @@ class ADBHost(ADBCommand):
                 if remainder:
                     try:
                         device.update(dict([j.split(':')
                                             for j in remainder.split(' ')]))
                     except ValueError:
                         self._logger.warning('devices: Unable to parse '
                                              'remainder for device %s' % line)
                 devices.append(device)
+        for device in devices:
+            if device['state'] == 'no permissions':
+                raise ADBListDevicesError(
+                    "No permissions to detect devices. You should restart the"
+                    " adb server as root:\n"
+                    "\n# adb kill-server\n# adb start-server\n"
+                    "\nor maybe configure your udev rules.",
+                    devices)
         return devices
 
 
 class ADBDevice(ADBCommand):
     """ADBDevice is an abstract base class which provides methods which
     can be used to interact with the associated Android or B2G based
     device. It must be used via one of the concrete implementations in
     :class:`ADBAndroid` or :class:`ADBB2G`.
--- a/testing/mozbase/mozdevice/setup.py
+++ b/testing/mozbase/mozdevice/setup.py
@@ -1,16 +1,16 @@
 # 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/.
 
 from setuptools import setup
 
 PACKAGE_NAME = 'mozdevice'
-PACKAGE_VERSION = '0.47'
+PACKAGE_VERSION = '0.48'
 
 deps = ['mozfile >= 1.0',
         'mozlog >= 3.0',
         'moznetwork >= 0.24',
         'mozprocess >= 0.19',
        ]
 
 setup(name=PACKAGE_NAME,