OLD | NEW |
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, root, first_sln, revision_mapping, fail_patch=False, | 17 def output_json(self, master, builder, slave, root, first_sln, |
| 18 revision_mapping, git_mode, force=False, fail_patch=False, |
18 output_manifest=False, fixed_revisions=None): | 19 output_manifest=False, fixed_revisions=None): |
19 """Deterministically synthesize json.output test data for gclient's | 20 """Deterministically synthesize json.output test data for gclient's |
20 --output-json option. | 21 --output-json option. |
21 """ | 22 """ |
| 23 active = bot_update.check_valid_host(master, builder, slave) or force |
22 | 24 |
23 output = { | 25 output = { |
24 'did_run': True, | 26 'did_run': active, |
25 'patch_failure': False | 27 'patch_failure': False |
26 } | 28 } |
27 | 29 |
28 properties = { | 30 # Add in extra json output if active. |
29 property_name: self.gen_revision(project_name, True) | 31 if active: |
30 for project_name, property_name in revision_mapping.iteritems() | 32 properties = { |
31 } | 33 property_name: self.gen_revision(project_name, git_mode) |
32 properties.update({ | 34 for project_name, property_name in revision_mapping.iteritems() |
33 '%s_cp' % property_name: ('refs/heads/master@{#%s}' % | 35 } |
34 self.gen_revision(project_name, False)) | 36 properties.update({ |
35 for project_name, property_name in revision_mapping.iteritems() | 37 '%s_cp' % property_name: ('refs/heads/master@{#%s}' % |
36 }) | 38 self.gen_revision(project_name, False)) |
37 | 39 for project_name, property_name in revision_mapping.iteritems() |
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 } | |
54 }) | 40 }) |
55 | 41 |
56 if fixed_revisions: | 42 # We also want to simulate outputting "got_revision_git": ... |
57 output['fixed_revisions'] = fixed_revisions | 43 # when git mode is off to match what bot_update.py does. |
| 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 }) |
58 | 49 |
59 if fail_patch: | 50 output.update({ |
60 output['log_lines'] = [('patch error', 'Patch failed to apply'),] | 51 'patch_root': root or first_sln, |
61 output['patch_failure'] = True | 52 'root': first_sln, |
62 output['patch_apply_return_code'] = 1 | 53 'properties': properties, |
63 if fail_patch == 'download': | 54 'step_text': 'Some step text' |
64 output['patch_apply_return_code'] = 3 | 55 }) |
| 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 |
65 return self.m.json.output(output) | 77 return self.m.json.output(output) |
66 | 78 |
67 @staticmethod | 79 @staticmethod |
68 def gen_revision(project, git_mode): | 80 def gen_revision(project, GIT_MODE): |
69 """Hash project to bogus deterministic revision values.""" | 81 """Hash project to bogus deterministic revision values.""" |
70 h = hashlib.sha1(project) | 82 h = hashlib.sha1(project) |
71 if git_mode: | 83 if GIT_MODE: |
72 return h.hexdigest() | 84 return h.hexdigest() |
73 else: | 85 else: |
74 return struct.unpack('!I', h.digest()[:4])[0] % 300000 | 86 return struct.unpack('!I', h.digest()[:4])[0] % 300000 |
OLD | NEW |