| OLD | NEW |
| 1 # Copyright 2015 The Chromium Authors. All rights reserved. | 1 # Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 import base64 | 5 import base64 |
| 6 import contextlib | 6 import contextlib |
| 7 import datetime | 7 import datetime |
| 8 import json | 8 import json |
| 9 | 9 |
| 10 from components import auth | 10 from components import auth |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 recipe=project_config_pb2.Swarming.Recipe( | 53 recipe=project_config_pb2.Swarming.Recipe( |
| 54 properties=['predefined-property:x'], | 54 properties=['predefined-property:x'], |
| 55 properties_j=['predefined-property-bool:true'], | 55 properties_j=['predefined-property-bool:true'], |
| 56 ), | 56 ), |
| 57 priority=108, | 57 priority=108, |
| 58 ), | 58 ), |
| 59 ], | 59 ], |
| 60 ), | 60 ), |
| 61 ) | 61 ) |
| 62 self.mock( | 62 self.mock( |
| 63 config, 'get_bucket_async', lambda name: futuristic(self.bucket_cfg)) | 63 config, 'get_bucket_async', |
| 64 lambda name: futuristic(('chromium', self.bucket_cfg))) |
| 64 | 65 |
| 65 task_template = { | 66 task_template = { |
| 66 'name': 'buildbucket-$bucket-$builder', | 67 'name': 'buildbucket-$bucket-$builder', |
| 67 'priority': '100', | 68 'priority': '100', |
| 68 'expiration_secs': '3600', | 69 'expiration_secs': '3600', |
| 69 'properties': { | 70 'properties': { |
| 70 'execution_timeout_secs': '3600', | 71 'execution_timeout_secs': '3600', |
| 71 'inputs_ref': { | 72 'inputs_ref': { |
| 72 'isolatedserver': 'https://isolateserver.appspot.com', | 73 'isolatedserver': 'https://isolateserver.appspot.com', |
| 73 'namespace': 'default-gzip', | 74 'namespace': 'default-gzip', |
| 74 'isolated': 'cbacbdcbabcd' | 75 'isolated': 'cbacbdcbabcd' |
| 75 }, | 76 }, |
| 76 'extra_args': [ | 77 'extra_args': [ |
| 77 'cook', | 78 'cook', |
| 78 '-repository', '$repository', | 79 '-repository', '$repository', |
| 79 '-revision', '$revision', | 80 '-revision', '$revision', |
| 80 '-recipe', '$recipe', | 81 '-recipe', '$recipe', |
| 81 '-properties', '$properties_json', | 82 '-properties', '$properties_json', |
| 83 '-logdog-project', '$project', |
| 82 ], | 84 ], |
| 83 }, | 85 }, |
| 84 'numerical_value_for_coverage_in_format_obj': 42, | 86 'numerical_value_for_coverage_in_format_obj': 42, |
| 85 } | 87 } |
| 86 self.mock(config_component, 'get_self_config_async', mock.Mock()) | 88 self.mock(config_component, 'get_self_config_async', mock.Mock()) |
| 87 config_component.get_self_config_async.return_value = ( | 89 config_component.get_self_config_async.return_value = ( |
| 88 futuristic((None, json.dumps(task_template)))) | 90 futuristic((None, json.dumps(task_template)))) |
| 89 | 91 |
| 90 self.mock(auth, 'delegate_async', mock.Mock()) | 92 self.mock(auth, 'delegate_async', mock.Mock()) |
| 91 auth.delegate_async.return_value = futuristic('blah') | 93 auth.delegate_async.return_value = futuristic('blah') |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 builder_cfg = project_config_pb2.Swarming.Builder(name='fast-builder') | 154 builder_cfg = project_config_pb2.Swarming.Builder(name='fast-builder') |
| 153 | 155 |
| 154 build = model.Build( | 156 build = model.Build( |
| 155 bucket='bucket', | 157 bucket='bucket', |
| 156 parameters={ | 158 parameters={ |
| 157 'builder_name': 'fast-builder', | 159 'builder_name': 'fast-builder', |
| 158 }, | 160 }, |
| 159 ) | 161 ) |
| 160 | 162 |
| 161 task_def = swarming.create_task_def_async( | 163 task_def = swarming.create_task_def_async( |
| 162 self.bucket_cfg.swarming, builder_cfg, build).get_result() | 164 'chromium', self.bucket_cfg.swarming, builder_cfg, build).get_result() |
| 163 | 165 |
| 164 self.assertEqual( | 166 self.assertEqual( |
| 165 task_def['properties']['execution_timeout_secs'], 120) | 167 task_def['properties']['execution_timeout_secs'], 120) |
| 166 | 168 |
| 167 builder_cfg.execution_timeout_secs = 60 | 169 builder_cfg.execution_timeout_secs = 60 |
| 168 task_def = swarming.create_task_def_async( | 170 task_def = swarming.create_task_def_async( |
| 169 self.bucket_cfg.swarming, builder_cfg, build).get_result() | 171 'chromium', self.bucket_cfg.swarming, builder_cfg, build).get_result() |
| 170 self.assertEqual( | 172 self.assertEqual( |
| 171 task_def['properties']['execution_timeout_secs'], 60) | 173 task_def['properties']['execution_timeout_secs'], 60) |
| 172 | 174 |
| 173 def test_create_task_async(self): | 175 def test_create_task_async(self): |
| 174 build = model.Build( | 176 build = model.Build( |
| 175 bucket='bucket', | 177 bucket='bucket', |
| 176 tags=['builder:builder'], | 178 tags=['builder:builder'], |
| 177 parameters={ | 179 parameters={ |
| 178 'builder_name': 'builder', | 180 'builder_name': 'builder', |
| 179 'swarming': { | 181 'swarming': { |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 246 '-repository', 'https://example.com/repo', | 248 '-repository', 'https://example.com/repo', |
| 247 '-revision', 'badcoffee', | 249 '-revision', 'badcoffee', |
| 248 '-recipe', 'recipe', | 250 '-recipe', 'recipe', |
| 249 '-properties', json.dumps({ | 251 '-properties', json.dumps({ |
| 250 'a': 'b', | 252 'a': 'b', |
| 251 'blamelist': ['bob@example.com'], | 253 'blamelist': ['bob@example.com'], |
| 252 'buildername': 'builder', | 254 'buildername': 'builder', |
| 253 'predefined-property': 'x', | 255 'predefined-property': 'x', |
| 254 'predefined-property-bool': True, | 256 'predefined-property-bool': True, |
| 255 'repository': 'https://chromium.googlesource.com/chromium/src', | 257 'repository': 'https://chromium.googlesource.com/chromium/src', |
| 256 }, sort_keys=True) | 258 }, sort_keys=True), |
| 259 '-logdog-project', 'chromium', |
| 257 ], | 260 ], |
| 258 'dimensions': sorted([ | 261 'dimensions': sorted([ |
| 259 {'key': 'cores', 'value': '8'}, | 262 {'key': 'cores', 'value': '8'}, |
| 260 {'key': 'os', 'value': 'Linux'}, | 263 {'key': 'os', 'value': 'Linux'}, |
| 261 {'key': 'pool', 'value': 'Chrome'}, | 264 {'key': 'pool', 'value': 'Chrome'}, |
| 262 ]), | 265 ]), |
| 263 }, | 266 }, |
| 264 'pubsub_topic': 'projects/testbed-test/topics/swarming', | 267 'pubsub_topic': 'projects/testbed-test/topics/swarming', |
| 265 'pubsub_userdata': json.dumps({ | 268 'pubsub_userdata': json.dumps({ |
| 266 'created_ts': utils.datetime_to_timestamp(utils.utcnow()), | 269 'created_ts': utils.datetime_to_timestamp(utils.utcnow()), |
| (...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 616 self.assertEqual(build.status, model.BuildStatus.COMPLETED) | 619 self.assertEqual(build.status, model.BuildStatus.COMPLETED) |
| 617 self.assertEqual(build.result, model.BuildResult.FAILURE) | 620 self.assertEqual(build.result, model.BuildResult.FAILURE) |
| 618 self.assertEqual(build.failure_reason, model.FailureReason.INFRA_FAILURE) | 621 self.assertEqual(build.failure_reason, model.FailureReason.INFRA_FAILURE) |
| 619 self.assertIsNotNone(build.result_details) | 622 self.assertIsNotNone(build.result_details) |
| 620 self.assertIsNone(build.lease_key) | 623 self.assertIsNone(build.lease_key) |
| 621 self.assertIsNotNone(build.complete_time) | 624 self.assertIsNotNone(build.complete_time) |
| 622 | 625 |
| 623 | 626 |
| 624 def b64json(data): | 627 def b64json(data): |
| 625 return base64.b64encode(json.dumps(data)) | 628 return base64.b64encode(json.dumps(data)) |
| OLD | NEW |