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)
28 from PLC.Shell import Shell
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):
46 for method in PLC.Methods.methods:
47 # ignore path-defined methods for now
49 setattr(self,method,DummyShell.Callable(method,self.index))
55 ## try to support reload
67 # number of 'system' persons
68 # builtin maint, local root, 2 persons for the peering
70 # among that, 1 gets refreshed - other ones have conflicting names
71 system_persons_cross = 1
73 system_slices_ids = (1,)
75 return len(system_slices_ids)
77 return number_slices+system_slices()
79 def system_slivers ():
80 return len(system_slices_ids)
82 # too tedious to do the maths : how many slices attached to node 1
85 global expected_slivers
86 if expected_slivers is None:
88 actual_nodes_per_slice = min (number_nodes,number_nodes_per_slice)
89 for ns in myrange(number_slices):
90 slice_range = [ map_on_node (n+ns) for n in range(actual_nodes_per_slice)]
93 return expected_slivers+system_slivers()
96 # set initial conditions
97 # actual persons_per_slice is min(number_persons,number_persons_per_slice)
98 # actual nodes_per_slice is min(number_nodes,number_nodes_per_slice)
99 # this is to prevent quadractic test times on big tests
100 def define_test (sites,persons,nodes,slices,
101 keys_per_person,nodes_per_slice,persons_per_slice,fast_mode=None):
102 global number_sites, number_persons, number_nodes, number_slices
103 global number_keys_per_person, number_nodes_per_slice, number_persons_per_slice, fast_flag
105 number_persons=persons
108 number_keys_per_person=keys_per_person
109 number_nodes_per_slice=nodes_per_slice
110 number_persons_per_slice=persons_per_slice
111 if fast_mode is not None:
114 # when we run locally on a given peer
118 print '%d sites, %d persons, %d nodes & %d slices'%(
119 number_sites,number_persons,number_nodes,number_slices)
120 print '%d keys/person, %d nodes/slice & %d persons/slice'%(
121 number_keys_per_person,number_nodes_per_slice,number_persons_per_slice)
122 print 'fast_flag',fast_flag
123 if local_peer is not None:
124 print 'Running locally on index %d'%local_peer
127 define_test(1,1,1,1,1,1,1,True)
130 define_test (sites=4,persons=4,nodes=5,slices=4,
131 keys_per_person=2,nodes_per_slice=3,persons_per_slice=6,fast_mode=False)
133 def apply_factor (factor):
134 global number_sites, number_persons, number_nodes, number_slices
135 [number_sites, number_persons, number_nodes, number_slices] = \
136 [factor*x for x in [number_sites, number_persons, number_nodes, number_slices]]
139 # use only 1 key in this case
142 global number_sites, number_persons, number_nodes, number_slices
147 global nodes_per_slice
149 global number_keys_per_person
150 number_keys_per_person=1
151 global number_persons_per_slice
152 number_persons_per_slice=3
156 global number_sites, number_persons, number_nodes, number_slices
161 global nodes_per_slice
163 global number_keys_per_person
164 number_keys_per_person=1
165 global number_persons_per_slice
166 number_persons_per_slice=3
168 # use mini test by default in interactive mode
173 # argh, for login_name that doesn't accept digits
174 plain_numbers=['zero','one','two','three','four','five','six','seven','eight','nine','ten',
175 'eleven','twelve','thirteen','fourteen','fifteen','sixteen','seventeen','eighteen','nineteen','twenty']
176 plain_digits=['a','b','c','d','e','f','g','h','i','j']
178 plc[1]={ 'plcname':'Thierry plc1',
179 'hostname':'planetlab-devbox.inria.fr',
180 'url-format':'https://%s:443/PLCAPI/',
181 'builtin-admin-id':'root@plc1.org',
182 'builtin-admin-password':'root',
183 'peer-admin-name':'peer1@planet-lab.org',
184 'peer-admin-password':'peer',
185 'node-format':'n1-%03d.plc1.org',
187 'site-format':'one%s',
188 'person-format' : 'user1-%d@plc1.org',
189 'key-format':'ssh-rsa 11key4plc11 user%d-key%d',
190 'person-password' : 'password1',
191 'gpg-keyring':'gpg_plc2.pub',
192 'api-cacert':'api_plc2.crt',
194 plc[2]={ 'plcname':'Thierry plc2',
195 'hostname':'lurch.cs.princeton.edu',
196 'url-format':'https://%s:443/PLCAPI/',
197 'builtin-admin-id':'root@plc2.org',
198 'builtin-admin-password':'root',
199 'peer-admin-name':'peer2@planet-lab.org',
200 'peer-admin-password':'peer',
201 'node-format':'n2-%03d.plc2.org',
203 'site-format':'two%s',
204 'person-format' : 'user2-%d@plc2.org',
205 'key-format':'ssh-rsa 22key4plc22 user%d-key%d',
206 'person-password' : 'password2',
207 'gpg-keyring':'gpg_plc1.pub',
208 'api-cacert':'api_plc1.crt',
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)
292 def myassert (message,boolean):
294 print 'ASSERTION FAILED',message
300 print 'TEST FAILED with %d errors'%errors
305 def test00_init (args=[1,2],builtin_person=False):
308 url=plc[i]['url-format']%plc[i]['hostname']
310 if local_peer is None:
311 # the regular remote mode
312 print 'initializing s[%d]=>%s'%(i,url),
314 user=plc[i]['builtin-admin-id']
315 password=plc[i]['builtin-admin-password']
317 user=plc[i]['peer-admin-name']
318 password=plc[i]['peer-admin-password']
323 elif local_peer == i:
324 # local mode - use Shell's Direct mode - use /etc/planetlab/plc_config
327 # remote peer in local mode : use dummy shell instead
330 # use new person's account
332 def test00_print (args=[1,2]):
334 print '==================== s[%d]'%i
336 print 'show_config obsoleted'
337 print '===================='
339 def check_nodes (el,ef,args=[1,2]):
341 # use a single request and sort afterwards for efficiency
342 # could have used GetNodes's scope as well
343 all_nodes = s[i].GetNodes()
344 n = len ([ x for x in all_nodes if x['peer_id'] is None])
345 f = len ([ x for x in all_nodes if x['peer_id'] is not None])
346 print '%02d: Checking nodes: got %d local (e=%d) & %d foreign (e=%d)'%(i,n,el,f,ef)
347 myassert ('local nodes',n==el)
348 myassert ('foreign nodes',f==ef)
350 def check_keys (el,ef,args=[1,2]):
352 # use a single request and sort afterwards for efficiency
353 # could have used GetKeys's scope as well
354 all_keys = s[i].GetKeys()
355 n = len ([ x for x in all_keys if x['peer_id'] is None])
356 f = len ([ x for x in all_keys if x['peer_id'] is not None])
357 print '%02d: Checking keys: got %d local (e=%d) & %d foreign (e=%d)'%(i,n,el,f,ef)
358 myassert ('local keys',n==el)
359 myassert ('foreign_keys',f==ef)
361 def check_persons (el,ef,args=[1,2]):
363 # use a single request and sort afterwards for efficiency
364 # could have used GetPersons's scope as well
365 all_persons = s[i].GetPersons()
366 n = len ([ x for x in all_persons if x['peer_id'] is None])
367 f = len ([ x for x in all_persons if x['peer_id'] is not None])
368 print '%02d: Checking persons: got %d local (e=%d) & %d foreign (e=%d)'%(i,n,el,f,ef)
369 myassert ('local persons',n==el)
370 myassert ('foreign persons',f==ef)
372 # expected : local slices, foreign slices
373 def check_slices (els,efs,args=[1,2]):
375 ls=len(s[i].GetSlices({'peer_id':None}))
376 fs=len(s[i].GetSlices({'~peer_id':None}))
377 print '%02d: Checking slices: got %d local (e=%d) & %d foreign (e=%d)'%(i,ls,els,fs,efs)
378 myassert ('local slices',els==ls)
379 myassert ('foreign slices',efs==fs)
381 def show_nodes (i,node_ids):
383 all_nodes = s[i].GetNodes(node_ids)
384 loc_nodes = filter (lambda n: n['peer_id'] is None, all_nodes)
385 for_nodes = filter (lambda n: n['peer_id'] is not None, all_nodes)
387 for message,nodes in [ ['LOC',loc_nodes], ['FOR',for_nodes] ] :
389 print '[%s:%d] : '%(message,len(nodes)),
391 print node['hostname']+' ',
394 def check_slice_nodes (expected_nodes, is_local_slice, args=[1,2]):
395 for ns in myrange(number_slices):
396 check_slice_nodes_n (ns,expected_nodes, is_local_slice, args)
398 def check_slice_nodes_n (ns,expected_nodes, is_local_slice, args=[1,2]):
402 sname=slice_name(i,ns)
403 slice=s[i].GetSlices({'name':[sname],'peer_id':None})[0]
406 sname=slice_name(peer,ns)
407 slice=s[i].GetSlices({'name':[sname],'~peer_id':None})[0]
409 print '%02d: %s slice %s (e=%d) '%(i,message,sname,expected_nodes),
410 slice_node_ids=slice['node_ids']
411 print 'on nodes ',slice_node_ids
412 show_nodes (i,slice_node_ids)
413 myassert ('slice nodes',len(slice_node_ids)>=expected_nodes)
414 if len(slice_node_ids) != expected_nodes:
417 # expected : nodes on local slice
418 def check_local_slice_nodes (expected, args=[1,2]):
419 check_slice_nodes(expected,True,args)
421 # expected : nodes on foreign slice
422 def check_foreign_slice_nodes (expected, args=[1,2]):
423 check_slice_nodes(expected,False,args)
425 def check_conf_files (args=[1,2]):
426 for nn in myrange(number_nodes):
427 check_conf_files_n (nn,args)
429 def check_conf_files_n (nn,args=[1,2]):
431 nodename=node_name(i,nn)
432 ndict= s[i].GetSlivers([nodename])[0]
433 myassert ('conf files',ndict['hostname'] == nodename)
434 conf_files = ndict['conf_files']
435 print '%02d: %d conf_files in GetSlivers for node %s'%(i,len(conf_files),nodename)
436 for conf_file in conf_files:
437 print 'source=',conf_file['source'],'|',
438 print 'dest=',conf_file['dest'],'|',
439 print 'enabled=',conf_file['enabled'],'|',
443 pp = pprint.PrettyPrinter(indent=3)
445 def check_slivers (esn,args=[1,2]):
446 for nn in myrange(number_nodes):
447 check_slivers_n (nn,esn,args)
449 # too verbose to check all nodes, let's check only the first one
450 def check_slivers_1 (esn,args=[1,2]):
451 check_slivers_n (1,esn,args)
453 def check_slivers_n (nn,esn,args=[1,2]):
455 nodename=node_name(i,nn)
456 ndict= s[i].GetSlivers(nodename)
457 myassert ('slivers hostname',ndict['hostname'] == nodename)
458 slivers = ndict['slivers']
459 print '%02d: %d slivers (exp. %d) in GetSlivers for node %s'\
460 %(i,len(slivers),esn,nodename)
461 for sliver in slivers:
462 print '>>slivername = ',sliver['name']
463 pretty_printer.pprint(sliver)
464 myassert ('slivers count',len(slivers) == esn)
468 def test00_admin_person (args=[1,2]):
471 email = plc[i]['peer-admin-name']
473 p=s[i].GetPersons([email])[0]
474 plc[i]['peer-admin-id']=p['person_id']
476 person_id=s[i].AddPerson({'first_name':'Local',
477 'last_name':'PeerPoint',
480 'password':plc[i]['peer-admin-password']})
482 print '%02d:== created peer admin account %d, %s - %s'%(
483 i, person_id,plc[i]['peer-admin-name'],plc[i]['peer-admin-password'])
484 plc[i]['peer-admin-id']=person_id
486 def test00_admin_enable (args=[1,2]):
488 if s[i].AdmSetPersonEnabled(plc[i]['peer-admin-id'],True):
489 s[i].AddRoleToPerson('admin',plc[i]['peer-admin-id'])
490 print '%02d:== enabled+admin on account %d:%s'%(i,plc[i]['peer-admin-id'],plc[i]['peer-admin-name'])
493 def locate_key (filename):
494 " tries to locate a key file, either in . or in /etc/planetlab"
496 return file("./"+filename).read()
499 return file("/etc/planetlab/"+filename).read()
501 raise Exception,"Could not locate key %s"%filename
504 def test00_peer (args=[1,2]):
508 peername = plc_name(peer)
510 p=s[i].GetPeers ( [peername])[0]
513 keyringname=plc[i]['gpg-keyring']
514 cacertname=plc[i]['api-cacert']
515 print 'Trying to locate keys for peer on plc[%d]'%i,
516 print 'in %s and %s'%(keyringname,cacertname)
518 keyring=locate_key(keyringname)
519 cacert=locate_key(cacertname)
520 peer_id=s[i].AddPeer ( {'peername':peername,
521 'peer_url':plc[peer]['url'],
525 print '%02d:Created peer %d'%(i,peer_id)
527 print 'Could not create peer,',e
529 # push various stuff across hosts through external ssh/scp
530 # this is broken, use peers-test.mk instead
531 #def test00_push_public_peer_material (args=[1,2]):
535 # ### the gpg keyring
537 # local_keyring="/etc/planetlab/gpg_keyring.pub"
538 # command="ssh root@%s gpg --homedir=/etc/planetlab --export --armor > %s"\
539 # %(plc[i]['hostname'],local_keyring)
540 # retcod=os.system(command)
541 # print '#',command,'->',retcod
546 # src_url='root@%s:%s'%(plc[i]['hostname'],local_keyring)
547 # dst_url='root@%s:%s'%(plc[peer]['hostname'], plc[i]['gpg-keyring'])
548 # command = 'scp %s %s'%(src_url,dst_url)
549 # retcod=os.system(command)
550 # print '#',command,'->',retcod
555 # local_cacert='/etc/planetlab/api_ca_ssl.crt'
556 # src_url='root@%s:%s'%(plc[i]['hostname'],local_cacert)
557 # dst_url='root@%s:%s'%(plc[peer]['hostname'], plc[i]['api-cacert'])
558 # command = 'scp %s %s'%(src_url,dst_url)
559 # retcod=os.system(command)
560 # print '#',command,'->',retcod
562 # this one gets cached
565 return plc[i]['peer_id']
567 peername = plc_name (peer_index(i))
568 peer_id = s[i].GetPeers([peername])[0]['peer_id']
569 plc[i]['peer_id'] = peer_id
572 ##############################
573 def test00_refresh (message,args=[1,2]):
574 print '=== refresh',message
577 print '%02d:== Refreshing peer'%(i),
578 retcod=s[i].RefreshPeer(get_peer_id(i))
583 if "time" not in key:
584 print key,retcod[key],
586 print "+++ ellapsed: {",
591 print key,timers[key],
596 def test01_site (args=[1,2]):
597 for ns in myrange(number_sites):
598 test01_site_n (ns,True,args)
600 def test01_del_site (args=[1,2]):
601 for ns in myrange(number_sites):
602 test01_site_n (ns,False,args)
604 def test01_site_n (ns,add_if_true,args=[1,2]):
606 login_base = site_login_base (i,ns)
608 site_id = s[i].GetSites([login_base])[0]['site_id']
610 if s[i].DeleteSite(site_id):
611 print "%02d:== deleted site_id %d"%(i,site_id)
614 sitename=site_name(i,ns)
615 abbrev_name="abbr"+str(i)
616 max_slices = number_slices
617 site_id=s[i].AddSite ( {'name':plc_name(i),
618 'abbreviated_name': abbrev_name,
619 'login_base': login_base,
621 'url': 'http://%s.com/'%abbrev_name,
622 'max_slices':max_slices})
623 ### max_slices does not seem taken into account at that stage
625 s[i].UpdateSite(site_id,{'max_slices':max_slices})
626 print '%02d:== Created site %d with max_slices=%d'%(i,site_id,max_slices)
629 def test02_person (args=[1,2]):
630 for np in myrange(number_persons):
631 test02_person_n (np,True,args)
633 def test02_del_person (args=[1,2]):
634 for np in myrange(number_persons):
635 test02_person_n (np,False,args)
637 def test02_person_n (np,add_if_true,args=[1,2]):
638 test02_person_n_ks (np, myrange(number_keys_per_person),add_if_true,args)
640 def test02_person_n_ks (np,nks,add_if_true,args=[1,2]):
642 email = person_name(i,np)
644 person_id=s[i].GetPersons([email])[0]['person_id']
646 if s[i].DeletePerson(person_id):
647 print "%02d:== deleted person_id %d"%(i,person_id)
650 password = plc[i]['person-password']
651 person_id=s[i].AddPerson({'first_name':'Your average',
652 'last_name':'User%d'%np,
655 'password': password })
657 print '%02d:== created user account %d, %s - %s'%(i, person_id,email,password)
659 key=key_name(i,np,nk)
660 s[i].AddPersonKey(email,{'key_type':'ssh', 'key':key})
661 print '%02d:== added key %s to person %s'%(i,key,email)
664 # retrieves node_id from hostname - checks for local nodes only
665 def get_local_node_id(i,nodename):
666 return s[i].GetNodes({'hostname':nodename,'peer_id':None})[0]['node_id']
668 # clean all local nodes - foreign nodes are not supposed to be cleaned up manually
669 def clean_all_nodes (args=[1,2]):
671 print '%02d:== Cleaning all nodes'%i
672 local_nodes = s[i].GetNodes({'peer_id':None})
674 for node in local_nodes:
675 print '%02d:==== Cleaning node %d'%(i,node['node_id'])
676 s[i].DeleteNode(node['node_id'])
678 def test03_node (args=[1,2]):
679 for nn in myrange(number_nodes):
680 test03_node_n (nn,args)
682 def test03_node_n (nn,args=[1,2]):
684 nodename = node_name(i,nn)
686 get_local_node_id(i,nodename)
688 login_base=site_login_base(i,map_on_site(nn))
689 n=s[i].AddNode(login_base,{'hostname': nodename})
691 print '%02d:== Added node %d %s'%(i,n,node_name(i,nn))
693 def test02_delnode (args=[1,2]):
694 for nn in myrange(number_nodes):
695 test02_delnode_n (nn,args)
697 def test02_delnode_n (nn,args=[1,2]):
699 nodename = node_name(i,nn)
700 node_id = get_local_node_id (i,nodename)
701 retcod=s[i].DeleteNode(nodename)
703 print '%02d:== Deleted node %d, returns %s'%(i,node_id,retcod)
706 def clean_all_slices (args=[1,2]):
708 print '%02d:== Cleaning all slices'%i
709 for slice in s[i].GetSlices({'peer_id':None}):
710 slice_id = slice['slice_id']
711 if slice_id not in system_slices_ids:
712 if s[i].DeleteSlice(slice_id):
713 print '%02d:==== Cleaned slice %d'%(i,slice_id)
715 def test04_slice (args=[1,2]):
716 for n in myrange(number_slices):
717 test04_slice_n (n,args)
719 def test04_slice_n (ns,args=[1,2]):
723 slicename=slice_name(i,ns)
724 max_nodes=number_nodes
726 s[i].GetSlices([slicename])[0]
728 slice_id=s[i].AddSlice ({'name':slicename,
729 'description':'slice %s on %s'%(slicename,plcname),
730 'url':'http://planet-lab.org/%s'%slicename,
731 'max_nodes':max_nodes,
732 'instanciation':'plc-instantiated',
735 print '%02d:== created slice %d - max nodes=%d'%(i,slice_id,max_nodes)
736 actual_persons_per_slice = min (number_persons,number_persons_per_slice)
737 person_indexes=[map_on_person (p+ns) for p in range(actual_persons_per_slice)]
738 for np in person_indexes:
739 email = person_name (i,np)
740 retcod = s[i].AddPersonToSlice (email, slicename)
741 print '%02d:== Attached person %s to slice %s'%(i,email,slicename)
744 def test04_node_slice (is_local, add_if_true, args=[1,2]):
745 for ns in myrange(number_slices):
746 test04_node_slice_ns (ns,is_local, add_if_true, args)
748 def test04_node_slice_ns (ns,is_local, add_if_true, args=[1,2]):
749 actual_nodes_per_slice = min (number_nodes,number_nodes_per_slice)
750 node_indexes = [ map_on_node (n+ns) for n in range(actual_nodes_per_slice)]
751 test04_node_slice_nl_n (node_indexes,ns,is_local, add_if_true, args)
753 def test04_node_slice_nl_n (nnl,ns,is_local, add_if_true, args=[1,2]):
756 sname = slice_name (i,ns)
759 hostnames=[node_name(i,nn) for nn in nnl]
762 hostnames=[node_name(peer,nn) for nn in nnl]
765 res=s[i].AddSliceToNodes (sname,hostnames)
768 res=s[i].DeleteSliceFromNodes (sname,hostnames)
771 print '%02d:== %s in slice %s %s '%(i,message,sname,nodetype),
774 def test04_slice_add_lnode (args=[1,2]):
775 test04_node_slice (True,True,args)
777 def test04_slice_add_fnode (args=[1,2]):
778 test04_node_slice (False,True,args)
780 def test04_slice_del_lnode (args=[1,2]):
781 test04_node_slice (True,False,args)
783 def test04_slice_del_fnode (args=[1,2]):
784 test04_node_slice (False,False,args)
787 def test05_sat (args=[1,2]):
791 sat_id=s[i].GetSliceAttributeTypes ([name])[0]
793 description="custom sat on plc%d"%i
795 sat_id=s[i].AddSliceAttributeType ({ 'name':name,
796 'description': description,
797 'min_role_id' : min_role_id})
799 print '%02d:== created SliceAttributeType = %d'%(i,sat_id)
801 # for test, we create 4 slice_attributes
802 # on slice1 - sat=custom_made (see above) - all nodes
803 # on slice1 - sat=custom_made (see above) - node=n1
804 # on slice1 - sat='net_max' - all nodes
805 # on slice1 - sat='net_max' - node=n1
807 def test05_sa_atom (slice_name,sat_name,value,node,i):
808 sa_id=s[i].GetSliceAttributes({'name':sat_name,
812 sa_id=s[i].AddSliceAttribute(slice_name,
817 print 'slice_name',slice_name,'sat_name',sat_name
818 sa_id=s[i].AddSliceAttribute(slice_name,
822 print '%02d:== created SliceAttribute = %d'%(i,sa_id),
823 print 'On slice',slice_name,'and node',node
825 def test05_sa (args=[1,2]):
827 test05_sa_atom (slice_name(i,1),sat_name(i),'custom sat/all nodes',None,i)
828 test05_sa_atom (slice_name(i,1),sat_name(i),'custom sat/node1',node_name(i,1),i)
829 test05_sa_atom (slice_name(i,1),'vref','predefined sat/all nodes',None,i)
830 test05_sa_atom (slice_name(i,1),'vref','predefined sat/node1',node_name(i,1),i)
832 ##############################
834 ##############################
836 print s['site_id'],s['peer_id'],s['login_base'],s['name'],s['node_ids']
839 print k['key_id'],k['peer_id'],k['key']
842 print p['person_id'],p['peer_id'],p['email'],'keys:',p['key_ids'],'sites:',p['site_ids']
845 print n['node_id'],n['peer_id'],n['hostname'],'sls=',n['slice_ids'],'site=',n['site_id']
848 print 'name: %-12s'%s['name'],'id: %02d'%s['slice_id'],'peer:',s['peer_id'],'nodes=',s['node_ids'],'persons=',s['person_ids']
849 print '---','sa_ids=',s['slice_attribute_ids'],'creator: %03d'%s['creator_person_id']
850 print "--- 'expires':",s['expires']
853 print 'sat_id: %02d'%sat['attribute_type_id'], 'min_role_id:',sat['min_role_id'],
854 print 'name:', sat['name'],'<',sat['description'],'>'
857 print 'name: %-12s'%sa['name'],
858 print 'sa_id: %02d'%sa['slice_attribute_id'],'sat_id: %02d'%sa['attribute_type_id'],
859 print 'sl=%02d'%sa['slice_id'],'v=',sa['value'],'n=',sa['node_id']
862 pretty_printer=pprint.PrettyPrinter(5)
864 def p_sliver (margin,x):
865 print margin,'SLIVERS for : hostname',x['hostname']
866 print margin,'%d config files'%len(x['conf_files'])
867 for sv in x['slivers']:
868 p_sliver_slice(margin,sv,x['hostname'])
870 def p_sliver_slice(margin,sliver,hostname):
871 print margin,'SLIVER on hostname %s, s='%hostname,sliver['name']
873 pretty_printer.pprint(sliver['keys'])
874 print margin,'ATTRIBUTES',
875 pretty_printer.pprint(sliver['attributes'])
877 def dump (args=[1,2]):
879 print '%02d:============================== DUMPING'%i
880 print '%02d: SITES'%i
881 [p_site(x) for x in s[i].GetSites()]
883 [p_key(x) for x in s[i].GetKeys()]
884 print '%02d: PERSONS'%i
885 [p_person(x) for x in s[i].GetPersons()]
886 print '%02d: NODES'%i
887 [p_node(x) for x in s[i].GetNodes()]
888 print '%02d: SLICES'%i
889 [p_slice(x) for x in s[i].GetSlices()]
890 print '%02d: Slice Attribute Types'%i
891 [p_sat(x) for x in s[i].GetSliceAttributeTypes()]
892 print '%02d: Slice Attributes'%i
893 [p_sa(x) for x in s[i].GetSliceAttributes()]
895 snodes=min(3,number_nodes)
896 print '%02d: SLIVERS for first %d nodes'%(i,snodes)
897 print 'WARNING - GetSlivers needs fix'
898 # for id in myrange(snodes):
899 # p_sliver('%02d:'%i,s[i].GetSlivers(id))
901 print '%02d:============================== END DUMP'%i
904 ## for usage under the api
911 print (x['key_id'],x['peer_id'],x['key'])
914 for x in GetPersons():
922 for x in GetSlices():
926 for x in GetSliceAttributeTypes():
930 for x in GetSliceAttributes():
934 for s in GetSlivers():
948 print 'SLICE ATTR TYPES'
957 def test_all_init ():
959 test00_init (builtin_person=True)
961 test00_admin_person ()
962 test00_admin_enable ()
963 test00_init (builtin_person=False)
964 # required before we can add peers
965 # use make -f peers-test.mk peers instead
966 # test00_push_public_peer_material()
969 def test_all_sites ():
971 test00_refresh ('after site creation')
973 def test_all_persons ():
975 test00_refresh ('before persons&keys creation')
977 check_persons(system_persons,system_persons_cross)
978 message ("Creating persons&keys")
981 message ("1 extra del/add cycle for unique indexes")
982 test02_del_person([2])
984 check_keys(number_persons*number_keys_per_person,0)
985 check_persons(system_persons+number_persons,system_persons_cross)
986 test00_refresh ('after persons&keys creation')
987 check_keys(number_persons*number_keys_per_person,number_persons*number_keys_per_person)
988 check_persons(system_persons+number_persons,system_persons_cross+number_persons)
990 def test_all_nodes ():
992 message ("RESETTING NODES")
994 test00_refresh ('cleaned nodes')
997 # create one node on each site
998 message ("CREATING NODES")
1000 check_nodes(number_nodes,0)
1001 test00_refresh ('after node creation')
1002 check_nodes(number_nodes,number_nodes)
1005 message ("2 extra del/add cycles on plc2 for different indexes")
1010 check_nodes(0,number_nodes,[2])
1011 test00_refresh('after deletion on plc2')
1012 check_nodes(number_nodes,0,[1])
1013 check_nodes(0,number_nodes,[2])
1014 message ("ADD on plc2 for different indexes")
1016 check_nodes (number_nodes,0,[1])
1017 check_nodes (number_nodes,number_nodes,[2])
1018 test00_refresh('after re-creation on plc2')
1019 check_nodes (number_nodes,number_nodes,)
1021 def test_all_addslices ():
1024 message ("RESETTING SLICES TEST")
1028 test00_refresh ("After slices init")
1030 # create slices on plc1
1031 message ("CREATING SLICES on plc1")
1034 check_slices (total_slices(),system_slices(),[1])
1035 check_slices (system_slices(),system_slices(),[2])
1036 test00_refresh ("after slice created on plc1")
1037 check_slices (total_slices(),system_slices(),[1])
1038 check_slices (system_slices(),total_slices(),[2])
1039 # no slice has any node yet
1040 check_local_slice_nodes(0,[1])
1041 check_foreign_slice_nodes(0,[2])
1043 # insert local nodes in local slice on plc1
1044 message ("ADDING LOCAL NODES IN SLICES")
1045 test04_slice_add_lnode ([1])
1046 # of course the change is only local
1047 check_local_slice_nodes (number_nodes_per_slice,[1])
1048 check_foreign_slice_nodes(0,[2])
1051 test00_refresh ("After local nodes were added on plc1")
1052 check_local_slice_nodes (number_nodes_per_slice,[1])
1053 check_foreign_slice_nodes (number_nodes_per_slice,[2])
1055 # now we add foreign nodes into local slice
1056 message ("ADDING FOREIGN NODES IN SLICES")
1057 test04_slice_add_fnode ([1])
1058 check_local_slice_nodes (2*number_nodes_per_slice,[1])
1059 check_foreign_slice_nodes (number_nodes_per_slice,[2])
1062 test00_refresh ("After foreign nodes were added in plc1")
1063 # remember that foreign slices only know about LOCAL nodes
1064 # so this does not do anything
1065 check_local_slice_nodes (2*number_nodes_per_slice,[1])
1066 check_foreign_slice_nodes (2*number_nodes_per_slice,[2])
1068 check_slivers_1(total_slivers())
1070 def test_all_delslices ():
1072 message ("DELETING FOREIGN NODES FROM SLICES")
1073 test04_slice_del_fnode([1])
1074 check_local_slice_nodes (number_nodes_per_slice,[1])
1075 check_foreign_slice_nodes (2*number_nodes_per_slice,[2])
1077 check_slivers_1(total_slivers(),[1])
1079 test00_refresh ("After foreign nodes were removed on plc1")
1080 check_local_slice_nodes (number_nodes_per_slice,[1])
1081 check_foreign_slice_nodes (number_nodes_per_slice,[2])
1083 message ("DELETING LOCAL NODES FROM SLICES")
1084 test04_slice_del_lnode([1])
1085 check_local_slice_nodes (0,[1])
1086 check_foreign_slice_nodes (number_nodes_per_slice,[2])
1088 test00_refresh ("After local nodes were removed on plc1")
1089 check_local_slice_nodes (0,[1])
1090 check_foreign_slice_nodes (0,[2])
1092 message ("CHECKING SLICES CLEAN UP")
1093 clean_all_slices([1])
1094 check_slices (system_slices(),system_slices(),[1])
1095 check_slices (system_slices(),total_slices(),[2])
1096 test00_refresh ("After slices clenaup")
1097 check_slices(system_slices(),system_slices())
1099 def test_all_slices ():
1100 test_all_addslices ()
1101 test_all_delslices ()
1103 def test_all_sats ():
1105 test00_refresh("after SliceAttributeType creation")
1124 ### ad hoc test sequences
1125 # we just create objects here so we can dump the DB
1138 test04_slice_add_lnode([1])
1147 test00_init(builtin_person=False)
1148 test00_refresh ("Peer 1 for publishing foreign nodes from 2",[1])
1150 test04_slice_add_fnode([1])
1152 test00_refresh("populate: refresh all")
1154 test00_refresh("empty refresh")
1159 # temporary - scratch as needed
1164 # test00_refresh('peer 1 gets plc2 nodes',[1])
1165 # test04_slice_add_fnode([1])
1166 # test00_refresh('final',[1])
1170 # clean_all_slices()
1175 print "Usage: %s [-n] [-f]"%sys.argv[0]
1176 print " -n runs test_now instead of test_all"
1177 print " -p runs populate instead of test_all"
1178 print " -e runs populate_end of test_all"
1179 print " -m run in mini mode (1 instance of each class)"
1180 print " -b performs big run"
1181 print " -H performs huge run"
1182 print " -f n : increases normal sizes by <n>"
1183 print " -l n : tester runs locally for peer <n>, rather than through xmlrpc"
1189 (o,a) = getopt.getopt(sys.argv[1:], "emnpbHf:l:")
1195 print 'Running test_now'
1198 print 'Running populate'
1201 print 'Running populate_end'
1211 apply_factor(factor)
1215 if local_peer not in (1,2):
1226 if __name__ == '__main__':