| OLD | NEW |
| 1 # coding: utf-8 | 1 # coding: utf-8 |
| 2 # Copyright 2014 The LUCI Authors. All rights reserved. | 2 # Copyright 2014 The LUCI Authors. All rights reserved. |
| 3 # Use of this source code is governed by the Apache v2.0 license that can be | 3 # Use of this source code is governed by the Apache v2.0 license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 """Base class for handlers_*_test.py""" | 6 """Base class for handlers_*_test.py""" |
| 7 | 7 |
| 8 import base64 | 8 import base64 |
| 9 import json | 9 import json |
| 10 import os | 10 import os |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 from components import auth_testing | 25 from components import auth_testing |
| 26 from components import stats_framework | 26 from components import stats_framework |
| 27 import gae_ts_mon | 27 import gae_ts_mon |
| 28 from test_support import test_case | 28 from test_support import test_case |
| 29 | 29 |
| 30 from server import acl | 30 from server import acl |
| 31 from server import large | 31 from server import large |
| 32 from server import stats | 32 from server import stats |
| 33 | 33 |
| 34 | 34 |
| 35 PINNED_PACKAGE_VERSION = 'deadbeefdeadbeefdeadbeefdeadbeefdeadbeef' | |
| 36 | |
| 37 | |
| 38 class AppTestBase(test_case.TestCase): | 35 class AppTestBase(test_case.TestCase): |
| 39 APP_DIR = test_env.APP_DIR | 36 APP_DIR = test_env.APP_DIR |
| 40 | 37 |
| 41 def setUp(self): | 38 def setUp(self): |
| 42 super(AppTestBase, self).setUp() | 39 super(AppTestBase, self).setUp() |
| 43 self.bot_version = None | 40 self.bot_version = None |
| 44 self.source_ip = '192.168.2.2' | 41 self.source_ip = '192.168.2.2' |
| 45 self.testbed.init_user_stub() | 42 self.testbed.init_user_stub() |
| 46 self.testbed.init_search_stub() | 43 self.testbed.init_search_stub() |
| 47 | 44 |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 211 return task_id | 208 return task_id |
| 212 | 209 |
| 213 # Client | 210 # Client |
| 214 | 211 |
| 215 def endpoint_call(self, service, name, args): | 212 def endpoint_call(self, service, name, args): |
| 216 body = json.loads(protojson.encode_message(args)) | 213 body = json.loads(protojson.encode_message(args)) |
| 217 return test_case.Endpoints(service).call_api(name, body=body).json | 214 return test_case.Endpoints(service).call_api(name, body=body).json |
| 218 | 215 |
| 219 def _client_create_task(self, properties=None, **kwargs): | 216 def _client_create_task(self, properties=None, **kwargs): |
| 220 """Creates an isolated command TaskRequest via the Cloud Endpoints API.""" | 217 """Creates an isolated command TaskRequest via the Cloud Endpoints API.""" |
| 221 params = { | 218 props = { |
| 222 'packages': [{ | 219 'cipd_input': { |
| 223 'package_name': 'rm', | 220 'client_package': { |
| 224 'version': PINNED_PACKAGE_VERSION, | 221 'package_name': 'infra/tools/cipd/${platform}', |
| 225 }], | 222 'version': 'git_revision:deadbeef', |
| 223 }, |
| 224 'packages': [{ |
| 225 'package_name': 'rm', |
| 226 'version': 'git_revision:deadbeef', |
| 227 }], |
| 228 'server': 'https://chrome-infra-packages.appspot.com', |
| 229 }, |
| 226 'dimensions': [ | 230 'dimensions': [ |
| 227 {'key': 'os', 'value': 'Amiga'}, | 231 {'key': 'os', 'value': 'Amiga'}, |
| 228 {'key': 'pool', 'value': 'default'}, | 232 {'key': 'pool', 'value': 'default'}, |
| 229 ], | 233 ], |
| 230 'env': [], | 234 'env': [], |
| 231 'execution_timeout_secs': 3600, | 235 'execution_timeout_secs': 3600, |
| 232 'io_timeout_secs': 1200, | 236 'io_timeout_secs': 1200, |
| 233 } | 237 } |
| 234 params.update(properties or {}) | 238 props.update(properties or {}) |
| 235 props = swarming_rpcs.TaskProperties(**params) | |
| 236 | 239 |
| 237 params = { | 240 params = { |
| 238 'expiration_secs': 24*60*60, | 241 'expiration_secs': 24*60*60, |
| 239 'name': 'hi', | 242 'name': 'hi', |
| 240 'priority': 10, | 243 'priority': 10, |
| 244 'properties': props, |
| 241 'tags': [], | 245 'tags': [], |
| 242 'user': 'joe@localhost', | 246 'user': 'joe@localhost', |
| 243 } | 247 } |
| 244 params.update(kwargs) | 248 params.update(kwargs) |
| 245 request = swarming_rpcs.TaskRequest(properties=props, **params) | 249 |
| 250 # Note that protorpc message constructor accepts dicts for submessages. |
| 251 request = swarming_rpcs.TaskRequest(**params) |
| 246 response = self.endpoint_call( | 252 response = self.endpoint_call( |
| 247 handlers_endpoints.SwarmingTasksService, 'new', request) | 253 handlers_endpoints.SwarmingTasksService, 'new', request) |
| 248 return response, response['task_id'] | 254 return response, response['task_id'] |
| 249 | 255 |
| 250 def client_create_task_isolated(self, properties=None, **kwargs): | 256 def client_create_task_isolated(self, properties=None, **kwargs): |
| 251 properties = (properties or {}).copy() | 257 properties = (properties or {}).copy() |
| 252 properties['inputs_ref'] = { | 258 properties['inputs_ref'] = { |
| 253 'isolated': '0123456789012345678901234567890123456789', | 259 'isolated': '0123456789012345678901234567890123456789', |
| 254 'isolatedserver': 'http://localhost:1', | 260 'isolatedserver': 'http://localhost:1', |
| 255 'namespace': 'default-gzip', | 261 'namespace': 'default-gzip', |
| 256 } | 262 } |
| 257 return self._client_create_task(properties, **kwargs) | 263 return self._client_create_task(properties, **kwargs) |
| 258 | 264 |
| 259 def client_create_task_raw(self, properties=None, **kwargs): | 265 def client_create_task_raw(self, properties=None, **kwargs): |
| 260 """Creates a raw command TaskRequest via the Cloud Endpoints API.""" | 266 """Creates a raw command TaskRequest via the Cloud Endpoints API.""" |
| 261 properties = (properties or {}).copy() | 267 properties = (properties or {}).copy() |
| 262 properties['command'] = ['python', 'run_test.py'] | 268 properties['command'] = ['python', 'run_test.py'] |
| 263 return self._client_create_task(properties, **kwargs) | 269 return self._client_create_task(properties, **kwargs) |
| 264 | 270 |
| 265 def client_get_results(self, task_id): | 271 def client_get_results(self, task_id): |
| 266 api = test_case.Endpoints(handlers_endpoints.SwarmingTaskService) | 272 api = test_case.Endpoints(handlers_endpoints.SwarmingTaskService) |
| 267 return api.call_api('result', body={'task_id': task_id}).json | 273 return api.call_api('result', body={'task_id': task_id}).json |
| OLD | NEW |