Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 # coding: utf-8 | |
| 1 # Copyright 2014 The LUCI Authors. All rights reserved. | 2 # Copyright 2014 The LUCI Authors. All rights reserved. |
| 2 # 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 |
| 3 # that can be found in the LICENSE file. | 4 # that can be found in the LICENSE file. |
| 4 | 5 |
| 5 """OS specific utility functions. | 6 """OS specific utility functions. |
| 6 | 7 |
| 7 Includes code: | 8 Includes code: |
| 8 - to declare the current system this code is running under. | 9 - to declare the current system this code is running under. |
| 9 - to run a command on user login. | 10 - to run a command on user login. |
| 10 - to reboot the host. | 11 - to reboot the host. |
| (...skipping 496 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 507 if sys.platform == 'darwin': | 508 if sys.platform == 'darwin': |
| 508 return platforms.osx.get_uptime() | 509 return platforms.osx.get_uptime() |
| 509 if sys.platform == 'win32': | 510 if sys.platform == 'win32': |
| 510 return platforms.win.get_uptime() | 511 return platforms.win.get_uptime() |
| 511 if sys.platform == 'cygwin': | 512 if sys.platform == 'cygwin': |
| 512 # Not important. | 513 # Not important. |
| 513 return 0. | 514 return 0. |
| 514 return platforms.linux.get_uptime() | 515 return platforms.linux.get_uptime() |
| 515 | 516 |
| 516 | 517 |
| 518 def get_named_caches(): | |
| 519 """Returns the list of named caches.""" | |
| 520 # Strictly speaking, this is a layering violation. This data is managed by | |
| 521 # run_isolated.py but this is valuable to expose this as a Swarming bot | |
| 522 # dimensions so ¯\_(ツ)_/¯ | |
| 523 # | |
| 524 # Assumptions: | |
| 525 # - ../__main__.py calls os.chdir(__file__) | |
| 526 # - ../bot_code/bot_main.py specifies | |
| 527 # --named-cache-root os.path.join(botobj.base_dir, 'c') to run_isolated. | |
| 528 # - ../client/named_cache.py behavior | |
| 529 # | |
| 530 # A better implementation would require: | |
| 531 # - Access to bot.Bot instance to query bot.base_dir | |
| 532 # - Access to named_cache.py to load state.json | |
| 533 # - Access to --named-cache-root hardcoded in bot_main.py | |
| 534 # | |
| 535 # but hey, the following code is 4 lines... | |
| 536 d = os.path.join(os.getcwd(), u'c', u'named') | |
|
nodir
2017/05/31 16:52:06
"named" symlinks are best effort. Better not to pu
M-A Ruel
2017/05/31 20:45:32
Then maybe we shouldn't create them. :/
Either we
nodir
2017/05/31 21:03:21
we keep them for troopers and alike. My point is t
| |
| 537 if not os.path.isdir(d): | |
| 538 return [] | |
| 539 return [i for i in os.listdir(d)] | |
| 540 | |
| 541 | |
| 517 class AuthenticatedHttpRequestFailure(Exception): | 542 class AuthenticatedHttpRequestFailure(Exception): |
| 518 pass | 543 pass |
| 519 | 544 |
| 520 | 545 |
| 521 def authenticated_http_request(service_account, *args, **kwargs): | 546 def authenticated_http_request(service_account, *args, **kwargs): |
| 522 """Sends an OAuth2-authenticated HTTP request. | 547 """Sends an OAuth2-authenticated HTTP request. |
| 523 | 548 |
| 524 Args: | 549 Args: |
| 525 service_account: Service account to use. For GCE, the name of the service | 550 service_account: Service account to use. For GCE, the name of the service |
| 526 account, otherwise the path to the service account JSON file. | 551 account, otherwise the path to the service account JSON file. |
| (...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 842 u'cores': [unicode(get_num_processors())], | 867 u'cores': [unicode(get_num_processors())], |
| 843 u'cpu': [ | 868 u'cpu': [ |
| 844 cpu_type, | 869 cpu_type, |
| 845 cpu_type + u'-' + cpu_bitness, | 870 cpu_type + u'-' + cpu_bitness, |
| 846 ], | 871 ], |
| 847 u'gpu': get_gpu()[0], | 872 u'gpu': get_gpu()[0], |
| 848 u'id': [get_hostname_short()], | 873 u'id': [get_hostname_short()], |
| 849 u'os': [os_name], | 874 u'os': [os_name], |
| 850 u'pool': [u'default'], | 875 u'pool': [u'default'], |
| 851 } | 876 } |
| 877 caches = get_named_caches() | |
| 878 if caches: | |
| 879 dimensions[u'caches'] = caches | |
| 852 if u'avx2' in cpuinfo.get(u'flags', []): | 880 if u'avx2' in cpuinfo.get(u'flags', []): |
| 853 dimensions[u'cpu'].append(cpu_type + u'-' + cpu_bitness + u'-avx2') | 881 dimensions[u'cpu'].append(cpu_type + u'-' + cpu_bitness + u'-avx2') |
| 854 if any(u'avx512' in x for x in cpuinfo.get(u'flags', [])): | 882 if any(u'avx512' in x for x in cpuinfo.get(u'flags', [])): |
| 855 dimensions[u'cpu'].append(cpu_type + u'-' + cpu_bitness + u'-avx512') | 883 dimensions[u'cpu'].append(cpu_type + u'-' + cpu_bitness + u'-avx512') |
| 856 if sys.platform == 'win32': | 884 if sys.platform == 'win32': |
| 857 dimensions[u'os'].extend( | 885 dimensions[u'os'].extend( |
| 858 u'%s-%s' % (os_name, n) for n in platforms.win.get_os_version_names()) | 886 u'%s-%s' % (os_name, n) for n in platforms.win.get_os_version_names()) |
| 859 else: | 887 else: |
| 860 dimensions[u'os'].append(u'%s-%s' % (os_name, get_os_version_number())) | 888 dimensions[u'os'].append(u'%s-%s' % (os_name, get_os_version_number())) |
| 861 if u'none' not in dimensions[u'gpu']: | 889 if u'none' not in dimensions[u'gpu']: |
| (...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1204 | 1232 |
| 1205 | 1233 |
| 1206 def trim_rolled_log(name): | 1234 def trim_rolled_log(name): |
| 1207 try: | 1235 try: |
| 1208 for item in glob.iglob('%s.??' % name): | 1236 for item in glob.iglob('%s.??' % name): |
| 1209 os.remove(item) | 1237 os.remove(item) |
| 1210 for item in glob.iglob('%s.???' % name): | 1238 for item in glob.iglob('%s.???' % name): |
| 1211 os.remove(item) | 1239 os.remove(item) |
| 1212 except Exception as e: | 1240 except Exception as e: |
| 1213 logging.exception('trim_rolled_log(%s) failed: %s', name, e) | 1241 logging.exception('trim_rolled_log(%s) failed: %s', name, e) |
| OLD | NEW |