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

83 lines
2.4 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,
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
fixed_revisions=None):
"""Deterministically synthesize json.output test data for gclient's
--output-json option.
"""
output = {
'did_run': True,
'patch_failure': False
}
properties = {
property_name: self.gen_revision(project_name)
for property_name, project_name in revision_mapping.iteritems()
}
properties.update({
'%s_cp' % property_name: ('refs/heads/master@{#%s}' %
self.gen_commit_position(project_name))
for property_name, project_name in revision_mapping.iteritems()
})
output.update({
'patch_root': root or first_sln,
'root': first_sln,
'properties': properties,
'step_text': 'Some step text'
})
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
output.update({
'manifest': {
project_name: {
'repository': 'https://fake.org/%s.git' % project_name,
'revision': self.gen_revision(project_name),
}
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
for project_name in set(revision_mapping.values())
}
})
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)
return h.hexdigest()
@staticmethod
def gen_commit_position(project):
"""Hash project to bogus deterministic Cr-Commit-Position values."""
h = hashlib.sha1(project)
return struct.unpack('!I', h.digest()[:4])[0] % 300000