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

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

Issue 1942143002: swarming: isolate defaults (Closed) Base URL: https://chromium.googlesource.com/external/github.com/luci/luci-py@swarming-ns-re
Patch Set: swarming: isolate defaults and output 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
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 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 def test_bootstrap(self): 129 def test_bootstrap(self):
130 self._test_file('bootstrap') 130 self._test_file('bootstrap')
131 131
132 def test_bot_config(self): 132 def test_bot_config(self):
133 self._test_file('bot_config') 133 self._test_file('bot_config')
134 134
135 135
136 class TasksApiTest(BaseTest): 136 class TasksApiTest(BaseTest):
137 api_service_cls = handlers_endpoints.SwarmingTasksService 137 api_service_cls = handlers_endpoints.SwarmingTasksService
138 138
139 def setUp(self):
140 super(TasksApiTest, self).setUp()
141 utils.clear_cache(config.settings)
142
139 def test_new_ok_raw(self): 143 def test_new_ok_raw(self):
140 """Asserts that new generates appropriate metadata.""" 144 """Asserts that new generates appropriate metadata."""
141 self.mock(random, 'getrandbits', lambda _: 0x88) 145 self.mock(random, 'getrandbits', lambda _: 0x88)
142 now = datetime.datetime(2010, 1, 2, 3, 4, 5) 146 now = datetime.datetime(2010, 1, 2, 3, 4, 5)
143 self.mock_now(now) 147 self.mock_now(now)
144 str_now = unicode(now.strftime(self.DATETIME_NO_MICRO)) 148 str_now = unicode(now.strftime(self.DATETIME_NO_MICRO))
145 request = swarming_rpcs.NewTaskRequest( 149 request = swarming_rpcs.NewTaskRequest(
146 expiration_secs=30, 150 expiration_secs=30,
147 name='job1', 151 name='job1',
148 priority=200, 152 priority=200,
(...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after
498 u'priority:200', 502 u'priority:200',
499 u'user:joe@localhost', 503 u'user:joe@localhost',
500 ], 504 ],
501 u'user': u'joe@localhost', 505 u'user': u'joe@localhost',
502 }, 506 },
503 u'task_id': u'5cee488008810', 507 u'task_id': u'5cee488008810',
504 } 508 }
505 response = self.call_api('new', body=message_to_dict(request)) 509 response = self.call_api('new', body=message_to_dict(request))
506 self.assertEqual(expected, response.json) 510 self.assertEqual(expected, response.json)
507 511
512 def test_new_ok_isolated_with_defaults(self):
513 self.mock(random, 'getrandbits', lambda _: 0x88)
514 now = datetime.datetime(2010, 1, 2, 3, 4, 5)
515 self.mock_now(now)
516 str_now = unicode(now.strftime(self.DATETIME_NO_MICRO))
517
518 cfg = config.settings()
519 cfg.isolate.default_server_host = 'isolateserver.appspot.com'
520 cfg.isolate.default_namespace = 'default-gzip'
521 self.mock(config, 'settings', lambda: cfg)
522
523 request = swarming_rpcs.NewTaskRequest(
524 expiration_secs=30,
525 name='job1',
526 priority=200,
527 properties=swarming_rpcs.TaskProperties(
528 dimensions=[
529 swarming_rpcs.StringPair(key='pool', value='default'),
530 swarming_rpcs.StringPair(key='foo', value='bar'),
531 ],
532 env=[
533 swarming_rpcs.StringPair(key='PATH', value='/'),
534 ],
535 execution_timeout_secs=30,
536 inputs_ref=swarming_rpcs.FilesRef(isolated='1'*40),
537 io_timeout_secs=30),
538 tags=['foo:bar'],
539 user='joe@localhost')
540 expected = {
541 u'request': {
542 u'authenticated': u'user:user@example.com',
543 u'created_ts': str_now,
544 u'expiration_secs': u'30',
545 u'name': u'job1',
546 u'priority': u'200',
547 u'properties': {
548 u'dimensions': [
549 {u'key': u'foo', u'value': u'bar'},
550 {u'key': u'pool', u'value': u'default'},
551 ],
552 u'env': [
553 {u'key': u'PATH', u'value': u'/'},
554 ],
555 u'execution_timeout_secs': u'30',
556 u'grace_period_secs': u'30',
557 u'idempotent': False,
558 u'inputs_ref': {
559 'isolated': '1'*40,
560 'isolatedserver': 'https://isolateserver.appspot.com',
561 'namespace': 'default-gzip',
562 },
563 u'io_timeout_secs': u'30',
564 },
565 u'tags': [
566 u'foo:bar',
567 u'pool:default',
568 u'priority:200',
569 u'user:joe@localhost',
570 ],
571 u'user': u'joe@localhost',
572 },
573 u'task_id': u'5cee488008810',
574 }
575 response = self.call_api('new', body=message_to_dict(request))
576 self.assertEqual(expected, response.json)
577
508 def test_new_ok_isolated_output(self): 578 def test_new_ok_isolated_output(self):
509 """Asserts that new generates appropriate metadata.""" 579 """Asserts that new generates appropriate metadata."""
510 self.mock(random, 'getrandbits', lambda _: 0x88) 580 self.mock(random, 'getrandbits', lambda _: 0x88)
511 now = datetime.datetime(2010, 1, 2, 3, 4, 5) 581 now = datetime.datetime(2010, 1, 2, 3, 4, 5)
512 self.mock_now(now) 582 self.mock_now(now)
513 str_now = unicode(now.strftime(self.DATETIME_NO_MICRO)) 583 str_now = unicode(now.strftime(self.DATETIME_NO_MICRO))
514 request = swarming_rpcs.NewTaskRequest( 584 request = swarming_rpcs.NewTaskRequest(
515 expiration_secs=30, 585 expiration_secs=30,
516 name='job1', 586 name='job1',
517 priority=200, 587 priority=200,
518 properties=swarming_rpcs.TaskProperties( 588 properties=swarming_rpcs.TaskProperties(
589 command=['rm', '-rf', '/'],
590 dimensions=[
591 swarming_rpcs.StringPair(key='pool', value='default'),
592 swarming_rpcs.StringPair(key='foo', value='bar'),
593 ],
594 env=[
595 swarming_rpcs.StringPair(key='PATH', value='/'),
596 ],
597 execution_timeout_secs=30,
598 io_timeout_secs=30,
599 outputs_target=swarming_rpcs.IsolatedOutputsTarget(
600 isolatedserver='http://localhost:1',
601 namespace='default-gzip')),
602 tags=['foo:bar'],
603 user='joe@localhost')
604 expected = {
605 u'request': {
606 u'authenticated': u'user:user@example.com',
607 u'created_ts': str_now,
608 u'expiration_secs': u'30',
609 u'name': u'job1',
610 u'priority': u'200',
611 u'properties': {
612 u'command': [u'rm', u'-rf', u'/'],
613 u'dimensions': [
614 {u'key': u'foo', u'value': u'bar'},
615 {u'key': u'pool', u'value': u'default'},
616 ],
617 u'env': [
618 {u'key': u'PATH', u'value': u'/'},
619 ],
620 u'execution_timeout_secs': u'30',
621 u'grace_period_secs': u'30',
622 u'idempotent': False,
623 u'io_timeout_secs': u'30',
624 u'outputs_target': {
625 'isolatedserver': 'http://localhost:1',
626 'namespace': 'default-gzip',
627 },
628 },
629 u'tags': [
630 u'foo:bar',
631 u'pool:default',
632 u'priority:200',
633 u'user:joe@localhost',
634 ],
635 u'user': u'joe@localhost',
636 },
637 u'task_id': u'5cee488008810',
638 }
639 response = self.call_api('new', body=message_to_dict(request))
640 self.assertEqual(expected, response.json)
641
642 def test_new_ok_isolated_output_with_defaults(self):
643 self.mock(random, 'getrandbits', lambda _: 0x88)
644 now = datetime.datetime(2010, 1, 2, 3, 4, 5)
645 self.mock_now(now)
646 str_now = unicode(now.strftime(self.DATETIME_NO_MICRO))
647
648 cfg = config.settings()
649 cfg.isolate.default_server_host = 'isolateserver.appspot.com'
650 cfg.isolate.default_namespace = 'default-gzip'
651 self.mock(config, 'settings', lambda: cfg)
652
653 request = swarming_rpcs.NewTaskRequest(
654 expiration_secs=30,
655 name='job1',
656 priority=200,
657 properties=swarming_rpcs.TaskProperties(
519 command=['rm', '-rf', '/'], 658 command=['rm', '-rf', '/'],
520 dimensions=[ 659 dimensions=[
521 swarming_rpcs.StringPair(key='pool', value='default'), 660 swarming_rpcs.StringPair(key='pool', value='default'),
522 swarming_rpcs.StringPair(key='foo', value='bar'), 661 swarming_rpcs.StringPair(key='foo', value='bar'),
523 ], 662 ],
524 env=[ 663 env=[
525 swarming_rpcs.StringPair(key='PATH', value='/'), 664 swarming_rpcs.StringPair(key='PATH', value='/'),
526 ], 665 ],
527 execution_timeout_secs=30, 666 execution_timeout_secs=30,
528 io_timeout_secs=30, 667 io_timeout_secs=30),
529 outputs_target=swarming_rpcs.IsolatedOutputsTarget(
530 isolatedserver='http://localhost:1',
531 namespace='default-gzip')),
532 tags=['foo:bar'], 668 tags=['foo:bar'],
533 user='joe@localhost') 669 user='joe@localhost')
534 expected = { 670 expected = {
535 u'request': { 671 u'request': {
536 u'authenticated': u'user:user@example.com', 672 u'authenticated': u'user:user@example.com',
537 u'created_ts': str_now, 673 u'created_ts': str_now,
538 u'expiration_secs': u'30', 674 u'expiration_secs': u'30',
539 u'name': u'job1', 675 u'name': u'job1',
540 u'priority': u'200', 676 u'priority': u'200',
541 u'properties': { 677 u'properties': {
542 u'command': [u'rm', u'-rf', u'/'], 678 u'command': [u'rm', u'-rf', u'/'],
543 u'dimensions': [ 679 u'dimensions': [
544 {u'key': u'foo', u'value': u'bar'}, 680 {u'key': u'foo', u'value': u'bar'},
545 {u'key': u'pool', u'value': u'default'}, 681 {u'key': u'pool', u'value': u'default'},
546 ], 682 ],
547 u'env': [ 683 u'env': [
548 {u'key': u'PATH', u'value': u'/'}, 684 {u'key': u'PATH', u'value': u'/'},
549 ], 685 ],
550 u'execution_timeout_secs': u'30', 686 u'execution_timeout_secs': u'30',
551 u'grace_period_secs': u'30', 687 u'grace_period_secs': u'30',
552 u'idempotent': False, 688 u'idempotent': False,
553 u'io_timeout_secs': u'30', 689 u'io_timeout_secs': u'30',
554 u'outputs_target': { 690 u'outputs_target': {
555 'isolatedserver': 'http://localhost:1', 691 'isolatedserver': 'https://isolateserver.appspot.com',
556 'namespace': 'default-gzip', 692 'namespace': 'default-gzip',
557 }, 693 },
558 }, 694 },
559 u'tags': [ 695 u'tags': [
560 u'foo:bar', 696 u'foo:bar',
561 u'pool:default', 697 u'pool:default',
562 u'priority:200', 698 u'priority:200',
563 u'user:joe@localhost', 699 u'user:joe@localhost',
564 ], 700 ],
565 u'user': u'joe@localhost', 701 u'user': u'joe@localhost',
(...skipping 861 matching lines...) Expand 10 before | Expand all | Expand 10 after
1427 self.assertEqual(expected, response.json) 1563 self.assertEqual(expected, response.json)
1428 1564
1429 1565
1430 if __name__ == '__main__': 1566 if __name__ == '__main__':
1431 if '-v' in sys.argv: 1567 if '-v' in sys.argv:
1432 unittest.TestCase.maxDiff = None 1568 unittest.TestCase.maxDiff = None
1433 logging.basicConfig(level=logging.DEBUG) 1569 logging.basicConfig(level=logging.DEBUG)
1434 else: 1570 else:
1435 logging.basicConfig(level=logging.CRITICAL) 1571 logging.basicConfig(level=logging.CRITICAL)
1436 unittest.main() 1572 unittest.main()
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698