diff options
Diffstat (limited to 'cbuildbot/commands.py')
-rw-r--r-- | cbuildbot/commands.py | 105 |
1 files changed, 70 insertions, 35 deletions
diff --git a/cbuildbot/commands.py b/cbuildbot/commands.py index 84e6d9622..520294490 100644 --- a/cbuildbot/commands.py +++ b/cbuildbot/commands.py @@ -62,6 +62,7 @@ _DEFAULT_HWTEST_TIMEOUT_MINS = 1440 _SWARMING_EXPIRATION = 20 * 60 _RUN_SUITE_PATH = '/usr/local/autotest/site_utils/run_suite.py' _ABORT_SUITE_PATH = '/usr/local/autotest/site_utils/abort_suite.py' +_MAX_HWTEST_CMD_RETRY = 10 # =========================== Command Helpers ================================= @@ -176,14 +177,16 @@ def BuildRootGitCleanup(buildroot): try: if os.path.isdir(cwd): git.CleanAndDetachHead(cwd) - git.GarbageCollection(cwd) + + if os.path.isdir(repo_git_store): + git.GarbageCollection(repo_git_store) except cros_build_lib.RunCommandError as e: result = e.result logging.PrintBuildbotStepWarnings() logging.warning('\n%s', result.error) # If there's no repository corruption, just delete the index. - corrupted = git.IsGitRepositoryCorrupted(cwd) + corrupted = git.IsGitRepositoryCorrupted(repo_git_store) lock.write_lock() logging.warning('Deleting %s because %s failed', cwd, result.cmd) osutils.RmDir(cwd, ignore_missing=True) @@ -904,11 +907,13 @@ def RunHWTestSuite(build, suite, board, pool=None, num=None, file_bugs=None, try: cmd = [_RUN_SUITE_PATH] cmd += _GetRunSuiteArgs(build, suite, board, pool, num, file_bugs, - wait_for_results, priority, timeout_mins, retry, - max_retries, minimum_duts, suite_min_duts, - offload_failures_only, subsystems) + priority, timeout_mins, retry, max_retries, + minimum_duts, suite_min_duts, offload_failures_only, + subsystems) swarming_args = _CreateSwarmingArgs(build, suite, timeout_mins) - HWTestCreateAndWait(cmd, swarming_args, debug) + job_id = _HWTestCreate(cmd, swarming_args, debug) + if wait_for_results and job_id: + _HWTestWait(cmd, job_id, swarming_args) except cros_build_lib.RunCommandError as e: result = e.result if not result.task_summary_json: @@ -960,8 +965,7 @@ def RunHWTestSuite(build, suite, board, pool=None, num=None, file_bugs=None, # pylint: disable=docstring-missing-args def _GetRunSuiteArgs(build, suite, board, pool=None, num=None, - file_bugs=None, wait_for_results=None, - priority=None, timeout_mins=None, + file_bugs=None, priority=None, timeout_mins=None, retry=None, max_retries=None, minimum_duts=0, suite_min_duts=0, offload_failures_only=None, subsystems=None): @@ -990,9 +994,6 @@ def _GetRunSuiteArgs(build, suite, board, pool=None, num=None, if file_bugs is not None: args += ['--file_bugs', str(file_bugs)] - if wait_for_results is not None: - args += ['--no_wait', str(not wait_for_results)] - if priority is not None: args += ['--priority', priority] @@ -1064,21 +1065,23 @@ def _CreateSwarmingArgs(build, suite, timeout_mins=None): return swarming_args -def HWTestCreateAndWait(cmd, swarming_args, debug=False): - """Start and wait on HWTest suite in the lab. +def _HWTestCreate(cmd, swarming_args, debug=False): + """Start a suite in the HWTest lab, and return its id. - This method first run a command to create the suite. - And then run a second command to wait for the suite result. - Since we are using swarming client, which contiuously send - request to swarming server to poll task result, there is - no need to retry on any network related failures. + This method runs a command to create the suite. Since we are using + swarming client, which contiuously send request to swarming server + to poll task result, there is no need to retry on any network + related failures. Args: cmd: Proxied run_suite command. debug: If True, log command rather than running it. swarming_args: A dictionary of args to passed to RunSwarmingCommand. + + Returns: + Job id of created suite. Returned id will be None if no job id was created. """ - # Start the suite + # Start the suite. start_cmd = list(cmd) + ['-c'] if debug: @@ -1096,15 +1099,27 @@ def HWTestCreateAndWait(cmd, swarming_args, debug=False): m = re.search(r'Created suite job:.*object_id=(?P<job_id>\d*)', result.output) if m: - job_id = m.group('job_id') - # Wait on the suite - wait_cmd = list(cmd) + ['-m', str(job_id)] - result = swarming_lib.RunSwarmingCommand( - wait_cmd, capture_output=True, combine_stdout_stderr=True, - **swarming_args) - for output in result.task_summary_json['shards'][0]['outputs']: - sys.stdout.write(output) - sys.stdout.flush() + return m.group('job_id') + return None + +def _HWTestWait(cmd, job_id, swarming_args): + """Wait for HWTest suite to complete. + + Args: + cmd: Proxied run_suite command. + job_id: The job id of the suite that was created. + swarming_args: A dictionary of args to passed to RunSwarmingCommand. + """ + # Wait on the suite + wait_cmd = list(cmd) + ['-m', str(job_id)] + result = swarming_lib.RunSwarmingCommandWithRetries( + max_retry=_MAX_HWTEST_CMD_RETRY, + error_check=swarming_lib.SwarmingRetriableErrorCheck, + cmd=wait_cmd, capture_output=True, combine_stdout_stderr=True, + **swarming_args) + for output in result.task_summary_json['shards'][0]['outputs']: + sys.stdout.write(output) + sys.stdout.flush() def AbortHWTests(config_type_or_name, version, debug, suite=''): @@ -1562,21 +1577,33 @@ def UploadArchivedFile(archive_dir, upload_urls, filename, debug, _UploadPathToGS(uploaded_file_path, upload_urls, debug, timeout) -def UploadSymbols(buildroot, board, official, cnt, failed_list): +def UploadSymbols(buildroot, board=None, official=False, cnt=None, + failed_list=None, breakpad_root=None, product_name=None, + error_code_ok=True): """Upload debug symbols for this build.""" - cmd = ['upload_symbols', '--yes', '--board', board, - '--root', os.path.join(buildroot, constants.DEFAULT_CHROOT_DIR)] - if failed_list is not None: - cmd += ['--failed-list', str(failed_list)] + cmd = ['upload_symbols', '--yes'] + + if board is not None: + # Board requires both root and board to be set to be useful. + cmd += [ + '--root', os.path.join(buildroot, constants.DEFAULT_CHROOT_DIR), + '--board', board] if official: cmd.append('--official_build') if cnt is not None: cmd += ['--upload-limit', str(cnt)] + if failed_list is not None: + cmd += ['--failed-list', str(failed_list)] + if breakpad_root is not None: + cmd += ['--breakpad_root', breakpad_root] + if product_name is not None: + cmd += ['--product_name', product_name] # We don't want to import upload_symbols directly because it uses the # swarming module which itself imports a _lot_ of stuff. It has also # been known to hang. We want to keep cbuildbot isolated & robust. - ret = RunBuildScript(buildroot, cmd, chromite_cmd=True, error_code_ok=True) + ret = RunBuildScript(buildroot, cmd, chromite_cmd=True, + error_code_ok=error_code_ok) if ret.returncode: # TODO(davidjames): Convert this to a fatal error. # See http://crbug.com/212437 @@ -1959,7 +1986,15 @@ def BuildStandaloneArchive(archive_dir, image_dir, artifact_info): A KeyError is a required field is missing from artifact_info. """ if 'archive' not in artifact_info: - # Nothing to do, just return the list as-is. + # Copy the file in 'paths' as is to the archive directory. + if len(artifact_info['paths']) > 1: + raise ValueError('default archive type does not support multiple inputs') + src_image = os.path.join(image_dir, artifact_info['paths'][0]) + tgt_image = os.path.join(archive_dir, artifact_info['paths'][0]) + if not os.path.exists(tgt_image): + # The image may have already been copied into place. If so, overwriting it + # can affect parallel processes. + shutil.copy(src_image, tgt_image) return artifact_info['paths'] inputs = artifact_info['paths'] |