Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(190)

Side by Side Diff: client/run_isolated.py

Issue 2663023004: swarming: delete named cache symlinks before workdir (Closed)
Patch Set: pylint Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « client/named_cache.py ('k') | client/tests/run_isolated_test.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright 2012 The LUCI Authors. All rights reserved. 2 # Copyright 2012 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 """Runs a command with optional isolated input/output. 6 """Runs a command with optional isolated input/output.
7 7
8 Despite name "run_isolated", can run a generic non-isolated command specified as 8 Despite name "run_isolated", can run a generic non-isolated command specified as
9 args. 9 args.
10 10
(...skipping 472 matching lines...) Expand 10 before | Expand all | Expand 10 after
483 483
484 # If we have an explicit list of files to return, make sure their 484 # If we have an explicit list of files to return, make sure their
485 # directories exist now. 485 # directories exist now.
486 if storage and outputs: 486 if storage and outputs:
487 isolateserver.create_directories(run_dir, outputs) 487 isolateserver.create_directories(run_dir, outputs)
488 488
489 command = tools.fix_python_path(command) 489 command = tools.fix_python_path(command)
490 command = process_command(command, out_dir, bot_file) 490 command = process_command(command, out_dir, bot_file)
491 file_path.ensure_command_has_abs_path(command, cwd) 491 file_path.ensure_command_has_abs_path(command, cwd)
492 492
493 init_named_caches(run_dir) 493 with init_named_caches(run_dir):
494 494 sys.stdout.flush()
495 sys.stdout.flush() 495 start = time.time()
496 start = time.time() 496 try:
497 try: 497 result['exit_code'], result['had_hard_timeout'] = run_command(
498 result['exit_code'], result['had_hard_timeout'] = run_command( 498 command, cwd, get_command_env(tmp_dir, cipd_info),
499 command, cwd, get_command_env(tmp_dir, cipd_info), 499 hard_timeout, grace_period)
500 hard_timeout, grace_period) 500 finally:
501 finally: 501 result['duration'] = max(time.time() - start, 0)
502 result['duration'] = max(time.time() - start, 0)
503 except Exception as e: 502 except Exception as e:
504 # An internal error occurred. Report accordingly so the swarming task will 503 # An internal error occurred. Report accordingly so the swarming task will
505 # be retried automatically. 504 # be retried automatically.
506 logging.exception('internal failure: %s', e) 505 logging.exception('internal failure: %s', e)
507 result['internal_failure'] = str(e) 506 result['internal_failure'] = str(e)
508 on_error.report(None) 507 on_error.report(None)
509 508
510 # Clean up 509 # Clean up
511 finally: 510 finally:
512 try: 511 try:
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
591 isolated_hash: the SHA-1 of the .isolated file that must be retrieved to 590 isolated_hash: the SHA-1 of the .isolated file that must be retrieved to
592 recreate the tree of files to run the target executable. 591 recreate the tree of files to run the target executable.
593 The command specified in the .isolated is executed. 592 The command specified in the .isolated is executed.
594 Mutually exclusive with command argument. 593 Mutually exclusive with command argument.
595 storage: an isolateserver.Storage object to retrieve remote objects. This 594 storage: an isolateserver.Storage object to retrieve remote objects. This
596 object has a reference to an isolateserver.StorageApi, which does 595 object has a reference to an isolateserver.StorageApi, which does
597 the actual I/O. 596 the actual I/O.
598 isolate_cache: an isolateserver.LocalCache to keep from retrieving the 597 isolate_cache: an isolateserver.LocalCache to keep from retrieving the
599 same objects constantly by caching the objects retrieved. 598 same objects constantly by caching the objects retrieved.
600 Can be on-disk or in-memory. 599 Can be on-disk or in-memory.
601 init_named_caches: a function (run_dir) => void that creates symlinks for 600 init_named_caches: a function (run_dir) => context manager that creates
602 named caches in |run_dir|. 601 symlinks for named caches in |run_dir|.
603 leak_temp_dir: if true, the temporary directory will be deliberately leaked 602 leak_temp_dir: if true, the temporary directory will be deliberately leaked
604 for later examination. 603 for later examination.
605 result_json: file path to dump result metadata into. If set, the process 604 result_json: file path to dump result metadata into. If set, the process
606 exit code is always 0 unless an internal error occurred. 605 exit code is always 0 unless an internal error occurred.
607 root_dir: path to the directory to use to create the temporary directory. If 606 root_dir: path to the directory to use to create the temporary directory. If
608 not specified, a random temporary directory is created. 607 not specified, a random temporary directory is created.
609 hard_timeout: kills the process if it lasts more than this amount of 608 hard_timeout: kills the process if it lasts more than this amount of
610 seconds. 609 seconds.
611 grace_period: number of seconds to wait between SIGTERM and SIGKILL. 610 grace_period: number of seconds to wait between SIGTERM and SIGKILL.
612 extra_args: optional arguments to add to the command stated in the .isolate 611 extra_args: optional arguments to add to the command stated in the .isolate
(...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after
954 953
955 cipd.validate_cipd_options(parser, options) 954 cipd.validate_cipd_options(parser, options)
956 955
957 install_packages_fn = noop_install_packages 956 install_packages_fn = noop_install_packages
958 if options.cipd_enabled: 957 if options.cipd_enabled:
959 install_packages_fn = lambda run_dir: install_packages( 958 install_packages_fn = lambda run_dir: install_packages(
960 run_dir, cipd.parse_package_args(options.cipd_packages), 959 run_dir, cipd.parse_package_args(options.cipd_packages),
961 options.cipd_server, options.cipd_client_package, 960 options.cipd_server, options.cipd_client_package,
962 options.cipd_client_version, cache_dir=options.cipd_cache) 961 options.cipd_client_version, cache_dir=options.cipd_cache)
963 962
963 @contextlib.contextmanager
964 def init_named_caches(run_dir): 964 def init_named_caches(run_dir):
965 # WARNING: this function depends on "options" variable defined in the outer
966 # function.
965 with named_cache_manager.open(): 967 with named_cache_manager.open():
966 named_cache_manager.create_symlinks(run_dir, options.named_caches) 968 named_cache_manager.create_symlinks(run_dir, options.named_caches)
969 try:
970 yield
971 finally:
972 if not options.leak_temp_dir:
973 named_cache_manager.delete_symlinks(run_dir, options.named_caches)
967 974
968 try: 975 try:
969 command = [] if options.isolated else args 976 command = [] if options.isolated else args
970 if options.isolate_server: 977 if options.isolate_server:
971 storage = isolateserver.get_storage( 978 storage = isolateserver.get_storage(
972 options.isolate_server, options.namespace) 979 options.isolate_server, options.namespace)
973 with storage: 980 with storage:
974 # Hashing schemes used by |storage| and |isolate_cache| MUST match. 981 # Hashing schemes used by |storage| and |isolate_cache| MUST match.
975 assert storage.hash_algo == isolate_cache.hash_algo 982 assert storage.hash_algo == isolate_cache.hash_algo
976 return run_tha_test( 983 return run_tha_test(
(...skipping 30 matching lines...) Expand all
1007 return 1 1014 return 1
1008 1015
1009 1016
1010 if __name__ == '__main__': 1017 if __name__ == '__main__':
1011 subprocess42.inhibit_os_error_reporting() 1018 subprocess42.inhibit_os_error_reporting()
1012 # Ensure that we are always running with the correct encoding. 1019 # Ensure that we are always running with the correct encoding.
1013 fix_encoding.fix_encoding() 1020 fix_encoding.fix_encoding()
1014 file_path.enable_symlink() 1021 file_path.enable_symlink()
1015 1022
1016 sys.exit(main(sys.argv[1:])) 1023 sys.exit(main(sys.argv[1:]))
OLDNEW
« no previous file with comments | « client/named_cache.py ('k') | client/tests/run_isolated_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698