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 # expected : nodes on local slice
142 def check_local_slice_nodes (eln, args=[1,2]):
145 lname=full_slice_name(i)
146 ls=s[i].GetSlices(a[i],[lname])[0]
148 print '%02d: local slice (%s) on nodes '%(i,lname),lsn
152 # expected : nodes on foreign slice
153 def check_foreign_slice_nodes (efn, args=[1,2]):
157 fname=full_slice_name(peer)
158 fs=s[i].GetForeignSlices(a[i],[fname])[0]
160 print '%02d: foreign slice (%s) on nodes '%(i,fname),fsn
164 def check_conf_files (args=[1,2]):
167 nodename=plc[i]['nodename']
168 ndict= s[i].GetSlivers(a[i],[nodename])[0]
169 assert ndict['hostname'] == nodename
170 conf_files = ndict['conf_files']
171 print '%02d: %d conf_files in GetSlivers for node %s'%(i,len(conf_files),nodename)
172 for conf_file in conf_files:
173 print 'source=',conf_file['source'],'|',
174 print 'dest=',conf_file['dest'],'|',
175 print 'enabled=',conf_file['enabled'],'|',
179 pp = pprint.PrettyPrinter(indent=3)
181 def check_slivers (esn,args=[1,2]):
184 nodename=plc[i]['nodename']
185 ndict= s[i].GetSlivers(a[i],[nodename])[0]
186 assert ndict['hostname'] == nodename
187 slivers = ndict['slivers']
188 assert len(slivers) == esn
189 print '%02d: %d slivers in GetSlivers for node %s'%(i,len(slivers),nodename)
190 for sliver in slivers:
191 print '>>slivername = ',sliver['name']
196 def test00_admin (args=[1,2]):
200 person_id=s[i].AddPerson(aa[i],{'first_name':'Local', 'last_name':'PeerPoint', 'role_ids':[10],
201 'email':plc[i]['peer_admin_name'],'password':plc[i]['peer_admin_password']})
202 print '%02d: created peer admin account %d, %s - %s'%(i,person_id,plc[i]['peer_admin_name'],plc[i]['peer_admin_password'])
203 plc[i]['peer_admin_id']=person_id
205 def test00_enable (args=[1,2]):
209 s[i].AdmSetPersonEnabled(aa[i],plc[i]['peer_admin_id'],True)
210 s[i].AddRoleToPerson(aa[i],'admin',plc[i]['peer_admin_id'])
211 print '%02d: enabled+admin on account %d:%s'%(i,plc[i]['peer_admin_id'],plc[i]['peer_admin_name'])
213 def test01_node (args=[1,2]):
216 n=s[i].AddNode(a[i],1,{'hostname': plc[i]['nodename']})
217 print '%02d: Added node %d %s'%(i,n,plc[i]['nodename'])
220 def test01_delnode (args=[1,2]):
223 retcod=s[i].DeleteNode(a[i],plc[i]['node_id'])
224 print '%02d: Deleted node %d, got %s'%(i,plc[i]['node_id'],retcod)
225 plc[i]['node_id']=None
227 def test01_peer_person (args=[1,2]):
231 person_id = s[i].AddPerson (a[i], {'first_name':'Peering(plain passwd)', 'last_name':plc[peer]['name'], 'role_ids':[3000],
232 'email':plc[peer]['peer_admin_name'],'password':plc[peer]['peer_admin_password']})
233 print '%02d:Created person %d as the peer person'%(i,person_id)
234 plc[i]['peer_person_id']=person_id
236 def test01_peer (args=[1,2]):
240 peer_id=s[i].AddPeer (a[i], {'peername':plc[peer]['name'],'peer_url':plc[peer]['url'],'person_id':plc[i]['peer_person_id']})
241 # NOTE : need to manually reset the encrypted password through SQL at this point
242 print '%02d:Created peer %d'%(i,peer_id)
243 plc[i]['peer_id']=peer_id
244 print "PLEASE manually set password for person_id=%d in DB%d"%(plc[i]['peer_person_id'],i)
246 def test01_peer_passwd (args=[1,2]):
249 # using an ad-hoc local command for now - never could get quotes to reach sql....
250 print "Attempting to set passwd for person_id=%d in DB%d"%(plc[i]['peer_person_id'],i),
251 retcod=os.system("ssh root@%s new_plc_api/person-password.sh %d"%(plc[i]['hostname'],plc[i]['peer_person_id']))
254 def test02_refresh (args=[1,2]):
257 print '%02d: Refreshing peer'%(i),
258 retcod=s[i].RefreshPeer(a[i],plc[i]['peer_id'])
261 def test03_site (args=[1,2]):
265 ### create a site (required for creating a slice)
266 sitename=site_name(i)
267 abbrev_name="abbr"+str(i)
268 site_id=s[i].AddSite (a[i], {'name':plc[i]['name'],
269 'abbreviated_name': abbrev_name,
270 'login_base': plc[i]['plainname'],
272 'url': 'http://%s.com/'%abbrev_name,
274 ### max_slices does not seem taken into account at that stage
275 s[i].UpdateSite(a[i],site_id,{'max_slices':10})
276 print '%02d: Created site %d with max_slices=10'%(i,site_id)
277 plc[i]['site_id']=site_id
279 def test03_slice (args=[1,2]):
283 plain=full_slice_name(i)
286 slice_id=s[i].AddSlice (a[i],{'name':plain,
287 'description':'slice %s on plc %s'%(plain,plc[i]['name']),
288 'url':'http://planet-lab.org/%s'%name,
290 'instanciation':'plc-instantiated',
292 print '%02d: created slice %d'%(i,slice_id)
293 plc[i]['slice_id']=slice_id
296 def test04_node_slice (is_local, args=[1,2]):
301 hostname=plc[i]['nodename']
303 hostname=plc[peer]['nodename']
304 s[i].AddSliceToNodes (a[i], plc[i]['slice_id'],[hostname])
305 print '%02d: added in slice %d local node %s'%(i,plc[i]['slice_id'],hostname)
307 def test04_lnode_slice (args=[1,2]):
308 test04_node_slice (True,args)
310 def test04_fnode_slice (args=[1,2]):
311 test04_node_slice (False,args)
314 def test_all_init ():
320 test01_peer_person ()
322 test01_peer_passwd ()
327 def test_all_nodes ():
328 # create one node on each site
336 check_nodes (1,1,[1])
337 check_nodes (0,1,[2])
339 check_nodes (1,0,[1])
340 check_nodes (0,1,[2])
344 check_nodes (1,0,[1])
345 check_nodes (1,1,[2])
349 # make sure node indexes differ
359 def test_all_slices ():
360 # each site has 3 local slices and 1 foreign slice
362 # no slice has any node yet
363 check_local_slice_nodes(0)
364 check_foreign_slice_nodes(0)
366 # insert one local node in local slice on plc1
367 test04_lnode_slice ([1])
368 # of course the change is only local
369 check_local_slice_nodes (1,[1])
370 check_local_slice_nodes (0,[2])
371 check_foreign_slice_nodes(0)
375 # remember that foreign slices only know about LOCAL nodes
376 # so refreshing does not do anything
377 check_local_slice_nodes (1,[1])
378 check_local_slice_nodes (0,[2])
379 check_foreign_slice_nodes(0)
381 # now we add a foreign node into local slice
382 test04_fnode_slice ([1])
383 check_local_slice_nodes (2,[1])
384 check_foreign_slice_nodes (0,[1])
385 check_local_slice_nodes (0,[2])
386 check_foreign_slice_nodes (0,[2])
390 # remember that foreign slices only know about LOCAL nodes
391 # so this does not do anything
392 check_local_slice_nodes (2,[1])
393 check_foreign_slice_nodes (0,[1])
394 check_local_slice_nodes (0,[2])
395 check_foreign_slice_nodes (1,[2])
406 if __name__ == '__main__':