def test_create_task_async_override_cfg(self): build = model.Build( id=1, bucket='bucket', create_time=utils.utcnow(), created_by=auth.Identity('user', '*****@*****.**'), parameters={ 'builder_name': 'linux_chromium_rel_ng', 'swarming': { 'override_builder_cfg': { # Override cores dimension. 'dimensions': ['cores:16'], 'recipe': { 'revision': 'badcoffee' }, }, } }, ) self.json_response = { 'task_id': 'deadbeef', 'request': { 'properties': { 'dimensions': [ { 'key': 'cores', 'value': '16' }, { 'key': 'os', 'value': 'Linux' }, { 'key': 'pool', 'value': 'Chrome' }, ], }, 'tags': [ 'build_address:bucket/linux_chromium_rel_ng/1', 'builder:linux_chromium_rel_ng', 'buildertag:yes', 'commontag:yes', 'master:master.bucket', 'priority:108', 'recipe_name:recipe', 'recipe_repository:https://example.com/repo', 'recipe_revision:badcoffee', ] } } swarming.create_task_async(build).get_result() actual_task_def = net.json_request_async.call_args[1]['payload'] self.assertIn({ 'key': 'cores', 'value': '16' }, actual_task_def['properties']['dimensions'])
def test_create_task_async_on_leased_build(self): build = model.Build( bucket='bucket', parameters={'builder_name': 'builder'}, lease_key=12345, ) with self.assertRaises(errors.InvalidInputError): swarming.create_task_async(build).get_result()
def test_create_task_async_on_leased_build(self): build = model.Build( id=1, bucket='bucket', parameters={'builder_name': 'linux_chromium_rel_ng'}, lease_key=12345, ) with self.assertRaises(errors.InvalidInputError): swarming.create_task_async(build).get_result()
def test_create_task_async_for_non_swarming_bucket(self): self.bucket_cfg.ClearField('swarming') build = model.Build( id=1, bucket='bucket', parameters={'builder_name': 'linux_chromium_rel_ng'}, ) with self.assertRaises(errors.InvalidInputError): swarming.create_task_async(build).get_result()
def test_create_task_async_without_template(self): self.task_template = None self.task_template_canary = None build = model.Build( id=1, bucket='bucket', parameters={'builder_name': 'linux_chromium_rel_ng'}, ) with self.assertRaises(swarming.TemplateNotFound): swarming.create_task_async(build).get_result()
def test_create_task_async_no_canary_template_implicit( self, should_use_canary_template): should_use_canary_template.return_value = True self.task_template_canary = None self.bucket_cfg.swarming.task_template_canary_percentage.value = 54 self.json_response = { 'task_id': 'deadbeef', 'request': { 'properties': { 'dimensions': [ { 'key': 'cores', 'value': '8' }, { 'key': 'os', 'value': 'Linux' }, { 'key': 'pool', 'value': 'Chrome' }, ], }, 'tags': [ 'build_address:bucket/linux_chromium_rel_ng/1', 'builder:linux_chromium_rel_ng', 'buildertag:yes', 'commontag:yes', 'master:master.bucket', 'priority:108', 'recipe_name:recipe', 'recipe_repository:https://example.com/repo', 'recipe_revision:HEAD', ] } } build = model.Build( id=1, bucket='bucket', create_time=utils.utcnow(), created_by=auth.Identity('user', '*****@*****.**'), parameters={'builder_name': 'linux_chromium_rel_ng'}, ) swarming.create_task_async(build).get_result() actual_task_def = net.json_request_async.call_args[1]['payload'] self.assertIn('buildbucket_template_canary:false', actual_task_def['tags']) should_use_canary_template.assert_called_with(54)
def test_create_task_async_403(self): build = model.Build( bucket='bucket', parameters={ 'builder_name': 'builder', }, ) http403 = net.AuthError('403', 403, 'nope') self.mock(net, 'json_request_async', mock.Mock(side_effect=http403)) with self.assertRaises(auth.AuthorizationError): swarming.create_task_async(build).get_result()
def test_create_task_async_no_canary_template_explicit(self): build = model.Build( id=1, bucket='bucket', create_time=utils.utcnow(), created_by=auth.Identity('user', '*****@*****.**'), parameters={ 'builder_name': 'linux_chromium_rel_ng', 'swarming': { 'canary_template': True, } }, ) self.task_template_canary = None with self.assertRaises(errors.InvalidInputError): swarming.create_task_async(build).get_result()
def test_create_task_async_bad_request(self): build = model.Build(id=1, bucket='bucket') with self.assertRaises(errors.InvalidInputError): swarming.create_task_async(build).get_result() with self.assertRaises(errors.InvalidInputError): build.parameters = { 'builder_name': 'non-existent builder', } swarming.create_task_async(build).get_result() with self.assertRaises(errors.InvalidInputError): build.parameters['builder_name'] = 2 swarming.create_task_async(build).get_result()
def test_create_task_async(self): build = model.Build( bucket='bucket', tags=['builder:builder'], parameters={ 'builder_name': 'builder', 'swarming': { 'recipe': {'revision': 'badcoffee'}, }, 'properties': { 'a': 'b', } }, ) self.mock(net, 'json_request_async', mock.Mock(return_value=futuristic({ 'task_id': 'deadbeef', 'request': { 'properties': { 'dimensions': [ {'key': 'cores', 'value': '8'}, {'key': 'os', 'value': 'Linux'}, ], }, 'tags': [ 'builder:builder', 'buildertag:yes', 'commontag:yes', 'master:master.bucket', 'priority:108', 'recipe_name:recipe', 'recipe_repository:https://example.com/repo', 'recipe_revision:badcoffee', ] } }))) swarming.create_task_async(build).get_result() # Test swarming request. self.assertEqual( net.json_request_async.call_args[0][0], 'https://chromium-swarm.appspot.com/_ah/api/swarming/v1/tasks/new') actual_task_def = net.json_request_async.call_args[1]['payload'] del actual_task_def['pubsub_auth_token'] self.maxDiff =24566 expected_task_def = { 'name': 'buildbucket-bucket-builder', 'priority': 108, 'expiration_secs': '3600', 'tags': [ 'buildbucket_bucket:bucket', 'buildbucket_hostname:None', 'builder:builder', 'buildertag:yes', 'commontag:yes', 'recipe_name:recipe', 'recipe_repository:https://example.com/repo', 'recipe_revision:badcoffee', ], 'properties': { 'execution_timeout_secs': '3600', 'inputs_ref': { 'isolatedserver': 'https://isolateserver.appspot.com', 'namespace': 'default-gzip', 'isolated': 'cbacbdcbabcd' }, 'extra_args': [ 'cook', '-repository', 'https://example.com/repo', '-revision', 'badcoffee', '-recipe', 'recipe', '-properties', '{"a": "b", "predefined-property": "x"}', ], 'dimensions': [ {'key': 'cores', 'value': '8'}, {'key': 'os', 'value': 'Linux'}, ], }, 'pubsub_topic': 'projects/testbed-test/topics/swarming', 'pubsub_userdata': json.dumps({ 'created_ts': utils.datetime_to_timestamp(utils.utcnow()), 'swarming_hostname': 'chromium-swarm.appspot.com', }, sort_keys=True), 'numerical_value_for_coverage_in_format_obj': 42, } self.assertEqual(actual_task_def, expected_task_def) self.assertEqual(set(build.tags), { 'builder:builder', 'swarming_dimension:cores:8', 'swarming_dimension:os:Linux', 'swarming_hostname:chromium-swarm.appspot.com', 'swarming_tag:builder:builder', 'swarming_tag:buildertag:yes', 'swarming_tag:commontag:yes', 'swarming_tag:master:master.bucket', 'swarming_tag:priority:108', 'swarming_tag:recipe_name:recipe', 'swarming_tag:recipe_repository:https://example.com/repo', 'swarming_tag:recipe_revision:badcoffee', 'swarming_task_id:deadbeef', }) self.assertEqual( build.url, 'https://example.com/chromium-swarm.appspot.com/deadbeef')
def test_create_task_async_override_cfg_malformed(self): build = model.Build( id=1, bucket='bucket', create_time=utils.utcnow(), created_by=auth.Identity('user', '*****@*****.**'), parameters={ 'builder_name': 'linux_chromium_rel_ng', 'swarming': { 'override_builder_cfg': [], } }, ) with self.assertRaises(errors.InvalidInputError): swarming.create_task_async(build).get_result() build = model.Build( id=1, bucket='bucket', parameters={ 'builder_name': 'linux_chromium_rel_ng', 'swarming': { 'override_builder_cfg': { 'name': 'x', }, } }, ) with self.assertRaises(errors.InvalidInputError): swarming.create_task_async(build).get_result() build = model.Build( id=1, bucket='bucket', parameters={ 'builder_name': 'linux_chromium_rel_ng', 'swarming': { 'override_builder_cfg': { 'mixins': ['x'], }, } }, ) with self.assertRaises(errors.InvalidInputError): swarming.create_task_async(build).get_result() build = model.Build( id=1, bucket='bucket', parameters={ 'builder_name': 'linux_chromium_rel_ng', 'swarming': { 'override_builder_cfg': { 'blabla': 'x', }, } }, ) with self.assertRaises(errors.InvalidInputError): swarming.create_task_async(build).get_result() # Remove a required dimension. build = model.Build( id=1, bucket='bucket', parameters={ 'builder_name': 'linux_chromium_rel_ng', 'swarming': { 'override_builder_cfg': { 'dimensions': ['pool:'], }, } }, ) with self.assertRaises(errors.InvalidInputError): swarming.create_task_async(build).get_result() # Override build numbers build = model.Build( id=1, bucket='bucket', parameters={ 'builder_name': 'linux_chromium_rel_ng', 'swarming': { 'override_builder_cfg': { 'build_numbers': False, }, } }, ) with self.assertRaises(errors.InvalidInputError): swarming.create_task_async(build).get_result()
def test_create_task_async_canary_template(self): build = model.Build( id=1, bucket='bucket', create_time=utils.utcnow(), created_by=auth.Identity('user', '*****@*****.**'), parameters={ 'builder_name': 'linux_chromium_rel_ng', 'swarming': { 'canary_template': True, } }, ) self.json_response = { 'task_id': 'deadbeef', 'request': { 'properties': { 'dimensions': [ { 'key': 'cores', 'value': '8' }, { 'key': 'os', 'value': 'Linux' }, { 'key': 'pool', 'value': 'Chrome' }, ], }, 'tags': [ 'build_address:bucket/linux_chromium_rel_ng/1', 'builder:linux_chromium_rel_ng', 'buildertag:yes', 'commontag:yes', 'master:master.bucket', 'priority:108', 'recipe_name:recipe', 'recipe_repository:https://example.com/repo', ] } } swarming.create_task_async(build).get_result() # Test swarming request. self.assertEqual( net.json_request_async.call_args[0][0], 'https://chromium-swarm.appspot.com/_ah/api/swarming/v1/tasks/new') actual_task_def = net.json_request_async.call_args[1]['payload'] expected_task_def = { 'name': 'buildbucket:bucket:linux_chromium_rel_ng-canary', 'priority': '108', 'expiration_secs': '3600', 'tags': [ 'build_address:bucket/linux_chromium_rel_ng/1', 'buildbucket_bucket:bucket', 'buildbucket_build_id:1', 'buildbucket_hostname:cr-buildbucket.appspot.com', 'buildbucket_template_canary:true', 'buildbucket_template_revision:template_rev', 'builder:linux_chromium_rel_ng', 'buildertag:yes', 'commontag:yes', ('log_location:logdog://luci-logdog-dev.appspot.com/chromium/' 'buildbucket/cr-buildbucket.appspot.com/1/+/annotations'), 'luci_project:chromium', 'recipe_name:recipe', 'recipe_repository:https://example.com/repo', 'recipe_revision:HEAD', ], 'properties': { 'execution_timeout_secs': '3600', 'extra_args': [ 'cook', '-repository', 'https://example.com/repo', '-revision', 'HEAD', '-recipe', 'recipe', '-properties', json.dumps( { 'buildbucket': { 'build': { 'bucket': 'bucket', 'created_by': 'user:[email protected]', 'created_ts': utils.datetime_to_timestamp( build.create_time), 'id': '1', 'tags': [], }, }, 'buildername': 'linux_chromium_rel_ng', 'buildnumber': 1, 'predefined-property': 'x', 'predefined-property-bool': True, }, sort_keys=True), '-logdog-project', 'chromium', ], 'dimensions': sorted([ { 'key': 'cores', 'value': '8' }, { 'key': 'os', 'value': 'Linux' }, { 'key': 'pool', 'value': 'Chrome' }, ]), 'caches': [ { 'path': 'cache/a', 'name': 'a' }, { 'path': 'cache/builder', 'name': LINUX_CHROMIUM_REL_NG_CACHE_NAME }, { 'path': 'cache/git_cache', 'name': 'git_chromium' }, { 'path': 'cache/out', 'name': 'build_chromium' }, ], 'cipd_input': { 'packages': [ { 'package_name': 'infra/test/bar/${os_ver}', 'path': '.', 'version': 'latest', }, { 'package_name': 'infra/test/foo/${platform}', 'path': 'third_party', 'version': 'stable', }, ], } }, 'pubsub_topic': 'projects/testbed-test/topics/swarming', 'pubsub_userdata': json.dumps( { 'created_ts': utils.datetime_to_timestamp(utils.utcnow()), 'swarming_hostname': 'chromium-swarm.appspot.com', 'build_id': 1L, }, sort_keys=True), 'numerical_value_for_coverage_in_format_obj': 42, }