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 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
398 orig = bot_main.get_bot | 398 orig = bot_main.get_bot |
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, | |
409 'is_grpc': False, | |
410 'server': self.url, | 408 'server': self.url, |
411 'server_version': '1', | 409 'server_version': '1', |
412 }) | 410 }) |
413 self.mock( | 411 self.mock( |
414 bot_main, '_get_dimensions', lambda _: self.attributes['dimensions']) | 412 bot_main, '_get_dimensions', lambda _: self.attributes['dimensions']) |
415 self.mock(os_utilities, 'get_state', lambda *_: self.attributes['state']) | 413 self.mock(os_utilities, 'get_state', lambda *_: self.attributes['state']) |
416 | 414 |
417 # pylint: disable=unused-argument | 415 # pylint: disable=unused-argument |
418 class Popen(object): | 416 class Popen(object): |
419 def __init__( | 417 def __init__( |
(...skipping 508 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
928 self.assertEqual([[bot_main.THIS_FILE, 'start_slave', '--survive']], calls) | 926 self.assertEqual([[bot_main.THIS_FILE, 'start_slave', '--survive']], calls) |
929 | 927 |
930 | 928 |
931 if __name__ == '__main__': | 929 if __name__ == '__main__': |
932 fix_encoding.fix_encoding() | 930 fix_encoding.fix_encoding() |
933 if '-v' in sys.argv: | 931 if '-v' in sys.argv: |
934 TestBotMain.maxDiff = None | 932 TestBotMain.maxDiff = None |
935 logging.basicConfig( | 933 logging.basicConfig( |
936 level=logging.DEBUG if '-v' in sys.argv else logging.CRITICAL) | 934 level=logging.DEBUG if '-v' in sys.argv else logging.CRITICAL) |
937 unittest.main() | 935 unittest.main() |
OLD | NEW |