OLD | NEW |
(Empty) | |
| 1 # Copyright (c) 2013 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 """ Runs a series of tests on a file which maps old builder names to new builder |
| 6 names. """ |
| 7 |
| 8 |
| 9 import json |
| 10 import os |
| 11 import sys |
| 12 |
| 13 |
| 14 EXPECTED_DIR = os.path.join(os.path.dirname(__file__), 'expected') |
| 15 |
| 16 |
| 17 def VerifyMapping(old_name, new_name, slaves_cfg, mapping): |
| 18 """ Run assertions to verify that the mapping from an old builder name to a |
| 19 new builder name is valid. """ |
| 20 try: |
| 21 # First, is the old name actually a builder name? |
| 22 assert os.path.isfile(os.path.join(EXPECTED_DIR, old_name)) |
| 23 |
| 24 # Trybots should maintain the trybot suffix. |
| 25 if old_name.endswith('Trybot'): |
| 26 assert new_name.endswith('Trybot') |
| 27 else: |
| 28 # If the builder isn't a trybot, it should be explicitly listed in |
| 29 # slaves.cfg. |
| 30 assert new_name in slaves_cfg |
| 31 |
| 32 # Assert that the new builder name isn't duplicated. |
| 33 match_count = 0 |
| 34 for val in mapping.itervalues(): |
| 35 if val == new_name: |
| 36 match_count += 1 |
| 37 assert match_count == 1 |
| 38 |
| 39 # ADD YOUR ASSERTIONS HERE |
| 40 |
| 41 except Exception: |
| 42 print 'Failed assertion for (%s to %s)' % (old_name, new_name) |
| 43 raise |
| 44 |
| 45 |
| 46 def main(argv): |
| 47 if len(argv) != 2: |
| 48 raise Exception('Invalid arguments given; you must provide a mapping file.') |
| 49 with open(argv[1]) as f: |
| 50 mapping = json.load(f) |
| 51 |
| 52 slaves_cfg_file = os.path.join('master', 'slaves.cfg') |
| 53 with open(slaves_cfg_file) as f: |
| 54 slaves_cfg = f.read() |
| 55 |
| 56 for old_name, new_name in mapping.iteritems(): |
| 57 VerifyMapping(old_name, new_name, slaves_cfg, mapping) |
| 58 |
| 59 |
| 60 if '__main__' == __name__: |
| 61 sys.exit(main(sys.argv)) |
OLD | NEW |