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 ##############################
17 # support reloading without wiping everything off
18 # dunno how to do (defvar plc)
20 ## we use indexes 1 and 2
30 ## the authentication objects
36 ## the builtin root user for bootstrapping
46 plc1={ 'name':'plc1 in federation',
47 'hostname':'lurch.cs.princeton.edu',
48 'url-format':'https://%s:443/PLCAPI/',
49 'builtin_admin_id':'root@localhost.localdomain',
50 'builtin_admin_password':'root',
51 'peer_admin_name':'plc1@planet-lab.org',
52 'peer_admin_password':'peer',
53 'nodename':'n11.plc1.org',
56 plc2={ 'name':'plc2 in federation',
57 'hostname':'planetlab-devbox.inria.fr',
58 'url-format':'https://%s:443/PLCAPI/',
59 'builtin_admin_id':'root@localhost.localdomain',
60 'builtin_admin_password':'root',
61 'peer_admin_name':'plc2@planet-lab.org',
62 'peer_admin_password':'peer',
63 'nodename':'n21.plc2.org',
78 def full_slice_name (i):
80 return plc[i]['plainname']+'_'+slice_name(i)
83 def test00_init (args=[1,2]):
85 ## have you loaded this file already (support for reload)
91 url=plc[i]['url-format']%plc[i]['hostname']
93 s[i]=xmlrpclib.Server(url)
94 print 'initializing s[%d]'%i,url
95 aa[i]={'Username':plc[i]['builtin_admin_id'],
96 'AuthMethod':'password',
97 'AuthString':plc[i]['builtin_admin_password'],
99 print 'initialized aa[%d]'%i, aa[i]
100 a[i]={'Username':plc[i]['peer_admin_name'],
101 'AuthMethod':'password',
102 'AuthString':plc[i]['peer_admin_password'],
104 print 'initialized a[%d]'%i, a[i]
106 def test00_print (args=[1,2]):
110 print 'aa[%d]'%i, aa[i]
111 print 'a[%d]'%i, a[i]
113 def check_nodes (en,ef,args=[1,2]):
116 n=len(s[i].GetNodes(a[i]))
117 f=len(s[i].GetForeignNodes(a[i]))
118 print '%02d: Checking connection: got %d local nodes & %d foreign nodes'%(i,n,f)
122 # expected : local slices, foreign slices
123 def check_slices (els,efs,args=[1,2]):
126 ls=len(s[i].GetSlices(a[i]))
127 fs=len(s[i].GetForeignSlices(a[i]))
128 print '%02d: Checking connection: got %d local slices & %d foreign slices'%(i,ls,fs)
132 def show_nodes (i,node_ids):
133 for message,nodes in [ ['LOC',s[i].GetNodes(a[i],node_ids)],
134 ['FOR',s[i].GetForeignNodes(a[i],node_ids)] ]:
136 print '[%s:%d] : '%(message,len(nodes)),
138 print node['hostname']+' ',
141 def check_slice_nodes (expected_nodes, is_local_slice, args=[1,2]):
146 sname=full_slice_name(i)
147 slice=s[i].GetSlices(a[i],[sname])[0]
150 sname=full_slice_name(peer)
151 slice=s[i].GetForeignSlices(a[i],[sname])[0]
153 print '%02d: %s slice (%s) '%(i,message,sname),
154 slice_node_ids=slice['node_ids']
155 print 'on nodes ',slice_node_ids
156 assert len(slice_node_ids)==expected_nodes
157 show_nodes (i,slice_node_ids)
159 # expected : nodes on local slice
160 def check_local_slice_nodes (expected, args=[1,2]):
161 check_slice_nodes(expected,True,args)
163 # expected : nodes on foreign slice
164 def check_foreign_slice_nodes (expected, args=[1,2]):
165 check_slice_nodes(expected,False,args)
167 def check_conf_files (args=[1,2]):
170 nodename=plc[i]['nodename']
171 ndict= s[i].GetSlivers(a[i],[nodename])[0]
172 assert ndict['hostname'] == nodename
173 conf_files = ndict['conf_files']
174 print '%02d: %d conf_files in GetSlivers for node %s'%(i,len(conf_files),nodename)
175 for conf_file in conf_files:
176 print 'source=',conf_file['source'],'|',
177 print 'dest=',conf_file['dest'],'|',
178 print 'enabled=',conf_file['enabled'],'|',
182 pp = pprint.PrettyPrinter(indent=3)
184 def check_slivers (esn,args=[1,2]):
187 nodename=plc[i]['nodename']
188 ndict= s[i].GetSlivers(a[i],[nodename])[0]
189 assert ndict['hostname'] == nodename
190 slivers = ndict['slivers']
191 assert len(slivers) == esn
192 print '%02d: %d slivers in GetSlivers for node %s'%(i,len(slivers),nodename)
193 for sliver in slivers:
194 print '>>slivername = ',sliver['name']
199 def test00_admin (args=[1,2]):
203 person_id=s[i].AddPerson(aa[i],{'first_name':'Local', 'last_name':'PeerPoint', 'role_ids':[10],
204 'email':plc[i]['peer_admin_name'],'password':plc[i]['peer_admin_password']})
205 print '%02d: created peer admin account %d, %s - %s'%(i,person_id,plc[i]['peer_admin_name'],plc[i]['peer_admin_password'])
206 plc[i]['peer_admin_id']=person_id
208 def test00_enable (args=[1,2]):
212 s[i].AdmSetPersonEnabled(aa[i],plc[i]['peer_admin_id'],True)
213 s[i].AddRoleToPerson(aa[i],'admin',plc[i]['peer_admin_id'])
214 print '%02d: enabled+admin on account %d:%s'%(i,plc[i]['peer_admin_id'],plc[i]['peer_admin_name'])
216 def test01_node (args=[1,2]):
219 n=s[i].AddNode(a[i],1,{'hostname': plc[i]['nodename']})
220 print '%02d: Added node %d %s'%(i,n,plc[i]['nodename'])
223 def test01_delnode (args=[1,2]):
226 retcod=s[i].DeleteNode(a[i],plc[i]['node_id'])
227 print '%02d: Deleted node %d, got %s'%(i,plc[i]['node_id'],retcod)
228 plc[i]['node_id']=None
230 def test01_peer_person (args=[1,2]):
234 person_id = s[i].AddPerson (a[i], {'first_name':'Peering(plain passwd)', 'last_name':plc[peer]['name'], 'role_ids':[3000],
235 'email':plc[peer]['peer_admin_name'],'password':plc[peer]['peer_admin_password']})
236 print '%02d:Created person %d as the peer person'%(i,person_id)
237 plc[i]['peer_person_id']=person_id
239 def test01_peer (args=[1,2]):
243 peer_id=s[i].AddPeer (a[i], {'peername':plc[peer]['name'],'peer_url':plc[peer]['url'],'person_id':plc[i]['peer_person_id']})
244 # NOTE : need to manually reset the encrypted password through SQL at this point
245 print '%02d:Created peer %d'%(i,peer_id)
246 plc[i]['peer_id']=peer_id
247 print "PLEASE manually set password for person_id=%d in DB%d"%(plc[i]['peer_person_id'],i)
249 def test01_peer_passwd (args=[1,2]):
252 # using an ad-hoc local command for now - never could get quotes to reach sql....
253 print "Attempting to set passwd for person_id=%d in DB%d"%(plc[i]['peer_person_id'],i),
254 retcod=os.system("ssh root@%s new_plc_api/person-password.sh %d"%(plc[i]['hostname'],plc[i]['peer_person_id']))
257 def test02_refresh (args=[1,2]):
260 print '%02d: Refreshing peer'%(i),
261 retcod=s[i].RefreshPeer(a[i],plc[i]['peer_id'])
264 def test03_site (args=[1,2]):
268 ### create a site (required for creating a slice)
269 sitename=site_name(i)
270 abbrev_name="abbr"+str(i)
271 site_id=s[i].AddSite (a[i], {'name':plc[i]['name'],
272 'abbreviated_name': abbrev_name,
273 'login_base': plc[i]['plainname'],
275 'url': 'http://%s.com/'%abbrev_name,
277 ### max_slices does not seem taken into account at that stage
278 s[i].UpdateSite(a[i],site_id,{'max_slices':10})
279 print '%02d: Created site %d with max_slices=10'%(i,site_id)
280 plc[i]['site_id']=site_id
282 def test03_slice (args=[1,2]):
286 plain=full_slice_name(i)
289 slice_id=s[i].AddSlice (a[i],{'name':plain,
290 'description':'slice %s on plc %s'%(plain,plc[i]['name']),
291 'url':'http://planet-lab.org/%s'%name,
293 'instanciation':'plc-instantiated',
295 print '%02d: created slice %d'%(i,slice_id)
296 plc[i]['slice_id']=slice_id
299 def test04_node_slice (is_local, add_if_true, args=[1,2]):
304 hostname=plc[i]['nodename']
307 hostname=plc[peer]['nodename']
310 s[i].AddSliceToNodes (a[i], plc[i]['slice_id'],[hostname])
313 s[i].DeleteSliceFromNodes (a[i], plc[i]['slice_id'],[hostname])
315 print '%02d: %s in slice %d %s node %s'%(i,message,plc[i]['slice_id'],nodetype,hostname)
317 def test04_slice_add_lnode (args=[1,2]):
318 test04_node_slice (True,True,args)
320 def test04_slice_add_fnode (args=[1,2]):
321 test04_node_slice (False,True,args)
323 def test04_slice_del_lnode (args=[1,2]):
324 test04_node_slice (True,False,args)
326 def test04_slice_del_fnode (args=[1,2]):
327 test04_node_slice (False,False,args)
330 def test_all_init ():
336 test01_peer_person ()
338 test01_peer_passwd ()
343 def test_all_nodes ():
344 # create one node on each site
352 check_nodes (1,1,[1])
353 check_nodes (0,1,[2])
355 check_nodes (1,0,[1])
356 check_nodes (0,1,[2])
360 check_nodes (1,0,[1])
361 check_nodes (1,1,[2])
365 # make sure node indexes differ
375 def test_all_addslices ():
376 # each site has 3 local slices and 1 foreign slice
378 # no slice has any node yet
379 check_local_slice_nodes(0)
380 check_foreign_slice_nodes(0)
382 # insert one local node in local slice on plc1
383 test04_slice_add_lnode ([1])
384 # of course the change is only local
385 check_local_slice_nodes (1,[1])
386 check_local_slice_nodes (0,[2])
387 check_foreign_slice_nodes(0)
391 # remember that foreign slices only know about LOCAL nodes
392 # so refreshing does not do anything
393 check_local_slice_nodes (1,[1])
394 check_local_slice_nodes (0,[2])
395 check_foreign_slice_nodes(0)
397 # now we add a foreign node into local slice
398 test04_slice_add_fnode ([1])
399 check_local_slice_nodes (2,[1])
400 check_foreign_slice_nodes (0,[1])
401 check_local_slice_nodes (0,[2])
402 check_foreign_slice_nodes (0,[2])
406 # remember that foreign slices only know about LOCAL nodes
407 # so this does not do anything
408 check_local_slice_nodes (2,[1])
409 check_foreign_slice_nodes (0,[1])
410 check_local_slice_nodes (0,[2])
411 check_foreign_slice_nodes (1,[2])
416 def test_all_delslices ():
417 test04_slice_del_fnode([1])
418 check_local_slice_nodes (1,[1])
419 check_foreign_slice_nodes (1,[2])
421 check_local_slice_nodes (1,[1])
422 check_foreign_slice_nodes (0,[2])
424 test04_slice_del_lnode([1])
425 check_local_slice_nodes (0,[1])
426 check_foreign_slice_nodes (0,[2])
428 check_local_slice_nodes (0,[1])
429 check_foreign_slice_nodes (0,[2])
434 test_all_addslices ()
435 test_all_delslices ()
437 if __name__ == '__main__':