aboutsummaryrefslogtreecommitdiff
path: root/crosperf/compare_machines.py
blob: 756753a2c606d36078356ef1880c3905923daeeb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# -*- coding: utf-8 -*-
# Copyright 2014 The ChromiumOS Authors
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

"""Module to compare two machines."""


import argparse
import os.path
import sys

from machine_manager import CrosMachine


def PrintUsage(msg):
    print(msg)
    print("Usage: ")
    print(
        "\n compare_machines.py --chromeos_root=/path/to/chroot/ "
        "machine1 machine2 ..."
    )


def Main(argv):

    parser = argparse.ArgumentParser()
    parser.add_argument(
        "--chromeos_root",
        default="/path/to/chromeos",
        dest="chromeos_root",
        help="ChromeOS root checkout directory",
    )
    parser.add_argument("remotes", nargs=argparse.REMAINDER)

    options = parser.parse_args(argv)

    machine_list = options.remotes
    if len(machine_list) < 2:
        PrintUsage("ERROR: Must specify at least two machines.")
        return 1
    elif not os.path.exists(options.chromeos_root):
        PrintUsage(
            "Error: chromeos_root does not exist %s" % options.chromeos_root
        )
        return 1

    chroot = options.chromeos_root
    cros_machines = []
    test_machine_checksum = None
    for m in machine_list:
        cm = CrosMachine(m, chroot, "average")
        cros_machines = cros_machines + [cm]
        test_machine_checksum = cm.machine_checksum

    ret = 0
    for cm in cros_machines:
        print("checksum for %s : %s" % (cm.name, cm.machine_checksum))
        if cm.machine_checksum != test_machine_checksum:
            ret = 1
            print("Machine checksums do not all match")

    if ret == 0:
        print("Machines all match.")

    return ret


if __name__ == "__main__":
    retval = Main(sys.argv[1:])
    sys.exit(retval)