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

Unified Diff: build/android/pylib/remote/device/remote_device_environment.py

Issue 745793002: Add AMP support to test runner. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: address comments on previous patch set Created 6 years 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 side-by-side diff with in-line comments
Download patch
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
new file mode 100644
index 0000000000000000000000000000000000000000..0a350975ffe0f5a9feaa9263ac09860b806b9fb6
--- /dev/null
+++ b/build/android/pylib/remote/device/remote_device_environment.py
@@ -0,0 +1,120 @@
+# Copyright 2014 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+"""Environment setup and teardown for remote devices."""
+
+import os
+import sys
+
+from pylib import constants
+from pylib.base import environment
+from pylib.remote.device import remote_device_helper
+
+sys.path.append(os.path.join(
+ constants.DIR_SOURCE_ROOT, 'third_party', 'appurify-python', 'src'))
+import appurify.api
+
+
+class RemoteDeviceEnvironment(environment.Environment):
+ """An environment for running on remote devices."""
+
+ def __init__(self, options, error_func):
+ """Constructor.
+
+ Args:
+ options: Command line options.
+ error_func: error to show when using bad command line options.
+ """
+ super(RemoteDeviceEnvironment, self).__init__()
+ if options.api_key_file:
jbudorick 2014/12/03 22:46:09 api_key_file and api_key should be mutually exclus
rnephew (Reviews Here) 2014/12/03 23:49:25 Done.
+ with open(options.api_key_file) as api_key_file:
+ self._api_key = api_key_file.read().strip()
+ if options.api_secret_file:
jbudorick 2014/12/03 22:46:09 Same re mutual exclusivity.
rnephew (Reviews Here) 2014/12/03 23:49:25 Done.
+ with open(options.api_secret_file) as api_secret_file:
+ self._api_secret = api_secret_file.read().strip()
+ if options.api_key:
+ self._api_key = options.api_key
+ if options.api_secret:
+ self._api_secret = options.api_secret
+ if not self._api_key:
+ error_func('Must set api key with --api-key or --api-key-file')
+ if not self._api_secret:
+ error_func('Must set api secret with --api-secret or --api-secret-file')
+ self._api_protocol = options.api_protocol
+ self._api_address = options.api_address
+ self._access_token = ''
+ self._results_path = options.results_path
+ self._remote_device = options.remote_device
+ self._remote_device_os = options.remote_device_os
+ self._runner_package = options.runner_package
+ self._runner_type = options.runner_type
+ self._device = ''
+
+ def SetUp(self):
+ """Set up the test environment."""
+ os.environ['APPURIFY_API_PROTO'] = self._api_protocol
+ os.environ['APPURIFY_API_HOST'] = self._api_address
+ os.environ['APPURIFY_API_PORT'] = '80'
jbudorick 2014/12/03 22:46:09 This shouldn't be hard-coded.
rnephew (Reviews Here) 2014/12/03 23:49:25 Done.
+ self._GetAccessToken()
+ self._device = self._SelectDevice()
+
+ def TearDown(self):
+ """Teardown the test environment."""
+ self._RevokeAccessToken()
+
+ def __enter__(self):
+ """Runs when entering with with keyword."""
+ self.SetUp()
+ return self
+
+ def __exit__(self, exc_type, exc_val, exc_tb):
+ """Runs when exiting with with keyword."""
+ self.TearDown()
+
+ def _GetAccessToken(self):
+ """Generates access token for remote device service."""
+ access_token_results = appurify.api.access_token_generate(
+ self._api_key, self._api_secret)
+ remote_device_helper.TestHttpResponse(access_token_results,
+ 'Unable to generate access token.')
+ self._access_token = access_token_results.json()['response']['access_token']
+
+ def _RevokeAccessToken(self):
+ """Destroys access token for remote device service."""
+ revoke_token_results = appurify.api.access_token_revoke(self._access_token)
+ remote_device_helper.TestHttpResponse(revoke_token_results,
+ 'Unable to revoke access token.')
+
+ def _SelectDevice(self):
+ """Select which device to use."""
+ dev_list_res = appurify.api.devices_list(self._access_token)
+ remote_device_helper.TestHttpResponse(dev_list_res,
+ 'Unable to generate access token.')
+ device_list = dev_list_res.json()['response']
+ for device in device_list:
+ if (device['name'] == self._remote_device and
+ device['os_version'] == self._remote_device_os):
+ return device['device_type_id']
+ raise remote_device_helper.RemoteDeviceError('No device found: %s %s' %(
+ self._remote_device, self._remote_device_os))
+
+ @property
+ def device(self):
+ return self._device
+
+ @property
+ def token(self):
+ return self._access_token
+
+ @property
+ def results_path(self):
+ return self._results_path
+
+ @property
+ def runner_type(self):
+ return self._runner_type
+
+ @property
+ def runner_package(self):
+ return self._runner_package

Powered by Google App Engine
This is Rietveld 408576698