various fixes
authorThierry Parmentelat <thierry.parmentelat@sophia.inria.fr>
Fri, 29 Feb 2008 15:19:19 +0000 (15:19 +0000)
committerThierry Parmentelat <thierry.parmentelat@sophia.inria.fr>
Fri, 29 Feb 2008 15:19:19 +0000 (15:19 +0000)
system/TestMain.py
system/TestNode.py
system/TestPlc.py
system/template-Qemu/start-qemu-node
system/utils.py

index 77c939f..04b5a28 100755 (executable)
@@ -40,7 +40,7 @@ class TestMain:
     @staticmethod
     def show_env (options, message):
         utils.header (message)
-        utils.show_spec("main options",options)
+        utils.pprint("main options",options)
 
     @staticmethod
     def optparse_list (option, opt, value, parser):
@@ -108,11 +108,13 @@ steps refer to a method in TestPlc or to a step_* module
             self.options.steps = self.args
 
         # handle defaults and option persistence
-        for (recname,filename,default) in ( ('myplc_url','arg-myplc-url',"") , 
-                                            ('build_url','arg-build-url',TestMain.default_build_url) ,
-                                            ('ips','arg-ips',[]) , 
-                                            ('config','arg-config',TestMain.default_config) , ) :
-            print 'handling',recname
+        for (recname,filename,default) in (
+            ('build_url','arg-build-url',TestMain.default_build_url) ,
+            ('ips','arg-ips',[]) , 
+            ('config','arg-config',TestMain.default_config) , 
+            ('myplc_url','arg-myplc-url',"") , 
+            ) :
+#            print 'handling',recname
             path="%s/%s"%(self.path,filename)
             is_list = isinstance(default,list)
             if not getattr(self.options,recname):
@@ -143,7 +145,7 @@ steps refer to a method in TestPlc or to a step_* module
                 for value in getattr(self.options,recname):
                     fsave.write(value + "\n")
             fsave.close()
-            utils.header('Saved %s into %s'%(recname,filename))
+#            utils.header('Saved %s into %s'%(recname,filename))
 
         # steps
         if not self.options.steps:
@@ -171,7 +173,7 @@ steps refer to a method in TestPlc or to a step_* module
                 print 'Cannot load config %s -- ignored'%modulename
                 raise
         # show config
-        utils.show_spec("Test specifications",all_plc_specs)
+        utils.show_test_spec("Test specifications",all_plc_specs)
         # build a TestPlc object from the result
         for spec in all_plc_specs:
             spec['disabled'] = False
index c77950d..5d31e1c 100644 (file)
@@ -104,55 +104,52 @@ class TestNode:
             utils.header('%s has reached debug state'%hostname)
         return status
 
-    def conffile(self,image,hostname,path):
+    def qemu_config(self,hostname,path):
         model=self.node_spec['node_fields']['model']
