~pwlars/ubuntu-test-cases/krillin-recovery

« back to all changes in this revision

Viewing changes to scripts/reboot-and-wait

  • Committer: Andy Doan
  • Date: 2013-09-10 13:21:26 UTC
  • mto: (19.1.3 touch)
  • mto: This revision was merged to the branch mainline in revision 20.
  • Revision ID: andy.doan@canonical.com-20130910132126-04w924583tmqd5k9
update the memevent test to use a configurable "probe" directory

We've had to change this in the past and will need to change it in
the future to support a writeable directory for read-only images.
This allows us to change run_utah_phablet.py's default probe directory
in the future w/o having the change this repo in lock-step.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/usr/bin/python
2
 
 
3
 
import argparse
4
 
import logging
5
 
import os
6
 
import subprocess
7
 
import time
8
 
 
9
 
from phabletutils.device import AndroidBridge
10
 
 
11
 
EMULATOR = os.environ.get('USE_EMULATOR', '')
12
 
 
13
 
 
14
 
def _get_arg_parser():
15
 
    parser = argparse.ArgumentParser(
16
 
        description='Reboot device and waits for networking to become active.')
17
 
    parser.add_argument('-s', '--serial', help='Device serial')
18
 
    parser.add_argument('-n', '--num-tries', type=int, default=3,
19
 
                        help='''How many times to retry on failure.
20
 
                             default=%(default)d''')
21
 
    return parser
22
 
 
23
 
 
24
 
def main(args):
25
 
    device = AndroidBridge(args.serial)
26
 
    device.wait_for_device()
27
 
    for i in range(args.num_tries):
28
 
        device.reboot()
29
 
        device.wait_for_device()
30
 
        time.sleep(5)
31
 
        device.wait_for_device()
32
 
        try:
33
 
            device.wait_for_network()
34
 
            return 0
35
 
        except:
36
 
            pass  # try the loop again
37
 
    logging.error('device failed to start and activate networking')
38
 
    return 1
39
 
 
40
 
 
41
 
def emulator_main(args):
42
 
    emulator = os.path.join(os.path.dirname(__file__), 'run-emulator')
43
 
    subprocess.check_call([emulator])
44
 
 
45
 
 
46
 
if __name__ == '__main__':
47
 
    logging.basicConfig(level=logging.INFO)
48
 
    logging.getLogger().name = 'reboot-and-wait'
49
 
    args = _get_arg_parser().parse_args()
50
 
    if EMULATOR:
51
 
        logging.info('using emulator logic for reboot')
52
 
        exit(emulator_main(args))
53
 
    else:
54
 
        exit(main(args))