OLD | NEW |
(Empty) | |
| 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 |
| 3 # found in the LICENSE file. |
| 4 |
| 5 import hashlib |
| 6 import os |
| 7 import struct |
| 8 import sys |
| 9 from recipe_engine import recipe_test_api |
| 10 |
| 11 # TODO(phajdan.jr): Clean up this somewhat ugly import. |
| 12 sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'resources')) |
| 13 import bot_update |
| 14 |
| 15 |
| 16 class BotUpdateTestApi(recipe_test_api.RecipeTestApi): |
| 17 def output_json(self, master, builder, slave, root, first_sln, |
| 18 revision_mapping, git_mode, force=False, fail_patch=False, |
| 19 output_manifest=False, fixed_revisions=None): |
| 20 """Deterministically synthesize json.output test data for gclient's |
| 21 --output-json option. |
| 22 """ |
| 23 active = bot_update.check_valid_host(master, builder, slave) or force |
| 24 |
| 25 output = { |
| 26 'did_run': active, |
| 27 'patch_failure': False |
| 28 } |
| 29 |
| 30 # Add in extra json output if active. |
| 31 if active: |
| 32 properties = { |
| 33 property_name: self.gen_revision(project_name, git_mode) |
| 34 for project_name, property_name in revision_mapping.iteritems() |
| 35 } |
| 36 properties.update({ |
| 37 '%s_cp' % property_name: ('refs/heads/master@{#%s}' % |
| 38 self.gen_revision(project_name, False)) |
| 39 for project_name, property_name in revision_mapping.iteritems() |
| 40 }) |
| 41 |
| 42 # We also want to simulate outputting "got_revision_git": ... |
| 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 }) |
| 49 |
| 50 output.update({ |
| 51 'patch_root': root or first_sln, |
| 52 'root': first_sln, |
| 53 'properties': properties, |
| 54 'step_text': 'Some step text' |
| 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 |
| 77 return self.m.json.output(output) |
| 78 |
| 79 @staticmethod |
| 80 def gen_revision(project, GIT_MODE): |
| 81 """Hash project to bogus deterministic revision values.""" |
| 82 h = hashlib.sha1(project) |
| 83 if GIT_MODE: |
| 84 return h.hexdigest() |
| 85 else: |
| 86 return struct.unpack('!I', h.digest()[:4])[0] % 300000 |
OLD | NEW |