-        if self.is_qemu():
-            host_box=self.host_box()
-            mac=self.node_spec['network_fields']['mac']
-            dest_dir=self.buildname()+"/qemu-%s"%(hostname)
-            utils.header('Storing the mac address for node %s'%hostname)
-            file=open(path+'/qemu-'+hostname+'/MAC','a')
-            file.write('%s\n'%mac)
-            file.write(dest_dir)
-            file.close()
-            utils.header ('Transferring configuration files for node %s into %s '%(hostname,host_box))
-            if ( not  self.is_local(host_box)):
-                cleandir_command="ssh root@%s rm -rf %s"%(host_box, dest_dir)
-                createdir_command = "ssh root@%s mkdir -p  %s"%(host_box, dest_dir)
-                createlog_command = "ssh root@%s touch  %s/%s.log "%(host_box, dest_dir,hostname)
-                self.test_plc.run_in_host(cleandir_command)
-                self.test_plc.run_in_host(createdir_command)
-                self.test_plc.run_in_host(createlog_command)
-                scp_command = "scp -r %s/qemu-%s/* root@%s:/root/%s"%(path,hostname,host_box,dest_dir)
-                self.test_plc.run_in_host(scp_command)
+        if not self.is_qemu():
+            raise Exception,"wrong"
+        host_box=self.host_box()
+        mac=self.node_spec['network_fields']['mac']
+        # dest_dir is the path that needs to be relevant when qemu is invoked
+        conf_filename="%s/qemu-%s/start-qemu.conf"%(path,hostname)
+        utils.header('Storing qemu config for %s in %s'%(hostname,conf_filename))
+        file=open(conf_filename,'w')
+        file.write('MACADDR=%s\n'%mac)
+        file.write('NODE_ISO=%s.iso\n'%hostname)
+        file.close()
+        if ( not  self.is_local(host_box)):
+            dest_dir="%s/qemu-%s"%(self.buildname(),hostname)
+            utils.header ("Transferring configuration files for node %s"%hostname)
+            utils.header ("Using dir %s on %s"%(dest_dir,host_box))
+            self.test_plc.run_in_host("ssh root@%s rm -rf %s"%(host_box, dest_dir))
+            self.test_plc.run_in_host("ssh root@%s mkdir -p  %s"%(host_box, dest_dir))
+            self.test_plc.run_in_host("ssh root@%s touch  %s/%s.log "%(host_box, dest_dir,hostname))
+            self.test_plc.run_in_host("scp -r %s/qemu-%s/* root@%s:%s"%(path,hostname,host_box,dest_dir))
 
     def create_boot_cd(self,path):
         model=self.node_spec['node_fields']['model']
         node_spec=self.node_spec
         hostname=node_spec['node_fields']['hostname']
+        utils.header("Calling GetBootMedium for %s"%hostname)
         encoded=self.test_plc.server.GetBootMedium(self.test_plc.auth_root(), hostname, 'node-iso', '', ['serial'])
         if (encoded == ''):
             raise Exception, 'boot.iso not found'
 
         if  model.find("qemu") >= 0:
-            clean_dir="rm -rf %s/qemu-%s"%(path,hostname)
-            mkdir_command="mkdir -p %s/qemu-%s"%(path,hostname)
-            self.test_plc.run_in_host(clean_dir)
-            self.test_plc.run_in_host(mkdir_command)
-            copy_command="cp -r  %s/template-Qemu/* %s/qemu-%s"%(path,path,hostname)
-            self.test_plc.run_in_host(copy_command)
-            utils.header('Creating boot medium for node %s'%hostname)
-            file=open(path+'/qemu-'+hostname+'/boot_file.iso','w')
+            nodepath="%s/qemu-%s"%(path,hostname)
+            self.test_plc.run_in_host("rm -rf %s"%nodepath)
+            self.test_plc.run_in_host("mkdir -p %s"%nodepath)
+            template="%s/template-Qemu"%path
+            self.test_plc.run_in_host("cp -r %s/* %s"%(template,nodepath))
+            self.qemu_config(hostname, path)
         else:
             nodepath="%s/real-%s"%(path,hostname)
             self.test_plc.run_in_host("rm -rf %s"%nodepath)
-            self.test_plc.run_in_host("mkdir %s"%nodepath)
-            file=open("%s/%s"%(nodepath,"/boot_file.iso"),'w')
+            self.test_plc.run_in_host("mkdir -p %s"%nodepath)
 
-        file.write(base64.b64decode(encoded))
-        file.close()
-        utils.header('boot cd created for %s'%hostname)
-        self.conffile('boot_file.iso',hostname, path)
+        filename="%s/%s.iso"%(nodepath,hostname)
+        utils.header('Storing boot medium into %s'%filename)
+        file(filename,'w').write(base64.b64decode(encoded))
     
     def start_node (self,options):
         model=self.node_spec['node_fields']['model']
@@ -163,21 +160,20 @@ class TestNode:
             utils.header("TestNode.start_node : ignoring model %s"%model)
 
     def start_qemu (self, options):
-        utils.header("Starting Qemu node")
+        utils.header("Starting qemu node")
         host_box=self.host_box()
         hostname=self.node_spec['node_fields']['hostname']
