• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python
2# Copyright 2015 The Chromium Authors. All rights reserved.
3# Use of this source code is governed by a BSD-style license that can be
4# found in the LICENSE file.
5
6"""Query build slave hardware info, and print it to stdout as csv."""
7
8import csv
9import json
10import logging
11import sys
12import urllib2
13
14
15_MASTERS = [
16    'chromium.perf',
17    'chromium.perf.fyi',
18    'client.catapult',
19    'tryserver.chromium.perf',
20    'tryserver.client.catapult',
21]
22
23
24_KEYS = [
25    'master', 'builder', 'hostname',
26
27    'os family', 'os version', 'bitness (userland)',
28
29    'product name', 'architecture', 'processor count', 'processor type',
30    'memory total',
31
32    'facter version', 'git version', 'puppet version', 'python version',
33    'ruby version',
34
35    'android device 1', 'android device 2', 'android device 3',
36    'android device 4', 'android device 5', 'android device 6',
37    'android device 7', 'android device 8',
38]
39_EXCLUDED_KEYS = frozenset([
40    'architecture (userland)',
41    'b directory',
42    'last puppet run',
43    'uptime',
44    'windows version',
45])
46
47
48def main():
49  writer = csv.DictWriter(sys.stdout, _KEYS)
50  writer.writeheader()
51
52  for master_name in _MASTERS:
53    master_data = json.load(urllib2.urlopen(
54        'http://build.chromium.org/p/%s/json/slaves' % master_name))
55
56    slaves = sorted(master_data.iteritems(),
57                    key=lambda x: (x[1]['builders'].keys(), x[0]))
58    for slave_name, slave_data in slaves:
59      for builder_name in slave_data['builders']:
60        row = {
61            'master': master_name,
62            'builder': builder_name,
63            'hostname': slave_name,
64        }
65
66        host_data = slave_data['host']
67        if host_data:
68          host_data = host_data.splitlines()
69          if len(host_data) > 1:
70            for line in host_data:
71              if not line:
72                continue
73              key, value = line.split(': ')
74              if key in _EXCLUDED_KEYS:
75                continue
76              row[key] = value
77
78        # Munge keys.
79        row = {key.replace('_', ' '): value for key, value in row.iteritems()}
80        if 'osfamily' in row:
81          row['os family'] = row.pop('osfamily')
82        if 'product name' not in row and slave_name.startswith('slave'):
83          row['product name'] = 'Google Compute Engine'
84
85        try:
86          writer.writerow(row)
87        except ValueError:
88          logging.error(row)
89          raise
90
91
92if __name__ == '__main__':
93  main()
94