Fix the creation of the dumpdir directory in stress_floppy Makefile
[ltp-debian.git] / testcases / network / nfsv4 / locks / locktests.py
blob3e3ff7a04fb07530122f1e86531293a88b2307be
1 #!/usr/bin/python
2 # This script aims to help to run locktests with several clients.
4 # Report bugs to Vincent ROQUETA : vincent.roqueta@ext.bull.net
6 import encodings
7 import shutil
8 import os, sys
9 import getopt, sys
10 import string
11 import socket
12 from stat import *
13 from sys import *
14 from os import *
16 NFS4_PATH="/mnt/nfsv4"
17 NFS4_SERVER=""
18 TEST_HOME="/home/vincent/locks/"
19 testfile=NFS4_PATH+"/testfile"
21 app="locktests"
22 SRC="locktests-2.tar.gz"
23 SRC_PATH="deploy"
24 install="'tar xzf "+SRC+"; cd locks; make `"
25 user="root"
31 class Machine:
33 def mkdir(self,dir):
34 self.command="mkdir -p "+dir
35 self.do()
36 def rmdir(self,dir):
37 self.command="rm -rf "+dir
38 self.do()
40 def printc(self):
41 print "->"+self.command
42 print "\n"
44 class Client(Machine):
46 def __init__(self, machine):
47 self.command=""
48 self.machine=machine
49 self.mountPath=NFS4_PATH
51 def do(self):
52 self.command="ssh "+user+"@"+self.machine+" "+self.command
53 os.system(self.command)
55 def isomount(self, dir):
56 export=NFS4_SERVER
57 mntpoint=NFS4_PATH
58 self.command="'mkdir -p "+mntpoint+"; mount -t nfs4 "+export+" "+mntpoint+"'"
59 self.do()
61 def umount(self, dir):
62 mntpoint=self.mountPath+"/"+dir
63 self.command="umount "+mntpoint
64 self.do()
65 def install(self, path):
66 self.command="'cd "+path+"; tar xzf "+SRC+"; cd locks; make'"
67 self.do()
69 def run(self, appli):
70 self.command=appli
71 self.do()
72 def cp(self, fichier, path):
73 command="scp "+fichier+" "+user+"@"+self.machine+":"+path
74 os.system(command)
77 class Serveur(Machine):
79 def __init__(self, ip, exportPath):
80 self.SERVEUR=ip
81 self.exportPath=exportPath
83 def do(self):
84 self.command="ssh "+self.SERVEUR+" "+self.command
85 os.system(self.command)
87 def configure(self, dir):
88 exportDir=self.exportPath+'/'+dir
89 self. mkdir(exportDir)
90 #self.printc()
91 self.export(exportDir)
92 #self.printc()
93 def clean(self, dir):
94 unexportDir=self.exportPath+'/'+dir
95 self.unexport(unexportDir)
96 self.rmdir(unexportDir)
97 def usage():
98 print "\n"
99 print "usage:"
100 print "locktests.py <-n process -f testfile ><--setup -s fs_server> -c host1, host2, host3 ... "
101 print "--setup : setup the configuration, deploy test on other test machines; This option also requires -c and -s"
102 print "-c <machine> : host list to deploy/run/clean the test"
103 print "-s <machine> : NFS server to use to setup the test"
104 print "-n <num> : number of processes each test machine will lauch to perform the test"
105 print "-f <file> : test file. This must be the same on each machine"
106 print " "
107 print "Example :"
108 print "========="
109 print "*Setup machines for testing"
110 print "./locktests.py --setup -c testmachine1 testmachine2 testmachine3 -s my_nfs_server:/"
111 print "\n"
112 print "*Run test on testmachine1,testmachine2 with 50 process on each machine using /mnt/nfsv4/testfile"
113 print "./locktests.py -n 50 -f /mnt/nfsv4/testfile -c testmachine1 testmachine2"
114 print "\n"
115 print "_________________________________"
116 print "Vincent ROQUETA - Bull SA - 2005\n"
118 return 0
122 def setup():
123 path=os.path.abspath(".")
124 fichier=SRC_PATH+"/"+SRC
125 commande=""
126 for i in clients:
127 print "Setting up machine "+i
128 c=Client(i)
129 c.mkdir(path)
130 c.cp(fichier, path)
131 c.install(path)
132 c.isomount(NFS4_PATH)
133 #Setup localhost
134 print "Setting up localhost"
135 commande="make; mkdir -p "+NFS4_PATH+" ; mount -t nfs4 "+NFS4_SERVER+" "+NFS4_PATH+" &"
136 os.system(commande)
139 def run():
140 path=os.path.abspath(".")
141 nbreClients=len(clients)
142 hostname=socket.gethostname()
143 # Lancement du serveur en local
144 # Launch the server locally
145 commande=path+"/"+app+" -n "+nbreProcess+" -f "+filename+" -c "+str(nbreClients)+" &"
146 os.system(commande)
147 commande=path+"/locks/"+app+" --server "+hostname
148 for i in clients:
149 c=Client(i)
150 c.run(commande)
152 def clean():
153 for i in clients:
154 client.umount(NFS4_PATH)
161 args=sys.argv[1:]
162 rge=range(len(args))
163 a=""
164 r=True
165 s=False
166 nfsServer=False
167 c=False
168 f=False
169 n=False
170 clients=[]
171 for i in rge:
172 if args[i] in ("--install", "-i", "--setup"):
173 r=False
174 s=True
175 continue
176 if args[i] in ("-s", "--server"):
177 a="nfsServer"
178 nfsServer=True
179 continue
180 if args[i] in ("-h", "--help"):
181 usage()
182 sys.exit(1)
183 if args[i] in ("--clients", "-c"):
184 a="clients"
185 c=True
186 continue
187 if args[i] == "-n":
188 a="nbre"
189 n=True
190 continue
191 if args[i] == "-f":
192 a="file"
193 f=True
194 continue
196 if a=="clients":
197 clients.append(args[i])
198 continue
199 if a=="file":
200 filename=args[i]
201 continue
202 if a=="nbre":
203 nbreProcess=args[i]
204 continue
205 if a=="nfsServer":
206 NFS4_SERVER=args[i]
207 continue
210 usage()
211 # For ...
212 if s:
213 if (not c) or (not nfsServer):
214 usage()
215 sys.exit(1)
216 print "Setup"
217 print NFS4_SERVER
218 setup()
219 print "Setup complete"
221 if r:
222 if (not c) or (not f) or (not n):
223 usage()
224 sys.exit(1)
226 print "Running test"
227 run()