ae59068e52d069fbb74250468b40102128c49801
[plcapi.git] / TestPeers.py
1 #!/usr/bin/env python
2 ###
3 ##############################
4 ###
5 ### preparation / requirements
6 ###
7 ### two separate instances of myplc
8 ### for now they are located on the same box on lurch
9 ###
10 ### expectations :
11 ### your myplcs should more or less come out of the box, 
12 ### I prefer not to alter the default PLC_ROOT_USER value,
13 ### instead we create a PI account on the site_id=1
14 ###
15 ##############################
16
17 # support reloading without wiping everything off
18 # dunno how to do (defvar plc)
19
20 import getopt
21 import sys
22
23 ## we use indexes 1 and 2 
24 try:
25     dir(plc)
26 except:
27     plc=[None,None,None]
28 ## the server objects
29 try:
30     dir(s)
31 except:
32     s=[None,None,None]
33 ## the authentication objects
34 ## our user
35 try:
36     dir(a)
37 except:
38     a=[None,None,None]
39 ## the builtin root user for bootstrapping
40 try:
41     dir(aa)
42 except:
43     aa=[None,None,None]
44
45 ####################
46 import xmlrpclib
47 import os
48
49 ####################
50 plc1={ 'plcname':'plc1 in federation',
51        'hostname':'lurch.cs.princeton.edu',
52        'url-format':'https://%s:443/PLCAPI/',
53        'builtin_admin_id':'root@localhost.localdomain',
54        'builtin_admin_password':'root',
55        'peer_admin_name':'plc1@planet-lab.org',
56        'peer_admin_password':'peer',
57        'peer_admin_key':'ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAIEAqK1lKNf61lAGYAXzG6xKnFQkfv3ViG0GP2Krp1zD7d/93IkmsXVEjLfGhEJQjRjzRc9/gFdATP703cDzp4Ag2eR2wdQz0e6SXOBd2sLuW3LqTwor1XMmp5f0QCOg5OSKXwozE3Tlt0+ewBNvAE8HWwZFjou5CFnrFMVZPjqfhpU= thierry.parmentelat@sophia.inria.fr',
58        'node-format':'n1%02d.plc1.org',
59        'plainname' : 'one',
60        'slice-format' : 's1%02d',
61        }
62 plc2={ 'plcname':'plc2 in federation',
63        'hostname':'planetlab-devbox.inria.fr',
64        'url-format':'https://%s:443/PLCAPI/',
65        'builtin_admin_id':'root@localhost.localdomain',
66        'builtin_admin_password':'root',
67        'peer_admin_name':'plc2@planet-lab.org',
68        'peer_admin_password':'peer',
69        'peer_admin_key':'ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAIEAlsX+X+sgN/rsNizPhsXMdHzArxVdwN1KJMG4vTY1m0KQMFJSilaX6xlMIirKhFmNDrVkrOPT2On59K4fDFjGgDq9gMMfdaAfEhxDdy2x1k/H/vJRQE/CqkoRZE8mVAt/cgMsOHTLJTDxBm/0RedaBlcXBpCwqBi3n05sGkS2BjM= VTHD-tester-ssh-v2',
70        'node-format':'n2%02d.plc2.org',
71        'plainname' : 'two',
72        'slice-format' : 's2%02d',
73        }
74
75 ####################
76 # set initial conditions
77 def define_test (nodes,slices):
78     global number_nodes, number_slices
79     number_nodes=nodes
80     number_slices=slices
81
82 def fast():
83     define_test(1,1)
84     
85 define_test (nodes=5,slices=3)
86
87 # predefined stuff
88 system_slices_ids = (1,2)
89 def system_slices ():
90     return len(system_slices_ids)
91 # temporary - the myplc I use doesnt know about 'system' yet
92 def system_slivers ():
93 #    return len(system_slices_ids)
94     return 0
95
96 def total_slices ():
97     return number_slices+system_slices()
98 def total_slivers ():
99     return number_slices+system_slivers()
100
101 ####################
102 def peer_index(i):
103     return 3-i
104
105 def plc_name (i):
106     return plc[i]['plcname']
107
108 def site_name (i):
109     return 'site'+str(i)
110
111 def node_name (i,n):
112     return plc[i]['node-format']%n
113
114 def slice_name (i,n):
115     return plc[i]['plainname']+'_'+plc[i]['slice-format']%n
116
117 # to have indexes start at 1
118 def myrange (n):
119     return range (1,n+1,1)
120
121 def message (*args):
122     print "====================",
123     print args
124     
125 ####################
126 def test00_init (args=[1,2]):
127     global plc,s,a,aa
128     ## have you loaded this file already (support for reload)
129     if plc[1]:
130         pass
131     else:
132         plc=[None,plc1,plc2]
133         for i in args:
134             url=plc[i]['url-format']%plc[i]['hostname']
135             plc[i]['url']=url
136             s[i]=xmlrpclib.ServerProxy(url,allow_none=True)
137             print 'initializing s[%d]'%i,url
138             aa[i]={'Username':plc[i]['builtin_admin_id'],
139                    'AuthMethod':'password',
140                    'AuthString':plc[i]['builtin_admin_password'],
141                    'Role':'admin'}
142             print 'initialized aa[%d]'%i, aa[i]
143             a[i]={'Username':plc[i]['peer_admin_name'],
144                   'AuthMethod':'password',
145                   'AuthString':plc[i]['peer_admin_password'],
146                   'Role':'admin'}
147             print 'initialized a[%d]'%i, a[i]
148
149 def test00_print (args=[1,2]):
150     global plc,s,a,aa
151     for i in args:
152         print 's[%d]'%i,s[i]
153         print 'aa[%d]'%i, aa[i]
154         print 'a[%d]'%i, a[i]
155
156 def check_nodes (en,ef,args=[1,2]):
157     global plc,s,a
158     for i in args:
159         # use a single request and sort afterwards for efficiency
160         # could have used GetNodes's scope as well
161         all_nodes = s[i].GetNodes(a[i])
162         n = len ([ x for x in all_nodes if x['peer_id'] is None])
163         f = len ([ x for x in all_nodes if x['peer_id'] is not None])
164         print '%02d: Checking nodes: got %d local (e=%d) & %d foreign (e=%d)'%(i,n,en,f,ef)
165         assert n==en
166         assert f==ef
167
168 # expected : local slices, foreign slices
169 def check_slices (els,efs,args=[1,2]):
170     global plc,s,a
171     for i in args:
172         ls=len(s[i].GetSlices(a[i],{'peer_id':None}))
173         fs=len(s[i].GetSlices(a[i],{'~peer_id':None}))
174         print '%02d: Checking slices: got %d local (e=%d) & %d foreign (e=%d)'%(i,ls,els,fs,efs)
175         assert els==ls
176         assert efs==fs
177
178 def show_nodes (i,node_ids):
179     # same as above
180     all_nodes = s[i].GetNodes(a[i],node_ids)
181     loc_nodes = filter (lambda n: n['peer_id'] is None, all_nodes)
182     for_nodes = filter (lambda n: n['peer_id'] is not None, all_nodes)
183
184     for message,nodes in [ ['LOC',loc_nodes], ['FOR',for_nodes] ] :
185         if nodes:
186             print '[%s:%d] : '%(message,len(nodes)),
187             for node in nodes:
188                 print node['hostname']+' ',
189             print ''
190
191 def check_slice_nodes (expected_nodes, is_local_slice, args=[1,2]):
192     for ns in myrange(number_slices):
193         check_slice_nodes_n (ns,expected_nodes, is_local_slice, args)
194
195 def check_slice_nodes_n (ns,expected_nodes, is_local_slice, args=[1,2]):
196     global plc,s,a
197     for i in args:
198         peer=peer_index(i)
199         if is_local_slice:
200             sname=slice_name(i,ns)
201             slice=s[i].GetSlices(a[i],{'name':[sname],'peer_id':None})[0]
202             message='local'
203         else:
204             sname=slice_name(peer,ns)
205             slice=s[i].GetSlices(a[i],{'name':[sname],'~peer_id':None})[0]
206             message='foreign'
207         print '%02d: %s slice %s (e=%d) '%(i,message,sname,expected_nodes),
208         slice_node_ids=slice['node_ids']
209         print 'on nodes ',slice_node_ids
210         show_nodes (i,slice_node_ids)
211         assert len(slice_node_ids)>=expected_nodes
212         if len(slice_node_ids) != expected_nodes:
213             print 'TEMPORARY'
214
215 # expected : nodes on local slice
216 def check_local_slice_nodes (expected, args=[1,2]):
217     check_slice_nodes(expected,True,args)
218
219 # expected : nodes on foreign slice
220 def check_foreign_slice_nodes (expected, args=[1,2]):
221     check_slice_nodes(expected,False,args)
222
223 def check_conf_files (args=[1,2]):
224     for nn in myrange(number_nodes):
225         check_conf_files_n (nn,args)
226
227 def check_conf_files_n (nn,args=[1,2]):
228     global plc,s,a
229     for i in args:
230         nodename=node_name(i,nn)
231         ndict= s[i].GetSlivers(a[i],[nodename])[0]
232         assert ndict['hostname'] == nodename
233         conf_files = ndict['conf_files']
234         print '%02d: %d conf_files in GetSlivers for node %s'%(i,len(conf_files),nodename)
235         for conf_file in conf_files:
236             print 'source=',conf_file['source'],'|',
237             print 'dest=',conf_file['dest'],'|',
238             print 'enabled=',conf_file['enabled'],'|',
239             print ''
240
241 import pprint
242 pp = pprint.PrettyPrinter(indent=3)
243
244 def check_slivers (esn,args=[1,2]):
245     for nn in myrange(number_nodes):
246         check_slivers_n (nn,esn,args)
247
248 # too verbose to check all nodes, let's check only the first one
249 def check_slivers_1 (esn,args=[1,2]):
250     check_slivers_n (1,esn,args)
251
252 def check_slivers_n (nn,esn,args=[1,2]):
253     global plc,s,a
254     for i in args:
255         nodename=node_name(i,nn)
256         ndict= s[i].GetSlivers(a[i],[nodename])[0]
257         assert ndict['hostname'] == nodename
258         slivers = ndict['slivers']
259         print '%02d: %d slivers (exp. %d) in GetSlivers for node %s'\
260               %(i,len(slivers),esn,nodename)
261         for sliver in slivers:
262             print '>>slivername = ',sliver['name']
263             pp.pprint(sliver)
264         assert len(slivers) == esn
265                 
266
267 ####################
268 def test00_admin_person (args=[1,2]):
269     global plc,s,a
270     for i in args:
271         email = plc[i]['peer_admin_name']
272         try:
273             p=s[i].GetPersons(a[i],[email])[0]
274             plc[i]['peer_admin_id']=p['person_id']
275         except:
276             person_id=s[i].AddPerson(aa[i],{'first_name':'Local', 
277                                             'last_name':'PeerPoint', 
278                                             'role_ids':[10],
279                                             'email':email,
280                                             'password':plc[i]['peer_admin_password']})
281             print '%02d: created peer admin account %d, %s - %s'%(i,
282                                                                   person_id,plc[i]['peer_admin_name'],
283                                                                   plc[i]['peer_admin_password'])
284             plc[i]['peer_admin_id']=person_id
285             s[i].AddPersonKey(aa[i],email,{'key_type':'ssh',
286                                            'key':plc[i]['peer_admin_key']})
287             print '%02d: added key to peer admin '%i
288
289 def test00_admin_enable (args=[1,2]):
290     global plc,s,a
291     for i in args:
292         s[i].AdmSetPersonEnabled(aa[i],plc[i]['peer_admin_id'],True)
293         s[i].AddRoleToPerson(aa[i],'admin',plc[i]['peer_admin_id'])
294         print '%02d: enabled+admin on account %d:%s'%(i,plc[i]['peer_admin_id'],plc[i]['peer_admin_name'])
295
296 ####################
297 def test01_site (args=[1,2]):
298     global plc,s,a
299     for i in args:
300         peer=peer_index(i)
301         ### create a site (required for creating a slice)
302         sitename=site_name(i)
303         abbrev_name="abbr"+str(i)
304         login_base=plc[i]['plainname']
305         ### should be enough - needs to check we can add/del slices
306         max_slices = number_slices 
307         try:
308             s[i].GetSites(a[i],{'login_base':login_base})[0]
309         except:
310             site_id=s[i].AddSite (a[i], {'name':plc_name(i),
311                                          'abbreviated_name': abbrev_name,
312                                          'login_base': login_base,
313                                          'is_public': True,
314                                          'url': 'http://%s.com/'%abbrev_name,
315                                          'max_slices':max_slices})
316         ### max_slices does not seem taken into account at that stage
317             s[i].UpdateSite(a[i],site_id,{'max_slices':max_slices})
318             print '%02d: Created site %d with max_slices=%d'%(i,site_id,max_slices)
319             plc[i]['site_id']=site_id
320
321 def test01_peer_person (args=[1,2]):
322     global plc,s,a
323     for i in args:
324         peer=peer_index(i)
325         email=plc[peer]['peer_admin_name']
326         try:
327             p=s[i].GetPersons(a[i],[email])[0]
328             plc[i]['peer_person_id']=p['person_id']
329         except:
330             person_id = s[i].AddPerson (a[i], {'first_name':'Peering(plain passwd)', 'last_name':plc_name(peer), 'role_ids':[3000],
331                                                'email':email,'password':plc[peer]['peer_admin_password']})
332             print '%02d:Created person %d as the peer person'%(i,person_id)
333             plc[i]['peer_person_id']=person_id
334
335 def test01_peer (args=[1,2]):
336     global plc,s,a
337     for i in args:
338         peer=peer_index(i)
339         peername = plc_name(peer)
340         try:
341             p=s[i].GetPeers (a[i], [peername])[0]
342             plc[i]['peer_id']=p['peer_id']
343         except:
344             peer_id=s[i].AddPeer (a[i], {'peername':peername,'peer_url':plc[peer]['url'],'person_id':plc[i]['peer_person_id']})
345             # NOTE : need to manually reset the encrypted password through SQL at this point
346             print '%02d:Created peer %d'%(i,peer_id)
347             plc[i]['peer_id']=peer_id
348             print "PLEASE manually set password for person_id=%d in DB%d"%(plc[i]['peer_person_id'],i)
349
350 def test01_peer_passwd (args=[1,2]):
351     global plc,s,a
352     for i in args:
353         # using an ad-hoc local command for now - never could get quotes to reach sql....
354         print "Attempting to set passwd for person_id=%d in DB%d"%(plc[i]['peer_person_id'],i),
355         retcod=os.system("ssh root@%s new_plc_api/person-password.sh %d"%(plc[i]['hostname'],plc[i]['peer_person_id']))
356         print '-> system returns',retcod
357     
358 ##############################
359 # this one gets cached 
360 def get_peer_id (i):
361     try:
362         return plc[i]['peer_id']
363     except:
364         peername = plc_name (peer_index(i))
365         peer_id = s[i].GetPeers(a[i],[peername])[0]['peer_id']
366         plc[i]['peer_id'] = peer_id
367         return peer_id
368
369 def test01_refresh (message,args=[1,2]):
370     global plc,s,a
371     print '=== refresh',message
372     for i in args:
373         print '%02d: Refreshing peer'%(i),
374         retcod=s[i].RefreshPeer(a[i],get_peer_id(i))
375         print 'got ',retcod
376
377 ####################
378 # retrieves node_id from hostname - checks for local nodes only
379 def get_local_node_id(i,nodename):
380     return s[i].GetNodes(a[i],[nodename],None,'local')[0]['node_id']
381
382 # clean all local nodes - foreign nodes are not supposed to be cleaned up manually
383 def clean_all_nodes (args=[1,2]):
384     global plc,s,a
385     for i in args:
386         print '%02d: Cleaning all nodes'%i
387         loc_nodes = s[i].GetNodes(a[i],None,None,'local')
388         for node in loc_nodes:
389             print '%02d: > Cleaning node %d'%(i,node['node_id'])
390             s[i].DeleteNode(a[i],node['node_id'])
391
392 def test02_node (args=[1,2]):
393     for nn in myrange(number_nodes):
394         test02_node_n (nn,args)
395
396 def test02_node_n (nn,args=[1,2]):
397     global plc,s,a
398     for i in args:
399         nodename = node_name(i,nn)
400         try:
401             get_local_node_id(i,nodename)
402         except:
403             n=s[i].AddNode(a[i],1,{'hostname': nodename})
404             print '%02d: Added node %d %s'%(i,n,node_name(i,i))
405
406 def test02_delnode (args=[1,2]):
407     for nn in myrange(number_nodes):
408         test02_delnode_n (nn,args)
409
410 def test02_delnode_n (nn,args=[1,2]):
411     global plc,s,a
412     for i in args:
413         nodename = node_name(i,nn)
414         node_id = get_local_node_id (i,nodename)
415         retcod=s[i].DeleteNode(a[i],nodename)
416         print '%02d: Deleted node %d, returns %s'%(i,node_id,retcod)
417
418 ####################
419 def clean_all_slices (args=[1,2]):
420     global plc,s,a
421     for i in args:
422         print '%02d: Cleaning all slices'%i
423         for slice in s[i].GetSlices(a[i],{'peer_id':None}):
424             slice_id = slice['slice_id']
425             if slice_id not in system_slices_ids:
426                 print '%02d: > Cleaning slice %d'%(i,slice_id)
427                 s[i].DeleteSlice(a[i],slice_id)
428
429 def get_local_slice_id (i,name):
430     return s[i].GetSlices(a[i],{'name':[name],'peer_id':None})[0]['slice_id']
431
432 def test03_slice (args=[1,2]):
433     for n in myrange(number_slices):
434         test03_slice_n (n,args)
435
436 def test03_slice_n (ns,args=[1,2]):
437     global plc,s,a
438     for i in args:
439         peer=peer_index(i)
440         plcname=plc_name(i)
441         slicename=slice_name(i,ns)
442         max_nodes=number_nodes
443         try:
444             s[i].GetSlices(a[i],[slicename])[0]
445         except:
446             slice_id=s[i].AddSlice (a[i],{'name':slicename,
447                                           'description':'slice %s on %s'%(slicename,plcname),
448                                           'url':'http://planet-lab.org/%s'%slicename,
449                                           'max_nodes':max_nodes,
450                                           'instanciation':'plc-instantiated',
451                                           })
452             print '%02d: created slice %d - max nodes=%d'%(i,slice_id,max_nodes)
453         
454
455 def test04_node_slice (is_local, add_if_true, args=[1,2]):
456     for ns in myrange(number_slices):
457         test04_node_slice_ns (ns,is_local, add_if_true, args)
458
459 def test04_node_slice_ns (ns,is_local, add_if_true, args=[1,2]):
460     test04_node_slice_nl_n (myrange(number_nodes),ns,is_local, add_if_true, args)
461
462 def test04_node_slice_nl_n (nnl,ns,is_local, add_if_true, args=[1,2]):
463     global plc,s,a
464     for i in args:
465         peer=peer_index(i)
466         slice_id = get_local_slice_id (i,slice_name (i,ns))
467         
468         if is_local:
469             hostnames=[node_name(i,nn) for nn in nnl]
470             nodetype='local'
471         else:
472             hostnames=[node_name(peer,nn) for nn in nnl]
473             nodetype='foreign'
474         if add_if_true:
475             s[i].AddSliceToNodes (a[i], slice_id,hostnames)
476             message="added"
477         else:
478             s[i].DeleteSliceFromNodes (a[i], slice_id,hostnames)
479             message="deleted"
480         print '%02d: %s in slice %d %s '%(i,message,slice_id,nodetype),
481         print hostnames
482
483 def test04_slice_add_lnode (args=[1,2]):
484     test04_node_slice (True,True,args)
485
486 def test04_slice_add_fnode (args=[1,2]):
487     test04_node_slice (False,True,args)
488
489 def test04_slice_del_lnode (args=[1,2]):
490     test04_node_slice (True,False,args)
491
492 def test04_slice_del_fnode (args=[1,2]):
493     test04_node_slice (False,False,args)
494
495 ####################
496 def test_all_init ():
497     message ("INIT")
498     test00_init ()
499     test00_print ()
500     test00_admin_person ()
501     test00_admin_enable ()
502     test01_peer_person ()
503     test01_peer ()
504     test01_peer_passwd ()
505
506     test01_site ()
507
508 def test_all_nodes ():
509
510     message ("RESETTING NODES")
511     clean_all_nodes ()
512     test01_refresh ('cleaned nodes')
513     check_nodes(0,0)
514
515     # create one node on each site
516     message ("CREATING NODES")
517     test02_node ()
518     check_nodes(number_nodes,0)
519     test01_refresh ('after node creation')
520     check_nodes(number_nodes,number_nodes)
521     message ("2 extra del/add cycles on plc2 for different indexes")
522     test02_delnode([2])
523     test02_node ([2])
524     test02_delnode([2])
525     test02_node ([2])
526     test02_delnode([2])
527     check_nodes(0,number_nodes,[2])
528     test01_refresh('after deletion on plc2')
529     check_nodes(number_nodes,0,[1])
530     check_nodes(0,number_nodes,[2])
531     message ("ADD on plc2 for different indexes")
532     test02_node ([2])
533     check_nodes (number_nodes,0,[1])
534     check_nodes (number_nodes,number_nodes,[2])
535     test01_refresh('after re-creation on plc2')
536     check_nodes (number_nodes,number_nodes,)
537
538 def test_all_addslices ():
539
540     # reset
541     message ("RESETTING SLICES TEST")
542     clean_all_nodes ()
543     test02_node ()
544     clean_all_slices ()
545     test01_refresh ("After slices init")
546
547     # create slices on plc1
548     message ("CREATING SLICES on plc1")
549     test03_slice ([1])
550     # each site has 3 local slices and 0 foreign slice
551     check_slices (total_slices(),0,[1])
552     check_slices (system_slices(),0,[2])
553     test01_refresh ("after slice created on plc1")
554     check_slices (total_slices(),0,[1])
555     check_slices (system_slices(),number_slices,[2])
556     # no slice has any node yet
557     check_local_slice_nodes(0,[1])
558     check_foreign_slice_nodes(0,[2])
559
560     # insert local nodes in local slice on plc1
561     message ("ADDING LOCAL NODES IN SLICES")
562     test04_slice_add_lnode ([1])
563     # of course the change is only local
564     check_local_slice_nodes (number_nodes,[1])
565     check_foreign_slice_nodes(0,[2])
566
567     # refreshing
568     test01_refresh ("After local nodes were added on plc1")
569     check_local_slice_nodes (number_nodes,[1])
570     check_foreign_slice_nodes (number_nodes,[2])
571
572     # now we add foreign nodes into local slice
573     message ("ADDING FOREIGN NODES IN SLICES")
574     test04_slice_add_fnode ([1])
575     check_local_slice_nodes (2*number_nodes,[1])
576     check_foreign_slice_nodes (number_nodes,[2])
577
578     # refreshing
579     test01_refresh ("After foreign nodes were added in plc1")
580     # remember that foreign slices only know about LOCAL nodes
581     # so this does not do anything
582     check_local_slice_nodes (2*number_nodes,[1])
583     check_foreign_slice_nodes (2*number_nodes,[2])
584
585     check_slivers_1(total_slivers())
586
587 def test_all_delslices ():
588
589     message ("DELETING FOREIGN NODES FROM SLICES")
590     test04_slice_del_fnode([1])
591     check_local_slice_nodes (number_nodes,[1])
592     check_foreign_slice_nodes (2*number_nodes,[2])
593     # mmh?
594     check_slivers_1(total_slivers(),[1])
595
596     test01_refresh ("After foreign nodes were removed on plc1")
597     check_local_slice_nodes (number_nodes,[1])
598     check_foreign_slice_nodes (number_nodes,[2])
599     
600     message ("DELETING LOCAL NODES FROM SLICES")
601     test04_slice_del_lnode([1])
602     check_local_slice_nodes (0,[1])
603     check_foreign_slice_nodes (number_nodes,[2])
604
605     test01_refresh ("After local nodes were removed on plc1")
606     check_local_slice_nodes (0,[1])
607     check_foreign_slice_nodes (0,[2])
608
609     message ("CHECKING SLICES CLEAN UP")
610     clean_all_slices([1])
611     check_slices (system_slices(),0,[1])
612     check_slices (system_slices(),number_slices,[2])
613     test01_refresh ("After slices clenaup")
614     check_slices(system_slices(),0)
615
616 def test_all_slices ():
617     test_all_addslices ()
618     test_all_delslices ()
619     
620 def test_all ():
621     test_all_init ()
622     test_all_nodes ()
623     test_all_slices ()
624
625 ### ad hoc test sequences
626 def populate ():
627     test02_node()
628     test03_slice([1])
629     test01_refresh ("populate: refreshing peer 1",[1])
630     test04_slice_add_lnode([1])
631     test04_slice_add_fnode([1])
632     test01_refresh("populate: refresh all")
633
634 def test_now ():
635     test_all_init()
636 #    clean_all_nodes()
637 #    clean_all_slices()
638 #    populate()
639
640 #####
641 def usage ():
642     print "Usage: %s [-n] [-f]"%sys.argv[0]
643     print " -f runs faster (1 node - 1 slice)"
644     print " -n runs test_now instead of test_all"
645     
646     sys.exit(1)
647
648 def main ():
649     try:
650         (o,a) = getopt.getopt(sys.argv[1:], "fn")
651     except:
652         usage()
653     now_opt = False;
654     for (opt,val) in o:
655         if opt=='-f':
656             fast()
657         elif opt=='-n':
658             now_opt=True
659         else:
660             usage()
661     if a:
662         usage()
663     print '%d nodes & %d slices'%(number_nodes,number_slices)
664     if now_opt:
665         print 'Running test_now'
666         test_now()   
667     else:
668         test_all()   
669  
670 if __name__ == '__main__':
671     main()
672