-        path=options.path
         dest_dir=self.buildname()+"/qemu-%s"%(hostname)
-        utils.header('Starting qemu for node %s and Redirect logs to /%s/%s.log '
-                     %(hostname, dest_dir, hostname))
+        utils.header("Starting qemu for node %s on %s"%(hostname,host_box))
+
         if (not self.is_local(host_box)):
-            host_string="ssh root@",host_box
+            host_string="ssh root@%s"%host_box
         else:
             host_string=""
         
-        self.test_plc.run_in_host(" %s ~/%s/env-qemu start >> ~/%s/%s.log "
+        self.test_plc.run_in_host("%s ~/%s/env-qemu start >> ~/%s/%s.log "
                                   %(host_string,  dest_dir, dest_dir, hostname ))
-        self.test_plc.run_in_host(" %s ~/%s/start-qemu-node %s >> ~/%s/%s.log & "
+        self.test_plc.run_in_host("%s ~/%s/start-qemu-node >> ~/%s/%s.log & "
                                   %(host_string, dest_dir, dest_dir, dest_dir, hostname))
 
     def kill_qemu (self):
index c590fdb..7671459 100644 (file)
@@ -359,7 +359,7 @@ class TestPlc:
             else:
                 utils.header("Creating nodes for site %s in %s"%(test_site.name(),self.name()))
                 for node_spec in site_spec['nodes']:
-                    utils.show_spec('Creating node %s'%node_spec,node_spec)
+                    utils.pprint('Creating node %s'%node_spec,node_spec)
                     test_node = TestNode (self,test_site,node_spec)
                     test_node.create_node ()
         return True
@@ -518,7 +518,7 @@ class TestPlc:
                    
     def initscripts (self, options):
         for initscript in self.plc_spec['initscripts']:
-            utils.show_spec('Adding Initscript in plc %s'%self.plc_spec['name'],initscript)
+            utils.pprint('Adding Initscript in plc %s'%self.plc_spec['name'],initscript)
             self.server.AddInitScript(self.auth_root(),initscript['initscript_fields'])
         return True
 
@@ -537,7 +537,7 @@ class TestPlc:
                 utils.header("Deleting slices in site %s"%test_site.name())
                 test_slice.delete_slice()
             else:    
-                utils.show_spec("Creating slice",slice)
+                utils.pprint("Creating slice",slice)
                 test_slice.create_slice()
                 utils.header('Created Slice %s'%slice['slice_fields']['name'])
         return True
index adbe6c2..222faa9 100755 (executable)
@@ -1,21 +1,19 @@
 #!/bin/bash
 
-#Getting the MAC address and the right path
-MACPATH=~/$1/MAC
-if [ ! -e ${MACPATH} ];then
+# cd in this command's directory
+cd $(dirname $0)
+
+#Getting the env. as passed by the test framework - mostly MACADDR and NODE_ISO
+CONFIG=start-qemu.conf
+if [ ! -e ${CONFIG} ];then
     echo "File for MAC Address not found"
     exit 1
 fi
-set $(cat ${MACPATH})
-MACADDR=$1
-NODE_DIR=$2
-shift $(($# -1))
+. $CONFIG
 
 #default Value
-CDROM_IMG=~/${NODE_DIR}/boot_file.iso
-SCRIPT=~/${NODE_DIR}/qemu-ifup
-FILENAME=hda_5.raw
-HDA=~/${NODE_DIR}/${FILENAME}; 
+SCRIPT=./qemu-ifup
+HDA=./FILENAME=hda_5.raw
 
 # qemu parameters
 RAM=520;
@@ -25,21 +23,22 @@ if [ -e "$HDA" ]; then
     echo "Disk already existing removing  it..."
     rm -rf $HDA
 fi
+
 #Creating new HDA
 echo "Creating hard disk for Qemu install under $HDA"
-cd ~/$NODE_DIR
-set $(qemu-img create $FILENAME 10G)
-if [ -z "$1" ];then
+
+img=$(qemu-img create $FILENAME 10G)
+if [ -z "$img" ];then
        echo "Can't Create disk image..."
        exit 1
 fi
-shift $(($# - 1))
+
 echo "New $HDA is created..."
 
 #Command for running the Qemu Emulator
-ARGS="-boot d -cdrom ${CDROM_IMG} -hda ${HDA} -m ${RAM}  -net nic,macaddr=${MACADDR} -net $TAP -nographic";
-echo "Executing qemu $ARGS";
+ARGS="-boot d -cdrom ${NODE_ISO} -hda ${HDA} -m ${RAM}  -net nic,macaddr=${MACADDR} -net $TAP -nographic";
+echo "Running qemu $ARGS";
 qemu $ARGS
 
 
-exit
\ No newline at end of file
+exit
index 4468b20..a30b004 100644 (file)
@@ -2,17 +2,94 @@
 import time
 import os
 import commands
-import pprint
+from pprint import PrettyPrinter
 
 # how could this accept a list again ?
 def header(message):
     now=time.strftime("%H:%M:%S", time.localtime())
     print "*",now,'--',message
 
-def show_spec(message,spec,depth=2):
+def pprint(message,spec,depth=2):
     now=time.strftime("%H:%M:%S", time.localtime())
     print ">",now,"--",message
-    pprint.PrettyPrinter(indent=6,depth=depth).pprint(spec)
+    PrettyPrinter(indent=8,depth=depth).pprint(spec)
+
+def show_site_spec (site):
+    print '======== site',site['site_fields']['name']
+    for (k,v) in site.iteritems():
+        if k=='nodes':
+            if v: 
+                print '\t\t','nodes : ',
+                for node in v:  
+                    print node['node_fields']['hostname'],'',
+                print ''
+        elif k=='users':
+            if v: 
+                print '\t\tusers : ',
+                for user in v:  
+                    print user['name'],'',
+                print ''
+        elif k == 'site_fields':
+            print '\t\tlogin_base',':',v['login_base']
+        elif k == 'address_fields':
+            pass
+        else:
+            print '\t\t',k,
+            PrettyPrinter(indent=8,depth=2).pprint(v)
+        
+def show_initscript_spec (initscript):
+    print '======== initscript',initscript['initscript_fields']['name']
+
+def show_key_spec (key):
+    print '======== key',key['name']
+
+def show_slice_spec (slice):
+    print '======== slice',slice['slice_fields']['name']
+    for (k,v) in slice.iteritems():
+        if k=='nodenames':
+            if v: 
+                print '\t\tnodes : ',
+                for nodename in v:  
+                    print nodename,'',
+                print ''
+        elif k=='usernames':
+            if v: 
+                print '\t\tusers : ',
+                for username in v:  
+                    print username,'',
+                print ''
+        elif k=='slice_fields':
+            print '\t\tfields',':',
+            print 'max_nodes=',v['max_nodes'],
+            print ''
+        else:
+            print '\t\t',k,v
+
+def show_test_spec (message,all_plc_specs):
+    now=time.strftime("%H:%M:%S", time.localtime())
+    print ">",now,"--",message
+    for plc_spec in all_plc_specs:
+        show_test_spec_pass (plc_spec,1)
+        show_test_spec_pass (plc_spec,2)
+
+def show_test_spec_pass (plc_spec,passno):
+    for (key,val) in plc_spec.iteritems():
+        if passno == 2:
+            if key == 'sites':
+                for site in val:
+                    show_site_spec(site)
+            elif key=='initscripts':
+                for initscript in val:
+                    show_initscript_spec (initscript)
+            elif key=='slices':
+                for slice in val:
+                    show_slice_spec (slice)
+            elif key=='keys':
+                for key in val:
+                    show_key_spec (key)
+        elif passno == 1:
+            if key not in ['sites','initscripts','slices','keys']:
+                print '\t',key,':',val
 
 def system(command):
     now=time.strftime("%H:%M:%S", time.localtime())