3 ##############################
5 ### preparation / requirements
7 ### two separate instances of myplc
8 ### for now they are located on the same box on lurch
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
15 ##############################
21 # support reloading without wiping everything off
22 # dunno how to do (defvar plc)
31 # when running locally, we might wish to run only our local stuff
32 dummy_print_methods = [ 'RefreshPeer' ]
35 def __init__(self,method,index):
39 def __call__ (self, *args, **kwds):
40 if not self.printed or self.method in dummy_print_methods:
41 print "Dummy method %s on remote peer %d skipped"%(self.method,self.index)
44 def __init__(self,index):
47 for method in PLC.Methods.methods:
48 # ignore path-defined methods for now
50 setattr(self,method,DummyShell.Callable(method,self.index))
51 def show_config(self,*args):
58 ## try to support reload
70 # number of 'system' persons
71 # builtin maint, local root, 2 persons for the peering
73 # among that, 1 gets refreshed - other ones have conflicting names
74 system_persons_cross = 1
76 system_slices_ids = (1,2)
78 return len(system_slices_ids)
80 return number_slices+system_slices()
82 # temporary - the myplc I use doesnt know about 'system' yet
83 def system_slivers ():
84 # return len(system_slices_ids)
86 # too tedious to do the maths : how many slices attached to node 1
89 global expected_slivers
90 if expected_slivers is None:
92 actual_nodes_per_slice = min (number_nodes,number_nodes_per_slice)
93 for ns in myrange(number_slices):
94 slice_range = [ map_on_node (n+ns) for n in range(actual_nodes_per_slice)]
97 return expected_slivers+system_slivers()
100 # set initial conditions
101 # actual persons_per_slice is min(number_persons,number_persons_per_slice)
102 # actual nodes_per_slice is min(number_nodes,number_nodes_per_slice)
103 # this is to prevent quadractic test times on big tests
104 def define_test (sites,persons,nodes,slices,
105 keys_per_person,nodes_per_slice,persons_per_slice,fast_mode=None):
106 global number_sites, number_persons, number_nodes, number_slices
107 global number_keys_per_person, number_nodes_per_slice, number_persons_per_slice, fast_flag
109 number_persons=persons
112 number_keys_per_person=keys_per_person
113 number_nodes_per_slice=nodes_per_slice
114 number_persons_per_slice=persons_per_slice
115 if fast_mode is not None:
118 # when we run locally on a given peer
122 print '%d sites, %d persons, %d nodes & %d slices'%(
123 number_sites,number_persons,number_nodes,number_slices)
124 print '%d keys/person, %d nodes/slice & %d persons/slice'%(
125 number_keys_per_person,number_nodes_per_slice,number_persons_per_slice)
126 print 'fast_flag',fast_flag
127 if local_peer is not None:
128 print 'Running locally on index %d'%local_peer
131 define_test(1,1,1,1,1,1,1,True)
134 define_test (sites=4,persons=4,nodes=5,slices=4,
135 keys_per_person=2,nodes_per_slice=3,persons_per_slice=6,fast_mode=False)
137 def apply_factor (factor):
138 global number_sites, number_persons, number_nodes, number_slices
139 [number_sites, number_persons, number_nodes, number_slices] = \
140 [factor*x for x in [number_sites, number_persons, number_nodes, number_slices]]
143 # use only 1 key in this case
146 global number_sites, number_persons, number_nodes, number_slices
151 global nodes_per_slice
153 global number_keys_per_person
154 number_keys_per_person=1
155 global number_persons_per_slice
156 number_persons_per_slice=3
160 global number_sites, number_persons, number_nodes, number_slices
165 global nodes_per_slice
167 global number_keys_per_person
168 number_keys_per_person=1
169 global number_persons_per_slice
170 number_persons_per_slice=3
172 # use mini test by default in interactive mode
177 # argh, for login_name that doesn't accept digits
178 plain_numbers=['zero','one','two','three','four','five','six','seven','eight','nine','ten',
179 'eleven','twelve','thirteen','fourteen','fifteen','sixteen','seventeen','eighteen','nineteen','twenty']
180 plain_digits=['a','b','c','d','e','f','g','h','i','j']
182 plc[1]={ 'plcname':'plc1 in federation',
183 'hostname':'lurch.cs.princeton.edu',
184 'url-format':'https://%s:443/PLCAPI/',
185 'builtin-admin-id':'root@plc1.org',
186 'builtin-admin-password':'root',
187 'peer-admin-name':'peer1@planet-lab.org',
188 'peer-admin-password':'peer',
189 'node-format':'n1-%03d.plc1.org',
191 'site-format':'one%s',
192 'person-format' : 'user1-%d@plc1.org',
193 'key-format':'ssh-rsa 11key4plc11 user%d-key%d',
194 'person-password' : 'password1',
196 plc[2]={ 'plcname':'plc2 in federation',
197 'hostname':'planetlab-devbox.inria.fr',
198 'url-format':'https://%s:443/PLCAPI/',
199 'builtin-admin-id':'root@plc2.org',
200 'builtin-admin-password':'root',
201 'peer-admin-name':'peer2@planet-lab.org',
202 'peer-admin-password':'peer',
203 'node-format':'n2-%03d.plc2.org',
205 'site-format':'two%s',
206 'person-format' : 'user2-%d@plc2.org',
207 'key-format':'ssh-rsa 22key4plc22 user%d-key%d',
208 'person-password' : 'password2',
216 return plc[i]['plcname']
219 x=site_login_base(i,n)
220 return 'Site fullname '+x
222 def site_login_base (i,n):
224 if number_sites<len(plain_numbers):
225 return plc[i]['site-format']%plain_numbers[n]
231 string=plain_digits[rem]+string
236 return plc[i]['site-format']%string
238 def person_name (i,n):
239 return plc[i]['person-format']%n
241 def key_name (i,n,k):
242 return plc[i]['key-format']%(n,k)
245 return plc[i]['node-format']%n
247 def slice_name (i,n):
248 site_index=map_on_site(n)
249 return "%s_slice%d"%(site_login_base(i,site_index),n)
254 # to have indexes start at 1
262 return range (1,n+1,1)
265 return map_on (n,number_sites)
267 def map_on_person (n):
268 return map_on (n,number_persons)
271 return map_on (n,number_nodes)
274 print "====================",
279 global epoch,last_time
282 print '+++ timer start'
287 print '+++ %.02f seconds ellapsed (%.02f)'%(now-epoch,now-last_time)
291 def test00_init (args=[1,2]):
293 ## have you loaded this file already (support for reload)
295 url=plc[i]['url-format']%plc[i]['hostname']
297 if local_peer is None:
298 # the regular remote mode
300 # xxx todo - Shell.py still needs a non-empty config even if we define everything
301 '--config','dummy-config',
303 '--user',plc[i]['builtin-admin-id'],
304 '--password',plc[i]['builtin-admin-password']]
305 print 'initializing s[%d]=>%s'%(i,url)
306 s[i]=Shell.Shell(argv)
308 elif local_peer == i:
309 # local mode - use Shell's Direct mode - use /etc/planetlab/plc_config
310 s[i]=Shell.Shell([sys.argv[0]])
313 # remote peer in local mode : use dummy shell instead
317 def test00_print (args=[1,2]):
319 print '==================== s[%d]'%i
321 print '===================='
323 def check_nodes (el,ef,args=[1,2]):
325 # use a single request and sort afterwards for efficiency
326 # could have used GetNodes's scope as well
327 all_nodes = s[i].GetNodes()
328 n = len ([ x for x in all_nodes if x['peer_id'] is None])
329 f = len ([ x for x in all_nodes if x['peer_id'] is not None])
330 print '%02d: Checking nodes: got %d local (e=%d) & %d foreign (e=%d)'%(i,n,el,f,ef)
334 def check_keys (el,ef,args=[1,2]):
336 # use a single request and sort afterwards for efficiency
337 # could have used GetKeys's scope as well
338 all_keys = s[i].GetKeys()
339 n = len ([ x for x in all_keys if x['peer_id'] is None])
340 f = len ([ x for x in all_keys if x['peer_id'] is not None])
341 print '%02d: Checking keys: got %d local (e=%d) & %d foreign (e=%d)'%(i,n,el,f,ef)
345 def check_persons (el,ef,args=[1,2]):
347 # use a single request and sort afterwards for efficiency
348 # could have used GetPersons's scope as well
349 all_persons = s[i].GetPersons()
350 n = len ([ x for x in all_persons if x['peer_id'] is None])
351 f = len ([ x for x in all_persons if x['peer_id'] is not None])
352 print '%02d: Checking persons: got %d local (e=%d) & %d foreign (e=%d)'%(i,n,el,f,ef)
356 # expected : local slices, foreign slices
357 def check_slices (els,efs,args=[1,2]):
359 ls=len(s[i].GetSlices({'peer_id':None}))
360 fs=len(s[i].GetSlices({'~peer_id':None}))
361 print '%02d: Checking slices: got %d local (e=%d) & %d foreign (e=%d)'%(i,ls,els,fs,efs)
365 def show_nodes (i,node_ids):
367 all_nodes = s[i].GetNodes(node_ids)
368 loc_nodes = filter (lambda n: n['peer_id'] is None, all_nodes)
369 for_nodes = filter (lambda n: n['peer_id'] is not None, all_nodes)
371 for message,nodes in [ ['LOC',loc_nodes], ['FOR',for_nodes] ] :
373 print '[%s:%d] : '%(message,len(nodes)),
375 print node['hostname']+' ',
378 def check_slice_nodes (expected_nodes, is_local_slice, args=[1,2]):
379 for ns in myrange(number_slices):
380 check_slice_nodes_n (ns,expected_nodes, is_local_slice, args)
382 def check_slice_nodes_n (ns,expected_nodes, is_local_slice, args=[1,2]):
386 sname=slice_name(i,ns)
387 slice=s[i].GetSlices({'name':[sname],'peer_id':None})[0]
390 sname=slice_name(peer,ns)
391 slice=s[i].GetSlices({'name':[sname],'~peer_id':None})[0]
393 print '%02d: %s slice %s (e=%d) '%(i,message,sname,expected_nodes),
394 slice_node_ids=slice['node_ids']
395 print 'on nodes ',slice_node_ids
396 show_nodes (i,slice_node_ids)
397 assert len(slice_node_ids)>=expected_nodes
398 if len(slice_node_ids) != expected_nodes:
401 # expected : nodes on local slice
402 def check_local_slice_nodes (expected, args=[1,2]):
403 check_slice_nodes(expected,True,args)
405 # expected : nodes on foreign slice
406 def check_foreign_slice_nodes (expected, args=[1,2]):
407 check_slice_nodes(expected,False,args)
409 def check_conf_files (args=[1,2]):
410 for nn in myrange(number_nodes):
411 check_conf_files_n (nn,args)
413 def check_conf_files_n (nn,args=[1,2]):
415 nodename=node_name(i,nn)
416 ndict= s[i].GetSlivers([nodename])[0]
417 assert ndict['hostname'] == nodename
418 conf_files = ndict['conf_files']
419 print '%02d: %d conf_files in GetSlivers for node %s'%(i,len(conf_files),nodename)
420 for conf_file in conf_files:
421 print 'source=',conf_file['source'],'|',
422 print 'dest=',conf_file['dest'],'|',
423 print 'enabled=',conf_file['enabled'],'|',
427 pp = pprint.PrettyPrinter(indent=3)
429 def check_slivers (esn,args=[1,2]):
430 for nn in myrange(number_nodes):
431 check_slivers_n (nn,esn,args)
433 # too verbose to check all nodes, let's check only the first one
434 def check_slivers_1 (esn,args=[1,2]):
435 check_slivers_n (1,esn,args)
437 def check_slivers_n (nn,esn,args=[1,2]):
439 nodename=node_name(i,nn)
440 ndict= s[i].GetSlivers([nodename])[0]
441 assert ndict['hostname'] == nodename
442 slivers = ndict['slivers']
443 print '%02d: %d slivers (exp. %d) in GetSlivers for node %s'\
444 %(i,len(slivers),esn,nodename)
445 for sliver in slivers:
446 print '>>slivername = ',sliver['name']
447 pretty_printer.pprint(sliver)
448 assert len(slivers) == esn
452 def test00_admin_person (args=[1,2]):
455 email = plc[i]['peer-admin-name']
457 p=s[i].GetPersons([email])[0]
458 plc[i]['peer-admin-id']=p['person_id']
460 person_id=s[i].AddPerson({'first_name':'Local',
461 'last_name':'PeerPoint',
464 'password':plc[i]['peer-admin-password']})
466 print '%02d:== created peer admin account %d, %s - %s'%(
467 i, person_id,plc[i]['peer-admin-name'],plc[i]['peer-admin-password'])
468 plc[i]['peer-admin-id']=person_id
470 def test00_admin_enable (args=[1,2]):
472 if s[i].AdmSetPersonEnabled(plc[i]['peer-admin-id'],True):
473 s[i].AddRoleToPerson('admin',plc[i]['peer-admin-id'])
474 print '%02d:== enabled+admin on account %d:%s'%(i,plc[i]['peer-admin-id'],plc[i]['peer-admin-name'])
476 def test00_peer_person (args=[1,2]):
480 email=plc[peer]['peer-admin-name']
482 p=s[i].GetPersons([email])[0]
483 plc[i]['peer_person_id']=p['person_id']
485 person_id = s[i].AddPerson ( {'first_name':'Peering(plain passwd)', 'last_name':plc_name(peer), 'role_ids':[3000],
486 'email':email,'password':plc[peer]['peer-admin-password']})
488 print '%02d:== Created person %d as the peer person'%(i,person_id)
489 plc[i]['peer_person_id']=person_id
492 def test00_peer (args=[1,2]):
496 peername = plc_name(peer)
498 p=s[i].GetPeers ( [peername])[0]
499 plc[i]['peer_id']=p['peer_id']
501 peer_id=s[i].AddPeer ( {'peername':peername,'peer_url':plc[peer]['url'],'person_id':plc[i]['peer_person_id']})
502 # NOTE : need to manually reset the encrypted password through SQL at this point
504 print '%02d:Created peer %d'%(i,peer_id)
505 print "PLEASE manually set password for person_id=%d in DB%d"%(plc[i]['peer_person_id'],i)
506 plc[i]['peer_id']=peer_id
508 def test00_peer_passwd (args=[1,2]):
509 if local_peer is None:
511 # using an ad-hoc local command for now - never could get quotes to reach sql....
512 print "Attempting to remotely set passwd for person_id=%d in DB%d"%(plc[i]['peer_person_id'],i),
513 retcod=os.system("ssh root@%s new_plc_api/person-password.sh %d"%(plc[i]['hostname'],plc[i]['peer_person_id']))
514 print '-> system returns',retcod
517 print "Locally setting passwd for person_id=%d in DB%d"%(plc[i]['peer_person_id'],i),
518 retcod=os.system("./person-password.sh -l %d"%(plc[i]['peer_person_id']))
519 print '-> system returns',retcod
521 # this one gets cached
524 return plc[i]['peer_id']
526 peername = plc_name (peer_index(i))
527 peer_id = s[i].GetPeers([peername])[0]['peer_id']
528 plc[i]['peer_id'] = peer_id
531 ##############################
532 def test00_refresh (message,args=[1,2]):
533 print '=== refresh',message
536 print '%02d:== Refreshing peer'%(i),
537 retcod=s[i].RefreshPeer(get_peer_id(i))
542 if "time" not in key:
543 print key,retcod[key],
545 print "+++ ellapsed: {",
546 timers=retcod['timers']
550 print key,timers[key],
555 def test01_site (args=[1,2]):
556 for ns in myrange(number_sites):
557 test01_site_n (ns,True,args)
559 def test01_del_site (args=[1,2]):
560 for ns in myrange(number_sites):
561 test01_site_n (ns,False,args)
563 def test01_site_n (ns,add_if_true,args=[1,2]):
565 login_base = site_login_base (i,ns)
567 site_id = s[i].GetSites([login_base])[0]['site_id']
569 if s[i].DeleteSite(site_id):
570 print "%02d:== deleted site_id %d"%(i,site_id)
573 sitename=site_name(i,ns)
574 abbrev_name="abbr"+str(i)
575 max_slices = number_slices
576 site_id=s[i].AddSite ( {'name':plc_name(i),
577 'abbreviated_name': abbrev_name,
578 'login_base': login_base,
580 'url': 'http://%s.com/'%abbrev_name,
581 'max_slices':max_slices})
582 ### max_slices does not seem taken into account at that stage
584 s[i].UpdateSite(site_id,{'max_slices':max_slices})
585 print '%02d:== Created site %d with max_slices=%d'%(i,site_id,max_slices)
588 def test02_person (args=[1,2]):
589 for np in myrange(number_persons):
590 test02_person_n (np,True,args)
592 def test02_del_person (args=[1,2]):
593 for np in myrange(number_persons):
594 test02_person_n (np,False,args)
596 def test02_person_n (np,add_if_true,args=[1,2]):
597 test02_person_n_ks (np, myrange(number_keys_per_person),add_if_true,args)
599 def test02_person_n_ks (np,nks,add_if_true,args=[1,2]):
601 email = person_name(i,np)
603 person_id=s[i].GetPersons([email])[0]['person_id']
605 if s[i].DeletePerson(person_id):
606 print "%02d:== deleted person_id %d"%(i,person_id)
609 password = plc[i]['person-password']
610 person_id=s[i].AddPerson({'first_name':'Your average',
611 'last_name':'User%d'%np,
614 'password': password })
616 print '%02d:== created user account %d, %s - %s'%(i, person_id,email,password)
618 key=key_name(i,np,nk)
619 s[i].AddPersonKey(email,{'key_type':'ssh', 'key':key})
620 print '%02d:== added key %s to person %s'%(i,key,email)
623 # retrieves node_id from hostname - checks for local nodes only
624 def get_local_node_id(i,nodename):
625 return s[i].GetNodes({'hostname':nodename,'peer_id':None})[0]['node_id']
627 # clean all local nodes - foreign nodes are not supposed to be cleaned up manually
628 def clean_all_nodes (args=[1,2]):
630 print '%02d:== Cleaning all nodes'%i
631 local_nodes = s[i].GetNodes({'peer_id':None})
633 for node in local_nodes:
634 print '%02d:==== Cleaning node %d'%(i,node['node_id'])
635 s[i].DeleteNode(node['node_id'])
637 def test03_node (args=[1,2]):
638 for nn in myrange(number_nodes):
639 test03_node_n (nn,args)
641 def test03_node_n (nn,args=[1,2]):
643 nodename = node_name(i,nn)
645 get_local_node_id(i,nodename)
647 login_base=site_login_base(i,map_on_site(nn))
648 n=s[i].AddNode(login_base,{'hostname': nodename})
650 print '%02d:== Added node %d %s'%(i,n,node_name(i,nn))
652 def test02_delnode (args=[1,2]):
653 for nn in myrange(number_nodes):
654 test02_delnode_n (nn,args)
656 def test02_delnode_n (nn,args=[1,2]):
658 nodename = node_name(i,nn)
659 node_id = get_local_node_id (i,nodename)
660 retcod=s[i].DeleteNode(nodename)
662 print '%02d:== Deleted node %d, returns %s'%(i,node_id,retcod)
665 def clean_all_slices (args=[1,2]):
667 print '%02d:== Cleaning all slices'%i
668 for slice in s[i].GetSlices({'peer_id':None}):
669 slice_id = slice['slice_id']
670 if slice_id not in system_slices_ids:
671 if s[i].DeleteSlice(slice_id):
672 print '%02d:==== Cleaned slice %d'%(i,slice_id)
674 def test04_slice (args=[1,2]):
675 for n in myrange(number_slices):
676 test04_slice_n (n,args)
678 def test04_slice_n (ns,args=[1,2]):
682 slicename=slice_name(i,ns)
683 max_nodes=number_nodes
685 s[i].GetSlices([slicename])[0]
687 slice_id=s[i].AddSlice ({'name':slicename,
688 'description':'slice %s on %s'%(slicename,plcname),
689 'url':'http://planet-lab.org/%s'%slicename,
690 'max_nodes':max_nodes,
691 'instanciation':'plc-instantiated',
694 print '%02d:== created slice %d - max nodes=%d'%(i,slice_id,max_nodes)
695 actual_persons_per_slice = min (number_persons,number_persons_per_slice)
696 person_indexes=[map_on_person (p+ns) for p in range(actual_persons_per_slice)]
697 for np in person_indexes:
698 email = person_name (i,np)
699 retcod = s[i].AddPersonToSlice (email, slicename)
700 print '%02d:== Attached person %s to slice %s'%(i,email,slicename)
703 def test04_node_slice (is_local, add_if_true, args=[1,2]):
704 for ns in myrange(number_slices):
705 test04_node_slice_ns (ns,is_local, add_if_true, args)
707 def test04_node_slice_ns (ns,is_local, add_if_true, args=[1,2]):
708 actual_nodes_per_slice = min (number_nodes,number_nodes_per_slice)
709 node_indexes = [ map_on_node (n+ns) for n in range(actual_nodes_per_slice)]
710 test04_node_slice_nl_n (node_indexes,ns,is_local, add_if_true, args)
712 def test04_node_slice_nl_n (nnl,ns,is_local, add_if_true, args=[1,2]):
715 sname = slice_name (i,ns)
718 hostnames=[node_name(i,nn) for nn in nnl]
721 hostnames=[node_name(peer,nn) for nn in nnl]
724 res=s[i].AddSliceToNodes (sname,hostnames)
727 res=s[i].DeleteSliceFromNodes (sname,hostnames)
730 print '%02d:== %s in slice %s %s '%(i,message,sname,nodetype),
733 def test04_slice_add_lnode (args=[1,2]):
734 test04_node_slice (True,True,args)
736 def test04_slice_add_fnode (args=[1,2]):
737 test04_node_slice (False,True,args)
739 def test04_slice_del_lnode (args=[1,2]):
740 test04_node_slice (True,False,args)
742 def test04_slice_del_fnode (args=[1,2]):
743 test04_node_slice (False,False,args)
746 def test05_sat (args=[1,2]):
750 sat_id=s[i].GetSliceAttributeTypes ([name])[0]
752 description="custom sat on plc%d"%i
754 sat_id=s[i].AddSliceAttributeType ({ 'name':name,
755 'description': description,
756 'min_role_id' : min_role_id})
758 print '%02d:== created SliceAttributeType = %d'%(i,sat_id)
760 # for test, we create 4 slice_attributes
761 # on slice1 - sat=custom_made (see above) - all nodes
762 # on slice1 - sat=custom_made (see above) - node=n1
763 # on slice1 - sat='net_max' - all nodes
764 # on slice1 - sat='net_max' - node=n1
766 def test05_sa_atom (slice_name,sat_name,value,node,i):
767 sa_id=s[i].GetSliceAttributes({'name':sat_name,
771 sa_id=s[i].AddSliceAttribute(slice_name,
776 print 'slice_name',slice_name,'sat_name',sat_name
777 sa_id=s[i].AddSliceAttribute(slice_name,
781 print '%02d:== created SliceAttribute = %d'%(i,sa_id),
782 print 'On slice',slice_name,'and node',node
784 def test05_sa (args=[1,2]):
786 test05_sa_atom (slice_name(i,1),sat_name(i),'custom sat/all nodes',None,i)
787 test05_sa_atom (slice_name(i,1),sat_name(i),'custom sat/node1',node_name(i,1),i)
788 test05_sa_atom (slice_name(i,1),'net_max','predefined sat/all nodes',None,i)
789 test05_sa_atom (slice_name(i,1),'net_max','predefined sat/node1',node_name(i,1),i)
791 ##############################
793 ##############################
795 print s['site_id'],s['peer_id'],s['login_base'],s['name'],s['node_ids']
798 print k['key_id'],k['peer_id'],k['key']
801 print p['person_id'],p['peer_id'],p['email'],'keys:',p['key_ids'],'sites:',p['site_ids']
804 print n['node_id'],n['peer_id'],n['hostname'],'sls=',n['slice_ids'],'site=',n['site_id']
807 print s['slice_id'],s['peer_id'],s['name'],'nodes=',s['node_ids'],'persons=',s['person_ids']
808 print '---','sas=',s['slice_attribute_ids'],s['name'],'crp=',s['creator_person_id']
809 print "--- 'expires':",s['expires']
812 print sat['attribute_type_id'],sat['peer_id'], sat['name'], sat['min_role_id'], sat['description']
815 print sa['slice_attribute_id'],sa['peer_id'],sa['name'],'AT_id:',sa['attribute_type_id']
816 print '---','v=',sa['value'],'sl=',sa['slice_id'],'n=',sa['node_id']
819 pretty_printer=pprint.PrettyPrinter(5)
821 def p_sliver (margin,x):
822 print margin,'SLIVERS for : hostname',x['hostname']
823 print margin,'%d config files'%len(x['conf_files'])
824 for sv in x['slivers']:
825 p_sliver_slice(margin,sv,x['hostname'])
827 def p_sliver_slice(margin,sliver,hostname):
828 print margin,'SLIVER on hostname %s, s='%hostname,sliver['name']
830 pretty_printer.pprint(sliver['keys'])
831 print margin,'ATTRIBUTES',
832 pretty_printer.pprint(sliver['attributes'])
834 def dump (args=[1,2]):
836 print '%02d:============================== DUMPING'%i
837 print '%02d: SITES'%i
838 [p_site(x) for x in s[i].GetSites()]
840 [p_key(x) for x in s[i].GetKeys()]
841 print '%02d: PERSONS'%i
842 [p_person(x) for x in s[i].GetPersons()]
843 print '%02d: NODES'%i
844 [p_node(x) for x in s[i].GetNodes()]
845 print '%02d: SLICES'%i
846 [p_slice(x) for x in s[i].GetSlices()]
847 print '%02d: Slice Attribute Types'%i
848 [p_sat(x) for x in s[i].GetSliceAttributeTypes()]
849 print '%02d: Slice Attributes'%i
850 [p_sa(x) for x in s[i].GetSliceAttributes()]
851 print '%02d: SLIVERS'%i
852 [p_sliver('%02d:'%i,x) for x in s[i].GetSlivers()]
853 print '%02d:============================== END DUMP'%i
856 ## for usage under the api
863 print (x['key_id'],x['peer_id'],x['key'])
866 for x in GetPersons():
874 for x in GetSlices():
878 for x in GetSliceAttributeTypes():
882 for x in GetSliceAttributes():
886 for s in GetSlivers():
900 print 'SLICE ATTR TYPES'
909 def test_all_init ():
913 test00_admin_person ()
914 test00_admin_enable ()
915 test00_peer_person ()
917 test00_peer_passwd ()
919 def test_all_sites ():
921 test00_refresh ('after site creation')
923 def test_all_persons ():
925 test00_refresh ('before persons&keys creation')
927 check_persons(system_persons,system_persons_cross)
928 message ("Creating persons&keys")
931 message ("1 extra del/add cycle for unique indexes")
932 test02_del_person([2])
934 check_keys(number_persons*number_keys_per_person,0)
935 check_persons(system_persons+number_persons,system_persons_cross)
936 test00_refresh ('after persons&keys creation')
937 check_keys(number_persons*number_keys_per_person,number_persons*number_keys_per_person)
938 check_persons(system_persons+number_persons,system_persons_cross+number_persons)
940 def test_all_nodes ():
942 message ("RESETTING NODES")
944 test00_refresh ('cleaned nodes')
947 # create one node on each site
948 message ("CREATING NODES")
950 check_nodes(number_nodes,0)
951 test00_refresh ('after node creation')
952 check_nodes(number_nodes,number_nodes)
955 message ("2 extra del/add cycles on plc2 for different indexes")
960 check_nodes(0,number_nodes,[2])
961 test00_refresh('after deletion on plc2')
962 check_nodes(number_nodes,0,[1])
963 check_nodes(0,number_nodes,[2])
964 message ("ADD on plc2 for different indexes")
966 check_nodes (number_nodes,0,[1])
967 check_nodes (number_nodes,number_nodes,[2])
968 test00_refresh('after re-creation on plc2')
969 check_nodes (number_nodes,number_nodes,)
971 def test_all_addslices ():
974 message ("RESETTING SLICES TEST")
978 test00_refresh ("After slices init")
980 # create slices on plc1
981 message ("CREATING SLICES on plc1")
983 # each site has 3 local slices and 0 foreign slice
984 check_slices (total_slices(),0,[1])
985 check_slices (system_slices(),0,[2])
986 test00_refresh ("after slice created on plc1")
987 check_slices (total_slices(),0,[1])
988 check_slices (system_slices(),number_slices,[2])
989 # no slice has any node yet
990 check_local_slice_nodes(0,[1])
991 check_foreign_slice_nodes(0,[2])
993 # insert local nodes in local slice on plc1
994 message ("ADDING LOCAL NODES IN SLICES")
995 test04_slice_add_lnode ([1])
996 # of course the change is only local
997 check_local_slice_nodes (number_nodes_per_slice,[1])
998 check_foreign_slice_nodes(0,[2])
1001 test00_refresh ("After local nodes were added on plc1")
1002 check_local_slice_nodes (number_nodes_per_slice,[1])
1003 check_foreign_slice_nodes (number_nodes_per_slice,[2])
1005 # now we add foreign nodes into local slice
1006 message ("ADDING FOREIGN NODES IN SLICES")
1007 test04_slice_add_fnode ([1])
1008 check_local_slice_nodes (2*number_nodes_per_slice,[1])
1009 check_foreign_slice_nodes (number_nodes_per_slice,[2])
1012 test00_refresh ("After foreign nodes were added in plc1")
1013 # remember that foreign slices only know about LOCAL nodes
1014 # so this does not do anything
1015 check_local_slice_nodes (2*number_nodes_per_slice,[1])
1016 check_foreign_slice_nodes (2*number_nodes_per_slice,[2])
1018 check_slivers_1(total_slivers())
1020 def test_all_delslices ():
1022 message ("DELETING FOREIGN NODES FROM SLICES")
1023 test04_slice_del_fnode([1])
1024 check_local_slice_nodes (number_nodes_per_slice,[1])
1025 check_foreign_slice_nodes (2*number_nodes_per_slice,[2])
1027 check_slivers_1(total_slivers(),[1])
1029 test00_refresh ("After foreign nodes were removed on plc1")
1030 check_local_slice_nodes (number_nodes_per_slice,[1])
1031 check_foreign_slice_nodes (number_nodes_per_slice,[2])
1033 message ("DELETING LOCAL NODES FROM SLICES")
1034 test04_slice_del_lnode([1])
1035 check_local_slice_nodes (0,[1])
1036 check_foreign_slice_nodes (number_nodes_per_slice,[2])
1038 test00_refresh ("After local nodes were removed on plc1")
1039 check_local_slice_nodes (0,[1])
1040 check_foreign_slice_nodes (0,[2])
1042 message ("CHECKING SLICES CLEAN UP")
1043 clean_all_slices([1])
1044 check_slices (system_slices(),0,[1])
1045 check_slices (system_slices(),number_slices,[2])
1046 test00_refresh ("After slices clenaup")
1047 check_slices(system_slices(),0)
1049 def test_all_slices ():
1050 test_all_addslices ()
1051 test_all_delslices ()
1053 def test_all_sats ():
1055 test00_refresh("after SliceAttributeType creation")
1074 ### ad hoc test sequences
1075 # we just create objects here so we can dump the DB
1088 test04_slice_add_lnode([1])
1098 test00_refresh ("populate: refreshing peer 1",[1])
1100 test04_slice_add_fnode([1])
1102 test00_refresh("populate: refresh all")
1104 test00_refresh("empty refresh")
1109 # temporary - scratch as needed
1114 # clean_all_slices()
1119 print "Usage: %s [-n] [-f]"%sys.argv[0]
1120 print " -n runs test_now instead of test_all"
1121 print " -p runs populate instead of test_all"
1122 print " -e runs populate_end of test_all"
1123 print " -m run in mini mode (1 instance of each class)"
1124 print " -b performs big run"
1125 print " -H performs huge run"
1126 print " -f n : increases normal sizes by <n>"
1127 print " -l n : tester runs locally for peer <n>, rather than through xmlrpc"
1133 (o,a) = getopt.getopt(sys.argv[1:], "emnpbHf:l:")
1139 print 'Running test_now'
1142 print 'Running populate'
1145 print 'Running populate_end'
1155 apply_factor(factor)
1159 if local_peer not in (1,2):
1169 if __name__ == '__main__':