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

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

Issue 814653003: Clean up logging and add device randomization. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase 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 import logging 7 import logging
8 import os 8 import os
9 import random
9 import sys 10 import sys
10 11
11 from pylib import constants 12 from pylib import constants
12 from pylib.base import environment 13 from pylib.base import environment
13 from pylib.remote.device import appurify_sanitized 14 from pylib.remote.device import appurify_sanitized
14 from pylib.remote.device import remote_device_helper 15 from pylib.remote.device import remote_device_helper
15 16
16 class RemoteDeviceEnvironment(environment.Environment): 17 class RemoteDeviceEnvironment(environment.Environment):
17 """An environment for running on remote devices.""" 18 """An environment for running on remote devices."""
18 19
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 error_func('Must set api port with --api-port.') 54 error_func('Must set api port with --api-port.')
54 self._api_port = args.api_port 55 self._api_port = args.api_port
55 56
56 self._access_token = '' 57 self._access_token = ''
57 self._results_path = args.results_path 58 self._results_path = args.results_path
58 self._remote_device = args.remote_device 59 self._remote_device = args.remote_device
59 self._remote_device_os = args.remote_device_os 60 self._remote_device_os = args.remote_device_os
60 self._runner_package = args.runner_package 61 self._runner_package = args.runner_package
61 self._runner_type = args.runner_type 62 self._runner_type = args.runner_type
62 self._device = '' 63 self._device = ''
64 self._verbose_count = args.verbose_count
65
63 if not args.trigger and not args.collect: 66 if not args.trigger and not args.collect:
64 self._trigger = True 67 self._trigger = True
65 self._collect = True 68 self._collect = True
66 else: 69 else:
67 self._trigger = args.trigger 70 self._trigger = args.trigger
68 self._collect = args.collect 71 self._collect = args.collect
69 72
70 def SetUp(self): 73 def SetUp(self):
71 """Set up the test environment.""" 74 """Set up the test environment."""
72 os.environ['APPURIFY_API_PROTO'] = self._api_protocol 75 os.environ['APPURIFY_API_PROTO'] = self._api_protocol
(...skipping 16 matching lines...) Expand all
89 self.__exit__(*sys.exc_info()) 92 self.__exit__(*sys.exc_info())
90 raise 93 raise
91 94
92 def __exit__(self, exc_type, exc_val, exc_tb): 95 def __exit__(self, exc_type, exc_val, exc_tb):
93 """Tears down the test run when used as a context manager.""" 96 """Tears down the test run when used as a context manager."""
94 self.TearDown() 97 self.TearDown()
95 98
96 def _GetAccessToken(self): 99 def _GetAccessToken(self):
97 """Generates access token for remote device service.""" 100 """Generates access token for remote device service."""
98 logging.info('Generating remote service access token') 101 logging.info('Generating remote service access token')
99 access_token_results = appurify_sanitized.api.access_token_generate( 102 with appurify_sanitized.SanitizeLogging(self._verbose_count,
100 self._api_key, self._api_secret) 103 logging.WARNING):
104 access_token_results = appurify_sanitized.api.access_token_generate(
105 self._api_key, self._api_secret)
101 remote_device_helper.TestHttpResponse(access_token_results, 106 remote_device_helper.TestHttpResponse(access_token_results,
102 'Unable to generate access token.') 107 'Unable to generate access token.')
103 self._access_token = access_token_results.json()['response']['access_token'] 108 self._access_token = access_token_results.json()['response']['access_token']
104 109
105 def _RevokeAccessToken(self): 110 def _RevokeAccessToken(self):
106 """Destroys access token for remote device service.""" 111 """Destroys access token for remote device service."""
107 logging.info('Revoking remote service access token') 112 logging.info('Revoking remote service access token')
108 revoke_token_results = appurify_sanitized.api.access_token_revoke( 113 with appurify_sanitized.SanitizeLogging(self._verbose_count,
109 self._access_token) 114 logging.WARNING):
115 revoke_token_results = appurify_sanitized.api.access_token_revoke(
116 self._access_token)
110 remote_device_helper.TestHttpResponse(revoke_token_results, 117 remote_device_helper.TestHttpResponse(revoke_token_results,
111 'Unable to revoke access token.') 118 'Unable to revoke access token.')
112 119
113 def _SelectDevice(self): 120 def _SelectDevice(self):
114 """Select which device to use.""" 121 """Select which device to use."""
115 logging.info('Finding %s with %s to run tests on.' % 122 logging.info('Finding device to run tests on.')
116 (self._remote_device, self._remote_device_os)) 123 with appurify_sanitized.SanitizeLogging(self._verbose_count,
117 dev_list_res = appurify_sanitized.api.devices_list(self._access_token) 124 logging.WARNING):
125 dev_list_res = appurify_sanitized.api.devices_list(self._access_token)
118 remote_device_helper.TestHttpResponse(dev_list_res, 126 remote_device_helper.TestHttpResponse(dev_list_res,
119 'Unable to generate access token.') 127 'Unable to generate access token.')
120 device_list = dev_list_res.json()['response'] 128 device_list = dev_list_res.json()['response']
129 random.shuffle(device_list)
121 for device in device_list: 130 for device in device_list:
122 if (device['name'] == self._remote_device 131 if device['os_name'] != 'Android':
123 and device['os_version'] == self._remote_device_os): 132 continue
133 if self._remote_device and device['name'] != self._remote_device:
134 continue
135 if (self._remote_device_os
136 and device['os_version'] != self._remote_device_os):
137 continue
138 if device['available_devices_count'] > 0:
139 logging.info('Found device: %s %s' %
jbudorick 2015/01/07 18:02:37 the linter should catch this... I need to check on
rnephew (Wrong account) 2015/01/07 18:11:24 Done.
140 (device['name'], device['os_version']))
124 return device['device_type_id'] 141 return device['device_type_id']
125 self._NoDeviceFound(device_list) 142 self._NoDeviceFound(device_list)
126 143
127 def _PrintAvailableDevices(self, device_list): 144 def _PrintAvailableDevices(self, device_list):
128 def compare_devices(a,b): 145 def compare_devices(a,b):
129 for key in ('os_version', 'name'): 146 for key in ('os_version', 'name'):
130 c = cmp(a[key], b[key]) 147 c = cmp(a[key], b[key])
131 if c: 148 if c:
132 return c 149 return c
133 return 0 150 return 0
134 151
135 logging.critical('Available Android Devices:') 152 logging.critical('Available Android Devices:')
136 android_devices = (d for d in device_list if d['os_name'] == 'Android') 153 android_devices = (d for d in device_list if d['os_name'] == 'Android')
137 for d in sorted(android_devices, compare_devices): 154 for d in sorted(android_devices, compare_devices):
138 logging.critical(' %s %s', d['os_version'].ljust(7), d['name']) 155 logging.critical(' %s %s', d['os_version'].ljust(7), d['name'])
139 156
140 def _NoDeviceFound(self, device_list): 157 def _NoDeviceFound(self, device_list):
141 self._PrintAvailableDevices(device_list) 158 self._PrintAvailableDevices(device_list)
142 raise remote_device_helper.RemoteDeviceError('No device found: %s %s' % 159 raise remote_device_helper.RemoteDeviceError('No device found.')
143 (self._remote_device, self._remote_device_os))
144 160
145 @property 161 @property
146 def device(self): 162 def device(self):
147 return self._device 163 return self._device
148 164
149 @property 165 @property
150 def token(self): 166 def token(self):
151 return self._access_token 167 return self._access_token
152 168
153 @property 169 @property
154 def results_path(self): 170 def results_path(self):
155 return self._results_path 171 return self._results_path
156 172
157 @property 173 @property
158 def runner_type(self): 174 def runner_type(self):
159 return self._runner_type 175 return self._runner_type
160 176
161 @property 177 @property
162 def runner_package(self): 178 def runner_package(self):
163 return self._runner_package 179 return self._runner_package
164 180
165 @property 181 @property
166 def trigger(self): 182 def trigger(self):
167 return self._trigger 183 return self._trigger
168 184
169 @property 185 @property
170 def collect(self): 186 def collect(self):
171 return self._collect 187 return self._collect
188
189 @property
190 def verbose_count(self):
191 return self._verbose_count
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698