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

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: Created 5 years, 11 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
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 from distutils.version import LooseVersion
jbudorick 2015/01/27 17:58:55 Do we know we'll have this everywhere? Also, if t
rnephew (Wrong account) 2015/01/27 18:46:21 I didnt' have to install it, and as far as I can f
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
(...skipping 10 matching lines...) Expand all
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
32 if args.api_key_file: 34 if args.api_key_file:
33 with open(args.api_key_file) as api_key_file: 35 with open(args.api_key_file) as api_key_file:
34 self._api_key = api_key_file.read().strip() 36 self._api_key = api_key_file.read().strip()
35 elif args.api_key: 37 elif args.api_key:
36 self._api_key = args.api_key 38 self._api_key = args.api_key
37 else:
38 error_func('Must set api key with --api-key or --api-key-file')
39 39
40 if args.api_secret_file: 40 if args.api_secret_file:
41 with open(args.api_secret_file) as api_secret_file: 41 with open(args.api_secret_file) as api_secret_file:
42 self._api_secret = api_secret_file.read().strip() 42 self._api_secret = api_secret_file.read().strip()
43 elif args.api_secret: 43 elif args.api_secret:
44 self._api_secret = args.api_secret 44 self._api_secret = args.api_secret
45 else:
46 error_func('Must set api secret with --api-secret or --api-secret-file')
47 45
48 if not args.api_protocol:
49 error_func('Must set api protocol with --api-protocol. Example: http')
50 self._api_protocol = args.api_protocol 46 self._api_protocol = args.api_protocol
51
52 if not args.api_address:
53 error_func('Must set api address with --api-address')
54 self._api_address = args.api_address 47 self._api_address = args.api_address
55
56 if not args.api_port:
57 error_func('Must set api port with --api-port.')
58 self._api_port = args.api_port 48 self._api_port = args.api_port
59 49
60 self._access_token = '' 50 self._access_token = ''
61 self._results_path = args.results_path 51 self._results_path = args.results_path
62 self._remote_device = args.remote_device 52 if args.remote_device:
63 self._remote_device_os = args.remote_device_os 53 self._remote_device = args.remote_device.split(',')
jbudorick 2015/01/27 17:58:55 I'm not sure these should necessarily support mult
rnephew (Wrong account) 2015/01/27 18:46:21 Done.
54 else:
55 self._remote_device = ''
56 if args.remote_device_os:
57 self._remote_device_os = args.remote_device_os.split(',')
jbudorick 2015/01/27 17:58:55 ditto
rnephew (Wrong account) 2015/01/27 18:46:21 Done.
58 else:
59 self._remote_device_os = ''
60 self._remote_device_minimum_os = args.remote_device_minimum_os
64 self._runner_package = args.runner_package 61 self._runner_package = args.runner_package
65 self._runner_type = args.runner_type 62 self._runner_type = args.runner_type
66 self._device = '' 63 self._device = ''
67 self._verbose_count = args.verbose_count 64 self._verbose_count = args.verbose_count
68 self._device_type = args.device_type 65 self._device_type = args.device_type
69 self._timeouts = { 66 self._timeouts = {
70 'queueing': 60 * 10, 67 'queueing': 60 * 10,
71 'installing': 60 * 10, 68 'installing': 60 * 10,
72 'in-progress': 60 * 30, 69 'in-progress': 60 * 30,
73 'unknown': 60 * 5 70 'unknown': 60 * 5
74 } 71 }
72 if args.remote_device_file:
73 with open(args.remote_device_file) as device_file:
74 device_json = json.load(device_file)
75 if 'remote_device' in device_json:
76 self._remote_device = device_json['remote_device'].split(',')
jbudorick 2015/01/27 17:58:55 oh, it is json. Why aren't remote_device and remo
rnephew (Wrong account) 2015/01/27 18:46:21 Done.
77 if 'remote_device_os' in device_json:
78 self._remote_device_os = device_json['remote_device_os'].split(',')
79 if 'remote_device_minimum_os' in device_json:
80 self._remote_device_minimum_os = (
81 device_json['remote_device_minimum_os'])
82 if 'api_address' in device_json:
83 self._api_address = device_json['api_address']
84 if 'api_secret' in device_json:
85 self._api_secret = device_json['api_secret']
86 if 'api_key' in device_json:
87 self._api_key = device_json['api_key']
jbudorick 2015/01/27 17:58:55 Most of these can just be self._blah = device_j
rnephew (Wrong account) 2015/01/27 18:46:21 I went with ..get('blah', self._blah) that way if
88 if 'api_protocol' in device_json:
89 self._api_protocol = device_json['api_protocol']
90 if 'api_port' in device_json:
91 self._api_port = device_json['api_port']
92 if 'timeouts' in device_json:
93 self._timeouts = device_json['timeouts']
94
95 if not self._api_address:
96 error_func('Must set api address with --api-address'
97 'or in --remote-device-file.')
98 if not self._api_protocol:
99 error_func('Must set api protocol with --api-protocol'
100 ' or in --remote-device-file. Example: http')
101 if not self._api_key:
102 error_func('Must set api key with --api-key, --api-key-file'
103 'or in --remote-device-file')
104 if not self._api_secret:
105 error_func('Must set api secret with --api-secret, --api-secret-file'
106 'or in --remote-device-file')
107 if not self._api_port:
108 error_func('Must set api port with --api-port'
109 'or in --remote-device-file')
110 if not isinstance(self._timeouts, dict):
111 error_func('Timeouts must be a dictionary.')
112 if ('queueing' not in self._timeouts
113 or 'installing' not in self._timeouts
114 or 'in-progress' not in self._timeouts
115 or 'unknown' not in self._timeouts) :
116 error_func('Timeouts must contain queueing,'
117 ' installing, in-progress, and unknown.')
118 # Sanitize inputs.
119 for x in range(0,len(self._remote_device)):
120 self._remote_device[x] = self._remote_device[x].strip()
121 for y in range(0,len(self._remote_device_os)):
122 self._remote_device_os[y] = self._remote_device_os[y].strip()
75 123
76 if not args.trigger and not args.collect: 124 if not args.trigger and not args.collect:
77 self._trigger = True 125 self._trigger = True
78 self._collect = True 126 self._collect = True
79 else: 127 else:
80 self._trigger = args.trigger 128 self._trigger = args.trigger
81 self._collect = args.collect 129 self._collect = args.collect
82 130
83 def SetUp(self): 131 def SetUp(self):
84 """Set up the test environment.""" 132 """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, 191 with appurify_sanitized.SanitizeLogging(self._verbose_count,
144 logging.WARNING): 192 logging.WARNING):
145 dev_list_res = appurify_sanitized.api.devices_list(self._access_token) 193 dev_list_res = appurify_sanitized.api.devices_list(self._access_token)
146 remote_device_helper.TestHttpResponse(dev_list_res, 194 remote_device_helper.TestHttpResponse(dev_list_res,
147 'Unable to generate access token.') 195 'Unable to generate access token.')
148 device_list = dev_list_res.json()['response'] 196 device_list = dev_list_res.json()['response']
149 random.shuffle(device_list) 197 random.shuffle(device_list)
150 for device in device_list: 198 for device in device_list:
151 if device['os_name'] != self._device_type: 199 if device['os_name'] != self._device_type:
152 continue 200 continue
153 if self._remote_device and device['name'] != self._remote_device: 201 if self._remote_device and device['name'] not in self._remote_device:
154 continue 202 continue
155 if (self._remote_device_os 203 if (self._remote_device_os
156 and device['os_version'] != self._remote_device_os): 204 and device['os_version'] not in self._remote_device_os):
205 continue
206 if (self._remote_device_minimum_os
207 and LooseVersion(device['os_version'])
208 < LooseVersion(self._remote_device_minimum_os)):
157 continue 209 continue
158 if ((self._remote_device and self._remote_device_os) 210 if ((self._remote_device and self._remote_device_os)
159 or device['available_devices_count']): 211 or device['available_devices_count']):
160 logging.info('Found device: %s %s', 212 logging.info('Found device: %s %s',
161 device['name'], device['os_version']) 213 device['name'], device['os_version'])
162 return device 214 return device
163 self._NoDeviceFound(device_list) 215 self._NoDeviceFound(device_list)
164 216
165 def _PrintAvailableDevices(self, device_list): 217 def _PrintAvailableDevices(self, device_list):
166 def compare_devices(a,b): 218 def compare_devices(a,b):
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 def trigger(self): 268 def trigger(self):
217 return self._trigger 269 return self._trigger
218 270
219 @property 271 @property
220 def verbose_count(self): 272 def verbose_count(self):
221 return self._verbose_count 273 return self._verbose_count
222 274
223 @property 275 @property
224 def device_type(self): 276 def device_type(self):
225 return self._device_type 277 return self._device_type
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698