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

Side by Side Diff: appengine/swarming/server/task_request_test.py

Issue 2069903003: swarming: custom cipd package paths (Closed) Base URL: https://chromium.googlesource.com/external/github.com/luci/luci-py@cipd-win
Patch Set: fix _validate_cipd_path Created 4 years, 6 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 #!/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 under the Apache License, Version 2.0 3 # Use of this source code is governed under the Apache License, Version 2.0
4 # that can be found in the LICENSE file. 4 # that can be found in the LICENSE file.
5 5
6 import datetime 6 import datetime
7 import logging 7 import logging
8 import random 8 import random
9 import sys 9 import sys
10 import unittest 10 import unittest
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 return result 42 return result
43 43
44 cipd_input = properties.pop('cipd_input', {}) 44 cipd_input = properties.pop('cipd_input', {})
45 cipd_input = merge(cipd_input, { 45 cipd_input = merge(cipd_input, {
46 'client_package': merge(cipd_input.pop('client_package', {}), { 46 'client_package': merge(cipd_input.pop('client_package', {}), {
47 'package_name': 'infra/tools/cipd/${platform}', 47 'package_name': 'infra/tools/cipd/${platform}',
48 'version': 'git_revision:deadbeef', 48 'version': 'git_revision:deadbeef',
49 }), 49 }),
50 'packages': [{ 50 'packages': [{
51 'package_name': 'rm', 51 'package_name': 'rm',
52 'path': 'bin',
52 'version': 'git_revision:deadbeef', 53 'version': 'git_revision:deadbeef',
53 }], 54 }],
54 'server': 'https://chrome-infra-packages.appspot.com' 55 'server': 'https://chrome-infra-packages.appspot.com'
55 }) 56 })
56 57
57 inputs_ref = properties.pop('inputs_ref', { 58 inputs_ref = properties.pop('inputs_ref', {
58 'isolatedserver': 'https://isolateserver.appspot.com', 59 'isolatedserver': 'https://isolateserver.appspot.com',
59 'namespace': 'default-gzip', 60 'namespace': 'default-gzip',
60 }) 61 })
61 62
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 # Compare with test_make_request_clone(). 211 # Compare with test_make_request_clone().
211 parent = mkreq(_gen_request()) 212 parent = mkreq(_gen_request())
212 # Hack: Would need to know about TaskResultSummary. 213 # Hack: Would need to know about TaskResultSummary.
213 parent_id = task_pack.pack_request_key(parent.key) + '1' 214 parent_id = task_pack.pack_request_key(parent.key) + '1'
214 r = _gen_request(properties=dict(idempotent=True), parent_task_id=parent_id) 215 r = _gen_request(properties=dict(idempotent=True), parent_task_id=parent_id)
215 request = mkreq(r) 216 request = mkreq(r)
216 expected_properties = { 217 expected_properties = {
217 'cipd_input': { 218 'cipd_input': {
218 'client_package': { 219 'client_package': {
219 'package_name': 'infra/tools/cipd/${platform}', 220 'package_name': 'infra/tools/cipd/${platform}',
221 'path': None,
220 'version': 'git_revision:deadbeef', 222 'version': 'git_revision:deadbeef',
221 }, 223 },
222 'packages': [{ 224 'packages': [{
223 'package_name': 'rm', 225 'package_name': 'rm',
226 'path': 'bin',
224 'version': 'git_revision:deadbeef', 227 'version': 'git_revision:deadbeef',
225 }], 228 }],
226 'server': 'https://chrome-infra-packages.appspot.com' 229 'server': 'https://chrome-infra-packages.appspot.com'
227 }, 230 },
228 'command': [u'command1', u'arg1'], 231 'command': [u'command1', u'arg1'],
229 'dimensions': { 232 'dimensions': {
230 u'OS': u'Windows-3.1.1', 233 u'OS': u'Windows-3.1.1',
231 u'hostname': u'localhost', 234 u'hostname': u'localhost',
232 u'pool': u'default', 235 u'pool': u'default',
233 }, 236 },
(...skipping 10 matching lines...) Expand all
244 'io_timeout_secs': None, 247 'io_timeout_secs': None,
245 } 248 }
246 expected_request = { 249 expected_request = {
247 'authenticated': auth_testing.DEFAULT_MOCKED_IDENTITY, 250 'authenticated': auth_testing.DEFAULT_MOCKED_IDENTITY,
248 'name': u'Request name', 251 'name': u'Request name',
249 'parent_task_id': unicode(parent_id), 252 'parent_task_id': unicode(parent_id),
250 'priority': 49, 253 'priority': 49,
251 'properties': expected_properties, 254 'properties': expected_properties,
252 # Intentionally hard code the hash value since it has to be deterministic. 255 # Intentionally hard code the hash value since it has to be deterministic.
253 # Other unit tests should use the calculated value. 256 # Other unit tests should use the calculated value.
254 'properties_hash': 'c07adb3b577d51169036f29e44764a5ddf132228', 257 'properties_hash': '411f20b8cda819b5fe47bcf26f5566c37afce0ed',
255 'pubsub_topic': None, 258 'pubsub_topic': None,
256 'pubsub_userdata': None, 259 'pubsub_userdata': None,
257 'tags': [ 260 'tags': [
258 u'OS:Windows-3.1.1', 261 u'OS:Windows-3.1.1',
259 u'hostname:localhost', 262 u'hostname:localhost',
260 u'pool:default', 263 u'pool:default',
261 u'priority:49', 264 u'priority:49',
262 u'tag:1', 265 u'tag:1',
263 u'user:Jesus', 266 u'user:Jesus',
264 ], 267 ],
(...skipping 15 matching lines...) Expand all
280 }, 283 },
281 })) 284 }))
282 # Hack: Would need to know about TaskResultSummary. 285 # Hack: Would need to know about TaskResultSummary.
283 parent_id = task_pack.pack_request_key(parent.key) + '1' 286 parent_id = task_pack.pack_request_key(parent.key) + '1'
284 request = mkreq(_gen_request( 287 request = mkreq(_gen_request(
285 properties={'idempotent':True}, parent_task_id=parent_id)) 288 properties={'idempotent':True}, parent_task_id=parent_id))
286 expected_properties = { 289 expected_properties = {
287 'cipd_input': { 290 'cipd_input': {
288 'client_package': { 291 'client_package': {
289 'package_name': 'infra/tools/cipd/${platform}', 292 'package_name': 'infra/tools/cipd/${platform}',
293 'path': None,
290 'version': 'git_revision:deadbeef', 294 'version': 'git_revision:deadbeef',
291 }, 295 },
292 'packages': [{ 296 'packages': [{
293 'package_name': 'rm', 297 'package_name': 'rm',
298 'path': 'bin',
294 'version': 'git_revision:deadbeef', 299 'version': 'git_revision:deadbeef',
295 }], 300 }],
296 'server': 'https://chrome-infra-packages.appspot.com' 301 'server': 'https://chrome-infra-packages.appspot.com'
297 }, 302 },
298 'command': [u'command1', u'arg1'], 303 'command': [u'command1', u'arg1'],
299 'dimensions': { 304 'dimensions': {
300 u'OS': u'Windows-3.1.1', 305 u'OS': u'Windows-3.1.1',
301 u'hostname': u'localhost', 306 u'hostname': u'localhost',
302 u'pool': u'default', 307 u'pool': u'default',
303 }, 308 },
(...skipping 10 matching lines...) Expand all
314 'io_timeout_secs': None, 319 'io_timeout_secs': None,
315 } 320 }
316 expected_request = { 321 expected_request = {
317 'authenticated': auth_testing.DEFAULT_MOCKED_IDENTITY, 322 'authenticated': auth_testing.DEFAULT_MOCKED_IDENTITY,
318 'name': u'Request name', 323 'name': u'Request name',
319 'parent_task_id': unicode(parent_id), 324 'parent_task_id': unicode(parent_id),
320 'priority': 49, 325 'priority': 49,
321 'properties': expected_properties, 326 'properties': expected_properties,
322 # Intentionally hard code the hash value since it has to be deterministic. 327 # Intentionally hard code the hash value since it has to be deterministic.
323 # Other unit tests should use the calculated value. 328 # Other unit tests should use the calculated value.
324 'properties_hash': 'c07adb3b577d51169036f29e44764a5ddf132228', 329 'properties_hash': '411f20b8cda819b5fe47bcf26f5566c37afce0ed',
325 'pubsub_topic': None, 330 'pubsub_topic': None,
326 'pubsub_userdata': None, 331 'pubsub_userdata': None,
327 'tags': [ 332 'tags': [
328 u'OS:Windows-3.1.1', 333 u'OS:Windows-3.1.1',
329 u'hostname:localhost', 334 u'hostname:localhost',
330 u'pool:default', 335 u'pool:default',
331 u'priority:49', 336 u'priority:49',
332 u'tag:1', 337 u'tag:1',
333 u'user:Jesus', 338 u'user:Jesus',
334 ], 339 ],
(...skipping 19 matching lines...) Expand all
354 _gen_request(parent_task_id='1d69b9f088008810') 359 _gen_request(parent_task_id='1d69b9f088008810')
355 360
356 def test_make_request_idempotent(self): 361 def test_make_request_idempotent(self):
357 request = mkreq(_gen_request(properties=dict(idempotent=True))) 362 request = mkreq(_gen_request(properties=dict(idempotent=True)))
358 as_dict = request.to_dict() 363 as_dict = request.to_dict()
359 self.assertEqual(True, as_dict['properties']['idempotent']) 364 self.assertEqual(True, as_dict['properties']['idempotent'])
360 # Intentionally hard code the hash value since it has to be deterministic. 365 # Intentionally hard code the hash value since it has to be deterministic.
361 # Other unit tests should use the calculated value. 366 # Other unit tests should use the calculated value.
362 # Ensure the algorithm is deterministic. 367 # Ensure the algorithm is deterministic.
363 self.assertEqual( 368 self.assertEqual(
364 'c07adb3b577d51169036f29e44764a5ddf132228', as_dict['properties_hash']) 369 '411f20b8cda819b5fe47bcf26f5566c37afce0ed', as_dict['properties_hash'])
365 370
366 def test_duped(self): 371 def test_duped(self):
367 # Two TestRequest with the same properties. 372 # Two TestRequest with the same properties.
368 request_1 = mkreq(_gen_request(properties=dict(idempotent=True))) 373 request_1 = mkreq(_gen_request(properties=dict(idempotent=True)))
369 now = utils.utcnow() 374 now = utils.utcnow()
370 request_2 = mkreq(_gen_request( 375 request_2 = mkreq(_gen_request(
371 name='Other', 376 name='Other',
372 user='Other', 377 user='Other',
373 priority=201, 378 priority=201,
374 created_ts=now, 379 created_ts=now,
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
522 data = _gen_request( 527 data = _gen_request(
523 properties=dict(idempotent=True), parent_task_id=parent_id) 528 properties=dict(idempotent=True), parent_task_id=parent_id)
524 request = task_request.make_request_clone(mkreq(data)) 529 request = task_request.make_request_clone(mkreq(data))
525 # Differences from make_request() are: 530 # Differences from make_request() are:
526 # - idempotent was reset to False. 531 # - idempotent was reset to False.
527 # - parent_task_id was reset to None. 532 # - parent_task_id was reset to None.
528 expected_properties = { 533 expected_properties = {
529 'cipd_input': { 534 'cipd_input': {
530 'client_package': { 535 'client_package': {
531 'package_name': 'infra/tools/cipd/${platform}', 536 'package_name': 'infra/tools/cipd/${platform}',
537 'path': None,
532 'version': 'git_revision:deadbeef', 538 'version': 'git_revision:deadbeef',
533 }, 539 },
534 'packages': [{ 540 'packages': [{
535 'package_name': 'rm', 541 'package_name': 'rm',
542 'path': 'bin',
536 'version': 'git_revision:deadbeef', 543 'version': 'git_revision:deadbeef',
537 }], 544 }],
538 'server': 'https://chrome-infra-packages.appspot.com' 545 'server': 'https://chrome-infra-packages.appspot.com'
539 }, 546 },
540 'command': [u'command1', u'arg1'], 547 'command': [u'command1', u'arg1'],
541 'dimensions': { 548 'dimensions': {
542 u'OS': u'Windows-3.1.1', 549 u'OS': u'Windows-3.1.1',
543 u'hostname': u'localhost', 550 u'hostname': u'localhost',
544 u'pool': u'default', 551 u'pool': u'default',
545 }, 552 },
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
621 ndb.Key(task_request.TaskRequest, 0x7f14acec2fcfffff), 628 ndb.Key(task_request.TaskRequest, 0x7f14acec2fcfffff),
622 task_request.request_id_to_key(0xeb5313d0300000)) 629 task_request.request_id_to_key(0xeb5313d0300000))
623 630
624 631
625 if __name__ == '__main__': 632 if __name__ == '__main__':
626 if '-v' in sys.argv: 633 if '-v' in sys.argv:
627 unittest.TestCase.maxDiff = None 634 unittest.TestCase.maxDiff = None
628 logging.basicConfig( 635 logging.basicConfig(
629 level=logging.DEBUG if '-v' in sys.argv else logging.ERROR) 636 level=logging.DEBUG if '-v' in sys.argv else logging.ERROR)
630 unittest.main() 637 unittest.main()
OLDNEW
« no previous file with comments | « appengine/swarming/server/task_request.py ('k') | appengine/swarming/swarming_bot/bot_code/task_runner.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698