-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.py
More file actions
98 lines (82 loc) · 3.44 KB
/
test.py
File metadata and controls
98 lines (82 loc) · 3.44 KB
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
import os
import getopt, sys
import traceback
__help_string_ = '''
Usage timer [OPTION] ...
-c, --config=CONFIG_FILE the configure file to load
-P --path=PATH path for nginx install
-n --num=NUMBER number for curl tries
-m, --max_peer_failed=MAX_PEER_FAILED max_peer_failed
-h, --help print this help infomation and exit
'''
def restart(conf, path, max_peer_failed):
'''restart the nginx with our own configure'''
cur_path = os.getcwd()
command = "%s/sbin/nginx -c %s/conf/%s >/dev/null"%(path, cur_path, conf)
print command
os.system( "killall -9 nginx" )
os.system( "export MAX_PEER_FAILED=%s"%max_peer_failed )
os.system( command )
def curl_test(curl_times):
for i in range(int(curl_times)):
# print i
#os.system( "curl http://localhost:8000/%d >> curl_result 2>/dev/null"%i )
os.system( "curl http://localhost:8000/%d >> curl_result 2>/dev/null"%i )
def get_result(path, max_peer_failed):
'''get result of this test'''
log = "%s/logs/error.log"%path
c_pc_tries = '''grep "pc->tries" %s |awk '{print (%s-$NF)}' |sort|uniq -c>>result'''%(log, int(max_peer_failed)+1)
c_rnode_index = '''grep "rnode index" %s |awk '{print $NF}'|sort |uniq -c|awk '{print $1, $2}'>>result '''%log
print c_pc_tries
print c_rnode_index
os.system( c_pc_tries )
os.system( c_rnode_index )
c_sum_pc_tries = ''' grep -v port result |awk '{sum+=$1} END {print "sum_pc_tries = ", sum}' '''
c_sum_rnode_touched = ''' grep port result |awk '{sum+=$1} END {print "sum_rnode_touched = ", sum}' '''
c_pc_failed = ''' grep "The page is temporarily unavailable" curl_result|awk '{sum+=1} END {print "sum_pc_failed= ", sum}' '''
os.system( c_sum_pc_tries )
os.system( c_sum_rnode_touched )
os.system( c_pc_failed )
os.system("cat result")
def clear_all(path):
''' clear log'''
os.system( ">%s/logs/error.log"%path )
os.system( ">curl_result" )
os.system( ">result" )
def test_main(conf, path, max_peer_failed, curl_times):
'''test main function for nginx consistent_hash '''
restart(conf, path, max_peer_failed)
curl_test(curl_times)
get_result(path, max_peer_failed)
clear_all(path)
if __name__ == "__main__":
try:
opts, args = getopt.gnu_getopt(sys.argv[1:], 'c:m:h:p:n:', ['config=',
'path', 'max_peer_failed=', 'help', 'num'])
conf = None
path = None
max_peer_failed = None
curl_times = None
#print opts
for o, a in opts:
if o == '-h' or o == '--help':
print __help_string_
exit()
if o == '-c' or o == '--config':
conf = a
if o == '-p' or o == '--path':
path = a
print a
if o == '-n' or o == '--num':
curl_times = a
print a
if o == '-m' or o == '--max_peer_failed':
max_peer_failed = a
if conf == None or path == None or max_peer_failed == None or curl_times == None:
print __help_string_
else:
print conf, path, max_peer_failed, curl_times
test_main(conf, path, max_peer_failed, curl_times)
except getopt.GetoptError:
#traceback.print_exc(file=sys.stdout)
print __help_string_