forked from mmadhusu/nfs-test-framework
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
executable file
·151 lines (124 loc) · 4 KB
/
main.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
#!/usr/bin/python
import sys,getopt,threading
from subprocess import call
import gluster_setup,os,time,check_tests,counter
from print_results import print_results
from tests.check_setup import check_setup
from usage import usage
import header
from mount import mount
server_ip=""
client_ip=""
lfile=""
cleanup=""
confile=""
fs=""
total=11
nfs4_total=0
nfs3_total=0
known_failures=13
version=""
test_list=list()
argv=sys.argv[1:]
try:
opts, args = getopt.getopt(argv,"hl:ns:v:t:f:b:e:",["nocleanup"])
except getopt.GetoptError:
print 'main.py -s <SERVER-HOST-IP> -e <EXPORT> -b <BACK-END-FILE-SYSTEM> -f <CONFIG_FILE> -l [LOG_FILE] -t [TESTS] -v [NFS_VERSION][-n|--nocleanup]'
sys.exit(2)
for opt, arg in opts:
if opt == '-h':
print 'main.py -i <logfile> -n|--nocleanup'
sys.exit()
elif opt in ("-n", "--nocleanup"):
cleanup = "yes"
print "Tests to be run in no cleanup mode"
elif opt == '-l':
lfile = arg
elif opt == '-s':
server_ip = arg
elif opt == '-f':
confile = arg
elif opt == '-t':
test_list.append(arg)
elif opt == '-v':
version = arg
elif opt == '-b':
fs = arg
elif opt == '-e':
export = arg
class Logger(object):
def __init__(self):
self.terminal = sys.stdout
self.log = open(lfile, "a")
def write(self, message):
self.terminal.write(message)
self.log.write(message)
class myThread (threading.Thread):
def __init__(self, name):
threading.Thread.__init__(self)
self.name = name
#self.test = test
def run(self):
os.system(self.name)
usage(server_ip)
usage(confile)
usage(fs)
usage(export)
check_setup(fs)
if lfile == "":
lfile="/tmp/ganesha.log"
if os.path.isfile(lfile) == True :
os.remove(lfile)
sys.stdout = Logger()
header.header_1(lfile)
test_list = check_tests.check_list(test_list, version);
if not test_list:
print "Nothing to be tested."
sys.exit(0)
original = os.getcwd()
gluster_setup.setup(export,server_ip,client_ip,confile)
def run_tests(list):
# os.chdir("./test-dir")
for test in list:
if test == "pynfs_tests.py":
thread1 = myThread("python %s %s %s %d %s " %('tests/test-dir/'+test,server_ip,export,known_failures,lfile))
else:
thread1 = myThread("python %s %s %s %s" %('tests/test-dir/'+test,lfile,server_ip,export))
thread1.start()
thread1.join()
if (version == "4" or version==""):
call('umount /mnt/ganesha-mnt',shell=True)
mount(export,server_ip,"4")
if os.path.ismount('/mnt/ganesha-mnt') == False:
if version == "4":
print "v4 mount failed,exiting."
sys.exit(1)
else:
print "v4 mount failed, skipping v4 tests"
else:
nfs4_total = len(test_list)
print "==============================Running v4 tests=============================="
counter.reset();
run_tests(test_list)
print_results(nfs4_total);
if (version == "3" or version==""):
call('umount /mnt/ganesha-mnt',shell=True)
mount(export,server_ip,"3")
if os.path.ismount('/mnt/ganesha-mnt') == False:
print "v3 mount failed,exiting."
sys.exit(1)
if "pynfs_tests.py" in test_list:
test_list.remove("pynfs_tests.py")
nfs3_total = len(test_list)
print "==============================Running v3 tests=============================="
counter.reset();
run_tests(test_list)
print_results(nfs3_total);
#passed=counter(0)
os.chdir(original)
os.environ['server_ip']=server_ip
os.environ['export']=export
if cleanup == "":
gluster_setup.clean()
os.system('ssh -t $server_ip "yes | /tmp/copy-to-server/cleanup.sh $export" ')
os.system('rm -rf /tmp/counter.txt')