10 def __init__ (self,test_plc,site_spec):
11 self.test_plc=test_plc
12 self.site_spec=site_spec
13 self.timset=time.strftime("%H:%M:%S", time.localtime())
15 def create_site (self):
17 print self.test_plc.auth_root()
18 self.site_id = self.test_plc.server.AddSite(self.test_plc.auth_root(),
19 self.site_spec['site_fields'])
20 self.test_plc.server.AddSiteAddress(self.test_plc.auth_root(),self.site_id,
21 self.site_spec['site_address'])
30 def create_user (self, user_spec):
34 print '========>Adding user at '+self.timset+ ': ',user_spec
35 self.person_id=self.test_plc.server.AddPerson(self.test_plc.auth_root(),
37 self.test_plc.server.UpdatePerson(self.test_plc.auth_root(),
38 self.person_id,{'enabled': True})
40 for i in range(0, len(user_spec['roles']) ):
41 self.test_plc.server.AddRoleToPerson(self.test_plc.auth_root(),
42 user_spec['roles'][i],
46 self.test_plc.server.AddPersonToSite(self.test_plc.auth_root(),
48 self.site_spec['site_fields']['login_base'])
54 def enable_user (self, user_spec):
56 persones=self.test_plc.server.GetPersons(self.test_plc.auth_root())
57 for person in persones:
58 if (person['enabled']!="True"):
59 self.test_plc.server.UpdatePerson(self.test_plc.auth_root(),
66 def add_key_user(self,user_spec):
68 if(user_spec ==self.site_spec['pi_spec']):
69 self.test_plc.server.AddPersonKey(self.pi_auth(), user_spec['email'], TestConfig.key)
70 elif(user_spec ==self.site_spec['tech_spec']):
71 self.test_plc.server.AddPersonKey(self.tech_auth(), user_spec['email'], TestConfig.key)
72 elif (user_spec ==self.site_spec['user_spec']):
73 self.test_plc.server.AddPersonKey(self.user_auth(), user_spec['email'], TestConfig.key)
74 elif (user_spec ==self.site_spec['tech_user_spec']):
75 self.test_plc.server.AddPersonKey(self.tech_user_auth(), user_spec['email'], TestConfig.key)
76 elif (user_spec ==self.site_spec['pi_tech_spec']):
77 self.test_plc.server.AddPersonKey(self.pi_tech_auth(), user_spec['email'], TestConfig.key)
83 def anyuser_auth (self,key):
84 return {'Username':self.site_spec[key]['email'],
85 'AuthMethod':'password',
86 'AuthString':self.site_spec[key]['password'],
87 'Role':self.site_spec[key]['roles'][0],
91 return self.anyuser_auth('pi_spec')
93 return self.anyuser_auth('tech_spec')
95 return self.anyuser_auth('user_spec')
96 def tech_user_auth (self):
97 return self.anyuser_auth('tech_user_spec')
98 def pi_tech_auth (self):
99 return self.anyuser_auth('pi_tech_spec')
101 def node_check_status(self,liste_nodes,bool):
104 filter=['boot_state']
105 bt={'boot_state':'boot'}
108 start_time = datetime.datetime.now() ##geting the current time
109 dead_time=datetime.datetime.now()+ datetime.timedelta(minutes=10)##adding 10minutes
111 start=time.strftime("%H:%M:%S", time.localtime())
112 print "time in the begining is :",start
115 for l in liste_nodes :
117 node_status=self.test_plc.server.GetNodes(self.test_plc.auth_root(),
118 l['hostname'], filter)
119 timset=time.strftime("%H:%M:%S", time.localtime())
120 print 'the actual status for the node '+l['hostname']+' at '+str(timset)+' is :',node_status
122 if (node_status[0] == bt):
123 test_name='\nTest Installation Node hosted: '+l['hostname']
124 self.test_plc.affiche_results(test_name, 'Successful', '')##printing out the result
125 break ##for exsiting and renaming virtual file to just installed
127 elif ( start_time <= dead_time ) :
128 start_time=datetime.datetime.now()+ datetime.timedelta(minutes=2)
137 print "Node correctly instaled and booted "
139 print "Node not fully booted "##cheek if configuration file already exist
141 test_name='\nTest Installation Node Hosted: ',l['hostname']
142 self.test_plc.affiche_results(test_name, 'Failure', '')##printing out the result
146 end=time.strftime("%H:%M:%S", time.localtime())
147 print "time at the end is :",end ##converting time to secondes
151 print "vmware killed if problems occur "
153 self.kill_all_vmwares()
156 def kill_all_vmwares(self):
157 os.system('pgrep vmware | xargs -r kill')
158 os.system('pgrep vmplayer | xargs -r kill ')
159 os.system('pgrep vmware | xargs -r kill -9')
160 os.system('pgrep vmplayer | xargs -r kill -9')
163 def run_vmware(self,liste_nodes,display):
164 path=os.path.dirname(sys.argv[0])
166 print " kill last vmware before any new installation "
167 self.kill_all_vmwares()
168 print 'i will be displayed here========>', display
169 arg='< /dev/null &>/dev/null &'
170 for l in liste_nodes :
171 #os.system('set -x; vmplayer VirtualFile-%s/My_Virtual_Machine.vmx %s '%(l['hostname'],arg))
172 os.system('set -x; DISPLAY=%s vmplayer %s/VirtualFile-%s/My_Virtual_Machine.vmx %s '%(display,path,l['hostname'],arg))
174 def delete_known_hosts(self):
176 file1=open('/root/.ssh/known_hosts','r')
177 file2=open('/root/.ssh/known_hosts_temp','w')
179 txt = file1.readline()
184 if txt[0:4]!='test' :
188 os.system('mv -f /root/.ssh/known_hosts_temp /root/.ssh/known_hosts')
193 def slice_access(self,liste_nodes):
198 self.delete_known_hosts()
199 start_time = datetime.datetime.now()
200 dead_time=start_time + datetime.timedelta(minutes=3)##adding 3minutes
201 for l in liste_nodes:
202 timset=time.strftime("%H:%M:%S", time.localtime())
204 print '=========>Try to Restart the Node Manager on %s at %s:'%(l['hostname'],str(timset))
205 access=os.system('set -x; ssh -i /etc/planetlab/root_ssh_key.rsa root@%s service nm restart'%l['hostname'])
207 print '=========>Node Manager Restarted on %s at %s:'%(l['hostname'],str(timset))
209 print '=========>Try to connect to the %s@%s at %s '%(TestConfig.slice_spec['name'],l['hostname'],str(time.strftime("%H:%M:%S", time.localtime())))
210 Date=os.system('set -x; ssh -i ~/.ssh/slices.rsa %s@%s echo "The Actual Time here is;" date'%(TestConfig.slice_spec['name'],l['hostname']))
213 elif ( start_time <= dead_time ) :
214 start_time=datetime.datetime.now()+ datetime.timedelta(seconds=30)
219 print '=========>connected to the '+TestConfig.slice_spec['name']+'@'+l['hostname']+'--->'
221 print '=========>access to one slice is denied but last chance'
222 print '=========>Retry to Restart the Node Manager on %s at %s:'%(l['hostname'],str(timset))
223 access=os.system('set -x; ssh -i /etc/planetlab/root_ssh_key.rsa root@%s service nm restart'%l['hostname'])
225 print '=========>Retry to connect to the %s@%s at %s '%(TestConfig.slice_spec['name'],l['hostname'],str(time.strftime("%H:%M:%S", time.localtime())))
226 Date=os.system('set -x; ssh -i ~/.ssh/slices.rsa %s@%s echo "The Actual Time here is;" date'%(TestConfig.slice_spec['name'],l['hostname']))
228 print '=========>connected to the '+TestConfig.slice_spec['name']+'@'+l['hostname']+'--->'
230 print '=========>the Access is finaly denied'
232 else :"=========>Last try failed"
234 elif ( start_time <= dead_time ) :
235 start_time=datetime.datetime.now()+ datetime.timedelta(minutes=1)
241 print 'Node manager problems'