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

Side by Side Diff: appengine/swarming/handlers_endpoints_test.py

Issue 1946253003: swarming: refactor cipd input (Closed) Base URL: https://chromium.googlesource.com/external/github.com/luci/luci-py@default-isolate-server
Patch Set: rebased Created 4 years, 7 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
« no previous file with comments | « appengine/swarming/handlers_endpoints.py ('k') | appengine/swarming/message_conversion.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # coding=utf-8 2 # coding=utf-8
3 # Copyright 2015 The LUCI Authors. All rights reserved. 3 # Copyright 2015 The LUCI Authors. All rights reserved.
4 # Use of this source code is governed by the Apache v2.0 license that can be 4 # Use of this source code is governed by the Apache v2.0 license that can be
5 # found in the LICENSE file. 5 # found in the LICENSE file.
6 6
7 import base64 7 import base64
8 import datetime 8 import datetime
9 import json 9 import json
10 import logging 10 import logging
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 """Asserts that new generates appropriate metadata.""" 144 """Asserts that new generates appropriate metadata."""
145 self.mock(random, 'getrandbits', lambda _: 0x88) 145 self.mock(random, 'getrandbits', lambda _: 0x88)
146 now = datetime.datetime(2010, 1, 2, 3, 4, 5) 146 now = datetime.datetime(2010, 1, 2, 3, 4, 5)
147 self.mock_now(now) 147 self.mock_now(now)
148 str_now = unicode(now.strftime(self.DATETIME_NO_MICRO)) 148 str_now = unicode(now.strftime(self.DATETIME_NO_MICRO))
149 request = swarming_rpcs.NewTaskRequest( 149 request = swarming_rpcs.NewTaskRequest(
150 expiration_secs=30, 150 expiration_secs=30,
151 name='job1', 151 name='job1',
152 priority=200, 152 priority=200,
153 properties=swarming_rpcs.TaskProperties( 153 properties=swarming_rpcs.TaskProperties(
154 cipd_input=swarming_rpcs.CipdInput(
155 client_package=swarming_rpcs.CipdPackage(
156 package_name='infra/tools/cipd/${platform}',
157 version='git_revision:deadbeef',
158 ),
159 packages=[
160 swarming_rpcs.CipdPackage(
161 package_name='rm', version='latest'),
162 ],
163 server='https://chrome-infra-packages.appspot.com',
164 ),
154 command=['rm', '-rf', '/'], 165 command=['rm', '-rf', '/'],
155 packages=[
156 swarming_rpcs.CipdPackage(package_name='rm', version='latest'),
157 ],
158 dimensions=[ 166 dimensions=[
159 swarming_rpcs.StringPair(key='pool', value='default'), 167 swarming_rpcs.StringPair(key='pool', value='default'),
160 ], 168 ],
161 env=[ 169 env=[
162 swarming_rpcs.StringPair(key='PATH', value='/'), 170 swarming_rpcs.StringPair(key='PATH', value='/'),
163 ], 171 ],
164 execution_timeout_secs=30, 172 execution_timeout_secs=30,
165 io_timeout_secs=30), 173 io_timeout_secs=30),
166 tags=['foo:bar'], 174 tags=['foo:bar'],
167 user='joe@localhost', 175 user='joe@localhost',
168 pubsub_topic='projects/abc/topics/def', 176 pubsub_topic='projects/abc/topics/def',
169 pubsub_auth_token='secret that must not be shown', 177 pubsub_auth_token='secret that must not be shown',
170 pubsub_userdata='userdata') 178 pubsub_userdata='userdata')
171 expected = { 179 expected = {
172 u'request': { 180 u'request': {
173 u'authenticated': u'user:user@example.com', 181 u'authenticated': u'user:user@example.com',
174 u'created_ts': str_now, 182 u'created_ts': str_now,
175 u'expiration_secs': u'30', 183 u'expiration_secs': u'30',
176 u'name': u'job1', 184 u'name': u'job1',
177 u'priority': u'200', 185 u'priority': u'200',
178 u'properties': { 186 u'properties': {
187 u'cipd_input': {
188 u'client_package': {
189 u'package_name': u'infra/tools/cipd/${platform}',
190 u'version': u'git_revision:deadbeef',
191 },
192 u'packages': [{
193 u'package_name': u'rm',
194 u'version': u'latest',
195 }],
196 u'server': u'https://chrome-infra-packages.appspot.com',
197 },
179 u'command': [u'rm', u'-rf', u'/'], 198 u'command': [u'rm', u'-rf', u'/'],
180 u'packages': [{
181 u'package_name': u'rm',
182 u'version': u'latest',
183 }],
184 u'dimensions': [ 199 u'dimensions': [
185 {u'key': u'pool', u'value': u'default'}, 200 {u'key': u'pool', u'value': u'default'},
186 ], 201 ],
187 u'env': [ 202 u'env': [
188 {u'key': u'PATH', u'value': u'/'}, 203 {u'key': u'PATH', u'value': u'/'},
189 ], 204 ],
190 u'execution_timeout_secs': u'30', 205 u'execution_timeout_secs': u'30',
191 u'grace_period_secs': u'30', 206 u'grace_period_secs': u'30',
192 u'idempotent': False, 207 u'idempotent': False,
193 u'io_timeout_secs': u'30', 208 u'io_timeout_secs': u'30',
(...skipping 29 matching lines...) Expand all
223 now_30 = self.mock_now(now, 30) 238 now_30 = self.mock_now(now, 30)
224 str_now_30 = unicode(now_30.strftime(self.DATETIME_NO_MICRO)) 239 str_now_30 = unicode(now_30.strftime(self.DATETIME_NO_MICRO))
225 self.set_as_user() 240 self.set_as_user()
226 241
227 request = swarming_rpcs.NewTaskRequest( 242 request = swarming_rpcs.NewTaskRequest(
228 expiration_secs=30, 243 expiration_secs=30,
229 name='job1', 244 name='job1',
230 priority=200, 245 priority=200,
231 properties=swarming_rpcs.TaskProperties( 246 properties=swarming_rpcs.TaskProperties(
232 command=['python', 'run_test.py'], 247 command=['python', 'run_test.py'],
248 cipd_input=swarming_rpcs.CipdInput(
249 client_package=swarming_rpcs.CipdPackage(
250 package_name='infra/tools/cipd/${platform}',
251 version='git_revision:deadbeef',
252 ),
253 packages=[
254 swarming_rpcs.CipdPackage(
255 package_name='rm',
256 version='git_revision:deadbeef'),
257 ],
258 server='https://chrome-infra-packages.appspot.com',
259 ),
233 dimensions=[ 260 dimensions=[
234 swarming_rpcs.StringPair(key='os', value='Amiga'), 261 swarming_rpcs.StringPair(key='os', value='Amiga'),
235 swarming_rpcs.StringPair(key='pool', value='default'), 262 swarming_rpcs.StringPair(key='pool', value='default'),
236 ], 263 ],
237 execution_timeout_secs=3600, 264 execution_timeout_secs=3600,
238 idempotent=True, 265 idempotent=True,
239 io_timeout_secs=1200, 266 io_timeout_secs=1200),
240 packages=[
241 swarming_rpcs.CipdPackage(
242 package_name='rm',
243 version=test_env_handlers.PINNED_PACKAGE_VERSION),
244 ]),
245 tags=['foo:bar'], 267 tags=['foo:bar'],
246 user='joe@localhost') 268 user='joe@localhost')
247 expected = { 269 expected = {
248 u'request': { 270 u'request': {
249 u'authenticated': u'user:user@example.com', 271 u'authenticated': u'user:user@example.com',
250 u'created_ts': str_now_30, 272 u'created_ts': str_now_30,
251 u'expiration_secs': u'30', 273 u'expiration_secs': u'30',
252 u'name': u'job1', 274 u'name': u'job1',
253 u'priority': u'200', 275 u'priority': u'200',
254 u'properties': { 276 u'properties': {
277 u'cipd_input': {
278 u'client_package': {
279 u'package_name': u'infra/tools/cipd/${platform}',
280 u'version': u'git_revision:deadbeef',
281 },
282 u'packages': [{
283 u'package_name': u'rm',
284 u'version': 'git_revision:deadbeef',
285 }],
286 u'server': u'https://chrome-infra-packages.appspot.com',
287 },
255 u'command': [u'python', u'run_test.py'], 288 u'command': [u'python', u'run_test.py'],
256 u'dimensions': [ 289 u'dimensions': [
257 {u'key': u'os', u'value': u'Amiga'}, 290 {u'key': u'os', u'value': u'Amiga'},
258 {u'key': u'pool', u'value': u'default'}, 291 {u'key': u'pool', u'value': u'default'},
259 ], 292 ],
260 u'execution_timeout_secs': u'3600', 293 u'execution_timeout_secs': u'3600',
261 u'grace_period_secs': u'30', 294 u'grace_period_secs': u'30',
262 u'idempotent': True, 295 u'idempotent': True,
263 u'io_timeout_secs': u'1200', 296 u'io_timeout_secs': u'1200',
264 u'packages': [{
265 u'package_name': u'rm',
266 u'version': test_env_handlers.PINNED_PACKAGE_VERSION,
267 }],
268 }, 297 },
269 u'tags': [ 298 u'tags': [
270 u'foo:bar', 299 u'foo:bar',
271 u'os:Amiga', 300 u'os:Amiga',
272 u'pool:default', 301 u'pool:default',
273 u'priority:200', 302 u'priority:200',
274 u'user:joe@localhost', 303 u'user:joe@localhost',
275 ], 304 ],
276 u'user': u'joe@localhost', 305 u'user': u'joe@localhost',
277 }, 306 },
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
376 request = swarming_rpcs.TasksRequest(start=start, end=end) 405 request = swarming_rpcs.TasksRequest(start=start, end=end)
377 expected = { 406 expected = {
378 u'items': [ 407 u'items': [
379 { 408 {
380 u'authenticated': u'user:user@example.com', 409 u'authenticated': u'user:user@example.com',
381 u'created_ts': str_now_30, 410 u'created_ts': str_now_30,
382 u'expiration_secs': u'30', 411 u'expiration_secs': u'30',
383 u'name': u'job1', 412 u'name': u'job1',
384 u'priority': u'200', 413 u'priority': u'200',
385 u'properties': { 414 u'properties': {
415 u'cipd_input': {
416 u'client_package': {
417 u'package_name': u'infra/tools/cipd/${platform}',
418 u'version': u'git_revision:deadbeef',
419 },
420 u'packages': [{
421 u'package_name': u'rm',
422 u'version': 'git_revision:deadbeef',
423 }],
424 u'server': u'https://chrome-infra-packages.appspot.com',
425 },
386 u'command': [u'python', u'run_test.py'], 426 u'command': [u'python', u'run_test.py'],
387 u'dimensions': [ 427 u'dimensions': [
388 {u'key': u'os', u'value': u'Amiga'}, 428 {u'key': u'os', u'value': u'Amiga'},
389 {u'key': u'pool', u'value': u'default'}, 429 {u'key': u'pool', u'value': u'default'},
390 ], 430 ],
391 u'execution_timeout_secs': u'3600', 431 u'execution_timeout_secs': u'3600',
392 u'grace_period_secs': u'30', 432 u'grace_period_secs': u'30',
393 u'idempotent': True, 433 u'idempotent': True,
394 u'io_timeout_secs': u'1200', 434 u'io_timeout_secs': u'1200',
395 u'packages': [{
396 u'package_name': u'rm',
397 u'version': test_env_handlers.PINNED_PACKAGE_VERSION,
398 }],
399 }, 435 },
400 u'tags': [ 436 u'tags': [
401 u'foo:bar', 437 u'foo:bar',
402 u'os:Amiga', 438 u'os:Amiga',
403 u'pool:default', 439 u'pool:default',
404 u'priority:200', 440 u'priority:200',
405 u'user:joe@localhost', 441 u'user:joe@localhost',
406 ], 442 ],
407 u'user': u'joe@localhost', 443 u'user': u'joe@localhost',
408 }, 444 },
409 { 445 {
410 u'authenticated': u'user:user@example.com', 446 u'authenticated': u'user:user@example.com',
411 u'created_ts': str_now, 447 u'created_ts': str_now,
412 u'expiration_secs': u'86400', 448 u'expiration_secs': u'86400',
413 u'name': u'task', 449 u'name': u'task',
414 u'priority': u'10', 450 u'priority': u'10',
415 u'properties': { 451 u'properties': {
452 u'cipd_input': {
453 u'client_package': {
454 u'package_name': u'infra/tools/cipd/${platform}',
455 u'version': u'git_revision:deadbeef',
456 },
457 u'packages': [{
458 u'package_name': u'rm',
459 u'version': 'git_revision:deadbeef',
460 }],
461 u'server': u'https://chrome-infra-packages.appspot.com',
462 },
416 u'command': [u'python', u'run_test.py'], 463 u'command': [u'python', u'run_test.py'],
417 u'dimensions': [ 464 u'dimensions': [
418 {u'key': u'os', u'value': u'Amiga'}, 465 {u'key': u'os', u'value': u'Amiga'},
419 {u'key': u'pool', u'value': u'default'}, 466 {u'key': u'pool', u'value': u'default'},
420 ], 467 ],
421 u'execution_timeout_secs': u'3600', 468 u'execution_timeout_secs': u'3600',
422 u'grace_period_secs': u'30', 469 u'grace_period_secs': u'30',
423 u'idempotent': True, 470 u'idempotent': True,
424 u'io_timeout_secs': u'1200', 471 u'io_timeout_secs': u'1200',
425 u'packages': [{
426 u'package_name': u'rm',
427 u'version': test_env_handlers.PINNED_PACKAGE_VERSION,
428 }],
429 }, 472 },
430 u'tags': [ 473 u'tags': [
431 u'commit:post', 474 u'commit:post',
432 u'os:Amiga', 475 u'os:Amiga',
433 u'os:Win', 476 u'os:Win',
434 u'pool:default', 477 u'pool:default',
435 u'priority:10', 478 u'priority:10',
436 u'project:yay', 479 u'project:yay',
437 u'user:joe@localhost', 480 u'user:joe@localhost',
438 ], 481 ],
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
568 u'priority:200', 611 u'priority:200',
569 u'user:joe@localhost', 612 u'user:joe@localhost',
570 ], 613 ],
571 u'user': u'joe@localhost', 614 u'user': u'joe@localhost',
572 }, 615 },
573 u'task_id': u'5cee488008810', 616 u'task_id': u'5cee488008810',
574 } 617 }
575 response = self.call_api('new', body=message_to_dict(request)) 618 response = self.call_api('new', body=message_to_dict(request))
576 self.assertEqual(expected, response.json) 619 self.assertEqual(expected, response.json)
577 620
621 def test_new_cipd_packages_with_defaults(self):
622 self.mock(random, 'getrandbits', lambda _: 0x88)
623 now = datetime.datetime(2010, 1, 2, 3, 4, 5)
624 self.mock_now(now)
625 str_now = unicode(now.strftime(self.DATETIME_NO_MICRO))
626
627 # Define settings on the server.
628 cfg = config.settings()
629 cfg.cipd.default_client_package.package_name = (
630 'infra/tools/cipd/${platform}')
631 cfg.cipd.default_client_package.version = 'git_revision:deadbeef'
632 cfg.cipd.default_server = 'https://chrome-infra-packages.appspot.com'
633 self.mock(config, 'settings', lambda: cfg)
634
635 request = swarming_rpcs.NewTaskRequest(
636 expiration_secs=30,
637 name='job1',
638 priority=200,
639 properties=swarming_rpcs.TaskProperties(
640 cipd_input=swarming_rpcs.CipdInput(
641 packages=[
642 swarming_rpcs.CipdPackage(
643 package_name='rm',
644 version='latest'),
645 ],
646 ),
647 command=['rm', '-rf', '/'],
648 dimensions=[
649 swarming_rpcs.StringPair(key='pool', value='default'),
650 ],
651 env=[
652 swarming_rpcs.StringPair(key='PATH', value='/'),
653 ],
654 execution_timeout_secs=30,
655 io_timeout_secs=30),
656 tags=['foo:bar'],
657 user='joe@localhost',
658 pubsub_topic='projects/abc/topics/def',
659 pubsub_auth_token='secret that must not be shown',
660 pubsub_userdata='userdata')
661 expected = {
662 u'request': {
663 u'authenticated': u'user:user@example.com',
664 u'created_ts': str_now,
665 u'expiration_secs': u'30',
666 u'name': u'job1',
667 u'priority': u'200',
668 u'properties': {
669 u'cipd_input': {
670 u'client_package': {
671 u'package_name': u'infra/tools/cipd/${platform}',
672 u'version': u'git_revision:deadbeef',
673 },
674 u'packages': [{
675 u'package_name': u'rm',
676 u'version': u'latest',
677 }],
678 u'server': u'https://chrome-infra-packages.appspot.com',
679 },
680 u'command': [u'rm', u'-rf', u'/'],
681 u'dimensions': [
682 {u'key': u'pool', u'value': u'default'},
683 ],
684 u'env': [
685 {u'key': u'PATH', u'value': u'/'},
686 ],
687 u'execution_timeout_secs': u'30',
688 u'grace_period_secs': u'30',
689 u'idempotent': False,
690 u'io_timeout_secs': u'30',
691 },
692 u'pubsub_topic': u'projects/abc/topics/def',
693 u'pubsub_userdata': u'userdata',
694 u'tags': [
695 u'foo:bar',
696 u'pool:default',
697 u'priority:200',
698 u'user:joe@localhost',
699 ],
700 u'user': u'joe@localhost',
701 },
702 u'task_id': u'5cee488008810',
703 }
704 response = self.call_api('new', body=message_to_dict(request))
705 self.assertEqual(expected, response.json)
706
578 def test_list_ok(self): 707 def test_list_ok(self):
579 """Asserts that list requests all TaskResultSummaries.""" 708 """Asserts that list requests all TaskResultSummaries."""
580 first, second, str_now_120, start, end = self._gen_two_tasks() 709 first, second, str_now_120, start, end = self._gen_two_tasks()
581 first_no_perf = first.copy() 710 first_no_perf = first.copy()
582 first_no_perf.pop('performance_stats') 711 first_no_perf.pop('performance_stats')
583 # Basic request. 712 # Basic request.
584 request = swarming_rpcs.TasksRequest( 713 request = swarming_rpcs.TasksRequest(
585 end=end, start=start, include_performance_stats=True) 714 end=end, start=start, include_performance_stats=True)
586 expected = {u'now': str_now_120, u'items': [second, first]} 715 expected = {u'now': str_now_120, u'items': [second, first]}
587 actual = self.call_api('list', body=message_to_dict(request)).json 716 actual = self.call_api('list', body=message_to_dict(request)).json
(...skipping 517 matching lines...) Expand 10 before | Expand all | Expand 10 after
1105 _, task_id = self.client_create_task_raw() 1234 _, task_id = self.client_create_task_raw()
1106 self.set_as_bot() 1235 self.set_as_bot()
1107 response = self.call_api('request', body={'task_id': task_id}) 1236 response = self.call_api('request', body={'task_id': task_id})
1108 expected = { 1237 expected = {
1109 u'authenticated': u'user:user@example.com', 1238 u'authenticated': u'user:user@example.com',
1110 u'created_ts': unicode(now.strftime(self.DATETIME_FORMAT)), 1239 u'created_ts': unicode(now.strftime(self.DATETIME_FORMAT)),
1111 u'expiration_secs': unicode(24 * 60 * 60), 1240 u'expiration_secs': unicode(24 * 60 * 60),
1112 u'name': u'hi', 1241 u'name': u'hi',
1113 u'priority': u'10', 1242 u'priority': u'10',
1114 u'properties': { 1243 u'properties': {
1244 u'cipd_input': {
1245 u'client_package': {
1246 u'package_name': u'infra/tools/cipd/${platform}',
1247 u'version': u'git_revision:deadbeef',
1248 },
1249 u'packages': [{
1250 u'package_name': u'rm',
1251 u'version': 'git_revision:deadbeef',
1252 }],
1253 u'server': u'https://chrome-infra-packages.appspot.com',
1254 },
1115 u'command': [u'python', u'run_test.py'], 1255 u'command': [u'python', u'run_test.py'],
1116 u'dimensions': [ 1256 u'dimensions': [
1117 {u'key': u'os', u'value': u'Amiga'}, 1257 {u'key': u'os', u'value': u'Amiga'},
1118 {u'key': u'pool', u'value': u'default'}, 1258 {u'key': u'pool', u'value': u'default'},
1119 ], 1259 ],
1120 u'execution_timeout_secs': u'3600', 1260 u'execution_timeout_secs': u'3600',
1121 u'grace_period_secs': u'30', 1261 u'grace_period_secs': u'30',
1122 u'idempotent': False, 1262 u'idempotent': False,
1123 u'io_timeout_secs': u'1200', 1263 u'io_timeout_secs': u'1200',
1124 u'packages': [{
1125 u'package_name': u'rm',
1126 u'version': test_env_handlers.PINNED_PACKAGE_VERSION,
1127 }],
1128 }, 1264 },
1129 u'tags': [ 1265 u'tags': [
1130 u'os:Amiga', 1266 u'os:Amiga',
1131 u'pool:default', 1267 u'pool:default',
1132 u'priority:10', 1268 u'priority:10',
1133 u'user:joe@localhost', 1269 u'user:joe@localhost',
1134 ], 1270 ],
1135 u'user': u'joe@localhost', 1271 u'user': u'joe@localhost',
1136 } 1272 }
1137 self.assertEqual(expected, response.json) 1273 self.assertEqual(expected, response.json)
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after
1433 self.assertEqual(expected, response.json) 1569 self.assertEqual(expected, response.json)
1434 1570
1435 1571
1436 if __name__ == '__main__': 1572 if __name__ == '__main__':
1437 if '-v' in sys.argv: 1573 if '-v' in sys.argv:
1438 unittest.TestCase.maxDiff = None 1574 unittest.TestCase.maxDiff = None
1439 logging.basicConfig(level=logging.DEBUG) 1575 logging.basicConfig(level=logging.DEBUG)
1440 else: 1576 else:
1441 logging.basicConfig(level=logging.CRITICAL) 1577 logging.basicConfig(level=logging.CRITICAL)
1442 unittest.main() 1578 unittest.main()
OLDNEW
« no previous file with comments | « appengine/swarming/handlers_endpoints.py ('k') | appengine/swarming/message_conversion.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698