diff mbox

[Branch,~linaro-validation/lava-dispatcher/trunk] Rev 573: merge with the branch that try a reboot when the adb connection can not be created after boot

Message ID 20130402103813.12857.45915.launchpad@ackee.canonical.com
State Accepted
Headers show

Commit Message

Yongqin Liu April 2, 2013, 10:38 a.m. UTC
Merge authors:
  Yongqin Liu (liuyq0307)
Related merge proposals:
  https://code.launchpad.net/~liuyq0307/lava-dispatcher/check-adb-at-boot/+merge/155881
  proposed by: Yongqin Liu (liuyq0307)
------------------------------------------------------------
revno: 573 [merge]
committer: Yongqin Liu <yongqin.liu@linaro.org>
branch nick: lava-dispatcher
timestamp: Tue 2013-04-02 18:36:49 +0800
message:
  merge with the branch that try a reboot when the adb connection can not be created after boot
modified:
  lava_dispatcher/actions/boot_control.py
  lava_dispatcher/client/base.py
  lava_dispatcher/errors.py
  lava_dispatcher/job.py


--
lp:lava-dispatcher
https://code.launchpad.net/~linaro-validation/lava-dispatcher/trunk

You are subscribed to branch lp:lava-dispatcher.
To unsubscribe from this branch go to https://code.launchpad.net/~linaro-validation/lava-dispatcher/trunk/+edit-subscription
diff mbox

Patch

=== modified file 'lava_dispatcher/actions/boot_control.py'
--- lava_dispatcher/actions/boot_control.py	2012-11-20 21:22:17 +0000
+++ lava_dispatcher/actions/boot_control.py	2013-03-27 11:22:07 +0000
@@ -23,7 +23,10 @@ 
 import logging
 
 from lava_dispatcher.actions import BaseAction, null_or_empty_schema
-from lava_dispatcher.errors import CriticalError
+from lava_dispatcher.errors import (
+    CriticalError,
+    ADBConnectError,
+)
 
 _boot_schema = {
     'type': 'object',
@@ -40,12 +43,20 @@ 
     """
 
     parameters_schema = _boot_schema
+    parameters_schema['properties']['adb_check'] = {
+        'default': False, 'optional': True
+    }
 
-    def run(self, options=[]):
+    def run(self, options=[], adb_check=False):
         client = self.client
         client.target_device.boot_options = options
         try:
-            client.boot_linaro_android_image()
+            client.boot_linaro_android_image(
+                adb_check=adb_check)
+        except ADBConnectError as err:
+            logging.exception(('boot_linaro_android_image failed to create'
+                               ' the adb connection: %s') % err)
+            raise err
         except Exception as e:
             logging.exception("boot_linaro_android_image failed: %s" % e)
             raise CriticalError("Failed to boot test image.")

=== modified file 'lava_dispatcher/client/base.py'
--- lava_dispatcher/client/base.py	2013-02-18 06:00:28 +0000
+++ lava_dispatcher/client/base.py	2013-03-27 11:22:07 +0000
@@ -34,6 +34,7 @@ 
     NetworkError,
     OperationFailed,
     CriticalError,
+    ADBConnectError,
 )
 
 
@@ -246,6 +247,9 @@ 
         match_id = adb_proc.expect([pattern1, pattern2, pattern3, pexpect.EOF])
         if match_id in [0, 1]:
             self.dev_name = adb_proc.match.groups()[0]
+        else:
+            raise ADBConnectError(('Failed to connected to device with'
+                                   ' command:%s') % cmd)
 
     def android_adb_over_tcp_disconnect(self):
         dev_ip = self.dev_ip
@@ -289,7 +293,7 @@ 
                 return
             time.sleep(3)
 
-        raise NetworkError(
+        raise ADBConnectError(
             "The android device(%s) isn't attached" % self._client.hostname)
 
     def wait_home_screen(self):
@@ -441,7 +445,7 @@ 
     def get_android_adb_interface(self):
         return self.config.default_network_interface
 
-    def boot_linaro_android_image(self):
+    def boot_linaro_android_image(self, adb_check=False):
         """Reboot the system to the test android image."""
         self._boot_linaro_android_image()
         TESTER_PS1_PATTERN = self.target_device.deployment_data['TESTER_PS1_PATTERN']
@@ -465,6 +469,14 @@ 
         if self.config.android_adb_over_tcp:
             self._enable_adb_over_tcp()
 
+        #check if the adb connection can be created.
+        #by adb connect dev_ip command
+        if adb_check:
+            try:
+                session = AndroidTesterCommandRunner(self)
+                session.connect()
+            finally:
+                session.disconnect()
 
     def _disable_suspend(self):
         """ disable the suspend of images.

=== modified file 'lava_dispatcher/errors.py'
--- lava_dispatcher/errors.py	2012-11-20 21:22:17 +0000
+++ lava_dispatcher/errors.py	2013-03-27 03:50:25 +0000
@@ -51,6 +51,12 @@ 
     """
 
 
+class ADBConnectError(NetworkError):
+    """
+    This is used when adb connection failed to created
+    """
+
+
 class OperationFailed(GeneralError):
     """
     The exception throws when a file system or system operation fails.

=== modified file 'lava_dispatcher/job.py'
--- lava_dispatcher/job.py	2013-01-23 22:37:53 +0000
+++ lava_dispatcher/job.py	2013-03-27 13:49:44 +0000
@@ -33,6 +33,7 @@ 
     CriticalError,
     TimeoutError,
     GeneralError,
+    ADBConnectError,
 )
 
 
@@ -175,6 +176,24 @@ 
                 try:
                     status = 'fail'
                     action.run(**params)
+                except ADBConnectError:
+                    if cmd.get('command') == 'boot_linaro_android_image':
+                        logging.warning(('[ACTION-E] %s failed to create the'
+                                         ' adb connection') % (cmd['command']))
+                        ## clear the session on the serial and wait a while
+                        ## and not put the following 3 sentences into the
+                        ## boot_linaro_android_image method just for
+                        ## avoiding effects when the method being called
+                        ## in other places
+                        logging.warning(
+                            'Now will reboot the image to try again')
+                        self.context.client.proc.sendcontrol("c")
+                        self.context.client.proc.sendline("")
+                        time.sleep(5)
+                        self.context.client.boot_linaro_android_image(
+                            adb_check=True)
+                        ## mark it as pass if the second boot works
+                        status = 'pass'
                 except TimeoutError as err:
                     if cmd.get('command').startswith('lava_android_test'):
                         logging.warning("[ACTION-E] %s times out." % (