You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
depot_tools/recipes/recipe_modules/bot_update/test_api.py

122 lines
3.8 KiB
Python

# Copyright 2014 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import hashlib
import struct
from recipe_engine import recipe_test_api
class BotUpdateTestApi(recipe_test_api.RecipeTestApi):
def output_json(self, root, first_sln, revision_mapping, fail_patch=False,
fixed_revisions=None, commit_positions=True):
"""Deterministically synthesize json.output test data for gclient's
--output-json option.
"""
output = {
'did_run': True,
'patch_failure': False
}
revisions = {
project_name: self.gen_revision(project_name)
for project_name in set(revision_mapping.values())
}
if fixed_revisions:
for project_name, revision in fixed_revisions.items():
if revision == 'HEAD':
revision = self.gen_revision(project_name)
elif revision.startswith('refs/') or revision.startswith('origin/'):
revision = self.gen_revision('{}@{}'.format(project_name, revision))
revisions[project_name] = revision
properties = {
property_name: revisions[project_name]
for property_name, project_name in revision_mapping.items()
}
Reland "Set a default got_revision property in the bot_update json output." This is a reland of commit 053817260a00cac70d8e5a2105d94b93b3f81e6f The change was not related to the errors that it was reverted for, so no changes are necessary. Original change's description: > Set a default got_revision property in the bot_update json output. > > The bot_update.py script sets a got_revision property by default even if > it is not present in the reverse revision mapping. This results in an > uncaught exception when set_output_commit is set to True if got_revision > isn't present in the reverse revision mapping, but it isn't caught until > production because the test API doesn't match that behavior. This change > updates the test API method to match the behavior of the script. > > Recipe-Nontrivial-Roll: build > Recipe-Nontrivial-Roll: build_limited > Recipe-Nontrivial-Roll: chromiumos > Recipe-Nontrivial-Roll: infra > Change-Id: Ideefa9d77d2a816ae66a2bb52737264ed3f5bcee > Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/3575361 > Reviewed-by: Robbie Iannucci <iannucci@chromium.org> > Reviewed-by: Josip Sokcevic <sokcevic@google.com> > Commit-Queue: Garrett Beaty <gbeaty@google.com> > Auto-Submit: Garrett Beaty <gbeaty@google.com> Recipe-Nontrivial-Roll: build Recipe-Nontrivial-Roll: build_limited Recipe-Nontrivial-Roll: chromiumos Recipe-Nontrivial-Roll: infra Change-Id: I80efeee8a2b951df43b00d89bb596dc2cf2fcec7 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/3582182 Reviewed-by: Robbie Iannucci <iannucci@chromium.org> Commit-Queue: Garrett Beaty <gbeaty@google.com>
3 years ago
properties.setdefault('got_revision', self.gen_revision(first_sln))
if commit_positions:
def get_ref(project_name):
revision = fixed_revisions.get(project_name, 'HEAD')
if revision.startswith('origin/'):
return revision.replace('origin/', 'refs/heads/', 1)
if revision.startswith('refs/'):
return revision
return 'refs/heads/main'
properties.update({
'%s_cp' % property_name:
('%s@{#%s}' %
(get_ref(project_name), self.gen_commit_position(project_name)))
for property_name, project_name in revision_mapping.items()
})
output.update({
'patch_root': root or first_sln,
'root': first_sln,
'properties': properties,
'step_text': 'Some step text'
})
output.update({
'manifest': {
project_name: {
'repository': 'https://fake.org/%s.git' % project_name,
'revision': revision,
}
for project_name, revision in revisions.items()
}
})
output.update({
'source_manifest': {
'version': 0,
'directories': {
project_name: {
'git_checkout': {
'repo_url': 'https://fake.org/%s.git' % project_name,
'revision': revision
}
}
for project_name, revision in revisions.items()
}
}
Reland "Remove obsolete bot_update flag" This reverts commit c91686c087704f3aeea594e6b7c82767fa7d753b. Reason for revert: Reland a light version of the original CL that keeps a dummy flag around. Original change's description: > Revert "Remove obsolete bot_update flag" > > This reverts commit 72048266d5cf68dc06c2cd20e173fbcb6f0dcfd2. > > Reason for revert: Skia depends on it. Need to clean that up first. Currently blocks roll: > https://skia-review.googlesource.com/c/14145/ > > Original change's description: > > Remove obsolete bot_update flag > > > > Using the manifest is the default since a long time. The flag was only introduced to smoothly switch it on. Now the flag is not needed anymore. > > > > Bug: 398105 > > Change-Id: I4eb1c98e26e025a69f8b0a7c48877d78c031702e > > Reviewed-on: https://chromium-review.googlesource.com/485659 > > Reviewed-by: Sergiy Byelozyorov <sergiyb@chromium.org> > > Reviewed-by: Paweł Hajdan Jr. <phajdan.jr@chromium.org> > > Commit-Queue: Michael Achenbach <machenbach@chromium.org> > > > > TBR=phajdan.jr@chromium.org,machenbach@chromium.org,tandrii@chromium.org,sergiyb@chromium.org,chromium-reviews@chromium.org > NOPRESUBMIT=true > NOTREECHECKS=true > NOTRY=true > > Change-Id: Iffc4d8076abd3c92feebfd7f3ef88be7ce34b692 > Reviewed-on: https://chromium-review.googlesource.com/486639 > Reviewed-by: Michael Achenbach <machenbach@chromium.org> > Commit-Queue: Michael Achenbach <machenbach@chromium.org> > R=phajdan.jr@chromium.org,machenbach@chromium.org,tandrii@chromium.org,sergiyb@chromium.org,chromium-reviews@chromium.org Bug: 398105 Change-Id: I817d446f8a8eff84c5d7143ac2b9c527a40991f1 Reviewed-on: https://chromium-review.googlesource.com/486640 Commit-Queue: Michael Achenbach <machenbach@chromium.org> Reviewed-by: Paweł Hajdan Jr. <phajdan.jr@chromium.org> Reviewed-by: Michael Achenbach <machenbach@chromium.org>
8 years ago
})
if fixed_revisions:
output['fixed_revisions'] = fixed_revisions
if fail_patch:
output['patch_failure'] = True
output['failed_patch_body'] = '\n'.join([
'Downloading patch...',
'Applying the patch...',
'Patch: foo/bar.py',
'Index: foo/bar.py',
'diff --git a/foo/bar.py b/foo/bar.py',
'index HASH..HASH MODE',
'--- a/foo/bar.py',
'+++ b/foo/bar.py',
'context',
'+something',
'-something',
'more context',
])
output['patch_apply_return_code'] = 1
if fail_patch == 'download':
output['patch_apply_return_code'] = 3
return self.m.json.output(output)
@staticmethod
def gen_revision(project):
"""Hash project to bogus deterministic git hash values."""
h = hashlib.sha1(project.encode('utf-8'))
return h.hexdigest()
@staticmethod
def gen_commit_position(project):
"""Hash project to bogus deterministic Cr-Commit-Position values."""
h = hashlib.sha1(project.encode('utf-8'))
return struct.unpack('!I', h.digest()[:4])[0] % 300000