forked from mozilla/briar-patch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkitten.py
122 lines (91 loc) · 3.42 KB
/
kitten.py
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#!/usr/bin/env python
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this file,
# You can obtain one at http://mozilla.org/MPL/2.0/.
""" Host check tool
:copyright: (c) 2012 by Mozilla
:license: MPLv2
Assumes Python v2.6+
Authors:
bear Mike Taylor <[email protected]>
"""
import sys, os
import re
import time
import json
import random
import logging
import datetime
import paramiko
from multiprocessing import get_logger, log_to_stderr
from releng import initOptions, initLogs, runCommand, initKeystore, relative
import releng.remote
log = get_logger()
def check(kitten):
s = '%s: ' % kitten
info = remoteEnv.hosts[kitten]
if info['enabled']:
s += 'enabled'
else:
# hopefully short term hack until tegras are
# handled properly by slavealloc...
if 'tegra' in kitten:
s += 'enabled'
else:
s += 'DISABLED'
print s
print '%12s: %s' % ('colo', info['datacenter'])
print '%12s: %s' % ('distro', info['distro'])
print '%12s: %s' % ('pool', info['pool'])
print '%12s: %s' % ('trustlevel', info['trustlevel'])
if len(info['notes']) > 0:
print '%12s: %s' % ('note', info['notes'])
if options.info:
print '%12s: %s' % ('master', info['current_master'])
else:
host = remoteEnv.getHost(kitten)
r = remoteEnv.check(host, dryrun=options.dryrun, verbose=options.verbose, indent=' ', reboot=options.reboot)
for key in ('fqdn', 'reachable', 'buildbot', 'tacfile', 'lastseen', 'master'):
s = r[key]
if key == 'lastseen':
if r[key] is None:
s = 'unknown'
else:
s = relative(r[key])
if key == 'master':
if r[key] is None:
s = info['current_master']
else:
if len(r[key]) > 0:
s = r[key][0]
else:
s = r[key]
print '%12s: %s' % (key, s)
if 'master' in r:
if r['master'] is not None and len(r['master']) > 0:
m = r['master'][0]
else:
m = ''
master = remoteEnv.findMaster(m)
current_master = remoteEnv.findMaster(info['current_master'])
if master['masterid'] != current_master['masterid']:
print '%12s: current master is different than buildbot.tac master [%s]' % ('error', m)
print '%12s: %s' % ('IPMI?', host.hasIPMI)
if options.stop:
print host.graceful_shutdown()
_options = { 'reboot': ('-r', '--reboot', False, 'reboot host if required', 'b'),
'info': ('-i', '--info', False, 'show passive info only, do not ssh to host', 'b'),
'stop': ('', '--stop', False, 'stop buildbot for host', 'b'),
}
if __name__ == "__main__":
options = initOptions(params=_options)
initLogs(options, chatty=False, loglevel=logging.ERROR)
log.debug('Starting')
initKeystore(options)
remoteEnv = releng.remote.RemoteEnvironment(options.tools)
for kitten in options.args:
if kitten in remoteEnv.hosts:
check(kitten)
else:
log.error('%s is not listed in slavealloc' % kitten)
log.debug('Finished')