blob: 6c69c21eeb63ea8b50f038d07d70153fd59a76b1 [file] [log] [blame]
maruel@chromium.org9c72d4e2012-09-28 19:20:25 +00001#!/usr/bin/env python
maruelea586f32016-04-05 11:11:33 -07002# Copyright 2012 The LUCI Authors. All rights reserved.
maruelf1f5e2a2016-05-25 17:10:39 -07003# Use of this source code is governed under the Apache License, Version 2.0
4# that can be found in the LICENSE file.
maruel@chromium.org9c72d4e2012-09-28 19:20:25 +00005
nodir55be77b2016-05-03 09:39:57 -07006"""Runs a command with optional isolated input/output.
maruel@chromium.org9c72d4e2012-09-28 19:20:25 +00007
nodir55be77b2016-05-03 09:39:57 -07008Despite name "run_isolated", can run a generic non-isolated command specified as
9args.
10
11If input isolated hash is provided, fetches it, creates a tree of hard links,
12appends args to the command in the fetched isolated and runs it.
13To improve performance, keeps a local cache.
14The local cache can safely be deleted.
Marc-Antoine Ruel2283ad12014-02-09 11:14:57 -050015
nodirbe642ff2016-06-09 15:51:51 -070016Any ${EXECUTABLE_SUFFIX} on the command line will be replaced with ".exe" string
17on Windows and "" on other platforms.
18
Marc-Antoine Ruel2283ad12014-02-09 11:14:57 -050019Any ${ISOLATED_OUTDIR} on the command line will be replaced by the location of a
20temporary directory upon execution of the command specified in the .isolated
21file. All content written to this directory will be uploaded upon termination
22and the .isolated file describing this directory will be printed to stdout.
bpastene447c1992016-06-20 15:21:47 -070023
24Any ${SWARMING_BOT_FILE} on the command line will be replaced by the value of
25the --bot-file parameter. This file is used by a swarming bot to communicate
26state of the host to tasks. It is written to by the swarming bot's
27on_before_task() hook in the swarming server's custom bot_config.py.
maruel@chromium.org9c72d4e2012-09-28 19:20:25 +000028"""
29
iannucci96fcccc2016-08-30 15:52:22 -070030__version__ = '0.8.5'
maruel@chromium.orgdedbf492013-09-12 20:42:11 +000031
maruel064c0a32016-04-05 11:47:15 -070032import base64
iannucci96fcccc2016-08-30 15:52:22 -070033import collections
maruel@chromium.org9c72d4e2012-09-28 19:20:25 +000034import logging
35import optparse
36import os
maruel@chromium.org9c72d4e2012-09-28 19:20:25 +000037import sys
38import tempfile
maruel064c0a32016-04-05 11:47:15 -070039import time
maruel@chromium.org9c72d4e2012-09-28 19:20:25 +000040
vadimsh@chromium.orga4326472013-08-24 02:05:41 +000041from third_party.depot_tools import fix_encoding
42
Vadim Shtayura6b555c12014-07-23 16:22:18 -070043from utils import file_path
maruel12e30012015-10-09 11:55:35 -070044from utils import fs
maruel064c0a32016-04-05 11:47:15 -070045from utils import large
Marc-Antoine Ruelf74cffe2015-07-15 15:21:34 -040046from utils import logging_utils
Marc-Antoine Ruelcfb60852014-07-02 15:22:00 -040047from utils import on_error
Marc-Antoine Ruelc44f5722015-01-08 16:10:01 -050048from utils import subprocess42
vadimsh@chromium.orga4326472013-08-24 02:05:41 +000049from utils import tools
vadimsh@chromium.org3e97deb2013-08-24 00:56:44 +000050from utils import zip_package
vadimsh@chromium.org8b9d56b2013-08-21 22:24:35 +000051
Vadim Shtayurae34e13a2014-02-02 11:23:26 -080052import auth
nodirbe642ff2016-06-09 15:51:51 -070053import cipd
maruel@chromium.orgdedbf492013-09-12 20:42:11 +000054import isolateserver
maruel@chromium.orgdedbf492013-09-12 20:42:11 +000055
vadimsh@chromium.orga4326472013-08-24 02:05:41 +000056
vadimsh@chromium.org85071062013-08-21 23:37:45 +000057# Absolute path to this file (can be None if running from zip on Mac).
tansella4949442016-06-23 22:34:32 -070058THIS_FILE_PATH = os.path.abspath(
59 __file__.decode(sys.getfilesystemencoding())) if __file__ else None
vadimsh@chromium.org8b9d56b2013-08-21 22:24:35 +000060
61# Directory that contains this file (might be inside zip package).
tansella4949442016-06-23 22:34:32 -070062BASE_DIR = os.path.dirname(THIS_FILE_PATH) if __file__.decode(
63 sys.getfilesystemencoding()) else None
vadimsh@chromium.org8b9d56b2013-08-21 22:24:35 +000064
65# Directory that contains currently running script file.
maruel@chromium.org814d23f2013-10-01 19:08:00 +000066if zip_package.get_main_script_path():
67 MAIN_DIR = os.path.dirname(
68 os.path.abspath(zip_package.get_main_script_path()))
69else:
70 # This happens when 'import run_isolated' is executed at the python
71 # interactive prompt, in that case __file__ is undefined.
72 MAIN_DIR = None
vadimsh@chromium.org8b9d56b2013-08-21 22:24:35 +000073
maruele2f2cb82016-07-13 14:41:03 -070074
75# Magic variables that can be found in the isolate task command line.
76ISOLATED_OUTDIR_PARAMETER = '${ISOLATED_OUTDIR}'
77EXECUTABLE_SUFFIX_PARAMETER = '${EXECUTABLE_SUFFIX}'
78SWARMING_BOT_FILE_PARAMETER = '${SWARMING_BOT_FILE}'
79
80
csharp@chromium.orgff2a4662012-11-21 20:49:32 +000081# The name of the log file to use.
82RUN_ISOLATED_LOG_FILE = 'run_isolated.log'
83
maruele2f2cb82016-07-13 14:41:03 -070084
csharp@chromium.orge217f302012-11-22 16:51:53 +000085# The name of the log to use for the run_test_cases.py command
vadimsh@chromium.org8b9d56b2013-08-21 22:24:35 +000086RUN_TEST_CASES_LOG = 'run_test_cases.log'
csharp@chromium.orge217f302012-11-22 16:51:53 +000087
vadimsh@chromium.org87d63262013-04-04 19:34:21 +000088
maruele2f2cb82016-07-13 14:41:03 -070089# Use short names for temporary directories. This is driven by Windows, which
90# imposes a relatively short maximum path length of 260 characters, often
91# referred to as MAX_PATH. It is relatively easy to create files with longer
92# path length. A use case is with recursive depedency treesV like npm packages.
93#
94# It is recommended to start the script with a `root_dir` as short as
95# possible.
96# - ir stands for isolated_run
97# - io stands for isolated_out
98# - it stands for isolated_tmp
99ISOLATED_RUN_DIR = u'ir'
100ISOLATED_OUT_DIR = u'io'
101ISOLATED_TMP_DIR = u'it'
102
103
vadimsh@chromium.org8b9d56b2013-08-21 22:24:35 +0000104def get_as_zip_package(executable=True):
105 """Returns ZipPackage with this module and all its dependencies.
106
107 If |executable| is True will store run_isolated.py as __main__.py so that
108 zip package is directly executable be python.
109 """
110 # Building a zip package when running from another zip package is
111 # unsupported and probably unneeded.
112 assert not zip_package.is_zipped_module(sys.modules[__name__])
vadimsh@chromium.org85071062013-08-21 23:37:45 +0000113 assert THIS_FILE_PATH
114 assert BASE_DIR
vadimsh@chromium.org8b9d56b2013-08-21 22:24:35 +0000115 package = zip_package.ZipPackage(root=BASE_DIR)
116 package.add_python_file(THIS_FILE_PATH, '__main__.py' if executable else None)
Marc-Antoine Ruel8bee66d2014-08-28 19:02:07 -0400117 package.add_python_file(os.path.join(BASE_DIR, 'isolated_format.py'))
maruel@chromium.orgdedbf492013-09-12 20:42:11 +0000118 package.add_python_file(os.path.join(BASE_DIR, 'isolateserver.py'))
Vadim Shtayurae34e13a2014-02-02 11:23:26 -0800119 package.add_python_file(os.path.join(BASE_DIR, 'auth.py'))
nodirbe642ff2016-06-09 15:51:51 -0700120 package.add_python_file(os.path.join(BASE_DIR, 'cipd.py'))
tanselle4288c32016-07-28 09:45:40 -0700121 package.add_directory(os.path.join(BASE_DIR, 'libs'))
vadimsh@chromium.org8b9d56b2013-08-21 22:24:35 +0000122 package.add_directory(os.path.join(BASE_DIR, 'third_party'))
123 package.add_directory(os.path.join(BASE_DIR, 'utils'))
124 return package
125
126
maruel03e11842016-07-14 10:50:16 -0700127def make_temp_dir(prefix, root_dir):
128 """Returns a new unique temporary directory."""
129 return unicode(tempfile.mkdtemp(prefix=prefix, dir=root_dir))
maruel@chromium.org9c72d4e2012-09-28 19:20:25 +0000130
131
Marc-Antoine Ruel7124e392014-01-09 11:49:21 -0500132def change_tree_read_only(rootdir, read_only):
133 """Changes the tree read-only bits according to the read_only specification.
134
135 The flag can be 0, 1 or 2, which will affect the possibility to modify files
136 and create or delete files.
137 """
138 if read_only == 2:
139 # Files and directories (except on Windows) are marked read only. This
140 # inhibits modifying, creating or deleting files in the test directory,
141 # except on Windows where creating and deleting files is still possible.
Marc-Antoine Ruele4ad07e2014-10-15 20:22:29 -0400142 file_path.make_tree_read_only(rootdir)
Marc-Antoine Ruel7124e392014-01-09 11:49:21 -0500143 elif read_only == 1:
144 # Files are marked read only but not the directories. This inhibits
145 # modifying files but creating or deleting files is still possible.
Marc-Antoine Ruele4ad07e2014-10-15 20:22:29 -0400146 file_path.make_tree_files_read_only(rootdir)
Marc-Antoine Ruel7124e392014-01-09 11:49:21 -0500147 elif read_only in (0, None):
Marc-Antoine Ruelf1d827c2014-11-24 15:22:25 -0500148 # Anything can be modified.
Marc-Antoine Ruel7124e392014-01-09 11:49:21 -0500149 # TODO(maruel): This is currently dangerous as long as DiskCache.touch()
150 # is not yet changed to verify the hash of the content of the files it is
151 # looking at, so that if a test modifies an input file, the file must be
152 # deleted.
Marc-Antoine Ruele4ad07e2014-10-15 20:22:29 -0400153 file_path.make_tree_writeable(rootdir)
Marc-Antoine Ruel7124e392014-01-09 11:49:21 -0500154 else:
155 raise ValueError(
156 'change_tree_read_only(%s, %s): Unknown flag %s' %
157 (rootdir, read_only, read_only))
158
159
nodir90bc8dc2016-06-15 13:35:21 -0700160def process_command(command, out_dir, bot_file):
nodirbe642ff2016-06-09 15:51:51 -0700161 """Replaces variables in a command line.
162
163 Raises:
164 ValueError if a parameter is requested in |command| but its value is not
165 provided.
166 """
maruela9cfd6f2015-09-15 11:03:15 -0700167 def fix(arg):
nodirbe642ff2016-06-09 15:51:51 -0700168 arg = arg.replace(EXECUTABLE_SUFFIX_PARAMETER, cipd.EXECUTABLE_SUFFIX)
169 replace_slash = False
nodir55be77b2016-05-03 09:39:57 -0700170 if ISOLATED_OUTDIR_PARAMETER in arg:
nodirbe642ff2016-06-09 15:51:51 -0700171 if not out_dir:
maruel7f63a272016-07-12 12:40:36 -0700172 raise ValueError(
173 'output directory is requested in command, but not provided; '
174 'please specify one')
nodir55be77b2016-05-03 09:39:57 -0700175 arg = arg.replace(ISOLATED_OUTDIR_PARAMETER, out_dir)
nodirbe642ff2016-06-09 15:51:51 -0700176 replace_slash = True
nodir90bc8dc2016-06-15 13:35:21 -0700177 if SWARMING_BOT_FILE_PARAMETER in arg:
178 if bot_file:
179 arg = arg.replace(SWARMING_BOT_FILE_PARAMETER, bot_file)
180 replace_slash = True
181 else:
182 logging.warning('SWARMING_BOT_FILE_PARAMETER found in command, but no '
183 'bot_file specified. Leaving parameter unchanged.')
nodirbe642ff2016-06-09 15:51:51 -0700184 if replace_slash:
185 # Replace slashes only if parameters are present
nodir55be77b2016-05-03 09:39:57 -0700186 # because of arguments like '${ISOLATED_OUTDIR}/foo/bar'
187 arg = arg.replace('/', os.sep)
maruela9cfd6f2015-09-15 11:03:15 -0700188 return arg
189
190 return [fix(arg) for arg in command]
191
192
maruel6be7f9e2015-10-01 12:25:30 -0700193def run_command(command, cwd, tmp_dir, hard_timeout, grace_period):
194 """Runs the command.
195
196 Returns:
197 tuple(process exit code, bool if had a hard timeout)
198 """
maruela9cfd6f2015-09-15 11:03:15 -0700199 logging.info('run_command(%s, %s)' % (command, cwd))
marueleb5fbee2015-09-17 13:01:36 -0700200
201 env = os.environ.copy()
202 if sys.platform == 'darwin':
tansella4949442016-06-23 22:34:32 -0700203 env['TMPDIR'] = tmp_dir.encode(sys.getfilesystemencoding())
marueleb5fbee2015-09-17 13:01:36 -0700204 elif sys.platform == 'win32':
tansella4949442016-06-23 22:34:32 -0700205 env['TEMP'] = tmp_dir.encode(sys.getfilesystemencoding())
marueleb5fbee2015-09-17 13:01:36 -0700206 else:
tansella4949442016-06-23 22:34:32 -0700207 env['TMP'] = tmp_dir.encode(sys.getfilesystemencoding())
maruel6be7f9e2015-10-01 12:25:30 -0700208 exit_code = None
209 had_hard_timeout = False
maruela9cfd6f2015-09-15 11:03:15 -0700210 with tools.Profiler('RunTest'):
maruel6be7f9e2015-10-01 12:25:30 -0700211 proc = None
212 had_signal = []
maruela9cfd6f2015-09-15 11:03:15 -0700213 try:
maruel6be7f9e2015-10-01 12:25:30 -0700214 # TODO(maruel): This code is imperfect. It doesn't handle well signals
215 # during the download phase and there's short windows were things can go
216 # wrong.
217 def handler(signum, _frame):
218 if proc and not had_signal:
219 logging.info('Received signal %d', signum)
220 had_signal.append(True)
maruel556d9052015-10-05 11:12:44 -0700221 raise subprocess42.TimeoutExpired(command, None)
maruel6be7f9e2015-10-01 12:25:30 -0700222
223 proc = subprocess42.Popen(command, cwd=cwd, env=env, detached=True)
224 with subprocess42.set_signal_handler(subprocess42.STOP_SIGNALS, handler):
225 try:
226 exit_code = proc.wait(hard_timeout or None)
227 except subprocess42.TimeoutExpired:
228 if not had_signal:
229 logging.warning('Hard timeout')
230 had_hard_timeout = True
231 logging.warning('Sending SIGTERM')
232 proc.terminate()
233
234 # Ignore signals in grace period. Forcibly give the grace period to the
235 # child process.
236 if exit_code is None:
237 ignore = lambda *_: None
238 with subprocess42.set_signal_handler(subprocess42.STOP_SIGNALS, ignore):
239 try:
240 exit_code = proc.wait(grace_period or None)
241 except subprocess42.TimeoutExpired:
242 # Now kill for real. The user can distinguish between the
243 # following states:
244 # - signal but process exited within grace period,
245 # hard_timed_out will be set but the process exit code will be
246 # script provided.
247 # - processed exited late, exit code will be -9 on posix.
248 logging.warning('Grace exhausted; sending SIGKILL')
249 proc.kill()
250 logging.info('Waiting for proces exit')
251 exit_code = proc.wait()
maruela9cfd6f2015-09-15 11:03:15 -0700252 except OSError:
253 # This is not considered to be an internal error. The executable simply
254 # does not exit.
maruela72f46e2016-02-24 11:05:45 -0800255 sys.stderr.write(
256 '<The executable does not exist or a dependent library is missing>\n'
257 '<Check for missing .so/.dll in the .isolate or GN file>\n'
258 '<Command: %s>\n' % command)
259 if os.environ.get('SWARMING_TASK_ID'):
260 # Give an additional hint when running as a swarming task.
261 sys.stderr.write(
262 '<See the task\'s page for commands to help diagnose this issue '
263 'by reproducing the task locally>\n')
maruela9cfd6f2015-09-15 11:03:15 -0700264 exit_code = 1
265 logging.info(
266 'Command finished with exit code %d (%s)',
267 exit_code, hex(0xffffffff & exit_code))
maruel6be7f9e2015-10-01 12:25:30 -0700268 return exit_code, had_hard_timeout
maruela9cfd6f2015-09-15 11:03:15 -0700269
270
maruel4409e302016-07-19 14:25:51 -0700271def fetch_and_map(isolated_hash, storage, cache, outdir, use_symlinks):
272 """Fetches an isolated tree, create the tree and returns (bundle, stats)."""
nodir6f801882016-04-29 14:41:50 -0700273 start = time.time()
274 bundle = isolateserver.fetch_isolated(
275 isolated_hash=isolated_hash,
276 storage=storage,
277 cache=cache,
maruel4409e302016-07-19 14:25:51 -0700278 outdir=outdir,
279 use_symlinks=use_symlinks)
nodir6f801882016-04-29 14:41:50 -0700280 return bundle, {
281 'duration': time.time() - start,
282 'initial_number_items': cache.initial_number_items,
283 'initial_size': cache.initial_size,
284 'items_cold': base64.b64encode(large.pack(sorted(cache.added))),
285 'items_hot': base64.b64encode(
tansell9e04a8d2016-07-28 09:31:59 -0700286 large.pack(sorted(set(cache.used) - set(cache.added)))),
nodir6f801882016-04-29 14:41:50 -0700287 }
288
289
maruela9cfd6f2015-09-15 11:03:15 -0700290def delete_and_upload(storage, out_dir, leak_temp_dir):
291 """Deletes the temporary run directory and uploads results back.
292
293 Returns:
nodir6f801882016-04-29 14:41:50 -0700294 tuple(outputs_ref, success, stats)
maruel064c0a32016-04-05 11:47:15 -0700295 - outputs_ref: a dict referring to the results archived back to the isolated
296 server, if applicable.
297 - success: False if something occurred that means that the task must
298 forcibly be considered a failure, e.g. zombie processes were left
299 behind.
nodir6f801882016-04-29 14:41:50 -0700300 - stats: uploading stats.
maruela9cfd6f2015-09-15 11:03:15 -0700301 """
302
303 # Upload out_dir and generate a .isolated file out of this directory. It is
304 # only done if files were written in the directory.
305 outputs_ref = None
maruel064c0a32016-04-05 11:47:15 -0700306 cold = []
307 hot = []
nodir6f801882016-04-29 14:41:50 -0700308 start = time.time()
309
maruel12e30012015-10-09 11:55:35 -0700310 if fs.isdir(out_dir) and fs.listdir(out_dir):
maruela9cfd6f2015-09-15 11:03:15 -0700311 with tools.Profiler('ArchiveOutput'):
312 try:
maruel064c0a32016-04-05 11:47:15 -0700313 results, f_cold, f_hot = isolateserver.archive_files_to_storage(
maruela9cfd6f2015-09-15 11:03:15 -0700314 storage, [out_dir], None)
315 outputs_ref = {
316 'isolated': results[0][0],
317 'isolatedserver': storage.location,
318 'namespace': storage.namespace,
319 }
maruel064c0a32016-04-05 11:47:15 -0700320 cold = sorted(i.size for i in f_cold)
321 hot = sorted(i.size for i in f_hot)
maruela9cfd6f2015-09-15 11:03:15 -0700322 except isolateserver.Aborted:
323 # This happens when a signal SIGTERM was received while uploading data.
324 # There is 2 causes:
325 # - The task was too slow and was about to be killed anyway due to
326 # exceeding the hard timeout.
327 # - The amount of data uploaded back is very large and took too much
328 # time to archive.
329 sys.stderr.write('Received SIGTERM while uploading')
330 # Re-raise, so it will be treated as an internal failure.
331 raise
nodir6f801882016-04-29 14:41:50 -0700332
333 success = False
maruela9cfd6f2015-09-15 11:03:15 -0700334 try:
maruel12e30012015-10-09 11:55:35 -0700335 if (not leak_temp_dir and fs.isdir(out_dir) and
maruel6eeea7d2015-09-16 12:17:42 -0700336 not file_path.rmtree(out_dir)):
maruela9cfd6f2015-09-15 11:03:15 -0700337 logging.error('Had difficulties removing out_dir %s', out_dir)
nodir6f801882016-04-29 14:41:50 -0700338 else:
339 success = True
maruela9cfd6f2015-09-15 11:03:15 -0700340 except OSError as e:
341 # When this happens, it means there's a process error.
maruel12e30012015-10-09 11:55:35 -0700342 logging.exception('Had difficulties removing out_dir %s: %s', out_dir, e)
nodir6f801882016-04-29 14:41:50 -0700343 stats = {
344 'duration': time.time() - start,
345 'items_cold': base64.b64encode(large.pack(cold)),
346 'items_hot': base64.b64encode(large.pack(hot)),
347 }
348 return outputs_ref, success, stats
maruela9cfd6f2015-09-15 11:03:15 -0700349
350
marueleb5fbee2015-09-17 13:01:36 -0700351def map_and_run(
nodir55be77b2016-05-03 09:39:57 -0700352 command, isolated_hash, storage, cache, leak_temp_dir, root_dir,
maruel4409e302016-07-19 14:25:51 -0700353 hard_timeout, grace_period, bot_file, extra_args, install_packages_fn,
354 use_symlinks):
nodir55be77b2016-05-03 09:39:57 -0700355 """Runs a command with optional isolated input/output.
356
357 See run_tha_test for argument documentation.
358
359 Returns metadata about the result.
360 """
361 assert bool(command) ^ bool(isolated_hash)
maruela9cfd6f2015-09-15 11:03:15 -0700362 result = {
maruel064c0a32016-04-05 11:47:15 -0700363 'duration': None,
maruela9cfd6f2015-09-15 11:03:15 -0700364 'exit_code': None,
maruel6be7f9e2015-10-01 12:25:30 -0700365 'had_hard_timeout': False,
maruela9cfd6f2015-09-15 11:03:15 -0700366 'internal_failure': None,
maruel064c0a32016-04-05 11:47:15 -0700367 'stats': {
nodir55715712016-06-03 12:28:19 -0700368 # 'isolated': {
nodirbe642ff2016-06-09 15:51:51 -0700369 # 'cipd': {
370 # 'duration': 0.,
371 # 'get_client_duration': 0.,
372 # },
nodir55715712016-06-03 12:28:19 -0700373 # 'download': {
374 # 'duration': 0.,
375 # 'initial_number_items': 0,
376 # 'initial_size': 0,
377 # 'items_cold': '<large.pack()>',
378 # 'items_hot': '<large.pack()>',
379 # },
380 # 'upload': {
381 # 'duration': 0.,
382 # 'items_cold': '<large.pack()>',
383 # 'items_hot': '<large.pack()>',
384 # },
maruel064c0a32016-04-05 11:47:15 -0700385 # },
386 },
iannucci96fcccc2016-08-30 15:52:22 -0700387 # 'cipd_pins': {
388 # 'packages': [
389 # {'package_name': ..., 'version': ..., 'path': ...},
390 # ...
391 # ],
392 # 'client_package': {'package_name': ..., 'version': ...},
393 # },
maruela9cfd6f2015-09-15 11:03:15 -0700394 'outputs_ref': None,
nodirbe642ff2016-06-09 15:51:51 -0700395 'version': 5,
maruela9cfd6f2015-09-15 11:03:15 -0700396 }
nodirbe642ff2016-06-09 15:51:51 -0700397
marueleb5fbee2015-09-17 13:01:36 -0700398 if root_dir:
nodire5028a92016-04-29 14:38:21 -0700399 file_path.ensure_tree(root_dir, 0700)
marueleb5fbee2015-09-17 13:01:36 -0700400 else:
maruel2e8d0f52016-07-16 07:51:29 -0700401 root_dir = os.path.dirname(cache.cache_dir) if cache.cache_dir else None
maruele2f2cb82016-07-13 14:41:03 -0700402 # See comment for these constants.
403 run_dir = make_temp_dir(ISOLATED_RUN_DIR, root_dir)
maruel03e11842016-07-14 10:50:16 -0700404 # storage should be normally set but don't crash if it is not. This can happen
405 # as Swarming task can run without an isolate server.
maruele2f2cb82016-07-13 14:41:03 -0700406 out_dir = make_temp_dir(ISOLATED_OUT_DIR, root_dir) if storage else None
407 tmp_dir = make_temp_dir(ISOLATED_TMP_DIR, root_dir)
nodir55be77b2016-05-03 09:39:57 -0700408 cwd = run_dir
maruela9cfd6f2015-09-15 11:03:15 -0700409
nodir55be77b2016-05-03 09:39:57 -0700410 try:
iannucci96fcccc2016-08-30 15:52:22 -0700411 cipd_info = install_packages_fn(run_dir)
412 if cipd_info:
413 result['stats']['cipd'] = cipd_info['stats']
414 result['cipd_pins'] = cipd_info['cipd_pins']
nodir90bc8dc2016-06-15 13:35:21 -0700415
nodir55be77b2016-05-03 09:39:57 -0700416 if isolated_hash:
nodir55715712016-06-03 12:28:19 -0700417 isolated_stats = result['stats'].setdefault('isolated', {})
maruel4409e302016-07-19 14:25:51 -0700418 bundle, isolated_stats['download'] = fetch_and_map(
nodir55be77b2016-05-03 09:39:57 -0700419 isolated_hash=isolated_hash,
420 storage=storage,
421 cache=cache,
maruel4409e302016-07-19 14:25:51 -0700422 outdir=run_dir,
423 use_symlinks=use_symlinks)
nodir55be77b2016-05-03 09:39:57 -0700424 if not bundle.command:
425 # Handle this as a task failure, not an internal failure.
426 sys.stderr.write(
427 '<The .isolated doesn\'t declare any command to run!>\n'
428 '<Check your .isolate for missing \'command\' variable>\n')
429 if os.environ.get('SWARMING_TASK_ID'):
430 # Give an additional hint when running as a swarming task.
431 sys.stderr.write('<This occurs at the \'isolate\' step>\n')
432 result['exit_code'] = 1
433 return result
434
435 change_tree_read_only(run_dir, bundle.read_only)
436 cwd = os.path.normpath(os.path.join(cwd, bundle.relative_cwd))
437 command = bundle.command + extra_args
nodirbe642ff2016-06-09 15:51:51 -0700438
nodir34d673c2016-05-24 09:30:48 -0700439 command = tools.fix_python_path(command)
nodir90bc8dc2016-06-15 13:35:21 -0700440 command = process_command(command, out_dir, bot_file)
maruela9cfd6f2015-09-15 11:03:15 -0700441 file_path.ensure_command_has_abs_path(command, cwd)
nodirbe642ff2016-06-09 15:51:51 -0700442
maruel064c0a32016-04-05 11:47:15 -0700443 sys.stdout.flush()
444 start = time.time()
445 try:
446 result['exit_code'], result['had_hard_timeout'] = run_command(
nodirbe642ff2016-06-09 15:51:51 -0700447 command, cwd, tmp_dir, hard_timeout, grace_period)
maruel064c0a32016-04-05 11:47:15 -0700448 finally:
449 result['duration'] = max(time.time() - start, 0)
maruela9cfd6f2015-09-15 11:03:15 -0700450 except Exception as e:
nodir90bc8dc2016-06-15 13:35:21 -0700451 # An internal error occurred. Report accordingly so the swarming task will
452 # be retried automatically.
maruel12e30012015-10-09 11:55:35 -0700453 logging.exception('internal failure: %s', e)
maruela9cfd6f2015-09-15 11:03:15 -0700454 result['internal_failure'] = str(e)
455 on_error.report(None)
456 finally:
457 try:
458 if leak_temp_dir:
459 logging.warning(
460 'Deliberately leaking %s for later examination', run_dir)
marueleb5fbee2015-09-17 13:01:36 -0700461 else:
maruel84537cb2015-10-16 14:21:28 -0700462 # On Windows rmtree(run_dir) call above has a synchronization effect: it
463 # finishes only when all task child processes terminate (since a running
464 # process locks *.exe file). Examine out_dir only after that call
465 # completes (since child processes may write to out_dir too and we need
466 # to wait for them to finish).
467 if fs.isdir(run_dir):
468 try:
469 success = file_path.rmtree(run_dir)
470 except OSError as e:
471 logging.error('Failure with %s', e)
472 success = False
473 if not success:
474 print >> sys.stderr, (
475 'Failed to delete the run directory, forcibly failing\n'
476 'the task because of it. No zombie process can outlive a\n'
477 'successful task run and still be marked as successful.\n'
478 'Fix your stuff.')
479 if result['exit_code'] == 0:
480 result['exit_code'] = 1
481 if fs.isdir(tmp_dir):
482 try:
483 success = file_path.rmtree(tmp_dir)
484 except OSError as e:
485 logging.error('Failure with %s', e)
486 success = False
487 if not success:
488 print >> sys.stderr, (
489 'Failed to delete the temporary directory, forcibly failing\n'
490 'the task because of it. No zombie process can outlive a\n'
491 'successful task run and still be marked as successful.\n'
492 'Fix your stuff.')
493 if result['exit_code'] == 0:
494 result['exit_code'] = 1
maruela9cfd6f2015-09-15 11:03:15 -0700495
marueleb5fbee2015-09-17 13:01:36 -0700496 # This deletes out_dir if leak_temp_dir is not set.
nodir9130f072016-05-27 13:59:08 -0700497 if out_dir:
nodir55715712016-06-03 12:28:19 -0700498 isolated_stats = result['stats'].setdefault('isolated', {})
499 result['outputs_ref'], success, isolated_stats['upload'] = (
nodir9130f072016-05-27 13:59:08 -0700500 delete_and_upload(storage, out_dir, leak_temp_dir))
maruela9cfd6f2015-09-15 11:03:15 -0700501 if not success and result['exit_code'] == 0:
502 result['exit_code'] = 1
503 except Exception as e:
504 # Swallow any exception in the main finally clause.
nodir9130f072016-05-27 13:59:08 -0700505 if out_dir:
506 logging.exception('Leaking out_dir %s: %s', out_dir, e)
maruela9cfd6f2015-09-15 11:03:15 -0700507 result['internal_failure'] = str(e)
508 return result
Marc-Antoine Ruel2283ad12014-02-09 11:14:57 -0500509
510
Marc-Antoine Ruel0ec868b2015-08-12 14:12:46 -0400511def run_tha_test(
nodir55be77b2016-05-03 09:39:57 -0700512 command, isolated_hash, storage, cache, leak_temp_dir, result_json,
bpastene3ae09522016-06-10 17:12:59 -0700513 root_dir, hard_timeout, grace_period, bot_file, extra_args,
maruel4409e302016-07-19 14:25:51 -0700514 install_packages_fn, use_symlinks):
nodir55be77b2016-05-03 09:39:57 -0700515 """Runs an executable and records execution metadata.
516
517 Either command or isolated_hash must be specified.
518
519 If isolated_hash is specified, downloads the dependencies in the cache,
520 hardlinks them into a temporary directory and runs the command specified in
521 the .isolated.
Marc-Antoine Ruel2283ad12014-02-09 11:14:57 -0500522
523 A temporary directory is created to hold the output files. The content inside
524 this directory will be uploaded back to |storage| packaged as a .isolated
525 file.
526
527 Arguments:
nodir55be77b2016-05-03 09:39:57 -0700528 command: the command to run, a list of strings. Mutually exclusive with
529 isolated_hash.
Marc-Antoine Ruel35b58432014-12-08 17:40:40 -0500530 isolated_hash: the SHA-1 of the .isolated file that must be retrieved to
Marc-Antoine Ruel2283ad12014-02-09 11:14:57 -0500531 recreate the tree of files to run the target executable.
nodir55be77b2016-05-03 09:39:57 -0700532 The command specified in the .isolated is executed.
533 Mutually exclusive with command argument.
Marc-Antoine Ruel2283ad12014-02-09 11:14:57 -0500534 storage: an isolateserver.Storage object to retrieve remote objects. This
535 object has a reference to an isolateserver.StorageApi, which does
536 the actual I/O.
537 cache: an isolateserver.LocalCache to keep from retrieving the same objects
538 constantly by caching the objects retrieved. Can be on-disk or
539 in-memory.
Kenneth Russell61d42352014-09-15 11:41:16 -0700540 leak_temp_dir: if true, the temporary directory will be deliberately leaked
541 for later examination.
maruela9cfd6f2015-09-15 11:03:15 -0700542 result_json: file path to dump result metadata into. If set, the process
nodirbe642ff2016-06-09 15:51:51 -0700543 exit code is always 0 unless an internal error occurred.
nodir90bc8dc2016-06-15 13:35:21 -0700544 root_dir: path to the directory to use to create the temporary directory. If
marueleb5fbee2015-09-17 13:01:36 -0700545 not specified, a random temporary directory is created.
maruel6be7f9e2015-10-01 12:25:30 -0700546 hard_timeout: kills the process if it lasts more than this amount of
547 seconds.
548 grace_period: number of seconds to wait between SIGTERM and SIGKILL.
Marc-Antoine Ruel2283ad12014-02-09 11:14:57 -0500549 extra_args: optional arguments to add to the command stated in the .isolate
nodir55be77b2016-05-03 09:39:57 -0700550 file. Ignored if isolate_hash is empty.
iannucci96fcccc2016-08-30 15:52:22 -0700551 install_packages_fn: function (dir) => {"stats": cipd_stats, "pins":
552 cipd_pins}. Installs packages.
maruel4409e302016-07-19 14:25:51 -0700553 use_symlinks: create tree with symlinks instead of hardlinks.
maruela9cfd6f2015-09-15 11:03:15 -0700554
555 Returns:
556 Process exit code that should be used.
maruel@chromium.org9c72d4e2012-09-28 19:20:25 +0000557 """
nodir55be77b2016-05-03 09:39:57 -0700558 assert bool(command) ^ bool(isolated_hash)
559 extra_args = extra_args or []
nodirbe642ff2016-06-09 15:51:51 -0700560
nodir55be77b2016-05-03 09:39:57 -0700561 if any(ISOLATED_OUTDIR_PARAMETER in a for a in (command or extra_args)):
562 assert storage is not None, 'storage is None although outdir is specified'
563
maruela76b9ee2015-12-15 06:18:08 -0800564 if result_json:
565 # Write a json output file right away in case we get killed.
566 result = {
567 'exit_code': None,
568 'had_hard_timeout': False,
569 'internal_failure': 'Was terminated before completion',
570 'outputs_ref': None,
nodirbe642ff2016-06-09 15:51:51 -0700571 'version': 5,
maruela76b9ee2015-12-15 06:18:08 -0800572 }
573 tools.write_json(result_json, result, dense=True)
574
maruela9cfd6f2015-09-15 11:03:15 -0700575 # run_isolated exit code. Depends on if result_json is used or not.
576 result = map_and_run(
nodir55be77b2016-05-03 09:39:57 -0700577 command, isolated_hash, storage, cache, leak_temp_dir, root_dir,
maruel4409e302016-07-19 14:25:51 -0700578 hard_timeout, grace_period, bot_file, extra_args, install_packages_fn,
579 use_symlinks)
maruela9cfd6f2015-09-15 11:03:15 -0700580 logging.info('Result:\n%s', tools.format_json(result, dense=True))
bpastene3ae09522016-06-10 17:12:59 -0700581
maruela9cfd6f2015-09-15 11:03:15 -0700582 if result_json:
maruel05d5a882015-09-21 13:59:02 -0700583 # We've found tests to delete 'work' when quitting, causing an exception
584 # here. Try to recreate the directory if necessary.
nodire5028a92016-04-29 14:38:21 -0700585 file_path.ensure_tree(os.path.dirname(result_json))
maruela9cfd6f2015-09-15 11:03:15 -0700586 tools.write_json(result_json, result, dense=True)
587 # Only return 1 if there was an internal error.
588 return int(bool(result['internal_failure']))
maruel@chromium.org781ccf62013-09-17 19:39:47 +0000589
maruela9cfd6f2015-09-15 11:03:15 -0700590 # Marshall into old-style inline output.
591 if result['outputs_ref']:
592 data = {
593 'hash': result['outputs_ref']['isolated'],
594 'namespace': result['outputs_ref']['namespace'],
595 'storage': result['outputs_ref']['isolatedserver'],
596 }
Marc-Antoine Ruelc44f5722015-01-08 16:10:01 -0500597 sys.stdout.flush()
maruela9cfd6f2015-09-15 11:03:15 -0700598 print(
599 '[run_isolated_out_hack]%s[/run_isolated_out_hack]' %
600 tools.format_json(data, dense=True))
maruelb76604c2015-11-11 11:53:44 -0800601 sys.stdout.flush()
maruela9cfd6f2015-09-15 11:03:15 -0700602 return result['exit_code'] or int(bool(result['internal_failure']))
maruel@chromium.org9c72d4e2012-09-28 19:20:25 +0000603
604
nodir90bc8dc2016-06-15 13:35:21 -0700605def install_packages(
nodirff531b42016-06-23 13:05:06 -0700606 run_dir, packages, service_url, client_package_name,
nodir90bc8dc2016-06-15 13:35:21 -0700607 client_version, cache_dir=None, timeout=None):
iannucci96fcccc2016-08-30 15:52:22 -0700608 """Installs packages. Returns stats, cipd client info and pins.
609
610 pins and the cipd client info are in the form of:
611 [
612 {
613 "path": path, "package_name": package_name, "version": version,
614 },
615 ...
616 ]
617 (the cipd client info is a single dictionary instead of a list)
618
619 such that they correspond 1:1 to all input package arguments from the command
620 line. These dictionaries make their all the way back to swarming, where they
621 become the arguments of CipdPackage.
nodirbe642ff2016-06-09 15:51:51 -0700622
623 Args:
nodir90bc8dc2016-06-15 13:35:21 -0700624 run_dir (str): root of installation.
iannucci96fcccc2016-08-30 15:52:22 -0700625 packages: packages to install, list [(path, package_name, version), ...]
nodirbe642ff2016-06-09 15:51:51 -0700626 service_url (str): CIPD server url, e.g.
627 "https://chrome-infra-packages.appspot.com."
nodir90bc8dc2016-06-15 13:35:21 -0700628 client_package_name (str): CIPD package name of CIPD client.
629 client_version (str): Version of CIPD client.
nodirbe642ff2016-06-09 15:51:51 -0700630 cache_dir (str): where to keep cache of cipd clients, packages and tags.
631 timeout: max duration in seconds that this function can take.
nodirbe642ff2016-06-09 15:51:51 -0700632 """
633 assert cache_dir
nodirff531b42016-06-23 13:05:06 -0700634 if not packages:
nodir90bc8dc2016-06-15 13:35:21 -0700635 return None
636
nodirbe642ff2016-06-09 15:51:51 -0700637 timeoutfn = tools.sliding_timeout(timeout)
nodirbe642ff2016-06-09 15:51:51 -0700638 start = time.time()
nodirbe642ff2016-06-09 15:51:51 -0700639 cache_dir = os.path.abspath(cache_dir)
640
nodir90bc8dc2016-06-15 13:35:21 -0700641 run_dir = os.path.abspath(run_dir)
nodir90bc8dc2016-06-15 13:35:21 -0700642
iannucci96fcccc2016-08-30 15:52:22 -0700643 package_pins = [None]*len(packages)
644 def insert_pin(path, name, version, idx):
645 path = path.replace(os.path.sep, '/')
646 package_pins[idx] = {
647 'package_name': name,
648 'path': path,
649 'version': version,
650 }
651
nodirbe642ff2016-06-09 15:51:51 -0700652 get_client_start = time.time()
653 client_manager = cipd.get_client(
654 service_url, client_package_name, client_version, cache_dir,
655 timeout=timeoutfn())
iannucci96fcccc2016-08-30 15:52:22 -0700656
657 by_path = collections.defaultdict(list)
658 for i, (path, name, version) in enumerate(packages):
659 path = path.replace('/', os.path.sep)
660 by_path[path].append((name, version, i))
661
nodirbe642ff2016-06-09 15:51:51 -0700662 with client_manager as client:
iannucci96fcccc2016-08-30 15:52:22 -0700663 client_package = {
664 'package_name': client.package_name,
665 'version': client.instance_id,
666 }
nodirbe642ff2016-06-09 15:51:51 -0700667 get_client_duration = time.time() - get_client_start
iannucci96fcccc2016-08-30 15:52:22 -0700668 for path, pkgs in sorted(by_path.iteritems()):
nodir90bc8dc2016-06-15 13:35:21 -0700669 site_root = os.path.abspath(os.path.join(run_dir, path))
670 if not site_root.startswith(run_dir):
671 raise cipd.Error('Invalid CIPD package path "%s"' % path)
672
673 # Do not clean site_root before installation because it may contain other
674 # site roots.
675 file_path.ensure_tree(site_root, 0770)
iannucci96fcccc2016-08-30 15:52:22 -0700676 pins = client.ensure(
677 site_root, [(name, vers) for name, vers, _ in pkgs],
nodirbe642ff2016-06-09 15:51:51 -0700678 cache_dir=os.path.join(cache_dir, 'cipd_internal'),
679 timeout=timeoutfn())
iannucci96fcccc2016-08-30 15:52:22 -0700680 for i, pin in enumerate(pins):
681 insert_pin(path, pin[0], pin[1], pkgs[i][2])
nodirbe642ff2016-06-09 15:51:51 -0700682 file_path.make_tree_files_read_only(site_root)
nodir90bc8dc2016-06-15 13:35:21 -0700683
684 total_duration = time.time() - start
685 logging.info(
686 'Installing CIPD client and packages took %d seconds', total_duration)
687
iannucci96fcccc2016-08-30 15:52:22 -0700688 assert None not in package_pins
689
nodir90bc8dc2016-06-15 13:35:21 -0700690 return {
iannucci96fcccc2016-08-30 15:52:22 -0700691 'stats': {
692 'duration': total_duration,
693 'get_client_duration': get_client_duration,
694 },
695 'cipd_pins': {
696 'client_package': client_package,
697 'packages': package_pins,
698 }
nodir90bc8dc2016-06-15 13:35:21 -0700699 }
nodirbe642ff2016-06-09 15:51:51 -0700700
701
702def create_option_parser():
Marc-Antoine Ruelf74cffe2015-07-15 15:21:34 -0400703 parser = logging_utils.OptionParserWithLogging(
nodir55be77b2016-05-03 09:39:57 -0700704 usage='%prog <options> [command to run or extra args]',
maruel@chromium.orgdedbf492013-09-12 20:42:11 +0000705 version=__version__,
706 log_file=RUN_ISOLATED_LOG_FILE)
maruela9cfd6f2015-09-15 11:03:15 -0700707 parser.add_option(
maruel36a963d2016-04-08 17:15:49 -0700708 '--clean', action='store_true',
709 help='Cleans the cache, trimming it necessary and remove corrupted items '
710 'and returns without executing anything; use with -v to know what '
711 'was done')
712 parser.add_option(
maruel2e8d0f52016-07-16 07:51:29 -0700713 '--no-clean', action='store_true',
714 help='Do not clean the cache automatically on startup. This is meant for '
715 'bots where a separate execution with --clean was done earlier so '
716 'doing it again is redundant')
717 parser.add_option(
maruel4409e302016-07-19 14:25:51 -0700718 '--use-symlinks', action='store_true',
719 help='Use symlinks instead of hardlinks')
720 parser.add_option(
maruela9cfd6f2015-09-15 11:03:15 -0700721 '--json',
722 help='dump output metadata to json file. When used, run_isolated returns '
723 'non-zero only on internal failure')
maruel6be7f9e2015-10-01 12:25:30 -0700724 parser.add_option(
maruel5c9e47b2015-12-18 13:02:30 -0800725 '--hard-timeout', type='float', help='Enforce hard timeout in execution')
maruel6be7f9e2015-10-01 12:25:30 -0700726 parser.add_option(
maruel5c9e47b2015-12-18 13:02:30 -0800727 '--grace-period', type='float',
maruel6be7f9e2015-10-01 12:25:30 -0700728 help='Grace period between SIGTERM and SIGKILL')
bpastene3ae09522016-06-10 17:12:59 -0700729 parser.add_option(
730 '--bot-file',
731 help='Path to a file describing the state of the host. The content is '
732 'defined by on_before_task() in bot_config.')
Marc-Antoine Ruel1687b5e2014-02-06 17:47:53 -0500733 data_group = optparse.OptionGroup(parser, 'Data source')
734 data_group.add_option(
Marc-Antoine Ruel185ded42015-01-28 20:49:18 -0500735 '-s', '--isolated',
nodir55be77b2016-05-03 09:39:57 -0700736 help='Hash of the .isolated to grab from the isolate server.')
Marc-Antoine Ruelf7d737d2014-12-10 15:36:29 -0500737 isolateserver.add_isolate_server_options(data_group)
Marc-Antoine Ruel1687b5e2014-02-06 17:47:53 -0500738 parser.add_option_group(data_group)
maruel@chromium.org9c72d4e2012-09-28 19:20:25 +0000739
Marc-Antoine Ruela57d7db2014-10-15 20:31:19 -0400740 isolateserver.add_cache_options(parser)
nodirbe642ff2016-06-09 15:51:51 -0700741
742 cipd.add_cipd_options(parser)
maruel@chromium.org9c72d4e2012-09-28 19:20:25 +0000743
Kenneth Russell61d42352014-09-15 11:41:16 -0700744 debug_group = optparse.OptionGroup(parser, 'Debugging')
745 debug_group.add_option(
746 '--leak-temp-dir',
747 action='store_true',
nodirbe642ff2016-06-09 15:51:51 -0700748 help='Deliberately leak isolate\'s temp dir for later examination. '
749 'Default: %default')
marueleb5fbee2015-09-17 13:01:36 -0700750 debug_group.add_option(
751 '--root-dir', help='Use a directory instead of a random one')
Kenneth Russell61d42352014-09-15 11:41:16 -0700752 parser.add_option_group(debug_group)
753
Vadim Shtayurae34e13a2014-02-02 11:23:26 -0800754 auth.add_auth_options(parser)
nodirbe642ff2016-06-09 15:51:51 -0700755
756 parser.set_defaults(cache='cache', cipd_cache='cipd_cache')
757 return parser
758
759
760def main(args):
761 parser = create_option_parser()
Marc-Antoine Ruel90c98162013-12-18 15:11:57 -0500762 options, args = parser.parse_args(args)
maruel36a963d2016-04-08 17:15:49 -0700763
764 cache = isolateserver.process_cache_options(options)
765 if options.clean:
766 if options.isolated:
767 parser.error('Can\'t use --isolated with --clean.')
768 if options.isolate_server:
769 parser.error('Can\'t use --isolate-server with --clean.')
770 if options.json:
771 parser.error('Can\'t use --json with --clean.')
772 cache.cleanup()
773 return 0
maruel2e8d0f52016-07-16 07:51:29 -0700774 if not options.no_clean:
775 cache.cleanup()
maruel36a963d2016-04-08 17:15:49 -0700776
nodir55be77b2016-05-03 09:39:57 -0700777 if not options.isolated and not args:
778 parser.error('--isolated or command to run is required.')
779
Vadim Shtayura5d1efce2014-02-04 10:55:43 -0800780 auth.process_auth_options(parser, options)
nodir55be77b2016-05-03 09:39:57 -0700781
782 isolateserver.process_isolate_server_options(
783 parser, options, True, False)
784 if not options.isolate_server:
785 if options.isolated:
786 parser.error('--isolated requires --isolate-server')
787 if ISOLATED_OUTDIR_PARAMETER in args:
788 parser.error(
789 '%s in args requires --isolate-server' % ISOLATED_OUTDIR_PARAMETER)
maruel@chromium.org9c72d4e2012-09-28 19:20:25 +0000790
nodir90bc8dc2016-06-15 13:35:21 -0700791 if options.root_dir:
792 options.root_dir = unicode(os.path.abspath(options.root_dir))
maruel12e30012015-10-09 11:55:35 -0700793 if options.json:
794 options.json = unicode(os.path.abspath(options.json))
nodir55be77b2016-05-03 09:39:57 -0700795
nodirbe642ff2016-06-09 15:51:51 -0700796 cipd.validate_cipd_options(parser, options)
797
nodir90bc8dc2016-06-15 13:35:21 -0700798 install_packages_fn = lambda run_dir: install_packages(
nodirff531b42016-06-23 13:05:06 -0700799 run_dir, cipd.parse_package_args(options.cipd_packages),
800 options.cipd_server, options.cipd_client_package,
801 options.cipd_client_version, cache_dir=options.cipd_cache)
nodirbe642ff2016-06-09 15:51:51 -0700802
803 try:
nodir90bc8dc2016-06-15 13:35:21 -0700804 command = [] if options.isolated else args
805 if options.isolate_server:
806 storage = isolateserver.get_storage(
807 options.isolate_server, options.namespace)
808 with storage:
809 # Hashing schemes used by |storage| and |cache| MUST match.
810 assert storage.hash_algo == cache.hash_algo
nodirbe642ff2016-06-09 15:51:51 -0700811 return run_tha_test(
nodir90bc8dc2016-06-15 13:35:21 -0700812 command, options.isolated, storage, cache, options.leak_temp_dir,
813 options.json, options.root_dir, options.hard_timeout,
maruel4409e302016-07-19 14:25:51 -0700814 options.grace_period, options.bot_file, args, install_packages_fn,
815 options.use_symlinks)
816 return run_tha_test(
817 command, options.isolated, None, cache, options.leak_temp_dir,
818 options.json, options.root_dir, options.hard_timeout,
819 options.grace_period, options.bot_file, args, install_packages_fn,
820 options.use_symlinks)
nodirbe642ff2016-06-09 15:51:51 -0700821 except cipd.Error as ex:
822 print >> sys.stderr, ex.message
823 return 1
maruel@chromium.org9c72d4e2012-09-28 19:20:25 +0000824
825
826if __name__ == '__main__':
maruel8e4e40c2016-05-30 06:21:07 -0700827 subprocess42.inhibit_os_error_reporting()
csharp@chromium.orgbfb98742013-03-26 20:28:36 +0000828 # Ensure that we are always running with the correct encoding.
vadimsh@chromium.orga4326472013-08-24 02:05:41 +0000829 fix_encoding.fix_encoding()
maruel4409e302016-07-19 14:25:51 -0700830 file_path.enable_symlink()
Marc-Antoine Ruel90c98162013-12-18 15:11:57 -0500831 sys.exit(main(sys.argv[1:]))