| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 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 import datetime | 6 import datetime |
| 7 import logging | 7 import logging |
| 8 import os | 8 import os |
| 9 import random | 9 import random |
| 10 import sys | 10 import sys |
| 11 import unittest | 11 import unittest |
| 12 | 12 |
| 13 import test_env | 13 import test_env |
| 14 test_env.setup_test_env() | 14 test_env.setup_test_env() |
| 15 | 15 |
| 16 from google.appengine.api import datastore_errors | 16 from google.appengine.api import datastore_errors |
| 17 from google.appengine.ext import ndb | 17 from google.appengine.ext import ndb |
| 18 | 18 |
| 19 from components import auth_testing | 19 from components import auth_testing |
| 20 from components import utils | 20 from components import utils |
| 21 from test_support import test_case | 21 from test_support import test_case |
| 22 | 22 |
| 23 from server import task_pack | 23 from server import task_pack |
| 24 from server import task_request | 24 from server import task_request |
| 25 | 25 |
| 26 | 26 |
| 27 # pylint: disable=W0212 | 27 # pylint: disable=W0212 |
| 28 | 28 |
| 29 | 29 |
| 30 PINNED_PACKAGE_VERSION = 'deadbeefdeadbeefdeadbeefdeadbeefdeadbeef' |
| 31 |
| 32 |
| 33 def mkreq(req): |
| 34 return task_request.make_request(req, True) |
| 35 |
| 36 |
| 30 def _gen_request(properties=None, **kwargs): | 37 def _gen_request(properties=None, **kwargs): |
| 31 """Creates a TaskRequest.""" | 38 """Creates a TaskRequest.""" |
| 39 properties = properties or {} |
| 40 packages = properties.pop('packages', [{ |
| 41 'package_name': 'rm', |
| 42 'version': PINNED_PACKAGE_VERSION, |
| 43 }]) |
| 32 props = { | 44 props = { |
| 33 'command': [u'command1', u'arg1'], | 45 'command': [u'command1', u'arg1'], |
| 46 'packages': [task_request.CipdPackage(**p) for p in packages], |
| 34 'dimensions': { | 47 'dimensions': { |
| 35 u'OS': u'Windows-3.1.1', | 48 u'OS': u'Windows-3.1.1', |
| 36 u'hostname': u'localhost', | 49 u'hostname': u'localhost', |
| 37 u'pool': u'default', | 50 u'pool': u'default', |
| 38 }, | 51 }, |
| 39 'env': {u'foo': u'bar', u'joe': u'2'}, | 52 'env': {u'foo': u'bar', u'joe': u'2'}, |
| 40 'execution_timeout_secs': 30, | 53 'execution_timeout_secs': 30, |
| 41 'grace_period_secs': 30, | 54 'grace_period_secs': 30, |
| 42 'idempotent': False, | 55 'idempotent': False, |
| 43 'io_timeout_secs': None, | 56 'io_timeout_secs': None, |
| 44 } | 57 } |
| 45 props.update(properties or {}) | 58 props.update(properties) |
| 46 now = utils.utcnow() | 59 now = utils.utcnow() |
| 47 args = { | 60 args = { |
| 48 'created_ts': now, | 61 'created_ts': now, |
| 49 'name': 'Request name', | 62 'name': 'Request name', |
| 50 'priority': 50, | 63 'priority': 50, |
| 51 'properties': task_request.TaskProperties(**props), | 64 'properties': task_request.TaskProperties(**props), |
| 52 'expiration_ts': now + datetime.timedelta(seconds=30), | 65 'expiration_ts': now + datetime.timedelta(seconds=30), |
| 53 'tags': [u'tag:1'], | 66 'tags': [u'tag:1'], |
| 54 'user': 'Jesus', | 67 'user': 'Jesus', |
| 55 } | 68 } |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 169 with self.assertRaises(ValueError): | 182 with self.assertRaises(ValueError): |
| 170 task_request.validate_request_key(ndb.Key('TaskRequest', 1)) | 183 task_request.validate_request_key(ndb.Key('TaskRequest', 1)) |
| 171 with self.assertRaises(ValueError): | 184 with self.assertRaises(ValueError): |
| 172 key = ndb.Key( | 185 key = ndb.Key( |
| 173 'TaskRequestShard', 'a' * (task_pack.DEPRECATED_SHARDING_LEVEL + 1), | 186 'TaskRequestShard', 'a' * (task_pack.DEPRECATED_SHARDING_LEVEL + 1), |
| 174 'TaskRequest', 0x100) | 187 'TaskRequest', 0x100) |
| 175 task_request.validate_request_key(key) | 188 task_request.validate_request_key(key) |
| 176 | 189 |
| 177 def test_make_request(self): | 190 def test_make_request(self): |
| 178 # Compare with test_make_request_clone(). | 191 # Compare with test_make_request_clone(). |
| 179 parent = task_request.make_request(_gen_request(), True) | 192 parent = mkreq(_gen_request()) |
| 180 # Hack: Would need to know about TaskResultSummary. | 193 # Hack: Would need to know about TaskResultSummary. |
| 181 parent_id = task_pack.pack_request_key(parent.key) + '1' | 194 parent_id = task_pack.pack_request_key(parent.key) + '1' |
| 182 r = _gen_request( | 195 r = _gen_request(properties=dict(idempotent=True), parent_task_id=parent_id) |
| 183 properties=dict(idempotent=True), parent_task_id=parent_id) | 196 request = mkreq(r) |
| 184 request = task_request.make_request(r, True) | |
| 185 expected_properties = { | 197 expected_properties = { |
| 186 'command': [u'command1', u'arg1'], | 198 'command': [u'command1', u'arg1'], |
| 187 'dimensions': { | 199 'dimensions': { |
| 188 u'OS': u'Windows-3.1.1', | 200 u'OS': u'Windows-3.1.1', |
| 189 u'hostname': u'localhost', | 201 u'hostname': u'localhost', |
| 190 u'pool': u'default', | 202 u'pool': u'default', |
| 191 }, | 203 }, |
| 192 'env': {u'foo': u'bar', u'joe': u'2'}, | 204 'env': {u'foo': u'bar', u'joe': u'2'}, |
| 193 'extra_args': [], | 205 'extra_args': [], |
| 194 'execution_timeout_secs': 30, | 206 'execution_timeout_secs': 30, |
| 195 'grace_period_secs': 30, | 207 'grace_period_secs': 30, |
| 196 'idempotent': True, | 208 'idempotent': True, |
| 197 'inputs_ref': None, | 209 'inputs_ref': None, |
| 198 'io_timeout_secs': None, | 210 'io_timeout_secs': None, |
| 211 'packages': [{'package_name': 'rm', 'version': PINNED_PACKAGE_VERSION}], |
| 199 } | 212 } |
| 200 expected_request = { | 213 expected_request = { |
| 201 'authenticated': auth_testing.DEFAULT_MOCKED_IDENTITY, | 214 'authenticated': auth_testing.DEFAULT_MOCKED_IDENTITY, |
| 202 'name': u'Request name', | 215 'name': u'Request name', |
| 203 'parent_task_id': unicode(parent_id), | 216 'parent_task_id': unicode(parent_id), |
| 204 'priority': 49, | 217 'priority': 49, |
| 205 'properties': expected_properties, | 218 'properties': expected_properties, |
| 206 # Intentionally hard code the hash value since it has to be deterministic. | 219 # Intentionally hard code the hash value since it has to be deterministic. |
| 207 # Other unit tests should use the calculated value. | 220 # Other unit tests should use the calculated value. |
| 208 'properties_hash': 'a406d174c469cb2ef6f56a49c3df0de0ae3db369', | 221 'properties_hash': '83b350298f05eff6072d54d2c6f031d06cc30449', |
| 209 'pubsub_topic': None, | 222 'pubsub_topic': None, |
| 210 'pubsub_userdata': None, | 223 'pubsub_userdata': None, |
| 211 'tags': [ | 224 'tags': [ |
| 212 u'OS:Windows-3.1.1', | 225 u'OS:Windows-3.1.1', |
| 213 u'hostname:localhost', | 226 u'hostname:localhost', |
| 214 u'pool:default', | 227 u'pool:default', |
| 215 u'priority:49', | 228 u'priority:49', |
| 216 u'tag:1', | 229 u'tag:1', |
| 217 u'user:Jesus', | 230 u'user:Jesus', |
| 218 ], | 231 ], |
| 219 'user': u'Jesus', | 232 'user': u'Jesus', |
| 220 } | 233 } |
| 221 actual = request.to_dict() | 234 actual = request.to_dict() |
| 222 actual.pop('created_ts') | 235 actual.pop('created_ts') |
| 223 actual.pop('expiration_ts') | 236 actual.pop('expiration_ts') |
| 224 self.assertEqual(expected_request, actual) | 237 self.assertEqual(expected_request, actual) |
| 225 self.assertEqual(30, request.expiration_secs) | 238 self.assertEqual(30, request.expiration_secs) |
| 226 | 239 |
| 227 def test_make_request_isolated(self): | 240 def test_make_request_isolated(self): |
| 228 parent = task_request.make_request( | 241 parent = mkreq(_gen_request(properties={ |
| 229 _gen_request( | 242 'command': [], |
| 230 properties={ | 243 'inputs_ref': { |
| 231 'command': [], | 244 'isolated': '0123456789012345678901234567890123456789', |
| 232 'inputs_ref': { | 245 'isolatedserver': 'http://localhost:1', |
| 233 'isolated': '0123456789012345678901234567890123456789', | 246 'namespace': 'default-gzip', |
| 234 'isolatedserver': 'http://localhost:1', | 247 }, |
| 235 'namespace': 'default-gzip', | 248 })) |
| 236 }, | |
| 237 }), | |
| 238 True) | |
| 239 # Hack: Would need to know about TaskResultSummary. | 249 # Hack: Would need to know about TaskResultSummary. |
| 240 parent_id = task_pack.pack_request_key(parent.key) + '1' | 250 parent_id = task_pack.pack_request_key(parent.key) + '1' |
| 241 request = task_request.make_request( | 251 request = mkreq(_gen_request( |
| 242 _gen_request(properties={'idempotent':True}, parent_task_id=parent_id), | 252 properties={'idempotent':True}, parent_task_id=parent_id)) |
| 243 True) | |
| 244 expected_properties = { | 253 expected_properties = { |
| 245 'command': [u'command1', u'arg1'], | 254 'command': [u'command1', u'arg1'], |
| 246 'dimensions': { | 255 'dimensions': { |
| 247 u'OS': u'Windows-3.1.1', | 256 u'OS': u'Windows-3.1.1', |
| 248 u'hostname': u'localhost', | 257 u'hostname': u'localhost', |
| 249 u'pool': u'default', | 258 u'pool': u'default', |
| 250 }, | 259 }, |
| 251 'env': {u'foo': u'bar', u'joe': u'2'}, | 260 'env': {u'foo': u'bar', u'joe': u'2'}, |
| 252 'extra_args': [], | 261 'extra_args': [], |
| 253 'execution_timeout_secs': 30, | 262 'execution_timeout_secs': 30, |
| 254 'grace_period_secs': 30, | 263 'grace_period_secs': 30, |
| 255 'idempotent': True, | 264 'idempotent': True, |
| 256 'inputs_ref': None, | 265 'inputs_ref': None, |
| 257 'io_timeout_secs': None, | 266 'io_timeout_secs': None, |
| 267 'packages': [{'package_name': 'rm', 'version': PINNED_PACKAGE_VERSION}], |
| 258 } | 268 } |
| 259 expected_request = { | 269 expected_request = { |
| 260 'authenticated': auth_testing.DEFAULT_MOCKED_IDENTITY, | 270 'authenticated': auth_testing.DEFAULT_MOCKED_IDENTITY, |
| 261 'name': u'Request name', | 271 'name': u'Request name', |
| 262 'parent_task_id': unicode(parent_id), | 272 'parent_task_id': unicode(parent_id), |
| 263 'priority': 49, | 273 'priority': 49, |
| 264 'properties': expected_properties, | 274 'properties': expected_properties, |
| 265 # Intentionally hard code the hash value since it has to be deterministic. | 275 # Intentionally hard code the hash value since it has to be deterministic. |
| 266 # Other unit tests should use the calculated value. | 276 # Other unit tests should use the calculated value. |
| 267 'properties_hash': 'a406d174c469cb2ef6f56a49c3df0de0ae3db369', | 277 'properties_hash': '83b350298f05eff6072d54d2c6f031d06cc30449', |
| 268 'pubsub_topic': None, | 278 'pubsub_topic': None, |
| 269 'pubsub_userdata': None, | 279 'pubsub_userdata': None, |
| 270 'tags': [ | 280 'tags': [ |
| 271 u'OS:Windows-3.1.1', | 281 u'OS:Windows-3.1.1', |
| 272 u'hostname:localhost', | 282 u'hostname:localhost', |
| 273 u'pool:default', | 283 u'pool:default', |
| 274 u'priority:49', | 284 u'priority:49', |
| 275 u'tag:1', | 285 u'tag:1', |
| 276 u'user:Jesus', | 286 u'user:Jesus', |
| 277 ], | 287 ], |
| 278 'user': u'Jesus', | 288 'user': u'Jesus', |
| 279 } | 289 } |
| 280 actual = request.to_dict() | 290 actual = request.to_dict() |
| 281 # expiration_ts - created_ts == scheduling_expiration_secs. | 291 # expiration_ts - created_ts == scheduling_expiration_secs. |
| 282 actual.pop('created_ts') | 292 actual.pop('created_ts') |
| 283 actual.pop('expiration_ts') | 293 actual.pop('expiration_ts') |
| 284 self.assertEqual(expected_request, actual) | 294 self.assertEqual(expected_request, actual) |
| 285 self.assertEqual(30, request.expiration_secs) | 295 self.assertEqual(30, request.expiration_secs) |
| 286 | 296 |
| 287 def test_make_request_parent(self): | 297 def test_make_request_parent(self): |
| 288 parent = task_request.make_request(_gen_request(), True) | 298 parent = mkreq(_gen_request()) |
| 289 # Hack: Would need to know about TaskResultSummary. | 299 # Hack: Would need to know about TaskResultSummary. |
| 290 parent_id = task_pack.pack_request_key(parent.key) + '1' | 300 parent_id = task_pack.pack_request_key(parent.key) + '1' |
| 291 child = task_request.make_request( | 301 child = mkreq(_gen_request(parent_task_id=parent_id)) |
| 292 _gen_request(parent_task_id=parent_id), True) | |
| 293 self.assertEqual(parent_id, child.parent_task_id) | 302 self.assertEqual(parent_id, child.parent_task_id) |
| 294 | 303 |
| 295 def test_make_request_invalid_parent_id(self): | 304 def test_make_request_invalid_parent_id(self): |
| 296 # Must ends with '1' or '2', not '0' | 305 # Must ends with '1' or '2', not '0' |
| 297 with self.assertRaises(ValueError): | 306 with self.assertRaises(ValueError): |
| 298 _gen_request(parent_task_id='1d69b9f088008810') | 307 _gen_request(parent_task_id='1d69b9f088008810') |
| 299 | 308 |
| 300 def test_make_request_idempotent(self): | 309 def test_make_request_idempotent(self): |
| 301 request = task_request.make_request( | 310 request = mkreq(_gen_request(properties=dict(idempotent=True))) |
| 302 _gen_request(properties=dict(idempotent=True)), True) | |
| 303 as_dict = request.to_dict() | 311 as_dict = request.to_dict() |
| 304 self.assertEqual(True, as_dict['properties']['idempotent']) | 312 self.assertEqual(True, as_dict['properties']['idempotent']) |
| 305 # Intentionally hard code the hash value since it has to be deterministic. | 313 # Intentionally hard code the hash value since it has to be deterministic. |
| 306 # Other unit tests should use the calculated value. | 314 # Other unit tests should use the calculated value. |
| 307 # Ensure the algorithm is deterministic. | 315 # Ensure the algorithm is deterministic. |
| 308 self.assertEqual( | 316 self.assertEqual( |
| 309 'a406d174c469cb2ef6f56a49c3df0de0ae3db369', as_dict['properties_hash']) | 317 '83b350298f05eff6072d54d2c6f031d06cc30449', as_dict['properties_hash']) |
| 310 | 318 |
| 311 def test_duped(self): | 319 def test_duped(self): |
| 312 # Two TestRequest with the same properties. | 320 # Two TestRequest with the same properties. |
| 313 request_1 = task_request.make_request( | 321 request_1 = mkreq(_gen_request(properties=dict(idempotent=True))) |
| 314 _gen_request(properties=dict(idempotent=True)), True) | |
| 315 now = utils.utcnow() | 322 now = utils.utcnow() |
| 316 request_2 = task_request.make_request( | 323 request_2 = mkreq(_gen_request( |
| 317 _gen_request( | 324 name='Other', |
| 318 name='Other', | 325 user='Other', |
| 319 user='Other', | 326 priority=201, |
| 320 priority=201, | 327 created_ts=now, |
| 321 created_ts=now, | 328 expiration_ts=now + datetime.timedelta(seconds=129), |
| 322 expiration_ts=now + datetime.timedelta(seconds=129), | 329 tags=['tag:2'], |
| 323 tags=['tag:2'], | 330 properties=dict(idempotent=True))) |
| 324 properties=dict(idempotent=True)), | |
| 325 True) | |
| 326 self.assertEqual( | 331 self.assertEqual( |
| 327 request_1.properties.properties_hash, | 332 request_1.properties.properties_hash, |
| 328 request_2.properties.properties_hash) | 333 request_2.properties.properties_hash) |
| 329 self.assertTrue(request_1.properties.properties_hash) | 334 self.assertTrue(request_1.properties.properties_hash) |
| 330 | 335 |
| 331 def test_different(self): | 336 def test_different(self): |
| 332 # Two TestRequest with different properties. | 337 # Two TestRequest with different properties. |
| 333 request_1 = task_request.make_request( | 338 request_1 = mkreq(_gen_request( |
| 334 _gen_request( | 339 properties=dict(execution_timeout_secs=30, idempotent=True))) |
| 335 properties=dict(execution_timeout_secs=30, idempotent=True)), True) | 340 request_2 = mkreq(_gen_request( |
| 336 request_2 = task_request.make_request( | 341 properties=dict(execution_timeout_secs=129, idempotent=True))) |
| 337 _gen_request( | |
| 338 properties=dict(execution_timeout_secs=129, idempotent=True)), True) | |
| 339 self.assertNotEqual( | 342 self.assertNotEqual( |
| 340 request_1.properties.properties_hash, | 343 request_1.properties.properties_hash, |
| 341 request_2.properties.properties_hash) | 344 request_2.properties.properties_hash) |
| 342 | 345 |
| 343 def test_bad_values(self): | 346 def test_bad_values(self): |
| 344 with self.assertRaises(AssertionError): | 347 with self.assertRaises(AssertionError): |
| 345 task_request.make_request(None, True) | 348 mkreq(None) |
| 346 with self.assertRaises(AssertionError): | 349 with self.assertRaises(AssertionError): |
| 347 task_request.make_request({}, True) | 350 mkreq({}) |
| 348 with self.assertRaises(AttributeError): | 351 with self.assertRaises(AttributeError): |
| 349 task_request.make_request(_gen_request(properties={'foo': 'bar'}), True) | 352 mkreq(_gen_request(properties={'foo': 'bar'})) |
| 350 task_request.make_request(_gen_request(), True) | 353 mkreq(_gen_request()) |
| 351 | 354 |
| 352 with self.assertRaises(datastore_errors.BadValueError): | 355 with self.assertRaises(datastore_errors.BadValueError): |
| 353 task_request.make_request( | 356 mkreq(_gen_request(properties=dict(command=[]))) |
| 354 _gen_request(properties=dict(command=[])), True) | |
| 355 with self.assertRaises(datastore_errors.BadValueError): | 357 with self.assertRaises(datastore_errors.BadValueError): |
| 356 task_request.make_request( | 358 mkreq(_gen_request(properties=dict(command={'a': 'b'}))) |
| 357 _gen_request(properties=dict(command={'a': 'b'})), True) | |
| 358 with self.assertRaises(datastore_errors.BadValueError): | 359 with self.assertRaises(datastore_errors.BadValueError): |
| 359 task_request.make_request( | 360 mkreq(_gen_request(properties=dict(command='python'))) |
| 360 _gen_request(properties=dict(command='python')), True) | 361 mkreq(_gen_request(properties=dict(command=['python']))) |
| 361 task_request.make_request( | 362 mkreq(_gen_request(properties=dict(command=[u'python']))) |
| 362 _gen_request(properties=dict(command=['python'])), True) | 363 |
| 363 task_request.make_request( | 364 with self.assertRaises(datastore_errors.BadValueError): |
| 364 _gen_request(properties=dict(command=[u'python'])), True) | 365 mkreq(_gen_request(properties=dict(packages=[{}]))) |
| 366 with self.assertRaises(datastore_errors.BadValueError): |
| 367 mkreq(_gen_request(properties=dict(packages=[dict(package_name='rm')]))) |
| 368 with self.assertRaises(datastore_errors.BadValueError): |
| 369 mkreq(_gen_request(properties=dict( |
| 370 packages=[{'package_name': 'infra|rm', 'version': 'latest'}]))) |
| 371 with self.assertRaises(datastore_errors.BadValueError): |
| 372 mkreq(_gen_request(properties=dict( |
| 373 packages=[ |
| 374 {'package_name': 'rm', 'version': 'latest'}, |
| 375 {'package_name': 'rm', 'version': 'canary'}, |
| 376 ]))) |
| 377 with self.assertRaises(datastore_errors.BadValueError): |
| 378 mkreq(_gen_request(properties=dict( |
| 379 idempotent=True, |
| 380 packages=[{'package_name': 'rm', 'version': 'latest'}]))) |
| 381 mkreq(_gen_request(properties=dict( |
| 382 packages=[{'package_name': 'rm', 'version': 'latest'}]))) |
| 365 | 383 |
| 366 with self.assertRaises(TypeError): | 384 with self.assertRaises(TypeError): |
| 367 task_request.make_request( | 385 mkreq(_gen_request(properties=dict(dimensions=[]))) |
| 368 _gen_request(properties=dict(dimensions=[])), True) | |
| 369 with self.assertRaises(datastore_errors.BadValueError): | 386 with self.assertRaises(datastore_errors.BadValueError): |
| 370 task_request.make_request( | 387 mkreq(_gen_request(properties=dict(dimensions={}))) |
| 371 _gen_request(properties=dict(dimensions={})), True) | |
| 372 with self.assertRaises(datastore_errors.BadValueError): | 388 with self.assertRaises(datastore_errors.BadValueError): |
| 373 task_request.make_request( | 389 mkreq(_gen_request( |
| 374 _gen_request( | 390 properties=dict(dimensions={u'id': u'b', u'a:': u'b'}))) |
| 375 properties=dict(dimensions={u'id': u'b', u'a:': u'b'})), True) | 391 mkreq(_gen_request( |
| 376 task_request.make_request( | 392 properties=dict(dimensions={u'id': u'b', u'a.': u'b'}))) |
| 377 _gen_request( | |
| 378 properties=dict(dimensions={u'id': u'b', u'a.': u'b'})), True) | |
| 379 | 393 |
| 380 with self.assertRaises(TypeError): | 394 with self.assertRaises(TypeError): |
| 381 task_request.make_request( | 395 mkreq(_gen_request(properties=dict(env=[]))) |
| 382 _gen_request(properties=dict(env=[])), True) | |
| 383 with self.assertRaises(TypeError): | 396 with self.assertRaises(TypeError): |
| 384 task_request.make_request( | 397 mkreq(_gen_request(properties=dict(env={u'a': 1}))) |
| 385 _gen_request(properties=dict(env={u'a': 1})), True) | 398 mkreq(_gen_request(properties=dict(env={}))) |
| 386 task_request.make_request(_gen_request(properties=dict(env={})), True) | |
| 387 | 399 |
| 388 with self.assertRaises(datastore_errors.BadValueError): | 400 with self.assertRaises(datastore_errors.BadValueError): |
| 389 task_request.make_request( | 401 mkreq(_gen_request(priority=task_request.MAXIMUM_PRIORITY+1)) |
| 390 _gen_request(priority=task_request.MAXIMUM_PRIORITY+1), True) | 402 mkreq(_gen_request(priority=task_request.MAXIMUM_PRIORITY)) |
| 391 task_request.make_request( | |
| 392 _gen_request(priority=task_request.MAXIMUM_PRIORITY), True) | |
| 393 | 403 |
| 394 with self.assertRaises(datastore_errors.BadValueError): | 404 with self.assertRaises(datastore_errors.BadValueError): |
| 395 task_request.make_request( | 405 mkreq(_gen_request( |
| 396 _gen_request( | 406 properties=dict(execution_timeout_secs=task_request._ONE_DAY_SECS+1))) |
| 397 properties=dict( | 407 mkreq(_gen_request( |
| 398 execution_timeout_secs=task_request._ONE_DAY_SECS+1)), | 408 properties=dict(execution_timeout_secs=task_request._ONE_DAY_SECS))) |
| 399 True) | |
| 400 task_request.make_request( | |
| 401 _gen_request( | |
| 402 properties=dict(execution_timeout_secs=task_request._ONE_DAY_SECS)), | |
| 403 True) | |
| 404 | 409 |
| 405 now = utils.utcnow() | 410 now = utils.utcnow() |
| 406 with self.assertRaises(datastore_errors.BadValueError): | 411 with self.assertRaises(datastore_errors.BadValueError): |
| 407 task_request.make_request( | 412 mkreq(_gen_request( |
| 408 _gen_request( | 413 created_ts=now, |
| 409 created_ts=now, | 414 expiration_ts=now + datetime.timedelta( |
| 410 expiration_ts= | 415 seconds=task_request._MIN_TIMEOUT_SECS-1))) |
| 411 now+datetime.timedelta( | |
| 412 seconds=task_request._MIN_TIMEOUT_SECS-1)), | |
| 413 True) | |
| 414 with self.assertRaises(datastore_errors.BadValueError): | 416 with self.assertRaises(datastore_errors.BadValueError): |
| 415 task_request.make_request( | 417 mkreq(_gen_request( |
| 416 _gen_request( | 418 created_ts=now, |
| 417 created_ts=now, | 419 expiration_ts= |
| 418 expiration_ts= | 420 now+datetime.timedelta(seconds=task_request._SEVEN_DAYS_SECS+1))) |
| 419 now+datetime.timedelta( | 421 mkreq(_gen_request( |
| 420 seconds=task_request._SEVEN_DAYS_SECS+1)), | 422 created_ts=now, |
| 421 True) | 423 expiration_ts= |
| 422 task_request.make_request( | 424 now+datetime.timedelta(seconds=task_request._MIN_TIMEOUT_SECS))) |
| 423 _gen_request( | 425 mkreq(_gen_request( |
| 424 created_ts=now, | 426 created_ts=now, |
| 425 expiration_ts= | 427 expiration_ts= |
| 426 now+datetime.timedelta( | 428 now + datetime.timedelta(seconds=task_request._SEVEN_DAYS_SECS))) |
| 427 seconds=task_request._MIN_TIMEOUT_SECS)), | |
| 428 True) | |
| 429 task_request.make_request( | |
| 430 _gen_request( | |
| 431 created_ts=now, | |
| 432 expiration_ts= | |
| 433 now+datetime.timedelta( | |
| 434 seconds=task_request._SEVEN_DAYS_SECS)), | |
| 435 True) | |
| 436 | 429 |
| 437 # Try with isolated/isolatedserver/namespace. | 430 # Try with isolated/isolatedserver/namespace. |
| 438 with self.assertRaises(datastore_errors.BadValueError): | 431 with self.assertRaises(datastore_errors.BadValueError): |
| 439 task_request.make_request( | 432 mkreq(_gen_request(properties=dict( |
| 440 _gen_request(properties=dict( | 433 command=['see', 'spot', 'run'], |
| 441 command=['see', 'spot', 'run'], | 434 inputs_ref=task_request.FilesRef()))) |
| 442 inputs_ref=task_request.FilesRef())), | |
| 443 True) | |
| 444 | 435 |
| 445 def test_make_request_clone(self): | 436 def test_make_request_clone(self): |
| 446 # Compare with test_make_request(). | 437 # Compare with test_make_request(). |
| 447 parent = task_request.make_request(_gen_request(), True) | 438 parent = mkreq(_gen_request()) |
| 448 # Hack: Would need to know about TaskResultSummary. | 439 # Hack: Would need to know about TaskResultSummary. |
| 449 parent_id = task_pack.pack_request_key(parent.key) + '1' | 440 parent_id = task_pack.pack_request_key(parent.key) + '1' |
| 450 data = _gen_request( | 441 data = _gen_request( |
| 451 properties=dict(idempotent=True), parent_task_id=parent_id) | 442 properties=dict(idempotent=True), parent_task_id=parent_id) |
| 452 request = task_request.make_request_clone( | 443 request = task_request.make_request_clone(mkreq(data)) |
| 453 task_request.make_request(data, True)) | |
| 454 # Differences from make_request() are: | 444 # Differences from make_request() are: |
| 455 # - idempotent was reset to False. | 445 # - idempotent was reset to False. |
| 456 # - parent_task_id was reset to None. | 446 # - parent_task_id was reset to None. |
| 457 expected_properties = { | 447 expected_properties = { |
| 458 'command': [u'command1', u'arg1'], | 448 'command': [u'command1', u'arg1'], |
| 459 'dimensions': { | 449 'dimensions': { |
| 460 u'OS': u'Windows-3.1.1', | 450 u'OS': u'Windows-3.1.1', |
| 461 u'hostname': u'localhost', | 451 u'hostname': u'localhost', |
| 462 u'pool': u'default', | 452 u'pool': u'default', |
| 463 }, | 453 }, |
| 464 'env': {u'foo': u'bar', u'joe': u'2'}, | 454 'env': {u'foo': u'bar', u'joe': u'2'}, |
| 465 'execution_timeout_secs': 30, | 455 'execution_timeout_secs': 30, |
| 466 'extra_args': [], | 456 'extra_args': [], |
| 467 'grace_period_secs': 30, | 457 'grace_period_secs': 30, |
| 468 'idempotent': False, | 458 'idempotent': False, |
| 469 'inputs_ref': None, | 459 'inputs_ref': None, |
| 470 'io_timeout_secs': None, | 460 'io_timeout_secs': None, |
| 461 'packages': [{'package_name': 'rm', 'version': PINNED_PACKAGE_VERSION}], |
| 471 } | 462 } |
| 472 # Differences from make_request() are: | 463 # Differences from make_request() are: |
| 473 # - parent_task_id was reset to None. | 464 # - parent_task_id was reset to None. |
| 474 # - tag 'user:' was replaced | 465 # - tag 'user:' was replaced |
| 475 # - user was replaced. | 466 # - user was replaced. |
| 476 expected_request = { | 467 expected_request = { |
| 477 'authenticated': auth_testing.DEFAULT_MOCKED_IDENTITY, | 468 'authenticated': auth_testing.DEFAULT_MOCKED_IDENTITY, |
| 478 'name': u'Request name (Retry #1)', | 469 'name': u'Request name (Retry #1)', |
| 479 'parent_task_id': None, | 470 'parent_task_id': None, |
| 480 'priority': 49, | 471 'priority': 49, |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 535 ndb.Key(task_request.TaskRequest, 0x7f14acec2fcfffff), | 526 ndb.Key(task_request.TaskRequest, 0x7f14acec2fcfffff), |
| 536 task_request.request_id_to_key(0xeb5313d0300000)) | 527 task_request.request_id_to_key(0xeb5313d0300000)) |
| 537 | 528 |
| 538 | 529 |
| 539 if __name__ == '__main__': | 530 if __name__ == '__main__': |
| 540 if '-v' in sys.argv: | 531 if '-v' in sys.argv: |
| 541 unittest.TestCase.maxDiff = None | 532 unittest.TestCase.maxDiff = None |
| 542 logging.basicConfig( | 533 logging.basicConfig( |
| 543 level=logging.DEBUG if '-v' in sys.argv else logging.ERROR) | 534 level=logging.DEBUG if '-v' in sys.argv else logging.ERROR) |
| 544 unittest.main() | 535 unittest.main() |
| OLD | NEW |