| 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 |
| 11 | 11 |
| 12 import test_env | 12 import test_env |
| 13 test_env.setup_test_env() | 13 test_env.setup_test_env() |
| 14 | 14 |
| 15 from google.appengine.api import users | 15 from google.appengine.api import users |
| 16 from google.appengine.ext import ndb | 16 from google.appengine.ext import ndb |
| 17 | 17 |
| 18 import endpoints | 18 import endpoints |
| 19 from protorpc.remote import protojson | 19 from protorpc.remote import protojson |
| 20 import webtest | 20 import webtest |
| 21 | 21 |
| 22 import handlers_endpoints | 22 import handlers_endpoints |
| 23 import swarming_rpcs | 23 import swarming_rpcs |
| 24 from components import auth | 24 from components import auth |
| 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 proto import config_pb2 |
| 30 from server import acl | 31 from server import acl |
| 31 from server import large | 32 from server import large |
| 32 from server import stats | 33 from server import stats |
| 33 | 34 |
| 34 | 35 |
| 35 PINNED_PACKAGE_VERSION = 'deadbeefdeadbeefdeadbeefdeadbeefdeadbeef' | 36 CIPD_SETTINGS = config_pb2.CipdSettings( |
| 37 server_host='chrome-infra-packages.appspot.com', |
| 38 client_package_name='infra/tools/cipd/${platform}', |
| 39 client_package_version='git_revision:deadbeef') |
| 40 PINNED_PACKAGE_VERSION = 'git_revision:deadbeef' |
| 36 | 41 |
| 37 | 42 |
| 38 class AppTestBase(test_case.TestCase): | 43 class AppTestBase(test_case.TestCase): |
| 39 APP_DIR = test_env.APP_DIR | 44 APP_DIR = test_env.APP_DIR |
| 40 | 45 |
| 41 def setUp(self): | 46 def setUp(self): |
| 42 super(AppTestBase, self).setUp() | 47 super(AppTestBase, self).setUp() |
| 43 self.bot_version = None | 48 self.bot_version = None |
| 44 self.source_ip = '192.168.2.2' | 49 self.source_ip = '192.168.2.2' |
| 45 self.testbed.init_user_stub() | 50 self.testbed.init_user_stub() |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 211 return task_id | 216 return task_id |
| 212 | 217 |
| 213 # Client | 218 # Client |
| 214 | 219 |
| 215 def endpoint_call(self, service, name, args): | 220 def endpoint_call(self, service, name, args): |
| 216 body = json.loads(protojson.encode_message(args)) | 221 body = json.loads(protojson.encode_message(args)) |
| 217 return test_case.Endpoints(service).call_api(name, body=body).json | 222 return test_case.Endpoints(service).call_api(name, body=body).json |
| 218 | 223 |
| 219 def _client_create_task(self, properties=None, **kwargs): | 224 def _client_create_task(self, properties=None, **kwargs): |
| 220 """Creates an isolated command TaskRequest via the Cloud Endpoints API.""" | 225 """Creates an isolated command TaskRequest via the Cloud Endpoints API.""" |
| 221 params = { | 226 props = { |
| 222 'packages': [{ | 227 'cipd_input': { |
| 223 'package_name': 'rm', | 228 'packages': [{ |
| 224 'version': PINNED_PACKAGE_VERSION, | 229 'package_name': 'rm', |
| 225 }], | 230 'version': PINNED_PACKAGE_VERSION, |
| 231 }], |
| 232 'settings': CIPD_SETTINGS.SerializeToString(), |
| 233 }, |
| 226 'dimensions': [ | 234 'dimensions': [ |
| 227 {'key': 'os', 'value': 'Amiga'}, | 235 {'key': 'os', 'value': 'Amiga'}, |
| 228 {'key': 'pool', 'value': 'default'}, | 236 {'key': 'pool', 'value': 'default'}, |
| 229 ], | 237 ], |
| 230 'env': [], | 238 'env': [], |
| 231 'execution_timeout_secs': 3600, | 239 'execution_timeout_secs': 3600, |
| 232 'io_timeout_secs': 1200, | 240 'io_timeout_secs': 1200, |
| 233 } | 241 } |
| 234 params.update(properties or {}) | 242 props.update(properties or {}) |
| 235 props = swarming_rpcs.TaskProperties(**params) | |
| 236 | 243 |
| 237 params = { | 244 params = { |
| 238 'expiration_secs': 24*60*60, | 245 'expiration_secs': 24*60*60, |
| 239 'name': 'hi', | 246 'name': 'hi', |
| 240 'priority': 10, | 247 'priority': 10, |
| 248 'properties': props, |
| 241 'tags': [], | 249 'tags': [], |
| 242 'user': 'joe@localhost', | 250 'user': 'joe@localhost', |
| 243 } | 251 } |
| 244 params.update(kwargs) | 252 params.update(kwargs) |
| 245 request = swarming_rpcs.TaskRequest(properties=props, **params) | 253 |
| 254 # Note that protorpc message constructor accepts dicts for submessages. |
| 255 request = swarming_rpcs.TaskRequest(**params) |
| 246 response = self.endpoint_call( | 256 response = self.endpoint_call( |
| 247 handlers_endpoints.SwarmingTasksService, 'new', request) | 257 handlers_endpoints.SwarmingTasksService, 'new', request) |
| 248 return response, response['task_id'] | 258 return response, response['task_id'] |
| 249 | 259 |
| 250 def client_create_task_isolated(self, properties=None, **kwargs): | 260 def client_create_task_isolated(self, properties=None, **kwargs): |
| 251 properties = (properties or {}).copy() | 261 properties = (properties or {}).copy() |
| 252 properties['inputs_ref'] = { | 262 properties['inputs_ref'] = { |
| 253 'isolated': '0123456789012345678901234567890123456789', | 263 'isolated': '0123456789012345678901234567890123456789', |
| 254 'isolatedserver': 'http://localhost:1', | 264 'isolatedserver': 'http://localhost:1', |
| 255 'namespace': 'default-gzip', | 265 'namespace': 'default-gzip', |
| 256 } | 266 } |
| 257 return self._client_create_task(properties, **kwargs) | 267 return self._client_create_task(properties, **kwargs) |
| 258 | 268 |
| 259 def client_create_task_raw(self, properties=None, **kwargs): | 269 def client_create_task_raw(self, properties=None, **kwargs): |
| 260 """Creates a raw command TaskRequest via the Cloud Endpoints API.""" | 270 """Creates a raw command TaskRequest via the Cloud Endpoints API.""" |
| 261 properties = (properties or {}).copy() | 271 properties = (properties or {}).copy() |
| 262 properties['command'] = ['python', 'run_test.py'] | 272 properties['command'] = ['python', 'run_test.py'] |
| 263 return self._client_create_task(properties, **kwargs) | 273 return self._client_create_task(properties, **kwargs) |
| 264 | 274 |
| 265 def client_get_results(self, task_id): | 275 def client_get_results(self, task_id): |
| 266 api = test_case.Endpoints(handlers_endpoints.SwarmingTaskService) | 276 api = test_case.Endpoints(handlers_endpoints.SwarmingTaskService) |
| 267 return api.call_api('result', body={'task_id': task_id}).json | 277 return api.call_api('result', body={'task_id': task_id}).json |
| OLD | NEW |