#!/usr/bin/env python
# $Id$
-import os, sys, time
+import os, sys
from optparse import OptionParser
+import pprint
+
+import utils
from TestPlc import TestPlc
from TestSite import TestSite
from TestNode import TestNode
import TestConfig
-import threading
class TestMain:
test_plcs=[]
test_nodes=[]
pids=[]
- timset=time.strftime("%H:%M:%S", time.localtime())
#test the existence of the URL
if (len (self.args) > 2):
parser.print_help()
print "Cannot determine myplc url"
parser.print_help()
sys.exit(1)
- print '* Using myplc url:',url
+ utils.header('* Using myplc at url : %s'%url)
#check where to display Virtual machines
if (self.options.Xterm):
display=self.options.Xterm
- print 'the display is', display
+ utils.header('X11 display : %s'% display)
#the debug option
if (self.options.debug):
- file=self.path+'/'+self.options.debug+'/My_Virtual_Machine.vmx'
+ file=self.path+'/'+self.options.debug+'/node.vmx'
if os.path.exists(file):
print 'vmx file is',file
arg='< /dev/null &>/dev/null &'
print "no way to find the virtual file"
sys.exit(1)
- print 'Saving myplc url into URL'
+ utils.header('Saving current myplc url into URL')
fsave=open('%s/URL'%self.path,"w")
fsave.write(url)
fsave.write('\n')
fsave.close()
+ pp = pprint.PrettyPrinter(indent=4,depth=2)
for plc_spec in TestConfig.plc_specs:
- print '========>Creating plc at '+timset+':',plc_spec
+ utils.header('Creating plc with spec')
+ pp.pprint(plc_spec)
test_plc = TestPlc(plc_spec)
test_plc.connect()
test_plcs.append(test_plc)
test_plc.cleanup_plc()
- print '========>Installing myplc at: ', timset
- if (len(sys.argv) > 1):
- test_plc.install_plc(url)
- test_plc.config_plc(plc_spec)
- else :
- print "========>PLease insert a valid url for the myplc install"
+ utils.header('Installing myplc from url %s'%url)
+ test_plc.install_plc(url)
+ test_plc.config_plc(plc_spec)
##create all the sites under the new plc,and then populate them with
##nodes,persons and slices
for site_spec in plc_spec['sites']:
- print '========>Creating site at '+timset+ ':',site_spec
+ utils.header('Creating site')
+ pp.pprint(site_spec)
test_site = test_plc.init_site(site_spec)
for node_spec in site_spec['nodes']:
- print '========>Creating node at '+ timset+' :',node_spec
+ utils.header('Creating node')
+ pp.pprint(node_spec)
test_nodes.append(node_spec)
test_node = test_plc.init_node(test_site,node_spec,self.path)
test_node.create_slice ("pi")
- print 'Runing Checkers and Vmwares for Site nodes at :',timset
+ utils.header('Starting vmware nodes')
test_site.run_vmware(test_nodes,display)
+ utils.header('Checking nodes')
if(test_site.node_check_status(test_nodes,True)):
test_plc.db_dump()
- test_site.slice_access(test_nodes)
- print "all is alright"
+ test_site.slice_access()
+ print "System test successful"
return 0
else :
- print "There is something wrong"
+ print "System test failed"
sys.exit(1)
except Exception, e:
print str(e)
-import os
-import sys
-import time
-import base64
-import TestConfig
+import os, sys, time, base64
import xmlrpclib
+import pprint
+
+import TestConfig
+import utils
class TestNode:
self.test_plc=test_plc
self.test_site=test_site
self.node_spec=node_spec
- self.timset=time.strftime("%H:%M:%S", time.localtime())
+
def create_node (self,role):
auth = self.test_site.anyuser_auth (role)
filter={'boot_state':'rins'}
try:
if (role=='pi' and self.node_spec['owned']=='pi'):
- self.node_id = self.test_plc.server.AddNode(auth,
- self.test_site.site_spec['site_fields']['login_base'],
- self.node_spec)
+ self.node_id = \
+ self.test_plc.server.AddNode(auth,
+ self.test_site.site_spec['site_fields']['login_base'],
+ self.node_spec)
self.test_plc.server.AddNodeNetwork(auth,self.node_id,
self.node_spec['network'])
self.test_plc.server.UpdateNode(auth, self.node_id, filter)
return self.node_id
elif (role=='tech' and self.node_spec['owned']=='tech'):
- self.node_id = self.test_plc.server.AddNode(auth,
- self.test_site.site_spec['site_fields']['login_base'],
- self.node_spec)
+ self.node_id = \
+ self.test_plc.server.AddNode(auth,
+ self.test_site.site_spec['site_fields']['login_base'],
+ self.node_spec)
self.test_plc.server.AddNodeNetwork(auth,self.node_id,
self.node_spec['network'])
self.test_plc.server.UpdateNode(auth, self.node_id, filter)
# liste_hosts.append(l['hostname'])
try:
for slicespec in TestConfig.slices_specs :
- print '========>Creating slice at :'+self.timset+' : ',slicespec
+ utils.header('Creating Slice')
+ pp = pprint.PrettyPrinter(indent=4)
+ pp.pprint(slicespec)
slice_id=self.test_plc.server.AddSlice(auth,slicespec['slice_spec'])
for sliceuser in slicespec['slice_users']:
- self.test_plc.server.AddPersonToSlice(auth, sliceuser['email'], slice_id)##affecting person to the slice
+ self.test_plc.server.AddPersonToSlice(auth,
+ sliceuser['email'],
+ slice_id)
for slicenode in slicespec['slice_nodes']:
liste_hosts.append(slicenode['hostname'])
- self.test_plc.server.AddSliceToNodes(auth, slice_id, liste_hosts)##add slice to the spec nodes
- print 'fin creation slices'
+ self.test_plc.server.AddSliceToNodes(auth,
+ slice_id,
+ liste_hosts)
except Exception, e:
print str(e)
sys.exit(1)
def conffile(self,image,hostname,path):
- try:
- file=path+'/VirtualFile-'+hostname+'/My_Virtual_Machine.vmx'
- f2=open(file,'w')
-
- f1=open(path+'/My-Virtual-Machine-model/My_Virtual_Machine.vmx','r')
- while 1:
- txt = f1.readline()
- if txt=='':
- f1.close()
- f2.close()
- break
- if txt[0]!='*' :
- f2.write(txt)
- else :
- f2.write('ide1:1.fileName = '+'"'+image+'"' '\n')
-
-
- except Exception, e:
- print str(e)
+ template='%s/template-vmplayer/node.vmx'%(path)
+ actual='%s/vmplayer-%s/node.vmx'%(path,hostname)
+ sed_command="sed -e s,@BOOTCD@,%s,g %s > %s"%(image,template,actual)
+ utils.header('Creating %s from %s'%(actual,template))
+ os.system('set -x; ' + sed_command)
- def create_boot_cd(self,node_spec,path):
+ def create_boot_cd(self,path):
+ node_spec=self.node_spec
+ hostname=node_spec['hostname']
try:
- os.system('mkdir -p %s/VirtualFile-%s && cp %s/My-Virtual-Machine-model/* %s/VirtualFile-%s'
- %(path, node_spec['hostname'], path, path, node_spec['hostname']))
- link1=self.test_plc.server.GetBootMedium(self.test_plc.auth_root(),
- node_spec['hostname'], 'node-iso', '')
- if (link1 == ''):
+ utils.header('Initializing vmplayer area for node %s'%hostname)
+ clean_dir="rm -rf %s/vmplayer-%s"%(path,hostname)
+ mkdir_command="mkdir -p %s/vmplayer-%s"%(path,hostname)
+ tar_command="tar -C %s/template-vmplayer -cf - . | tar -C %s/vmplayer-%s -xf -"%(path,path,hostname)
+ os.system('set -x; ' +clean_dir + ';' + mkdir_command + ';' + tar_command);
+ utils.header('Creating boot medium for node %s'%hostname)
+ encoded=self.test_plc.server.GetBootMedium(self.test_plc.auth_root(), hostname, 'node-iso', '')
+ if (encoded == ''):
raise Exception, 'boot.iso not found'
- file1=open(path+'/VirtualFile-'+node_spec['hostname']+'/boot_file.iso','w')
- file1.write(base64.b64decode(link1))
- file1.close()
- print '========> boot cd created for :',self.node_spec['hostname']
- self.conffile('boot_file.iso',self.node_spec['hostname'], path) #create 2 conf file for the vmware based
+ file=open(path+'/vmplayer-'+hostname+'/boot_file.iso','w')
+ file.write(base64.b64decode(encoded))
+ file.close()
+ utils.header('boot cd created for %s'%hostname)
+ self.conffile('boot_file.iso',hostname, path)
except Exception, e:
print str(e)
sys.exit(1)
os.system('set -x; rm %s'%tmpname)
def cleanup_plc(self):
- os.system('service plc safestop')
+ os.system('set -x; service plc safestop')
#####detecting the last myplc version installed and remove it
os.system('set -x; rpm -e myplc')
- print "=======================>Remove Myplc DONE!"
##### Clean up the /plc directory
os.system('set -x; rm -rf /plc/data')
- print "=======================>Clean up DONE!"
def install_plc(self,url):
- print url
- os.system('set -x; rpm -ivh '+url)
+ os.system('set -x; rpm -Uvh '+url)
os.system('set -x; service plc mount')
def init_site (self,site_spec):
test_node = TestNode(self, test_site, node_spec)
test_node.create_node ("pi")
test_node.create_node ("tech")
- test_node.create_boot_cd(node_spec,path)
+ test_node.create_boot_cd(path)
return test_node
def db_dump(self):
for l in list_host :
print display
- os.system('DISPLAY=%s vmplayer %s/VirtualFile-%s/My_Virtual_Machine.vmx &'%(display,self.path,l))
+ os.system('DISPLAY=%s vmplayer %s/vmplayer-%s/node.vmx &'%(display,self.path,l))
except Exception, e:
print str(e)
import sys
import datetime
import time
-from TestConfig import *
import xmlrpclib
+from TestConfig import *
+import utils
+
class TestSite:
def __init__ (self,test_plc,site_spec):
def create_user (self, user_spec):
try:
i=0
- print '========>Adding user at '+self.timset+ ': ',user_spec
+ utils.header('Adding user %s'%user_spec['email'])
self.person_id=self.test_plc.server.AddPerson(self.test_plc.auth_root(),
user_spec)
self.test_plc.server.UpdatePerson(self.test_plc.auth_root(),
return ret_value
except Exception, e:
print str(e)
- print "vmware killed if problems occur "
+ utils.header("will kill vmware in 10 seconds")
time.sleep(10)
self.kill_all_vmwares()
sys.exit(1)
def kill_all_vmwares(self):
+ utils.header('Killing any running vmware or vmplayer instance')
os.system('pgrep vmware | xargs -r kill')
os.system('pgrep vmplayer | xargs -r kill ')
os.system('pgrep vmware | xargs -r kill -9')
os.system('pgrep vmplayer | xargs -r kill -9')
- def run_vmware(self,liste_nodes,display):
+ def run_vmware(self,node_specs,display):
path=os.path.dirname(sys.argv[0])
- print "* Killing any running vmware or vmplayer instance"
self.kill_all_vmwares()
- print "* Displaying vmplayer on DISPLAY=",display
- for l in liste_nodes :
- print "* Starting vmplayer for node %s -- see vmplayer.log"%l['hostname']
- os.system('set -x; cd %s/VirtualFile-%s ; DISPLAY=%s vmplayer My_Virtual_Machine.vmx < /dev/null 2>&1 >> vmplayer.log &'%(path,l['hostname'],display))
+ utils.header('Displaying vmplayer on DISPLAY=%s'%display)
+ for spec in node_specs :
+ hostname=spec['hostname']
+ utils.header('Starting vmplayer for node %s -- see vmplayer.log'%hostname)
+ os.system('set -x; cd %s/vmplayer-%s ; DISPLAY=%s vmplayer node.vmx < /dev/null 2>&1 >> vmplayer.log &'%(path,hostname,display))
def delete_known_hosts(self):
+ utils.header("messing with known_hosts (cleaning hostnames starting with 'test'")
try:
file1=open('/root/.ssh/known_hosts','r')
file2=open('/root/.ssh/known_hosts_temp','w')
file2.write(txt)
- os.system('mv -f /root/.ssh/known_hosts_temp /root/.ssh/known_hosts')
+ os.system('set -x ; mv -f /root/.ssh/known_hosts_temp /root/.ssh/known_hosts')
except Exception, e:
print str(e)
- def slice_access(self,liste_nodes):
+ def slice_access(self):
try:
bool=True
bool1=True
dead_time=start_time + datetime.timedelta(minutes=3)##adding 3minutes
for slice in slices_specs:
for slicenode in slice['slice_nodes']:
- timset=time.strftime("%H:%M:%S", time.localtime())
+ hostname=slicenode['hostname']
+ slicename=slice['slice_spec']['name']
while(bool):
- print '=========>Try to Restart the Node Manager on %s at %s:'%(slicenode['hostname'],str(timset))
- access=os.system('set -x; ssh -i /etc/planetlab/root_ssh_key.rsa root@%s service nm restart'%slicenode['hostname'] )
+ utils.header('restarting nm on %s'%hostname)
+ access=os.system('set -x; ssh -i /etc/planetlab/root_ssh_key.rsa root@%s service nm restart'%hostname )
if (access==0):
- print '=========>Node Manager Restarted on %s at %s:'%(slicenode['hostname'] ,str(timset))
+ utils.header('nm restarted on %s'%hostname)
while(bool1):
- print '=========>Try to connect to the %s@%s at %s '%(slice['slice_spec']['name'],slicenode['hostname'],str(time.strftime("%H:%M:%S", time.localtime())))
- Date=os.system('set -x; ssh -i ~/.ssh/slices.rsa %s@%s echo "The Actual Time here is;" date'%(slice['slice_spec']['name'],slicenode['hostname']))
+ utils.header('trying to connect to %s@%s'%(slicename,hostname))
+ Date=os.system('set -x; ssh -i ~/.ssh/slices.rsa %s@%s date'%(slicename,hostname))
if (Date==0):
break
elif ( start_time <= dead_time ) :
else:
bool1=False
if(bool1):
- print '=========>connected to the '+slice['slice_spec']['name']+'@'+slicenode['hostname'] +'--->'
+ utils.header('connected to %s@%s -->'%(slicename,hostname))
else:
- print '=========>access to one slice is denied but last chance'
- print '=========>Retry to Restart the Node Manager on %s at %s:'%(slicenode['hostname'],str(timset))
- access=os.system('set -x; ssh -i /etc/planetlab/root_ssh_key.rsa root@%s service nm restart'%slicenode['hostname'] )
+ utils.header('%s@%s : last chance - restarting nm on %s'%(slicename,hostname,hostname))
+ access=os.system('set -x; ssh -i /etc/planetlab/root_ssh_key.rsa root@%s service nm restart'%hostname)
if (access==0):
- print '=========>Retry to connect to the %s@%s at %s '%(slice['slice_spec']['name'],slicenode['hostname'],str(time.strftime("%H:%M:%S", time.localtime())))
- Date=os.system('set -x; ssh -i ~/.ssh/slices.rsa %s@%s echo "The Actual Time here is;" date'%(slice['slice_spec']['name'],slicenode['hostname'] ))
+ utils.header('trying to connect (2) to %s@%s'%(slicename,hostname))
+ Date=os.system('set -x; ssh -i ~/.ssh/slices.rsa %s@%s date'%(slicename,hostname))
if (Date==0):
- print '=========>connected to the '+slice['slice_spec']['name']+'@'+slicenode['hostname']+'--->'
+ utils.header('connected to %s@%s -->'%(slicename,hostname))
else:
- print '=========>the Access is finaly denied'
+ utils.header('giving up with to %s@%s -->'%(slicename,hostname))
sys.exit(1)
- else :"=========>Last try failed"
+ else :
+ utils.header('Last chance failed on %s@%s -->'%(slicename,hostname))
break
elif ( start_time <= dead_time ) :
start_time=datetime.datetime.now()+ datetime.timedelta(minutes=1)
#!/usr/bin/vmplayer
-
-# Filename: My_Virtual_Machine.vmx
+# $Id$
# Generated 2007-05-28;11:47:54 by EasyVMX!
# http://www.easyvmx.com
#displayName
# These fields are free text description fields
-guestinfo.vmware.product.url = "amine.parmentelat.net"
+guestinfo.vmware.product.url = "test.one-lab.org"
guestinfo.vmware.product.class = "virtual machine"
# Number of virtual CPUs. Your virtual machine will not
ide1:0.fileName = "/dev/cdrom"
# Settings for the optional virtual CDROM, ISO-image
-ide1:1.present = "TRUE"
-*ide1:1.fileName = "amine.parmentelat.net-3.3.iso"
+ide1:1.present = "FALSE"
+ide1:1.fileName = "@BOOTCD@"
ide1:1.deviceType = "cdrom-image"
ide1:1.mode = "persistent"
ide1:1.startConnected = "TRUE"
--- /dev/null
+# $Id$
+import time
+
+# how could this accept a list again ?
+def header(message):
+ now=time.strftime("%H:%M:%S", time.localtime())
+ print "*",now,'--',message