Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(349)

Side by Side Diff: build/android/pylib/remote/device/remote_device_environment.py

Issue 879983002: Add multiple device/os filtering and a config file. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix variables not being set Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | build/android/test_runner.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright 2014 The Chromium Authors. All rights reserved. 1 # Copyright 2014 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 """Environment setup and teardown for remote devices.""" 5 """Environment setup and teardown for remote devices."""
6 6
7 import distutils.version
8 import json
7 import logging 9 import logging
8 import os 10 import os
9 import random 11 import random
10 import sys 12 import sys
11 13
12 from pylib import constants 14 from pylib import constants
13 from pylib.base import environment 15 from pylib.base import environment
14 from pylib.remote.device import appurify_sanitized 16 from pylib.remote.device import appurify_sanitized
15 from pylib.remote.device import remote_device_helper 17 from pylib.remote.device import remote_device_helper
16 18
17 class RemoteDeviceEnvironment(environment.Environment): 19 class RemoteDeviceEnvironment(environment.Environment):
18 """An environment for running on remote devices.""" 20 """An environment for running on remote devices."""
19 21
20 _ENV_KEY = 'env' 22 _ENV_KEY = 'env'
21 _DEVICE_KEY = 'device' 23 _DEVICE_KEY = 'device'
22 24
23 def __init__(self, args, error_func): 25 def __init__(self, args, error_func):
24 """Constructor. 26 """Constructor.
25 27
26 Args: 28 Args:
27 args: Command line arguments. 29 args: Command line arguments.
28 error_func: error to show when using bad command line arguments. 30 error_func: error to show when using bad command line arguments.
29 """ 31 """
30 super(RemoteDeviceEnvironment, self).__init__() 32 super(RemoteDeviceEnvironment, self).__init__()
31 33
34 if (args.remote_device_file
35 and (args.remote_device_os or args.remote_device)):
36 error_func('Cannot set --remote-device-file and --remote-device-os or'
37 ' --remote-device')
38 self._access_token = None
39 self._device = None
40 self._device_type = args.device_type
41 self._verbose_count = args.verbose_count
42 self._timeouts = {
43 'queueing': 60 * 10,
44 'installing': 60 * 10,
45 'in-progress': 60 * 30,
46 'unknown': 60 * 5
47 }
48 # Example config file:
49 # {
50 # "remote_device": ["Galaxy S4", "Galaxy S3"],
51 # "remote_device_os": ["4.4.2", "4.4.4"],
52 # "remote_device_minimum_os": "4.4.2",
53 # "api_address": "www.example.com",
54 # "api_port": "80",
55 # "api_protocol": "http",
56 # "api_secret": "apisecret",
57 # "api_key": "apikey",
58 # "timeouts": {
59 # "queueing": 600,
jbudorick 2015/01/29 17:52:56 nit: 2-space indent relative to timeouts
rnephew (Wrong account) 2015/01/29 22:10:27 Done.
60 # "installing": 600,
61 # "in-progress": 1800,
62 # "unknown": 300
63 # }
64 # }
65 if args.remote_device_file:
66 with open(args.remote_device_file) as device_file:
67 device_json = json.load(device_file)
68 else:
69 device_json = {}
70
71 self._remote_device = device_json.get('remote_device', None)
jbudorick 2015/01/29 17:52:56 nit: These sections would be easier to read if alp
rnephew (Wrong account) 2015/01/29 22:10:26 Done.
72 self._remote_device_os = device_json.get('remote_device_os', None)
73 self._remote_device_minimum_os = device_json.get(
74 'remote_device_minimum_os', None)
75 self._api_address = device_json.get('api_address', None)
76 self._api_secret = device_json.get('api_secret', None)
77 self._api_key = device_json.get('api_key', None)
78 self._api_protocol = device_json.get('api_protocol', None)
79 self._api_port = device_json.get('api_port', None)
80 self._device_type = device_json.get('device_type', self._device_type)
81 self._device_oem = device_json.get('device_oem', None)
82 self._runner_type = device_json.get('runner_type', None)
83 self._runner_package = device_json.get('runner_package', None)
84 self._results_path = device_json.get('results_path', None)
85 if 'timeouts' in device_json:
86 for key in device_json['timeouts']:
87 self._timeouts[key] = device_json['timeouts'][key]
88
32 if args.api_key_file: 89 if args.api_key_file:
33 with open(args.api_key_file) as api_key_file: 90 with open(args.api_key_file) as api_key_file:
34 self._api_key = api_key_file.read().strip() 91 self._api_key = api_key_file.read().strip()
35 elif args.api_key: 92 elif args.api_key:
36 self._api_key = args.api_key 93 self._api_key = args.api_key
37 else:
38 error_func('Must set api key with --api-key or --api-key-file')
39 94
40 if args.api_secret_file: 95 if args.api_secret_file:
41 with open(args.api_secret_file) as api_secret_file: 96 with open(args.api_secret_file) as api_secret_file:
42 self._api_secret = api_secret_file.read().strip() 97 self._api_secret = api_secret_file.read().strip()
43 elif args.api_secret: 98 elif args.api_secret:
44 self._api_secret = args.api_secret 99 self._api_secret = args.api_secret
45 else:
46 error_func('Must set api secret with --api-secret or --api-secret-file')
47 100
48 if not args.api_protocol: 101 if args.api_protocol:
jbudorick 2015/01/29 17:52:56 We should log something (probably at info level) i
rnephew (Wrong account) 2015/01/29 22:10:26 Done.
49 error_func('Must set api protocol with --api-protocol. Example: http') 102 self._api_protocol = args.api_protocol
50 self._api_protocol = args.api_protocol 103 if args.api_address:
104 self._api_address = args.api_address
105 if args.api_port:
106 self._api_port = args.api_port
107 if args.results_path:
108 self._results_path = args.results_path
109 if args.remote_device:
110 self._remote_device = args.remote_device
111 if args.remote_device_os:
112 self._remote_device_os = args.remote_device_os
113 if args.remote_device_minimum_os:
114 self._remote_device_minimum_os = args.remote_device_minimum_os
115 if args.device_oem:
116 self._device_oem = args.device_oem
117 if args.runner_package:
118 self._runner_package = args.runner_package
119 if args.runner_type:
120 self._runner_type = args.runner_type
51 121
52 if not args.api_address: 122 if not self._api_address:
53 error_func('Must set api address with --api-address') 123 error_func('Must set api address with --api-address'
54 self._api_address = args.api_address 124 ' or in --remote-device-file.')
125 if not self._api_protocol:
126 error_func('Must set api protocol with --api-protocol'
127 ' or in --remote-device-file. Example: http')
128 if not self._api_key:
129 error_func('Must set api key with --api-key, --api-key-file'
130 ' or in --remote-device-file')
131 if not self._api_secret:
132 error_func('Must set api secret with --api-secret, --api-secret-file'
133 ' or in --remote-device-file')
134 if not self._api_port:
135 error_func('Must set api port with --api-port'
136 ' or in --remote-device-file')
137 if not isinstance(self._timeouts, dict):
jbudorick 2015/01/29 17:52:56 Is this even possible?
rnephew (Wrong account) 2015/01/29 22:10:27 Before yes, after the last set of changes no.
138 error_func('Timeouts must be a dictionary.')
139 if ('queueing' not in self._timeouts
jbudorick 2015/01/29 17:52:56 Same question.
rnephew (Wrong account) 2015/01/29 22:10:26 Same.
140 or 'installing' not in self._timeouts
141 or 'in-progress' not in self._timeouts
142 or 'unknown' not in self._timeouts) :
143 error_func('Timeouts must contain queueing,'
144 ' installing, in-progress, and unknown.')
55 145
56 if not args.api_port: 146 logging.info('Remote device: %s', self._remote_device)
57 error_func('Must set api port with --api-port.') 147 logging.info('Remote device os: %s', self._remote_device_os)
58 self._api_port = args.api_port 148 logging.info('Remote device minimum os: %s',
59 149 self._remote_device_minimum_os)
60 self._access_token = '' 150 logging.info('Remote device OEM: %s', self._device_oem)
61 self._results_path = args.results_path 151 logging.info('Remote device type: %s', self._device_type)
62 self._remote_device = args.remote_device 152 logging.info('Api address: %s', self._api_address)
63 self._remote_device_os = args.remote_device_os 153 logging.info('Api protocol: %s', self._api_protocol)
64 self._runner_package = args.runner_package 154 logging.info('Api port: %s', self._api_port)
65 self._runner_type = args.runner_type 155 logging.info('Timeouts: %s', self._timeouts)
66 self._device = ''
67 self._verbose_count = args.verbose_count
68 self._device_type = args.device_type
69 self._timeouts = {
70 'queueing': 60 * 10,
71 'installing': 60 * 10,
72 'in-progress': 60 * 30,
73 'unknown': 60 * 5
74 }
75 156
76 if not args.trigger and not args.collect: 157 if not args.trigger and not args.collect:
77 self._trigger = True 158 self._trigger = True
78 self._collect = True 159 self._collect = True
79 else: 160 else:
80 self._trigger = args.trigger 161 self._trigger = args.trigger
81 self._collect = args.collect 162 self._collect = args.collect
82 163
83 def SetUp(self): 164 def SetUp(self):
84 """Set up the test environment.""" 165 """Set up the test environment."""
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 with appurify_sanitized.SanitizeLogging(self._verbose_count, 224 with appurify_sanitized.SanitizeLogging(self._verbose_count,
144 logging.WARNING): 225 logging.WARNING):
145 dev_list_res = appurify_sanitized.api.devices_list(self._access_token) 226 dev_list_res = appurify_sanitized.api.devices_list(self._access_token)
146 remote_device_helper.TestHttpResponse(dev_list_res, 227 remote_device_helper.TestHttpResponse(dev_list_res,
147 'Unable to generate access token.') 228 'Unable to generate access token.')
148 device_list = dev_list_res.json()['response'] 229 device_list = dev_list_res.json()['response']
149 random.shuffle(device_list) 230 random.shuffle(device_list)
150 for device in device_list: 231 for device in device_list:
151 if device['os_name'] != self._device_type: 232 if device['os_name'] != self._device_type:
152 continue 233 continue
153 if self._remote_device and device['name'] != self._remote_device: 234 if self._remote_device and device['name'] not in self._remote_device:
154 continue 235 continue
155 if (self._remote_device_os 236 if (self._remote_device_os
156 and device['os_version'] != self._remote_device_os): 237 and device['os_version'] not in self._remote_device_os):
238 continue
239 if self._device_oem and device['brand'] not in self._device_oem:
240 continue
241 if (self._remote_device_minimum_os
242 and distutils.version.LooseVersion(device['os_version'])
243 < distutils.version.LooseVersion(self._remote_device_minimum_os)):
157 continue 244 continue
158 if ((self._remote_device and self._remote_device_os) 245 if ((self._remote_device and self._remote_device_os)
159 or device['available_devices_count']): 246 or device['available_devices_count']):
160 logging.info('Found device: %s %s', 247 logging.info('Found device: %s %s',
161 device['name'], device['os_version']) 248 device['name'], device['os_version'])
162 return device 249 return device
163 self._NoDeviceFound(device_list) 250 self._NoDeviceFound(device_list)
164 251
165 def _PrintAvailableDevices(self, device_list): 252 def _PrintAvailableDevices(self, device_list):
166 def compare_devices(a,b): 253 def compare_devices(a,b):
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 def trigger(self): 303 def trigger(self):
217 return self._trigger 304 return self._trigger
218 305
219 @property 306 @property
220 def verbose_count(self): 307 def verbose_count(self):
221 return self._verbose_count 308 return self._verbose_count
222 309
223 @property 310 @property
224 def device_type(self): 311 def device_type(self):
225 return self._device_type 312 return self._device_type
OLDNEW
« no previous file with comments | « no previous file | build/android/test_runner.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698