Index: build/android/pylib/remote/device/remote_device_environment.py |
diff --git a/build/android/pylib/remote/device/remote_device_environment.py b/build/android/pylib/remote/device/remote_device_environment.py |
index a701d9541e6bae2b07497e1e6937339266d2ba81..b4ef12dc4ec53bf9ece143b98230bb3e89ae79ee 100644 |
--- a/build/android/pylib/remote/device/remote_device_environment.py |
+++ b/build/android/pylib/remote/device/remote_device_environment.py |
@@ -4,6 +4,8 @@ |
"""Environment setup and teardown for remote devices.""" |
+import distutils.version |
+import json |
import logging |
import os |
import random |
@@ -32,35 +34,25 @@ class RemoteDeviceEnvironment(environment.Environment): |
if args.api_key_file: |
with open(args.api_key_file) as api_key_file: |
self._api_key = api_key_file.read().strip() |
- elif args.api_key: |
- self._api_key = args.api_key |
else: |
- error_func('Must set api key with --api-key or --api-key-file') |
+ self._api_key = args.api_key |
if args.api_secret_file: |
with open(args.api_secret_file) as api_secret_file: |
self._api_secret = api_secret_file.read().strip() |
- elif args.api_secret: |
- self._api_secret = args.api_secret |
else: |
- error_func('Must set api secret with --api-secret or --api-secret-file') |
+ self._api_secret = args.api_secret |
- if not args.api_protocol: |
- error_func('Must set api protocol with --api-protocol. Example: http') |
self._api_protocol = args.api_protocol |
- |
- if not args.api_address: |
- error_func('Must set api address with --api-address') |
self._api_address = args.api_address |
- |
- if not args.api_port: |
- error_func('Must set api port with --api-port.') |
self._api_port = args.api_port |
self._access_token = '' |
self._results_path = args.results_path |
self._remote_device = args.remote_device |
self._remote_device_os = args.remote_device_os |
+ self._remote_device_minimum_os = args.remote_device_minimum_os |
+ self._device_oem=args.device_oem |
jbudorick
2015/01/28 16:09:54
nit: spaces around =
rnephew (Wrong account)
2015/01/28 16:47:53
Done.
|
self._runner_package = args.runner_package |
self._runner_type = args.runner_type |
self._device = '' |
@@ -72,6 +64,78 @@ class RemoteDeviceEnvironment(environment.Environment): |
'in-progress': 60 * 30, |
'unknown': 60 * 5 |
} |
+ # Example config file: |
+ # { |
+ # "remote_device": ["Galaxy S4", "Galaxy S3"], |
jbudorick
2015/01/28 16:09:54
nit: 2 space indent
rnephew (Wrong account)
2015/01/28 16:47:53
Done.
|
+ # "remote_device_os": ["4.4.2", "4.4.4"], |
+ # "remote_device_minimum_os": "4.4.2" |
jbudorick
2015/01/28 23:19:09
comma at the end
rnephew (Wrong account)
2015/01/29 01:58:34
Done.
|
+ # "api_address": www.example.com |
jbudorick
2015/01/28 23:19:09
needs quotes around example and a comma at the end
rnephew (Wrong account)
2015/01/29 01:58:34
Done.
|
+ # "api_port": "80", |
+ # "api_protocol": "http", |
+ # "api_secret": "apisecret", |
+ # "api_key": "apikey", |
+ # "timeouts": { |
+ # "queueing": 600, |
jbudorick
2015/01/28 16:09:54
nit: 2 space indent
rnephew (Wrong account)
2015/01/28 16:47:53
Done.
|
+ # "installing": 600, |
+ # "in-progress": 1800, |
+ # "unknown": 300 |
+ # } |
+ # } |
+ if (args.remote_device_file |
+ and ( args.remote_device_os or args.remote_device)): |
jbudorick
2015/01/28 16:09:54
nit: no space after (
rnephew (Wrong account)
2015/01/28 16:47:53
Done.
|
+ error_func('Cannot set --remote-device-file and --remote-device-os or' |
+ ' --remote-device') |
+ |
+ if args.remote_device_file: |
+ with open(args.remote_device_file) as device_file: |
+ device_json = json.load(device_file) |
+ self._remote_device = device_json.get('remote_device', None) |
+ self._remote_device_os = device_json.get('remote_device_os', None) |
+ self._remote_device_minimum_os = device_json.get( |
+ 'remote_device_minimum_os', None) |
+ self._api_address = device_json.get('api_address', None) |
jbudorick
2015/01/28 23:19:09
I think you mentioned this somewhere (out-of-band?
rnephew (Wrong account)
2015/01/29 01:58:34
I kept them as none, and switched them to have com
|
+ self._api_secret = device_json.get('api_secret', None) |
+ self._api_key = device_json.get('api_key', None) |
+ self._api_protocol = device_json.get('api_protocol', None) |
+ self._api_port = device_json.get('api_port', None) |
+ self._timeouts = device_json.get('timeouts', self._timeouts) |
jbudorick
2015/01/28 16:09:54
Could we let a user specify only some of the timeo
rnephew (Wrong account)
2015/01/28 16:47:53
Done.
|
+ self._device_type = device_json.get('device_type', self._device_type) |
+ self._device_oem = device_json.get('device_oem', None) |
+ |
+ if not self._api_address: |
+ error_func('Must set api address with --api-address' |
+ 'or in --remote-device-file.') |
jbudorick
2015/01/28 23:19:09
same as below
rnephew (Wrong account)
2015/01/29 01:58:34
Done.
|
+ if not self._api_protocol: |
+ error_func('Must set api protocol with --api-protocol' |
+ ' or in --remote-device-file. Example: http') |
+ if not self._api_key: |
+ error_func('Must set api key with --api-key, --api-key-file' |
+ 'or in --remote-device-file') |
jbudorick
2015/01/28 23:19:09
needs a space before "or"
rnephew (Wrong account)
2015/01/29 01:58:34
Done.
|
+ if not self._api_secret: |
+ error_func('Must set api secret with --api-secret, --api-secret-file' |
+ 'or in --remote-device-file') |
jbudorick
2015/01/28 23:19:09
same
rnephew (Wrong account)
2015/01/29 01:58:34
Done.
|
+ if not self._api_port: |
+ error_func('Must set api port with --api-port' |
+ 'or in --remote-device-file') |
jbudorick
2015/01/28 23:19:09
same
rnephew (Wrong account)
2015/01/29 01:58:34
Done.
|
+ if not isinstance(self._timeouts, dict): |
+ error_func('Timeouts must be a dictionary.') |
+ if ('queueing' not in self._timeouts |
+ or 'installing' not in self._timeouts |
+ or 'in-progress' not in self._timeouts |
+ or 'unknown' not in self._timeouts) : |
+ error_func('Timeouts must contain queueing,' |
+ ' installing, in-progress, and unknown.') |
+ |
+ logging.info('Remote device: %s', self._remote_device) |
+ logging.info('Remote device os: %s', self._remote_device_os) |
+ logging.info('Remote device minimum os: %s', |
+ self._remote_device_minimum_os) |
+ logging.info('Remote device OEM: %s', self._device_oem) |
+ logging.info('Remote device type: %s', self._device_type) |
+ logging.info('Api address: %s', self._api_address) |
+ logging.info('Api protocol: %s', self._api_protocol) |
+ logging.info('Api port: %s', self._api_port) |
+ logging.info('Timeouts: %s', self._timeouts) |
if not args.trigger and not args.collect: |
self._trigger = True |
@@ -150,10 +214,16 @@ class RemoteDeviceEnvironment(environment.Environment): |
for device in device_list: |
if device['os_name'] != self._device_type: |
continue |
- if self._remote_device and device['name'] != self._remote_device: |
+ if self._remote_device and device['name'] not in self._remote_device: |
continue |
if (self._remote_device_os |
- and device['os_version'] != self._remote_device_os): |
+ and device['os_version'] not in self._remote_device_os): |
+ continue |
+ if (self._device_oem and device['brand'] != self._device_oem): |
jbudorick
2015/01/28 16:09:54
Let's make device_oem a list, too.
rnephew (Wrong account)
2015/01/28 16:47:53
Done.
|
+ continue |
+ if (self._remote_device_minimum_os |
+ and distutils.version.LooseVersion(device['os_version']) |
+ < distutils.version.LooseVersion(self._remote_device_minimum_os)): |
continue |
if ((self._remote_device and self._remote_device_os) |
or device['available_devices_count']): |