1# Copyright 2014 The Chromium OS 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"""Module to compare two machines.""" 5 6from __future__ import print_function 7 8import os.path 9import sys 10import argparse 11 12from machine_manager import CrosMachine 13 14 15def PrintUsage(msg): 16 print(msg) 17 print('Usage: ') 18 print('\n compare_machines.py --chromeos_root=/path/to/chroot/ ' 19 'machine1 machine2 ...') 20 21 22def Main(argv): 23 24 parser = argparse.ArgumentParser() 25 parser.add_argument('--chromeos_root', 26 default='/path/to/chromeos', 27 dest='chromeos_root', 28 help='ChromeOS root checkout directory') 29 parser.add_argument('remotes', nargs=argparse.REMAINDER) 30 31 options = parser.parse_args(argv) 32 33 machine_list = options.remotes 34 if len(machine_list) < 2: 35 PrintUsage('ERROR: Must specify at least two machines.') 36 return 1 37 elif not os.path.exists(options.chromeos_root): 38 PrintUsage('Error: chromeos_root does not exist %s' % options.chromeos_root) 39 return 1 40 41 chroot = options.chromeos_root 42 cros_machines = [] 43 test_machine_checksum = None 44 for m in machine_list: 45 cm = CrosMachine(m, chroot, 'average') 46 cros_machines = cros_machines + [cm] 47 test_machine_checksum = cm.machine_checksum 48 49 ret = 0 50 for cm in cros_machines: 51 print('checksum for %s : %s' % (cm.name, cm.machine_checksum)) 52 if cm.machine_checksum != test_machine_checksum: 53 ret = 1 54 print('Machine checksums do not all match') 55 56 if ret == 0: 57 print('Machines all match.') 58 59 return ret 60 61 62if __name__ == '__main__': 63 retval = Main(sys.argv[1:]) 64 sys.exit(retval) 65