OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright 2013 The LUCI Authors. All rights reserved. | 2 # Copyright 2013 The LUCI Authors. All rights reserved. |
3 # Use of this source code is governed under the Apache License, Version 2.0 | 3 # Use of this source code is governed under the Apache License, Version 2.0 |
4 # that can be found in the LICENSE file. | 4 # that can be found in the LICENSE file. |
5 | 5 |
6 import copy | 6 import copy |
7 import json | 7 import json |
8 import logging | 8 import logging |
9 import os | 9 import os |
10 import sys | 10 import sys |
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
303 ('Host is stuck rebooting for: Starting new swarming bot: %s\n' | 303 ('Host is stuck rebooting for: Starting new swarming bot: %s\n' |
304 'Calling stack:\nfake stack') % bot_main.THIS_FILE, | 304 'Calling stack:\nfake stack') % bot_main.THIS_FILE, |
305 ] | 305 ] |
306 self.assertEqual(expected, [i[0][2] for i in post_event]) | 306 self.assertEqual(expected, [i[0][2] for i in post_event]) |
307 | 307 |
308 def test_post_error_task(self): | 308 def test_post_error_task(self): |
309 self.mock(time, 'time', lambda: 126.0) | 309 self.mock(time, 'time', lambda: 126.0) |
310 self.mock(logging, 'error', lambda *_, **_kw: None) | 310 self.mock(logging, 'error', lambda *_, **_kw: None) |
311 self.mock( | 311 self.mock( |
312 bot_main, 'get_config', | 312 bot_main, 'get_config', |
313 lambda: {'server': self.url, 'server_version': '1', 'is_grpc': False}) | 313 lambda: {'server': self.url, 'server_version': '1'}) |
314 expected_attribs = bot_main.get_attributes(None) | 314 expected_attribs = bot_main.get_attributes(None) |
315 self.expected_requests( | 315 self.expected_requests( |
316 [ | 316 [ |
317 ( | 317 ( |
318 'https://localhost:1/swarming/api/v1/bot/task_error/23', | 318 'https://localhost:1/swarming/api/v1/bot/task_error/23', |
319 { | 319 { |
320 'data': { | 320 'data': { |
321 'id': expected_attribs['dimensions']['id'][0], | 321 'id': expected_attribs['dimensions']['id'][0], |
322 'message': 'error', | 322 'message': 'error', |
323 'task_id': 23, | 323 'task_id': 23, |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
399 botobj = [None] | 399 botobj = [None] |
400 def get_bot(config): | 400 def get_bot(config): |
401 botobj[0] = orig(config) | 401 botobj[0] = orig(config) |
402 return botobj[0] | 402 return botobj[0] |
403 self.mock(bot_main, 'get_bot', get_bot) | 403 self.mock(bot_main, 'get_bot', get_bot) |
404 | 404 |
405 self.mock( | 405 self.mock( |
406 bot_main, 'get_config', | 406 bot_main, 'get_config', |
407 lambda: { | 407 lambda: { |
408 'enable_ts_monitoring': False, | 408 'enable_ts_monitoring': False, |
409 'is_grpc': False, | |
410 'server': self.url, | 409 'server': self.url, |
411 'server_version': '1', | 410 'server_version': '1', |
412 }) | 411 }) |
413 self.mock( | 412 self.mock( |
414 bot_main, '_get_dimensions', lambda _: self.attributes['dimensions']) | 413 bot_main, '_get_dimensions', lambda _: self.attributes['dimensions']) |
415 self.mock(os_utilities, 'get_state', lambda *_: self.attributes['state']) | 414 self.mock(os_utilities, 'get_state', lambda *_: self.attributes['state']) |
416 | 415 |
417 # pylint: disable=unused-argument | 416 # pylint: disable=unused-argument |
418 class Popen(object): | 417 class Popen(object): |
419 def __init__( | 418 def __init__( |
(...skipping 506 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
926 self.assertEqual([[bot_main.THIS_FILE, 'start_slave', '--survive']], calls) | 925 self.assertEqual([[bot_main.THIS_FILE, 'start_slave', '--survive']], calls) |
927 | 926 |
928 | 927 |
929 if __name__ == '__main__': | 928 if __name__ == '__main__': |
930 fix_encoding.fix_encoding() | 929 fix_encoding.fix_encoding() |
931 if '-v' in sys.argv: | 930 if '-v' in sys.argv: |
932 TestBotMain.maxDiff = None | 931 TestBotMain.maxDiff = None |
933 logging.basicConfig( | 932 logging.basicConfig( |
934 level=logging.DEBUG if '-v' in sys.argv else logging.CRITICAL) | 933 level=logging.DEBUG if '-v' in sys.argv else logging.CRITICAL) |
935 unittest.main() | 934 unittest.main() |
OLD | NEW |