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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
|
#!/usr/bin/python
#checks that the MBE can connect to the minions
# ===============================================
import sys
import os
import string
import time
import func.overlord.client as fc
BBLINE = ''
BBCOLOR="green"
DATE = time.strftime("%a %b %d %H:%M:%S %Z %Y", time.localtime(time.time()))
if os.environ['BB']:
#print os.environ['BB']
BB=os.environ['BB']
if os.environ['BBDISP']:
#print os.environ['BBDISP']
BBDISP=os.environ['BBDISP']
if os.environ['MACHINE']:
#print os.environ['MACHINE']
MACHINE=os.environ['MACHINE']
def readbb():
global hostlist
global mythtype
try:
infile = open('/data/srv/hobbit/etc/bb-hosts', 'r')
except(IOError), e:
print "couldn't open bb-hosts file"
sys.exit(1)
else:
bbhostlist = infile.readlines()
infile.close()
for line in bbhostlist:
cline=line.strip()
if not cline.startswith("#") and cline != '' and cline.find("bbd") == -1 and cline.find("func") != -1 :
host=cline.split("#")
host=host[0].split()
hostlist.append(host[1].strip())
infile.close()
try:
infile = open('/usr/local/share/mythtv/.releasetype')
mythtype= infile.readline()
infile.close()
except(IOError), e:
print "couldn't open mythfile "
mythtype='unkown'
def find_local_myth_version():
global mythtype
local_pkg_name="not_found"
pkgname="mythtv"
pkgname+=mythtype
cmd="/usr/bin/pacman -Q %s " %pkgname
result = os.popen2(cmd)[1].readlines()
for list in result:
l=list.strip()
if l.startswith('mythtv') :
local_pkg_name=l.strip()
break
return local_pkg_name
def mythversion_check(currentclient,local_myth_version):
global mythtype
pkgname="mythtv"
pkgname+=mythtype
remote_pkg_name="remote_pkg_not_found"
client = (fc.Client( currentclient ))
results=client.pacman.pkgversion(pkgname)
#print currentclient
#print local_myth_version
#print results[currentclient][1]
try:
for pkg in results[currentclient][1] :
p=pkg.strip()
if p.startswith('mythtv'):
remote_pkg_name=p
break
if (remote_pkg_name != local_myth_version):
BBLINE="Myth version MBE: %s does not match %s %s \n " %(local_myth_version,currentclient,remote_pkg_name)
LINE = "status " + currentclient + ".myth_version yellow" + " " + DATE + " " + BBLINE
if (remote_pkg_name == local_myth_version):
BBLINE="%s: success (green) Myth version match %s \n " %(currentclient,remote_pkg_name)
LINE = "status " + currentclient + ".myth_version green" + " " + DATE + " " + BBLINE
except:
BBLINE="Something went wrong! \n "
LINE = "status " + currentclient + ".myth_version red" + " " + DATE + " " + BBLINE
cmd = BB + ' ' + BBDISP + ' "' + LINE + '"'
os.system(cmd)
return
#-------------------------
global hostlist
global mythtype
mythtype=""
hostlist = []
readbb()
local_myth_version=find_local_myth_version()
for currentclient in hostlist:
client = (fc.Client( currentclient ))
cmd='/data/srv/hobbit/server/bin/bb 127.0.0.1 "query '
cmd+=currentclient
cmd+='.conn"'
bbresults=os.popen(cmd,'r' ).readline().strip().split()
bbstate=bbresults[0]
if bbstate == 'green':
results=client.test.add("1","2")
try:
#print currentclient
#print results[currentclient]
#print type(results[currentclient])
#print "----------"
if type(results[currentclient]) == str:
if results[currentclient] == '12':
BBLINE="%s: success (green) \n " %currentclient
LINE = "status " + currentclient + ".func green" + " " + DATE + " " + BBLINE
cmd = BB + ' ' + BBDISP + ' "' + LINE + '"'
os.system(cmd)
#REMOVE HOST FROM FAILED_FUNC
cmd='sed -i "/' + currentclient + '/d" /data/srv/httpd/htdocs/failed_func_hosts'
os.system(cmd)
mythversion_check(currentclient,local_myth_version)
else:
BBLINE="%s: connected but wtf (yellow) \n " %currentclient
LINE = "status " + currentclient + ".func yellow" + " " + DATE + " " + BBLINE
cmd = BB + ' ' + BBDISP + ' "' + LINE + '"'
os.system(cmd)
if BBCOLOR != "red":
BBCOLOR="yellow"
else:
BBLINE="%s: %s (red) \n " %(currentclient,results[currentclient])
LINE = "status " + currentclient + ".func red" + " " + DATE + " " + BBLINE
cmd = BB + ' ' + BBDISP + ' "' + LINE + '"'
cmd2= "echo " + currentclient + " >> /data/srv/httpd/htdocs/failed_func_hosts"
cmd3="sudo /usr/bin/certmaster-ca -c " + currentclient
os.system(cmd2)
os.system(cmd3)
os.system(cmd)
BBCOLOR="red"
except:
BBLINE="%s had an error : %s (red) \n " % (currentclient,str(results))
LINE = "status " + currentclient + ".func red" + " " + DATE + " " + BBLINE
cmd = BB + ' ' + BBDISP + ' "' + LINE + '"'
cmd2= "echo " + currentclient + " >> /data/srv/httpd/htdocs/failed_func_hosts"
os.system(cmd)
os.system(cmd2)
cmd3="sudo /usr/bin/certmaster-ca -c " + currentclient
os.system(cmd3)
BBCOLOR="red"
else:
BBLINE+= "not testing %s \n " % currentclient
#LINE = "status " + MACHINE + ".func green" + " " + DATE + " " + BBLINE
#cmd = BB + ' ' + BBDISP + ' "' + LINE + '"'
#os.system(cmd)
#print BBLINE
#print BBCOLOR
|