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 ##############################
20 plc1={ 'name':'plc1 in federation',
21 'hostname':'lurch.cs.princeton.edu',
22 'url-format':'https://%s:443/PLCAPI/',
23 'builtin_admin_id':'root@localhost.localdomain',
24 'builtin_admin_password':'root',
25 'peer_admin_name':'plc1@planet-lab.org',
26 'peer_admin_password':'peer',
27 'nodename':'n11.plc1.org'
29 plc2={ 'name':'plc2 in federation',
30 'hostname':'planetlab-devbox.inria.fr',
31 'url-format':'https://%s:443/PLCAPI/',
32 'builtin_admin_id':'root@localhost.localdomain',
33 'builtin_admin_password':'root',
34 'peer_admin_name':'plc2@planet-lab.org',
35 'peer_admin_password':'peer',
36 'nodename':'n21.plc2.org'
39 ## we use indexes 1 and 2
43 # the authentication objects
50 ### cant use digits in slice login name
57 raise Exception,"Unexpected input in plain_name"
59 def test00_init (args=[1,2]):
61 ## have you loaded this file already (support for reload)
67 url=plc[i]['url-format']%plc[i]['hostname']
69 s[i]=xmlrpclib.Server(url)
70 print 'initializing s[%d]'%i,url
71 aa[i]={'Username':plc[i]['builtin_admin_id'],
72 'AuthMethod':'password',
73 'AuthString':plc[i]['builtin_admin_password'],
75 print 'initialized aa[%d]'%i, aa[i]
76 a[i]={'Username':plc[i]['peer_admin_name'],
77 'AuthMethod':'password',
78 'AuthString':plc[i]['peer_admin_password'],
80 print 'initialized a[%d]'%i, a[i]
82 def test00_print (args=[1,2]):
86 print 'aa[%d]'%i, aa[i]
89 def test00_admin (args=[1,2]):
93 person_id=s[i].AddPerson(aa[i],{'first_name':'Local', 'last_name':'PeerPoint', 'role_ids':[10],
94 'email':plc[i]['peer_admin_name'],'password':plc[i]['peer_admin_password']})
95 print '%02d: created peer admin account %d, %s - %s'%(i,person_id,plc[i]['peer_admin_name'],plc[i]['peer_admin_password'])
96 plc[i]['peer_admin_id']=person_id
98 def test00_enable (args=[1,2]):
102 s[i].AdmSetPersonEnabled(aa[i],plc[i]['peer_admin_id'],True)
103 s[i].AddRoleToPerson(aa[i],'admin',plc[i]['peer_admin_id'])
104 print '%02d: enabled+admin on account %d:%s'%(i,plc[i]['peer_admin_id'],plc[i]['peer_admin_name'])
106 def test01_check (args=[1,2]):
109 n=len(s[i].GetNodes(aa[i]))
110 f=len(s[i].GetForeignNodes(a[i]))
111 print '%02d: Checking connection: got %d local nodes & %d foreign nodes'%(i,n,f)
113 def test01_node (args=[1,2]):
116 n=s[i].AddNode(a[i],1,{'hostname': plc[i]['nodename']})
117 print '%02d: Added node %d %s'%(i,n,plc[i]['nodename'])
119 def test01_peer_person (args=[1,2]):
123 person_id = s[i].AddPerson (a[i], {'first_name':'Peering(plain passwd)', 'last_name':plc[peer]['name'], 'role_ids':[3000],
124 'email':plc[peer]['peer_admin_name'],'password':plc[peer]['peer_admin_password']})
125 print '02%d:Created person %d as the peer person'%(i,person_id) hostname=plc[i]['nodename']
127 plc[i]['peer_person_id']=person_id
129 def test01_peer (args=[1,2]):
133 peer_id=s[i].AddPeer (a[i], {'peername':plc[peer]['name'],'peer_url':plc[peer]['url'],'person_id':plc[i]['peer_person_id']})
134 # NOTE : need to manually reset the encrypted password through SQL at this point
135 print '%02d:Created peer %d'%(i,peer_id)
136 plc[i]['peer_id']=peer_id
137 print "PLEASE manually set password for person_id=%d in DB%d"%(plc[i]['peer_person_id'],i)
139 def test01_peer_passwd (args=[1,2]):
142 # using an ad-hoc local command for now - never could get quotes to reach sql....
143 os.system("ssh root@%s new_plc_api/person-password.sh %d"%(plc[i]['hostname'],plc[i]['peer_person_id']))
144 print "Attempted to set passwd for person_id=%d in DB%d"%(plc[i]['peer_person_id'],i)
146 def test02_refresh (args=[1,2]):
149 print '%02d: Refreshing peer'%(i)
150 s[i].RefreshPeer(a[i],plc[i]['peer_id'])
152 def test03_site (args=[1,2]):
156 ### create a site (required for creating a slice)
157 sitename="site"+str(i)
158 abbrev_name="abbr"+str(i)
160 site_id=s[i].AddSite (a[i], {'name':plc[i]['name'],
161 'abbreviated_name': abbrev_name,
164 'url': 'http://%s.com/'%abbrev_name,
166 ### max_slices does not seem taken into account at that stage
167 s[i].UpdateSite(a[i],site_id,{'max_slices':10})
168 print '%02d: Created site %d with max_slices=10'%(i,site_id)
169 plc[i]['site_id']=site_id
171 def test03_slice (args=[1,2]):
177 slice_name="slic"+str(i)
178 slice_id=s[i].AddSlice (a[i],{'name':'%s_%s'%(plain,slice_name),
179 'description':'slice %s_%s on plc %s'%(plain,slice_name,plc[i]['name']),
180 'url':'http://planet-lab.org/%s'%slice_name,
182 'instanciation':'plc-instantiated',
184 print '%02d: created slice %d'%(i,slice_id)
185 plc[i]['slice_id']=slice_id
188 def test04_nodeslice (args=[1,2]):
193 hostname=plc[peer]['nodename']
194 s[i].AddSliceToNodes (a[i], plc[i]['slice_id'],[hostname])
195 print '%02d: added local node %s'%(i,hostname)
197 def catch_up (args=[1,2]):
199 plc[i]['peer_admin_id']=3
200 plc[i]['peer_person_id']=4
205 def test_all (args=[1,2]):
212 test01_peer_person (args)
214 test01_peer_passwd (args)
216 test02_refresh (args)
220 test04_nodeslice (args)
222 if __name__ == '__main__':