-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun_bullseye_stage2.py
executable file
·329 lines (314 loc) · 18.4 KB
/
run_bullseye_stage2.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
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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
#!/usr/bin/python
import sys
import re
import fileinput
import os
import shutil
import subprocess
import time
from datetime import datetime
import signal
import string
from threading import Timer
import yaml
import pdb
def kill_proc(proc, timeout):
timeout["value"] = True
py_version = sys.version_info[:2]
print "timeout, kill process."
if py_version > (2,5):
proc.kill()
else:
os.kill(proc.pid, signal.SIGTERM)
def run_qa_test(run_dir, test_dir, timeout_sec, args_list):
# Setup PYTHONPATH
print "setup PYTHONPATH"
py_path1 = os.path.join(run_dir, 'test')
py_path2 = os.path.join(run_dir, 'test', 'lib')
py_path3 = os.path.join(run_dir, 'test', 'lib', 'pytest', 'plugin')
os.environ['PYTHONPATH'] = py_path1 + ':' + py_path2 + ':' + py_path3
print "PYTHONPATH is: %s" % os.environ['PYTHONPATH']
# Setup SPLUNK_DB
splunkdb_path = os.path.join(os.environ['SPLUNK_HOME'], 'var', 'lib', 'splunk')
os.environ['SPLUNK_DB'] = splunkdb_path
print "SPLUNK_DB is %s" % os.environ['SPLUNK_DB']
# Define splunk & py.test command path
splunk_dir = os.path.join(os.environ['SPLUNK_HOME'], 'bin', 'splunk')
pytest_cmd = os.path.join(os.environ['SPLUNK_HOME'], 'bin', 'py.test')
print "py.test exists: %s" % os.path.exists(pytest_cmd)
command_line = "%s %s %s %s %s" % (splunk_dir, 'cmd', 'python', pytest_cmd, args_list)
command_list = [command_line, '-v']
proc = subprocess.Popen(command_list, shell=True, cwd=test_dir,
bufsize=0, stdin=subprocess.PIPE,
stdout=None, stderr=None, close_fds=True)
timeout = {"value" : False}
#print proc.stdout.read()
timer = Timer(timeout_sec, kill_proc, [proc, timeout])
timer.start()
stdout, stderr = proc.communicate()
timer.cancel()
return proc.returncode, stdout, stderr, timeout["value"]
def generate_reports(covfile, branch_path,
report_dir='/home/eserv/bullseye_reports',
output_dir='/home/eserv/bullseye_reports'):
print "generate reports"
html_file = os.path.join(branch_path, 'covbr.html')
covbr_cmd = ' '.join(['/usr/bullseye/bin/covbr', '--file', covfile,
'--html'])
p = subprocess.Popen(covbr_cmd, shell=True, bufsize=1024,
stdin=subprocess.PIPE, stdout=subprocess.PIPE,
stderr=subprocess.PIPE, close_fds=True)
html = p.stdout.read()
f = open(html_file, 'w')
f.write(html)
f.close()
report_commands = ['covdir', 'covsrc', 'covclass', 'covfn']
for rc in report_commands:
outfile = '.'.join([rc, 'csv'])
full_outfile = os.path.join(branch_path, outfile)
full_rc = os.path.join('/usr/bullseye/bin', rc)
full_cmd = ' '.join([full_rc, '--file', covfile, '-u', '-c'])
p = subprocess.Popen(full_cmd, shell=True, bufsize=1024,
stdin=subprocess.PIPE, stdout=subprocess.PIPE,
stderr=subprocess.PIPE, close_fds=True)
(child_stdin, child_stdout, child_stderr) = (p.stdin, p.stdout,
p.stderr)
op = child_stdout.readlines()
header_line = op[0]
if rc == 'covfn':
header_line = header_line.replace('out of', 'decision total')
header_line = header_line.replace('%', 'decision_percent')
else:
header_line = header_line.replace('out of', 'total functions', 1)
header_line = header_line.replace('%', 'func_percent', 1)
header_line = header_line.replace('out of', 'decision total')
header_line = header_line.replace('%', 'branch_percent')
op[0] = header_line
f = open(full_outfile, 'w')
f.write(''.join(op))
f.close()
shutil.copy(covfile, branch_path)
def kill_proc_and_release_port():
# This is a utility function to kill process bound on port
# 8000 and 8089
cmd = '/usr/sbin/lsof -i TCP:%s'
ports = ['8000', '8089']
for eachPort in ports:
proc = subprocess.Popen([cmd % eachPort], shell=True, bufsize=0, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, close_fds=True)
stdout, stderr = proc.communicate()
if not stderr:
if stdout:
cmd_line = stdout.split('\n')
if len(cmd_line) > 1:
second_line = cmd_line[1]
if second_line:
second_list = second_line.split()
if len(second_list) > 2:
pid = second_list[1]
if pid and isNumber(pid):
# Let us kill the process
print os.system('kill -9 ' + pid)
def isNumber(token):
for char in token:
if not char in string.digits: return False
return True
def main(argv):
print "======== run_bullseye_stage2.py ========"
os.environ['SPLUNK_HOME'] = '/home/eserv/splunk'
os.environ['SPLUNK_DB'] = '/home/eserv/splunk/var/lib/splunk'
os.environ['PATH'] = os.environ['PATH'] + ':' + '/sbin'
os.environ['JAVA_HOME'] = '/usr/java/jdk1.7.0_25'
# To support multiple branch, default set to ace
#branches = {'si-staging' : 'branches/si-staging'}
branches = {'current' : 'current'}
#if len(argv) > 0:
# if argv[0][0:8] == "-branch=":
# if branches_pool.has_key(argv[0][8:]):
# branches = {argv[0][8:]: branches_pool[argv[0][8:]]}
#n = datetime.now()
#dirname = n.strftime('%Y-%m-%d-%H_%M')
dir = '/home/eserv/bullseye_reports'
for name in os.listdir(dir):
if os.path.isdir(os.path.join(dir, name)) and re.match('\d{4}-\d{2}-\d{2}-\d{2}_\d{2}', name):
break
full_path = os.path.join('/home/eserv/bullseye_reports', name)
for branch in branches:
print "branch is: %s" % branch
branch_path = os.path.join(full_path, branch)
dirname = branches[branch]
covfile = '.'.join([branch, 'cov'])
full_covfile = os.path.join('/home/eserv/bullseye_reports', covfile)
if 'COVFILE' not in os.environ:
os.environ['COVFILE'] = full_covfile
print "COVFILE is %s in stage 2" % os.environ['COVFILE']
subprocess.call(['/usr/bullseye/bin/cov01', '-1'])
rundir = os.path.join('/home/eserv/perforce/splunk', dirname)
print "rundir is: %s " % rundir
# Kill hung process on port 8000 & 8089
kill_proc_and_release_port()
p_path = os.environ["PYTHONPATH"]
str_list = p_path.split(":")
if '/home/eserv/splunk/lib' in str_list[0] or '/home/eserv/splunk/lib' in str_list[0]:
str_list.append(str_list[0])
str_list.pop(0)
os.environ['PYTHONPATH'] = ":".join(str_list)
if 'PYTHONPATH' in os.environ:
os.environ['PYTHONPATH'] = os.environ['PYTHONPATH'] + ":" + \
"/home/eserv/splunk/lib/python2.7/site-packages" \
+ ":" + "/home/eserv/perforce/splunk/current/new_test/lib/splunktest/rest/feedparser"
else:
os.environ['PYTHONPATH'] = "/home/eserv/splunk/lib/python2.7/site-packages" \
+ ":" + "/home/eserv/perforce/splunk/current/new_test/lib/splunktest/rest/feedparser"
print "PYTHONPATH is: %s " % os.environ["PYTHONPATH"]
# Substitute conftest.py with install_from_archive
print "substitute conftest.py with install_from_archive"
conf_path = os.path.join(rundir, 'new_test', 'tests', 'forwarder_mgmt', 'backend', 'conftest.py')
for line in fileinput.input(conf_path, inplace=1):
if re.search('\w+\.(install_nightly)\(\w+.*\).*', line):
str_split = line.split('.')
str_split[1] = '.'
str_split.append('install_from_archive(\'/home/eserv/splunk_archive/splunk.tar.gz\')')
str_split.append('\n')
line = ''.join(str_split)
sys.stdout.write(line)
test_dir = '/home/eserv/perforce/splunk/current/new_test/tests/forwarder_mgmt/backend'
print "run forwarder mgmt backend new_test"
command_list = ['python /home/eserv/perforce/splunk/current/new_test/bin/pytest/pytest.py \
-v --ignore=webdriver --num_of_forwarders=2']
proc = subprocess.Popen(command_list, shell=True, cwd=test_dir,
bufsize=0, stdin=subprocess.PIPE,
stdout=None, stderr=None, close_fds=True)
proc.communicate()
# Substitute conftest.py with install_from_archive in structured_data conftest.py
print "substitute conftest.py with install_from_archive in structured_data"
conf_path = os.path.join(rundir, 'new_test', 'tests', 'forwarding', 'structured_data', 'conftest.py')
for line in fileinput.input(conf_path, inplace=1):
if re.search('(splunk_indexer\.install_nightly)\(\w+.*\).*', line) or \
re.search('(splunk_single_instance\.install_nightly)\(\w+.*\).*', line):
str_split = line.split('.')
str_split[1] = '.'
str_split.append('install_from_archive(\'/home/eserv/splunk_archive/splunk.tar.gz\')')
str_split.append('\n')
line = ''.join(str_split)
sys.stdout.write(line)
test_dir = '/home/eserv/perforce/splunk/current/new_test/tests/forwarding/structured_data'
command_list = ['python /home/eserv/perforce/splunk/current/new_test/bin/pytest/pytest.py \
-v --branch=current']
proc = subprocess.Popen(command_list, shell=True, cwd=test_dir,
bufsize=0, stdin=subprocess.PIPE,
stdout=None, stderr=None, close_fds=True)
# Stop test execution in case it hangs
timeout = {"value" : False}
timer = Timer(39600, kill_proc, [proc, timeout])
timer.start()
stdout, stderr = proc.communicate()
timer.cancel()
# Release bound port 8000 and 8089, otherwise test hangs !!!
kill_proc_and_release_port()
# Run clustering search test suite
print "Run clustering search test suite"
test_dir = '/home/eserv/perforce/splunk/current/new_test/tests/clustering/search'
command_list = ['python /home/eserv/perforce/splunk/current/new_test/bin/pytest/pytest.py \
-v test_batch_mode.py --conf-file=/home/eserv/perforce/splunk/current/new_test/config/clustering/_global-conf.yml \
--branch=current --new_password=notchangeme --local_build=/home/eserv/splunk']
proc = subprocess.Popen(command_list, shell=True, cwd=test_dir,
bufsize=0, stdin=subprocess.PIPE,
stdout=None, stderr=None, close_fds=True)
#pdb.set_trace()
# Stop test execution in case it hangs
timeout = {"value" : False}
timer = Timer(39600, kill_proc, [proc, timeout])
timer.start()
stdout, stderr = proc.communicate()
timer.cancel()
# Release bound port 8000 and 8089, otherwise test hangs !!!
kill_proc_and_release_port()
# Run clustering framework test suite
print "Run clustering framework test suite"
test_dir = '/home/eserv/perforce/splunk/current/new_test/tests/clustering/framework'
command_list = ['python /home/eserv/perforce/splunk/current/new_test/bin/pytest/pytest.py \
-v --branch=current --new_password=notchangeme --local_build=/home/eserv/splunk']
proc = subprocess.Popen(command_list, shell=True, cwd=test_dir,
bufsize=0, stdin=subprocess.PIPE,
stdout=None, stderr=None, close_fds=True)
# Stop test execution in case it hangs
timeout = {"value" : False}
timer = Timer(39600, kill_proc, [proc, timeout])
timer.start()
stdout, stderr = proc.communicate()
timer.cancel()
# Release bound port 8000 and 8089, otherwise test hangs !!!
kill_proc_and_release_port()
# Need to update yaml file
yaml_path = os.path.join(rundir, 'test', 'search', 'distributed')
yaml_file = 'bamboo-self-all.yml'
print "yaml_path=%s" % yaml_path
updateYamlFile(yaml_path, yaml_file)
# Make sure that COVFILE exists up to this moment
if 'COVFILE' not in os.environ:
os.environ['COVFILE'] = full_covfile
print "COVFILE is %s in stage 2" % os.environ['COVFILE']
subprocess.call(['/usr/bullseye/bin/cov01', '-1'])
tests = {
#'search standard' : os.path.join(rundir, 'test', 'search', 'standard'),
'3_cli' : os.path.join(rundir, 'test', 'tests', 'cli'),
'6_framework' : os.path.join(rundir, 'test', 'tests', 'framework'),
'4_rest' : os.path.join(rundir, 'test', 'tests', 'rest'),
'1_search longrunning' : os.path.join(rundir, 'test', 'search', 'longrunning'),
'2_search distributed' : os.path.join(rundir, 'test', 'search', 'distributed'),
'5_auth' : os.path.join(rundir, 'test', 'tests', 'auth')
}
args = {
#'search standard' : '',
'3_cli' : 'test_app.py test_find.py test_monitor.py test_password.py test_user.py test_tcp.py test_udp.py test_sync_async_search.py test_spool.py test_settings.py test_savedsearch.py test_forwarding.py test_index.py test_oneshot.py test_scripted.py test_receiving.py test_license.py test_deploy.py',
'6_framework' : 'test_input_modular.py test_app_lwf.py test_app_scoped_inputs.py test_cli_diag.py test_cluster.py test_deployment_server.py test_forwarding_clone.py test_forwarding_persistent_q.py test_forwarding_single.py test_free_restrictions.py test_gdb_rolling.py test_host_regex.py test_input_admon_grp.py test_input_admon.py test_input_archive.py test_input_batch.py test_input_blacklist.py test_input_catastrophe.py test_input_compressed.py test_input_datetime.py test_input_during_restart.py test_input_exec.py test_input_fifo.py test_input_hostname_normalization.py test_input_i18n.py test_input_net.py test_input_networktail.py test_input_pathlen.py test_input_perfmon.py test_input_regmon.py test_input_remote_file_system.py test_input_rolling.py test_input_rotated.py test_input_script.py test_input_sinkhole.py test_input_source.py test_input_sourcetype.py test_input_tail_err_retry.py test_input_tailfeatures.py test_input_tcp.py test_input_uncompressed.py test_input_upload.py test_input_whitelist.py test_memory_consumption.py test_startup_warnings.py',
#'cli' : 'test_tcp.py',
#'rest' : '-k -windows test_saved_search.py'
'4_rest' : '-k -windows test_saved_search.py test_scheduled_views.py test_search_distributed_config.py test_search_distributed_peers.py test_search_fields.py test_search_jobs_export.py test_search_parser.py test_search_results.py test_search_tags.py test_search_timeparser.py test_search_typeahead.py test_server_control.py test_server_info.py test_server_logger.py test_server_settings.py test_storage_passwords.py test_LDAP_authentication.py test_alerts_fired_alerts.py test_appbuilder.py test_apps_local.py test_auth_login.py test_authentication_changepassword.py test_authentication_httpauth-tokens.py test_authentication_users.py test_authorization_capabilities.py test_authorization_roles.py test_configs_conf.py test_data_indexes.py test_data_indexes_bucketInfo.py test_data_inputs_monitor.py test_data_inputs_oneshot.py test_data_inputs_script.py test_data_inputs_tcp_cooked.py test_data_inputs_tcp_raw.py test_data_inputs_tcp_ssl.py test_data_inputs_udp.py test_data_outputs_tcp_default.py test_data_outputs_tcp_group.py test_data_outputs_tcp_server.py test_data_outputs_tcp_syslog.py test_deployment_client.py test_deployment_server.py test_deployment_serverclass.py test_deployment_tenants.py test_directory.py test_fromxml.py test_ipv6_compliant.py test_licenser_groups.py test_licenser_licenses.py test_licenser_messages.py test_licenser_pools.py test_licenser_slaves.py test_licenser_stacks.py test_messages.py test_moving.py test_properties.py test_receivers_simple.py test_receivers_stream.py',
'1_search longrunning' : '',
'2_search distributed' : '-v --debug --dist-setup=bamboo-self-all-eserv.yml',
'5_auth' : '--auth=auth.yml -s'
}
# Sort the tests' keys
tests_keys = tests.keys()
tests_keys.sort()
for aTest in tests_keys:
print "Start %s test:" % aTest
# At the end of each test
# we do a cleanup
splunk_bin = os.path.join(os.environ['SPLUNK_HOME'], 'bin', 'splunk')
print "splunk_bin: %s" % splunk_bin
subprocess.call([splunk_bin, 'stop'])
subprocess.call([splunk_bin, 'clean', 'all', '-f'])
subprocess.call([splunk_bin, 'start'])
# Record the time spent
time1 = datetime.now()
rc, stdout, stderr, timeout_value = run_qa_test(rundir, tests[aTest], 39600, args[aTest])
time2 = datetime.now()
delta = time2 - time1
f = open(os.path.join(full_path, 'time_spent.log'), 'a')
f.write("%s time spent (seconds):\n" % aTest)
f.write("%s\n" % str(delta.seconds))
f.close()
if rc != 0:
print '%s tests return code is %s, %s %s %s' % (aTest, rc, stdout, stderr, timeout_value)
print 'finish %s test' % aTest
subprocess.call(['/usr/bullseye/bin/cov01', '-0'])
generate_reports(full_covfile, branch_path)
# Stop Splunk to be removed
subprocess.call([splunk_bin, 'stop'])
print '/bin/tar' + ' -rf' + ' /home/eserv/bullseye_reports/bullseye-%s.tar' % branch + ' ' + full_path + ' --exclude=*.cov'
subprocess.call(['/bin/tar', '-rf',
'/home/eserv/bullseye_reports/bullseye-%s.tar' % branch, full_path,
'--exclude=*.cov'])
def updateYamlFile(path, new_file):
stream = open(os.path.join(path, new_file), 'r')
input = yaml.load(stream)
input['peer1']['sshUser'] = 'eserv'
input['peer2']['sshUser'] = 'eserv'
input['head']['sshUser'] = 'eserv'
new_file_path = os.path.join(path, 'bamboo-self-all-eserv.yml')
stream = file(new_file_path, 'w')
yaml.dump(input, stream)
if __name__ == '__main__':
main(sys.argv[1:])