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 struct | 6 import struct |
7 | 7 |
8 from slave import bot_update | 8 from slave import bot_update |
9 from slave import recipe_test_api | 9 from slave import recipe_test_api |
10 | 10 |
11 | 11 |
12 class BotUpdateTestApi(recipe_test_api.RecipeTestApi): | 12 class BotUpdateTestApi(recipe_test_api.RecipeTestApi): |
13 def output_json(self, master, builder, slave, root, first_sln, | 13 def output_json(self, master, builder, slave, root, first_sln, |
14 revision_mapping, git_mode, force=False, fail_patch=False): | 14 revision_mapping, git_mode, force=False, fail_patch=False, |
| 15 output_manifest=False): |
15 """Deterministically synthesize json.output test data for gclient's | 16 """Deterministically synthesize json.output test data for gclient's |
16 --output-json option. | 17 --output-json option. |
17 """ | 18 """ |
18 active = bot_update.check_valid_host(master, builder, slave) or force | 19 active = bot_update.check_valid_host(master, builder, slave) or force |
19 | 20 |
20 output = { | 21 output = { |
21 'did_run': active, | 22 'did_run': active, |
22 'patch_failure': False | 23 'patch_failure': False |
23 } | 24 } |
24 | 25 |
25 # Add in extra json output if active. | 26 # Add in extra json output if active. |
26 if active: | 27 if active: |
27 properties = { | 28 properties = { |
28 property_name: self.gen_revision(project_name, git_mode) | 29 property_name: self.gen_revision(project_name, git_mode) |
29 for project_name, property_name in revision_mapping.iteritems() | 30 for project_name, property_name in revision_mapping.iteritems() |
30 } | 31 } |
31 properties.update({ | 32 properties.update({ |
32 '%s_cp' % property_name: ('refs/heads/master@{#%s}' % | 33 '%s_cp' % property_name: ('refs/heads/master@{#%s}' % |
33 self.gen_revision(project_name, False)) | 34 self.gen_revision(project_name, False)) |
34 for project_name, property_name in revision_mapping.iteritems() | 35 for project_name, property_name in revision_mapping.iteritems() |
35 }) | 36 }) |
36 | 37 |
37 # We also want to simulate outputting "got_revision_git": ... | 38 # We also want to simulate outputting "got_revision_git": ... |
38 # when git mode is off to match what bot_update.py does. | 39 # when git mode is off to match what bot_update.py does. |
39 if not git_mode: | 40 if not git_mode: |
40 properties.update({ | 41 properties.update({ |
41 '%s_git' % property_name: self.gen_revision(project_name, True) | 42 '%s_git' % property_name: self.gen_revision(project_name, True) |
42 for project_name, property_name in revision_mapping.iteritems() | 43 for project_name, property_name in revision_mapping.iteritems() |
43 }) | 44 }) |
| 45 |
44 output.update({ | 46 output.update({ |
45 'patch_root': root or first_sln, | 47 'patch_root': root or first_sln, |
46 'root': first_sln, | 48 'root': first_sln, |
47 'properties': properties, | 49 'properties': properties, |
48 'step_text': 'Some step text' | 50 'step_text': 'Some step text' |
49 }) | 51 }) |
50 | 52 |
| 53 if output_manifest: |
| 54 output.update({ |
| 55 'manifest': { |
| 56 project_name: { |
| 57 'repository': 'https://fake.org/%s.git' % project_name, |
| 58 'revision': self.gen_revision(project_name, git_mode), |
| 59 } |
| 60 for project_name in revision_mapping |
| 61 } |
| 62 }) |
| 63 |
51 if fail_patch: | 64 if fail_patch: |
52 output['log_lines'] = [('patch error', 'Patch failed to apply'),] | 65 output['log_lines'] = [('patch error', 'Patch failed to apply'),] |
53 output['patch_failure'] = True | 66 output['patch_failure'] = True |
54 return self.m.json.output(output) | 67 return self.m.json.output(output) |
55 | 68 |
56 @staticmethod | 69 @staticmethod |
57 def gen_revision(project, GIT_MODE): | 70 def gen_revision(project, GIT_MODE): |
58 """Hash project to bogus deterministic revision values.""" | 71 """Hash project to bogus deterministic revision values.""" |
59 h = hashlib.sha1(project) | 72 h = hashlib.sha1(project) |
60 if GIT_MODE: | 73 if GIT_MODE: |
61 return h.hexdigest() | 74 return h.hexdigest() |
62 else: | 75 else: |
63 return struct.unpack('!I', h.digest()[:4])[0] % 300000 | 76 return struct.unpack('!I', h.digest()[:4])[0] % 300000 |
OLD | NEW |