• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python3
2# This script aims to help to run locktests with several clients.
3#
4# Report bugs to Vincent ROQUETA : vincent.roqueta@ext.bull.net
5
6import encodings
7import shutil
8import os, sys
9import getopt, sys
10import string
11import socket
12from stat import *
13from sys import *
14from os import *
15
16NFS4_PATH="/mnt/nfsv4"
17NFS4_SERVER=""
18TEST_HOME="/home/vincent/locks/"
19testfile=NFS4_PATH+"/testfile"
20
21app="locktests"
22SRC="locktests.tar.gz"
23SRC_PATH="deploy"
24install="'tar xzf "+SRC+"; cd locks;  make `"
25user="root"
26
27
28
29
30
31class Machine:
32
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()
39
40    def printc(self):
41        print("->"+self.command)
42        print("\n")
43
44class Client(Machine):
45
46    def __init__(self, machine):
47        self.command=""
48        self.machine=machine
49        self.mountPath=NFS4_PATH
50
51    def do(self):
52        self.command="ssh "+user+"@"+self.machine+" "+self.command
53        os.system(self.command)
54
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()
60
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()
68
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)
75
76
77class Serveur(Machine):
78
79    def __init__(self, ip, exportPath):
80        self.SERVEUR=ip
81        self.exportPath=exportPath
82
83    def do(self):
84        self.command="ssh "+self.SERVEUR+" "+self.command
85        os.system(self.command)
86
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)
97def 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")
117
118		return 0
119
120
121
122def 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)
137
138
139def 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)
151
152def clean():
153   for i in clients:
154    client.umount(NFS4_PATH)
155
156
157
158
159
160
161args=sys.argv[1:]
162rge=list(range(len(args)))
163a=""
164r=True
165s=False
166nfsServer=False
167c=False
168f=False
169n=False
170clients=[]
171for 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
195
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
208
209
210    usage()
211# For ...
212if 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")
220
221if r:
222    if (not c) or (not f) or (not n):
223        usage()
224        sys.exit(1)
225
226    print("Running test")
227    run()
228
229
230
231
232
233
234
235
236
237