| OLD | NEW |
| 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 logging | 9 import logging |
| 10 import os | 10 import os |
| (...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 236 # Enqueue a task. | 236 # Enqueue a task. |
| 237 _, task_id = self.client_create_task_raw() | 237 _, task_id = self.client_create_task_raw() |
| 238 self.assertEqual('0', task_id[-1]) | 238 self.assertEqual('0', task_id[-1]) |
| 239 # Convert TaskResultSummary reference to TaskRunResult. | 239 # Convert TaskResultSummary reference to TaskRunResult. |
| 240 task_id = task_id[:-1] + '1' | 240 task_id = task_id[:-1] + '1' |
| 241 response = self.post_with_token('/swarming/api/v1/bot/poll', params, token) | 241 response = self.post_with_token('/swarming/api/v1/bot/poll', params, token) |
| 242 expected = { | 242 expected = { |
| 243 u'cmd': u'run', | 243 u'cmd': u'run', |
| 244 u'manifest': { | 244 u'manifest': { |
| 245 u'bot_id': u'bot1', | 245 u'bot_id': u'bot1', |
| 246 u'cipd_input': { |
| 247 u'client_package': { |
| 248 u'package_name': 'infra/tools/cipd/${platform}', |
| 249 u'version': 'git_revision:deadbeef', |
| 250 }, |
| 251 u'packages': [{ |
| 252 u'package_name': u'rm', |
| 253 u'version': 'git_revision:deadbeef', |
| 254 }], |
| 255 u'server': 'https://chrome-infra-packages.appspot.com', |
| 256 }, |
| 246 u'command': [u'python', u'run_test.py'], | 257 u'command': [u'python', u'run_test.py'], |
| 247 u'dimensions': { | 258 u'dimensions': { |
| 248 u'os': u'Amiga', | 259 u'os': u'Amiga', |
| 249 u'pool': u'default', | 260 u'pool': u'default', |
| 250 }, | 261 }, |
| 251 u'env': {}, | 262 u'env': {}, |
| 252 u'extra_args': [], | 263 u'extra_args': [], |
| 253 u'grace_period': 30, | 264 u'grace_period': 30, |
| 254 u'hard_timeout': 3600, | 265 u'hard_timeout': 3600, |
| 255 u'host': u'http://localhost:8080', | 266 u'host': u'http://localhost:8080', |
| 256 u'isolated': None, | 267 u'isolated': None, |
| 257 u'io_timeout': 1200, | 268 u'io_timeout': 1200, |
| 258 u'packages': [{ | |
| 259 u'package_name': u'rm', | |
| 260 u'version': test_env_handlers.PINNED_PACKAGE_VERSION, | |
| 261 }], | |
| 262 u'task_id': task_id, | 269 u'task_id': task_id, |
| 263 }, | 270 }, |
| 264 } | 271 } |
| 265 self.assertEqual(expected, response) | 272 self.assertEqual(expected, response) |
| 266 response = self.client_get_results(task_id) | 273 response = self.client_get_results(task_id) |
| 267 expected = { | 274 expected = { |
| 268 u'bot_dimensions': [ | 275 u'bot_dimensions': [ |
| 269 {u'key': u'id', u'value': [u'bot1']}, | 276 {u'key': u'id', u'value': [u'bot1']}, |
| 270 {u'key': u'os', u'value': [u'Amiga']}, | 277 {u'key': u'os', u'value': [u'Amiga']}, |
| 271 {u'key': u'pool', u'value': [u'default']}, | 278 {u'key': u'pool', u'value': [u'default']}, |
| (...skipping 25 matching lines...) Expand all Loading... |
| 297 # Enqueue a task. | 304 # Enqueue a task. |
| 298 _, task_id = self.client_create_task_isolated() | 305 _, task_id = self.client_create_task_isolated() |
| 299 self.assertEqual('0', task_id[-1]) | 306 self.assertEqual('0', task_id[-1]) |
| 300 # Convert TaskResultSummary reference to TaskRunResult. | 307 # Convert TaskResultSummary reference to TaskRunResult. |
| 301 task_id = task_id[:-1] + '1' | 308 task_id = task_id[:-1] + '1' |
| 302 response = self.post_with_token('/swarming/api/v1/bot/poll', params, token) | 309 response = self.post_with_token('/swarming/api/v1/bot/poll', params, token) |
| 303 expected = { | 310 expected = { |
| 304 u'cmd': u'run', | 311 u'cmd': u'run', |
| 305 u'manifest': { | 312 u'manifest': { |
| 306 u'bot_id': u'bot1', | 313 u'bot_id': u'bot1', |
| 314 u'cipd_input': { |
| 315 u'client_package': { |
| 316 u'package_name': 'infra/tools/cipd/${platform}', |
| 317 u'version': 'git_revision:deadbeef', |
| 318 }, |
| 319 u'packages': [{ |
| 320 u'package_name': u'rm', |
| 321 u'version': 'git_revision:deadbeef', |
| 322 }], |
| 323 u'server': 'https://chrome-infra-packages.appspot.com', |
| 324 }, |
| 307 u'command': None, | 325 u'command': None, |
| 308 u'dimensions': { | 326 u'dimensions': { |
| 309 u'os': u'Amiga', | 327 u'os': u'Amiga', |
| 310 u'pool': u'default', | 328 u'pool': u'default', |
| 311 }, | 329 }, |
| 312 u'env': {}, | 330 u'env': {}, |
| 313 u'extra_args': [], | 331 u'extra_args': [], |
| 314 u'hard_timeout': 3600, | 332 u'hard_timeout': 3600, |
| 315 u'grace_period': 30, | 333 u'grace_period': 30, |
| 316 u'host': u'http://localhost:8080', | 334 u'host': u'http://localhost:8080', |
| 317 u'isolated': { | 335 u'isolated': { |
| 318 u'input': u'0123456789012345678901234567890123456789', | 336 u'input': u'0123456789012345678901234567890123456789', |
| 319 u'server': u'http://localhost:1', | 337 u'server': u'http://localhost:1', |
| 320 u'namespace': u'default-gzip', | 338 u'namespace': u'default-gzip', |
| 321 }, | 339 }, |
| 322 u'io_timeout': 1200, | 340 u'io_timeout': 1200, |
| 323 u'packages': [{ | |
| 324 u'package_name': u'rm', | |
| 325 u'version': test_env_handlers.PINNED_PACKAGE_VERSION, | |
| 326 }], | |
| 327 u'task_id': task_id, | 341 u'task_id': task_id, |
| 328 }, | 342 }, |
| 329 } | 343 } |
| 330 self.assertEqual(expected, response) | 344 self.assertEqual(expected, response) |
| 331 | 345 |
| 332 # Complete the isolated task. | 346 # Complete the isolated task. |
| 333 params = { | 347 params = { |
| 334 'cost_usd': 0.1, | 348 'cost_usd': 0.1, |
| 335 'duration': 3., | 349 'duration': 3., |
| 336 'bot_overhead': 0.1, | 350 'bot_overhead': 0.1, |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 418 token, params = self.get_bot_token() | 432 token, params = self.get_bot_token() |
| 419 params['state']['lease_expiration_ts'] = ( | 433 params['state']['lease_expiration_ts'] = ( |
| 420 int(utils.time_time()) + 3600 + 1200 + 3 * 30 + 10 + 1) | 434 int(utils.time_time()) + 3600 + 1200 + 3 * 30 + 10 + 1) |
| 421 response = self.post_with_token('/swarming/api/v1/bot/poll', params, token) | 435 response = self.post_with_token('/swarming/api/v1/bot/poll', params, token) |
| 422 # Convert TaskResultSummary reference to TaskRunResult. | 436 # Convert TaskResultSummary reference to TaskRunResult. |
| 423 task_id = task_id[:-1] + '1' | 437 task_id = task_id[:-1] + '1' |
| 424 expected = { | 438 expected = { |
| 425 u'cmd': u'run', | 439 u'cmd': u'run', |
| 426 u'manifest': { | 440 u'manifest': { |
| 427 u'bot_id': u'bot1', | 441 u'bot_id': u'bot1', |
| 442 u'cipd_input': { |
| 443 u'client_package': { |
| 444 u'package_name': 'infra/tools/cipd/${platform}', |
| 445 u'version': 'git_revision:deadbeef', |
| 446 }, |
| 447 u'packages': [{ |
| 448 u'package_name': u'rm', |
| 449 u'version': 'git_revision:deadbeef', |
| 450 }], |
| 451 u'server': 'https://chrome-infra-packages.appspot.com', |
| 452 }, |
| 428 u'command': None, | 453 u'command': None, |
| 429 u'dimensions': { | 454 u'dimensions': { |
| 430 u'os': u'Amiga', | 455 u'os': u'Amiga', |
| 431 u'pool': u'default', | 456 u'pool': u'default', |
| 432 }, | 457 }, |
| 433 u'env': {}, | 458 u'env': {}, |
| 434 u'extra_args': [], | 459 u'extra_args': [], |
| 435 u'hard_timeout': 3600, | 460 u'hard_timeout': 3600, |
| 436 u'grace_period': 30, | 461 u'grace_period': 30, |
| 437 u'host': u'http://localhost:8080', | 462 u'host': u'http://localhost:8080', |
| 438 u'isolated': { | 463 u'isolated': { |
| 439 u'input': u'0123456789012345678901234567890123456789', | 464 u'input': u'0123456789012345678901234567890123456789', |
| 440 u'server': u'http://localhost:1', | 465 u'server': u'http://localhost:1', |
| 441 u'namespace': u'default-gzip', | 466 u'namespace': u'default-gzip', |
| 442 }, | 467 }, |
| 443 u'io_timeout': 1200, | 468 u'io_timeout': 1200, |
| 444 u'packages': [{ | |
| 445 u'package_name': u'rm', | |
| 446 u'version': test_env_handlers.PINNED_PACKAGE_VERSION, | |
| 447 }], | |
| 448 u'task_id': task_id, | 469 u'task_id': task_id, |
| 449 }, | 470 }, |
| 450 } | 471 } |
| 451 self.assertEqual(expected, response) | 472 self.assertEqual(expected, response) |
| 452 | 473 |
| 453 def test_bot_ereporter2_error(self): | 474 def test_bot_ereporter2_error(self): |
| 454 # ereporter2's //client/utils/on_error.py traps unhandled exceptions | 475 # ereporter2's //client/utils/on_error.py traps unhandled exceptions |
| 455 # automatically. | 476 # automatically. |
| 456 self.mock(random, 'getrandbits', lambda _: 0x88) | 477 self.mock(random, 'getrandbits', lambda _: 0x88) |
| 457 errors = [] | 478 errors = [] |
| (...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 874 self.assertEqual(expected, set(z.namelist())) | 895 self.assertEqual(expected, set(z.namelist())) |
| 875 | 896 |
| 876 | 897 |
| 877 if __name__ == '__main__': | 898 if __name__ == '__main__': |
| 878 if '-v' in sys.argv: | 899 if '-v' in sys.argv: |
| 879 unittest.TestCase.maxDiff = None | 900 unittest.TestCase.maxDiff = None |
| 880 logging.basicConfig( | 901 logging.basicConfig( |
| 881 level=logging.DEBUG if '-v' in sys.argv else logging.CRITICAL, | 902 level=logging.DEBUG if '-v' in sys.argv else logging.CRITICAL, |
| 882 format='%(levelname)-7s %(filename)s:%(lineno)3d %(message)s') | 903 format='%(levelname)-7s %(filename)s:%(lineno)3d %(message)s') |
| 883 unittest.main() | 904 unittest.main() |
| OLD | NEW |