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

Side by Side Diff: recipe_modules/bot_update/test_api.py

Issue 1686273002: Bot update cleanup (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools
Patch Set: Review Created 4 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 | Annotate | Revision Log
« no previous file with comments | « recipe_modules/bot_update/resources/patch.exe ('k') | tests/bot_update_coverage_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 # Copyright 2014 The Chromium Authors. All rights reserved. 1 # Copyright 2014 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 import hashlib 5 import hashlib
6 import os 6 import os
7 import struct 7 import struct
8 import sys 8 import sys
9 from recipe_engine import recipe_test_api 9 from recipe_engine import recipe_test_api
10 10
11 # TODO(phajdan.jr): Clean up this somewhat ugly import. 11 # TODO(phajdan.jr): Clean up this somewhat ugly import.
12 sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'resources')) 12 sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'resources'))
13 import bot_update 13 import bot_update
14 14
15 15
16 class BotUpdateTestApi(recipe_test_api.RecipeTestApi): 16 class BotUpdateTestApi(recipe_test_api.RecipeTestApi):
17 def output_json(self, master, builder, slave, root, first_sln, 17 def output_json(self, root, first_sln, revision_mapping, fail_patch=False,
18 revision_mapping, git_mode, force=False, fail_patch=False,
19 output_manifest=False, fixed_revisions=None): 18 output_manifest=False, fixed_revisions=None):
20 """Deterministically synthesize json.output test data for gclient's 19 """Deterministically synthesize json.output test data for gclient's
21 --output-json option. 20 --output-json option.
22 """ 21 """
23 active = bot_update.check_valid_host(master, builder, slave) or force
24 22
25 output = { 23 output = {
26 'did_run': active, 24 'did_run': True,
27 'patch_failure': False 25 'patch_failure': False
28 } 26 }
29 27
30 # Add in extra json output if active. 28 properties = {
31 if active: 29 property_name: self.gen_revision(project_name, True)
32 properties = { 30 for project_name, property_name in revision_mapping.iteritems()
33 property_name: self.gen_revision(project_name, git_mode) 31 }
34 for project_name, property_name in revision_mapping.iteritems() 32 properties.update({
35 } 33 '%s_cp' % property_name: ('refs/heads/master@{#%s}' %
36 properties.update({ 34 self.gen_revision(project_name, False))
37 '%s_cp' % property_name: ('refs/heads/master@{#%s}' % 35 for project_name, property_name in revision_mapping.iteritems()
38 self.gen_revision(project_name, False)) 36 })
39 for project_name, property_name in revision_mapping.iteritems() 37
38 output.update({
39 'patch_root': root or first_sln,
40 'root': first_sln,
41 'properties': properties,
42 'step_text': 'Some step text'
43 })
44
45 if output_manifest:
46 output.update({
47 'manifest': {
48 project_name: {
49 'repository': 'https://fake.org/%s.git' % project_name,
50 'revision': self.gen_revision(project_name, True),
51 }
52 for project_name in revision_mapping
53 }
40 }) 54 })
41 55
42 # We also want to simulate outputting "got_revision_git": ... 56 if fixed_revisions:
43 # when git mode is off to match what bot_update.py does. 57 output['fixed_revisions'] = fixed_revisions
44 if not git_mode:
45 properties.update({
46 '%s_git' % property_name: self.gen_revision(project_name, True)
47 for project_name, property_name in revision_mapping.iteritems()
48 })
49 58
50 output.update({ 59 if fail_patch:
51 'patch_root': root or first_sln, 60 output['log_lines'] = [('patch error', 'Patch failed to apply'),]
52 'root': first_sln, 61 output['patch_failure'] = True
53 'properties': properties, 62 output['patch_apply_return_code'] = 1
54 'step_text': 'Some step text' 63 if fail_patch == 'download':
55 }) 64 output['patch_apply_return_code'] = 3
56
57 if output_manifest:
58 output.update({
59 'manifest': {
60 project_name: {
61 'repository': 'https://fake.org/%s.git' % project_name,
62 'revision': self.gen_revision(project_name, git_mode),
63 }
64 for project_name in revision_mapping
65 }
66 })
67
68 if fixed_revisions:
69 output['fixed_revisions'] = fixed_revisions
70
71 if fail_patch:
72 output['log_lines'] = [('patch error', 'Patch failed to apply'),]
73 output['patch_failure'] = True
74 output['patch_apply_return_code'] = 1
75 if fail_patch == 'download':
76 output['patch_apply_return_code'] = 3
77 return self.m.json.output(output) 65 return self.m.json.output(output)
78 66
79 @staticmethod 67 @staticmethod
80 def gen_revision(project, GIT_MODE): 68 def gen_revision(project, git_mode):
81 """Hash project to bogus deterministic revision values.""" 69 """Hash project to bogus deterministic revision values."""
82 h = hashlib.sha1(project) 70 h = hashlib.sha1(project)
83 if GIT_MODE: 71 if git_mode:
84 return h.hexdigest() 72 return h.hexdigest()
85 else: 73 else:
86 return struct.unpack('!I', h.digest()[:4])[0] % 300000 74 return struct.unpack('!I', h.digest()[:4])[0] % 300000
OLDNEW
« no previous file with comments | « recipe_modules/bot_update/resources/patch.exe ('k') | tests/bot_update_coverage_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698