first draft for vserver-based native myplc
authorThierry Parmentelat <thierry.parmentelat@sophia.inria.fr>
Fri, 21 Dec 2007 15:17:35 +0000 (15:17 +0000)
committerThierry Parmentelat <thierry.parmentelat@sophia.inria.fr>
Fri, 21 Dec 2007 15:17:35 +0000 (15:17 +0000)
system/Makefile [new file with mode: 0644]
system/TestKey.py [new file with mode: 0644]
system/TestMain.py
system/TestNode.py
system/TestPlc.py
system/TestRestore.py [deleted file]
system/TestSite.py
system/TestUser.py
system/config-onelab.py [moved from system/config-onelab-chroot.py with 71% similarity]
system/utils.py

diff --git a/system/Makefile b/system/Makefile
new file mode 100644 (file)
index 0000000..37209ab
--- /dev/null
@@ -0,0 +1,2 @@
+tags:
+       find . -name '*.py' | xargs etags
diff --git a/system/TestKey.py b/system/TestKey.py
new file mode 100644 (file)
index 0000000..8284609
--- /dev/null
@@ -0,0 +1,33 @@
+import utils
+import os, os.path
+
+class TestKey:
+
+    def __init__ (self,test_plc,key_spec):
+       self.test_plc=test_plc
+       self.key_spec=key_spec
+        
+    def name(self):
+        return self.key_spec['name']
+
+    def publicpath(self):
+        return "%s/keys/%s.pub"%(self.test_plc.path,self.name())
+    def privatepath(self):
+        return "%s/keys/%s.rsa"%(self.test_plc.path,self.name())
+
+    def store_key(self):
+        pub=self.publicpath()
+        priv=self.privatepath()
+        utils.header("Storing key %s in %s"%(self.name(),pub))
+        dir=os.path.dirname(pub)
+        if not os.path.isdir(dir):
+            os.mkdir(dir)
+        f=open(pub,"w")
+        f.write(self.key_spec['key_fields']['key'])
+        f.close()
+        f=open(priv,"w")
+        f.write(self.key_spec['private'])
+        f.close()
+        os.chmod(priv,0400)
+        os.chmod(pub,0444)
+            
index 1aeea5c..9d5f505 100755 (executable)
@@ -3,7 +3,6 @@
 
 import os, sys
 from optparse import OptionParser
-import pprint
 import traceback
 
 import utils
@@ -12,9 +11,15 @@ from TestSite import TestSite
 from TestNode import TestNode
 
 
-#default_steps = ['uninstall','install','configure', 'populate' , 'check_nodes' ]
-default_steps = ['uninstall','install','configure', 'sites', 'nodes', 'initscripts', 'slices',  'bootcd', 'start_nodes', 'check-nodes', 'check-slices' ]
-other_steps = [ 'clean_sites', 'clean_slices' , 'stop_nodes' , 'db_dump' , 'fresh-install']
+default_config = [ 'onelab' ]
+
+default_steps = ['uninstall','install','configure', 'start', 'store_keys',
+                 'sites', 'nodes', 'initscripts', 'slices',  
+                 'bootcd', 'start_nodes', 
+                 'check-nodes', 'check-slices' ]
+other_steps = [ 'fresh-install', 'stop', 'clean_sites', 'clean_slices' , 'clean_keys',
+                'stop_nodes' ,  'db_dump' , 'db_restore',
+                ]
 
 class TestMain:
 
@@ -26,7 +31,7 @@ class TestMain:
     @staticmethod
     def show_env (options, message):
         utils.header (message)
-        pprint.PrettyPrinter(indent=4,depth=2).pprint(options)
+        utils.show_spec("main options",options)
 
     @staticmethod
     def optparse_list (option, opt, value, parser):
@@ -35,13 +40,14 @@ class TestMain:
         except:
             setattr(parser.values,option.dest,[value])
 
-    def main (self):
+    def test_main (self):
         usage = """usage: %prog [options] steps
 myplc-url defaults to the last value used, as stored in MYPLC-URL
 build-url defaults to the last value used, as stored in BUILD-URL
 steps refer to a method in TestPlc or to a step-* module"""
         usage += "\n  Defaut steps are %r"%default_steps
         usage += "\n  Other useful steps are %r"%other_steps
+        usage += "\n  Default config(s) are %r"%default_config
         parser=OptionParser(usage=usage,version=self.subversion_id)
         parser.add_option("-u","--url",action="store", dest="myplc_url", 
                           help="myplc URL - for locating build output")
@@ -52,6 +58,8 @@ steps refer to a method in TestPlc or to a step-* module"""
                           help="config module - can be set multiple times")
         parser.add_option("-a","--all",action="store_true",dest="all_steps", default=False,
                           help="Runs all default steps")
+        parser.add_option("-s","--state",action="store",dest="dbname",default=None,
+                           help="Used by db_dump and db_restore")
         parser.add_option("-d","--display", action="store", dest="display", default='bellami.inria.fr:0.0',
                           help="set DISPLAY for vmplayer")
         parser.add_option("-v","--verbose", action="store_true", dest="verbose", default=False, 
@@ -95,7 +103,7 @@ steps refer to a method in TestPlc or to a step-* module"""
         # config modules
         if not self.options.config:
             # legacy default - do not set in optparse
-            self.options.config=['onelab-chroot']
+            self.options.config=default_config
         # step modules
         if not self.options.steps:
             #default (all) steps
@@ -117,14 +125,15 @@ steps refer to a method in TestPlc or to a step-* module"""
             except :
                 traceback.print_exc()
                 print 'Cannot load config %s -- ignored'%modulename
+                raise
         # show config
-        utils.header ("Test specifications")
-        pprint.PrettyPrinter(indent=4,depth=2).pprint(all_plc_specs)
+        utils.show_spec("Test specifications",all_plc_specs)
         # build a TestPlc object from the result
         for spec in all_plc_specs:
             spec['disabled'] = False
         all_plcs = [ (x, TestPlc(x)) for x in all_plc_specs]
 
+        overall_result = True
         testplc_method_dict = __import__("TestPlc").__dict__['TestPlc'].__dict__
         all_step_infos=[]
         for step in self.options.steps:
@@ -145,6 +154,7 @@ steps refer to a method in TestPlc or to a step-* module"""
                 except :
                     print 'Step %s -- ignored'%(step)
                     traceback.print_exc()
+                    overall_result = False
             
         if self.options.dry_run:
             self.show_env(self.options,"Dry run")
@@ -156,15 +166,30 @@ steps refer to a method in TestPlc or to a step-* module"""
                 if not spec['disabled']:
                     try:
                         utils.header("Running step %s on plc %s"%(name,spec['name']))
-                        if method(obj,self.options):
+                        step_result = method(obj,self.options)
+                        if step_result:
                             utils.header('Successful step %s on %s'%(name,spec['name']))
                         else:
-                            utils.header('Step %s on %s FAILED - discarding'%(name,spec['name']))
+                            overall_result = False
                             spec['disabled'] = True
+                            utils.header('Step %s on %s FAILED - discarding that plc from further steps'%(name,spec['name']))
                     except:
+                        overall_result=False
                         spec['disabled'] = True
-                        print 'Cannot run step %s on plc %s'%(name,spec['name'])
+                        utils.header ('Step %s on plc %s FAILED (exception) - discarding this plc from further steps'%(name,spec['name']))
                         traceback.print_exc()
+        return overall_result
+
+    # wrapper to shell
+    def main(self):
+        try:
+            success=self.test_main()
+            if success:
+                return 0
+            else:
+                return 1 
+        except:
+            return 2
 
 if __name__ == "__main__":
-    TestMain().main()
+    sys.exit(TestMain().main())
index ceabd8d..b30ce8f 100644 (file)
@@ -1,6 +1,5 @@
 import os, sys, time, base64
 import xmlrpclib
-import pprint
 
 import utils
 from TestUser import TestUser
@@ -34,7 +33,7 @@ class TestNode:
         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)
+        utils.system(sed_command)
 
     def create_boot_cd(self,path):
         node_spec=self.node_spec
@@ -43,7 +42,9 @@ class TestNode:
         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.system(clean_dir)
+        utils.system(mkdir_command)
+        utils.system(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 == ''):
@@ -68,7 +69,7 @@ class TestNode:
         path=options.path
         display=options.display
         utils.header('Starting vmplayer for node %s on %s'%(hostname,display))
-        os.system('set -x; cd %s/vmplayer-%s ; DISPLAY=%s vmplayer node.vmx < /dev/null >/dev/null 2>/dev/null &'%(path,hostname,display))
+        utils.system('cd %s/vmplayer-%s ; DISPLAY=%s vmplayer node.vmx < /dev/null >/dev/null 2>/dev/null &'%(path,hostname,display))
 
     def start_qemu (self, options):
         utils.header ("TestNode.start_qemu: not implemented yet")
index 274d73c..88de2d7 100644 (file)
@@ -1,14 +1,14 @@
 # $Id$
-import os
+import os, os.path
 import sys
 import xmlrpclib
 import datetime
-import pprint
 import traceback
 import utils
 from TestSite import TestSite
 from TestNode import TestNode
 from TestUser import TestUser
+from TestKey import TestKey
 
 # step methods must take (self, options) and return a boolean
 
@@ -20,37 +20,55 @@ class TestPlc:
        self.server=xmlrpclib.Server(self.url,allow_none=True)
        self.path=os.path.dirname(sys.argv[0])
         try:
-            self.vserver=plc_spec['vserver']
+            self.vserverip=plc_spec['vserverip']
+            self.vservername=plc_spec['vservername']
+            self.vserver=True
         except:
-            self.vserver=None
+            self.vserver=False
         
     def name(self):
-        return self.plc_spec['name']
+        name=self.plc_spec['name']
+        if self.vserver:
+            return name+"[%s]"%self.vservername
+        else:
+            return name+"[chroot]"
 
+    # define the API methods on this object through xmlrpc
+    # would help, but not strictly necessary
     def connect (self):
-       # tricky : define les methodes de l'API sur cet object
        pass
     
+    # build the full command so command gets run in the chroot/vserver
+    def run_command(self,command):
+        if self.vserver:
+            return "vserver %s exec %s"%(self.vservername,command)
+        else:
+            return "chroot /plc/root %s"%command
+
+    def ssh_command(self,command):
+        if self.plc_spec['hostname'] == "localhost":
+            return command
+        else:
+            return "ssh " + self.plc_spec['hostname'] + " " + command
+
+    def full_command(self,command):
+        return self.ssh_command(self.run_command(command))
+
+    def run_in_guest (self,command):
+        return utils.system(self.full_command(command))
+    def run_in_host (self,command):
+        return utils.system(self.ssh_command(command))
+
+    # xxx quick n dirty
+    def run_in_guest_piped (self,local,remote):
+        return utils.system(local+" | "+self.full_command(command))
+
     def auth_root (self):
        return {'Username':self.plc_spec['PLC_ROOT_USER'],
                'AuthMethod':'password',
                'AuthString':self.plc_spec['PLC_ROOT_PASSWORD'],
                 'Role' : self.plc_spec['role']
                 }
-    def display_results(self, test_case_name, status, timers):
-        timers=datetime.datetime.now()
-        fileHandle = open (self.path+'/results.txt', 'a' )
-        fileHandle.write ( str(test_case_name)+'\t' +str(status)+'\t'+str(timers)+'\n')
-        fileHandle.close()
-        
-    def init_node (self,test_site,node_spec,path):
-
-        test_node = TestNode(self, test_site, node_spec)
-        test_node.create_node (test_site.locate_user("pi"))
-        test_node.create_node ("tech")
-        test_node.create_boot_cd(path)
-        return test_node
-    
     def locate_site (self,sitename):
         for site in self.plc_spec['sites']:
             if site['site_fields']['name'] == sitename:
@@ -67,29 +85,66 @@ class TestPlc:
         
     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')
+        utils.system('pgrep vmware | xargs -r kill')
+        utils.system('pgrep vmplayer | xargs -r kill ')
+        utils.system('pgrep vmware | xargs -r kill -9')
+        utils.system('pgrep vmplayer | xargs -r kill -9')
         
-    # step methods
-    def uninstall(self,options):
-        os.system('set -x; service plc safestop')
+    #################### step methods
+
+    ### uninstall
+    def uninstall_chroot(self,options):
+        self.run_in_host('service plc safestop')
         #####detecting the last myplc version installed and remove it
-        os.system('set -x; rpm -e myplc')
+        self.run_in_host('rpm -e myplc')
         ##### Clean up the /plc directory
-        os.system('set -x; rm -rf  /plc/data')
+        self.run_in_host('rm -rf  /plc/data')
         return True
-        
-    def install(self,options):
+
+    def uninstall_vserver(self,options):
+        self.run_in_host("vserver --silent delete %s"%self.vservername)
+
+    def uninstall(self,options):
+        if self.vserver:
+            return self.uninstall_vserver(options)
+        else:
+            return self.uninstall_chroot(options)
+
+    ### install
+    def install_chroot(self,options):
         utils.header('Installing from %s'%options.myplc_url)
         url=options.myplc_url
-        os.system('set -x; rpm -Uvh '+url)
-        os.system('set -x; service plc mount')
+        utils.system('rpm -Uvh '+url)
+        utils.system('service plc mount')
         return True
 
+    # xxx this would not work with hostname != localhost as mylc-init-vserver was extracted locally
+    def install_vserver(self,options):
+        # we need build dir for myplc-init-vserver
+        build_dir=self.path+"/build"
+        if not os.isdir(build_dir):
+            if utils.system("svn checkout %s %s"%(options.build_url,build_dir)) != 0:
+                raise Exception,"Cannot checkout build dir"
+        # the repo url is taken from myplc-url 
+        # with the last two steps (i386/myplc...) removed
+        repo_url = options.build_url
+        repo_url = os.path(repo_url)
+        repo_url = os.path(repo_url)
+        command="%s/myplc-init-vserver.sh %s %s -- --interface eth0:%s"%\
+            (build_url,self.servername,repo_url,self.vserverip)
+        if utils.system(command) != 0:
+            raise Exception,"Could not create vserver for %s"%self.vservername
+        self.run_in_host("yum -y install myplc-native")
+
+    def install(self,options):
+        if self.vserver:
+            return self.install_vserver(options)
+        else:
+            return self.install_chroot(options)
+
+    ### 
     def configure(self,options):
-        tmpname='/tmp/plc-config-tty-%d'%os.getpid()
+        tmpname='%s/%s.plc-config-tty'%(options.path,self.name())
         fileconf=open(tmpname,'w')
         for var in [ 'PLC_NAME',
                      'PLC_ROOT_PASSWORD',
@@ -106,14 +161,28 @@ class TestPlc:
         fileconf.write('w\n')
         fileconf.write('q\n')
         fileconf.close()
-        os.system('set -x ; cat %s'%tmpname)
-        os.system('set -x ; chroot /plc/root  plc-config-tty < %s'%tmpname)
-        os.system('set -x ; service plc start')
-        os.system('set -x; service sendmail stop')
-        os.system('set -x; chroot /plc/root service sendmail restart')
-        os.system('set -x; rm %s'%tmpname)
+        utils.system('cat %s'%tmpname)
+        self.run_in_guest('plc-config-tty < %s'%tmpname)
+        utils.system('rm %s'%tmpname)
+        return True
+
+    def start(self, options):
+        utils.system('service plc start')
+        return True
+        
+    def stop(self, options):
+        utils.system('service plc stop')
         return True
         
+    # could use a TestKey class
+    def store_keys(self, options):
+        for key_spec in self.plc_spec['keys']:
+            TestKey(self,key_spec).store_key()
+        return True
+
+    def clean_keys(self, options):
+        utils.system("rm -rf %s/keys/"%self.path)
+
     def sites (self,options):
         return self.do_sites(options)
     
@@ -140,8 +209,7 @@ class TestPlc:
             test_site = TestSite (self,site_spec)
             utils.header("Creating nodes for site %s in %s"%(test_site.name(),self.name()))
             for node_spec in site_spec['nodes']:
-                utils.header('Creating node %s'%node_spec)
-                pprint.PrettyPrinter(indent=4).pprint(node_spec)
+                utils.show_spec('Creating node %s'%node_spec,node_spec)
                 test_node = TestNode (self,test_site,node_spec)
                 test_node.create_node ()
         return True
@@ -156,9 +224,9 @@ class TestPlc:
             
     def initscripts (self, options):
         for initscript in self.plc_spec['initscripts']:
-            utils.header('Adding Initscript %s in plc %s'%\
-                         (initscript['name'],self.plc_spec['name']))
-            pprint.PrettyPrinter(indent=4).pprint(initscript)
+            utils.show_spec('Adding Initscript %s in plc %s'%\
+                                (initscript['name'],self.plc_spec['name']),
+                            initscript)
             self.server.AddInitScript(self.auth_root(),initscript['initscript_fields'])
         return True
 
@@ -181,7 +249,7 @@ class TestPlc:
                 self.server.DeleteSlice(auth,slice_fields['name'])
                 utils.header("Deleted slice %s"%slice_fields['name'])
                 continue
-            pprint.PrettyPrinter(indent=4).pprint(slice_fields)
+            utils.show_spec("Creating slice",slice_fields)
             self.server.AddSlice(auth,slice_fields)
             utils.header('Created Slice %s'%slice_fields['name'])
             for username in slice['usernames']:
@@ -214,16 +282,35 @@ class TestPlc:
         self.kill_all_vmwares ()
         return True
 
-    def db_dump(self, options):
+    # returns the filename to use for sql dump/restore, using options.dbname if set
+    def dbfile (self, database, options):
         # uses options.dbname if it is found
         try:
             name=options.dbname
+            if not isinstance(name,StringTypes):
+                raise Exception
         except:
             t=datetime.datetime.now()
             d=t.date()
             name=str(d)
-        dump='/data/%s.sql'%name
-        os.system('chroot /plc/root pg_dump -U pgsqluser planetlab4 -f '+ dump)
+        return "/root/%s-%s.sql"%(database,name)
+
+    def db_dump(self, options):
+        
+        dump=self.dbfile("planetab4",options)
+        self.run_in_guest('pg_dump -U pgsqluser planetlab4 -f '+ dump)
         utils.header('Dumped planetlab4 database in %s'%dump)
         return True
 
+    def db_restore(self, options):
+        dump=self.dbfile("planetab4",options)
+        ##stop httpd service
+        self.run_in_guest('service httpd stop')
+        # xxx - need another wrapper
+        self.run_in_guest_piped('echo drop database planetlab4','psql --user=pgsqluser template1')
+        self.run_in_guest('createdb -U postgres --encoding=UNICODE --owner=pgsqluser planetlab4')
+        self.run_in_guest('psql -U pgsqluser planetlab4 -f '+dump)
+        ##starting httpd service
+        self.run_in_guest('service httpd start')
+
+        utils.header('Database restored from ' + dump)
diff --git a/system/TestRestore.py b/system/TestRestore.py
deleted file mode 100755 (executable)
index 83e7d36..0000000
+++ /dev/null
@@ -1,109 +0,0 @@
-#!/usr/bin/env python
-
-import os, sys, time
-from optparse import OptionParser
-import xmlrpclib
-
-class TestRestore:
-
-    subversion_id = "$Id$"
-
-    def __init__ (self):
-        self.url="https://localhost:443/PLCAPI/"
-       self.server=xmlrpclib.Server(self.url,allow_none=True)
-        self.path=os.path.dirname(sys.argv[0])
-
-###################3
-    def auth_root (self):
-       return {'Username':'root@onelab-test.inria.fr',
-               'AuthMethod':'password',
-               'AuthString':'test++',
-                'Role' : 'root'
-                }
-    
-##############check if the db version exsit
-    def check_dir(self,dbname):
-
-        config_file = "/plc/data/var/lib/pgsql/backups/"+dbname
-        if (os.path.isfile (config_file)):
-            print "==>dbversion found "
-            return 1
-        else:
-            print "\n %s  non-existing Bdd version\n" % config_file
-            return 0
-            
-##############restoring one db return list of host nodes
-    def restore_db(self,db,display):
-        try:
-            list_host=[]
-            ##stop httpd service
-            os.system('chroot /plc/root  service httpd stop')
-            ##droping
-            os.system(' echo drop database planetlab4 |chroot /plc/root psql --user=pgsqluser template1')
-            ##creating
-            os.system('chroot /plc/root  createdb -U postgres --encoding=UNICODE --owner=pgsqluser planetlab4')
-            ##populating
-            os.system('chroot /plc/root psql -U pgsqluser planetlab4 -f /var/lib/pgsql/backups/'+db)
-            ##starting httpd service
-            os.system('chroot /plc/root  service httpd start')
-
-            print 'db.restored'
-            hosts=self.server.GetNodes(self.auth_root())
-            for host in hosts:
-                print host['hostname']
-                list_host.append(host['hostname'])
-                
-            for l in list_host :
-                print display
-                os.system('DISPLAY=%s vmplayer %s/vmplayer-%s/node.vmx &'%(display,self.path,l))
-
-        except Exception, e:
-            print str(e)
-###########################    
-
-
-
-
-    def main (self):
-        try:
-            usage = """usage: %prog [options] BDDversion"""
-            parser=OptionParser(usage=usage,version=self.subversion_id)
-            # verbosity
-            parser.add_option("-v","--verbose", action="store_true", dest="verbose", default=False, 
-                              help="Run in verbose mode")
-            #exporting Display
-            parser.add_option("-d","--display", action="store", dest="Xdisplay", default='bellami:0.0',
-                              help="export the display on the mentionneted one")
-       
-        
-            (self.options, self.args) = parser.parse_args()
-            
-            hosts=[]
-            i=0
-            dirname =''
-            display=''
-           
-            
-            if (self.options.Xdisplay):
-                display=self.options.Xdisplay
-                print 'the display is', display
-       
-                
-            if (len(self.args) == 0 ):
-                parser.print_help()
-                sys.exit(1)
-            else:
-                dirname=self.args[0]    
-               
-            if (not (self.check_dir(dirname))):
-                 parser.print_help()
-                 sys.exit(1)
-                 
-            self.restore_db(dirname,display)
-            
-        except Exception, e:
-            print str(e)
-            
-if __name__ == "__main__":
-    TestRestore().main()       
-     
index 9357d5f..d01e349 100644 (file)
@@ -1,13 +1,12 @@
-import os
-import sys
+import os.path
 import datetime
 import time
-import xmlrpclib
 import traceback
 
 import utils
 from TestNode import TestNode
 from TestUser import TestUser
+from TestKey import TestKey
 
 class TestSite:
 
@@ -20,19 +19,16 @@ class TestSite:
 
     def create_site (self):
         print self.test_plc.auth_root()
-        self.site_id = self.test_plc.server.AddSite(self.test_plc.auth_root(),
+        self.test_plc.server.AddSite(self.test_plc.auth_root(),
                                                     self.site_spec['site_fields'])
-        self.test_plc.server.AddSiteAddress(self.test_plc.auth_root(),self.site_id,
+        self.test_plc.server.AddSiteAddress(self.test_plc.auth_root(),self.name(),
                                             self.site_spec['address_fields'])
             
-        return self.site_id
-            
     def create_users (self):
         for user_spec in self.site_spec['users']:
             test_user=TestUser(self.test_plc,self,user_spec)
             test_user.create_user()
             test_user.add_keys()            
-        
 
     def delete_site (self):
         print self.test_plc.auth_root()
@@ -80,14 +76,12 @@ class TestSite:
                     utils.header('Actual status for node %s is [%s]'%(hostname,node_status))
                     try:
                         if (node_status[0] == bt):
-                            test_name='Test Installation Node hosted: '+hostname
-                            self.test_plc.display_results(test_name, 'Successful', '')
-                            break ##for existing and renaming virtual file to just installed
+                            utils.header('%s has reached boot state'%hostname)
+                            break 
                         elif (node_status[0] ==dbg):
-                            test_name='Test Installation Node hosted: '+hostname
-                            self.test_plc.display_results(test_name, 'En Debug', '')
+                            utils.header('%s has reached debug state'%hostname)
                             bool=False
-                            break ##for existing and renaming virtual file to just installed
+                            break 
                         elif ( start_time  <= dead_time ) :
                             start_time=datetime.datetime.now()+ datetime.timedelta(minutes=2)
                             time.sleep(secondes)
@@ -100,8 +94,6 @@ class TestSite:
                 else :
                     utils.header("Node %s not fully booted"%hostname)
                     ret_value=False
-                    test_name='Test Installation Node Hosted: ',hostname
-                    self.test_plc.display_results(test_name, 'Failure', '')
             
             utils.header("End checking for nodes in site %s"%self.name())
             return ret_value
@@ -120,7 +112,7 @@ class TestSite:
     def delete_known_hosts(self):
         utils.header("Messing with known_hosts (cleaning hostnames starting with 'test[0-9]')")
         sed_command="sed -i -e '/^test[0-9]/d' /root/.ssh/known_hosts"
-        os.system("set -x ; " + sed_command)
+        utils.system(sed_command)
 
     # xxx should be attached to TestPlc
     def check_slices(self):
@@ -134,14 +126,29 @@ class TestSite:
         for slice_spec in self.test_plc.plc_spec['slices']:
             for hostname in slice_spec['nodenames']:
                 slicename=slice_spec['slice_fields']['name']
+                # locate the first avail. key
+                found=False
+                for username in slice_spec['usernames']:
+                    user_spec=self.locate_user(username)
+                    for keyname in user_spec['keynames']:
+                        key_spec=self.test_plc.locate_key(keyname)
+                        publickey=TestKey(self.test_plc,key_spec).publicpath()
+                        privatekey=TestKey(self.test_plc,key_spec).privatepath()
+                        if os.path.isfile(publickey) and os.path.isfile(privatekey):
+                            found=True
+                            break
+                if not found:
+                    raise Exception,"Cannot find a valid key for slice %s"%slicename
+
                 while(bool):
                     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 )
+                    access=utils.system('ssh -i /etc/planetlab/root_ssh_key.rsa root@%s service nm restart'%hostname )
                     if (access==0):
                         utils.header('nm restarted on %s'%hostname)
                         while(bool1):
                             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))
+                            ### should use saved keys instead of this hard-coded stuff
+                            Date=utils.system('ssh -i %s %s@%s date'%(privatekey,slicename,hostname))
                             if (Date==0):
                                 break
                             elif ( start_time  <= dead_time ) :
@@ -153,15 +160,15 @@ class TestSite:
                             utils.header('connected to %s@%s -->'%(slicename,hostname))
                         else:
                             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)
+                            access=utils.system('ssh -i /etc/planetlab/root_ssh_key.rsa  root@%s service nm restart'%hostname)
                             if (access==0):
                                 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))
+                                Date=utils.system('ssh -i ~/.ssh/slices.rsa %s@%s date'%(slicename,hostname))
                                 if (Date==0):
                                     utils.header('connected to %s@%s -->'%(slicename,hostname))
                                 else:
                                     utils.header('giving up with to %s@%s -->'%(slicename,hostname))
-                                    sys.exit(1)
+                                    return False
                             else :
                                 utils.header('Last chance failed on %s@%s -->'%(slicename,hostname))
                         break
index 6646e04..9cf7886 100644 (file)
@@ -1,6 +1,5 @@
 import os, sys, time
 import xmlrpclib
-import pprint
 
 import utils
 
similarity index 71%
rename from system/config-onelab-chroot.py
rename to system/config-onelab.py
index 070788d..8a3fb53 100644 (file)
@@ -9,7 +9,7 @@ onelab="one-lab.org"
 
 # use a model that contains "vmware" to get the node actually started
 def nodes():
-    return [ {'node_fields': {'hostname': 'test1.one-lab.org',
+    nodes= [ {'node_fields': {'hostname': 'test1.one-lab.org',
                               'model':'vmware/minhw'},
               'owner' : 'pi',
               'network_fields': { 'method':'static',
@@ -36,6 +36,8 @@ def nodes():
                                   },
                },
              ]
+#    return nodes
+    return [nodes[0]]
 
 def all_nodenames ():
     return [ node['node_fields']['hostname'] for node in nodes()]
@@ -94,10 +96,43 @@ def sites ():
               'nodes': nodes(),
             }]
 
+##########
+public_key="""ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA4jNj8yT9ieEc6nSJz/ESu4fui9WrJ2y/MCfqIZ5WcdVKhBFUYyIenmUaeTduMcSqvoYRQ4QnFR1BFdLG8XR9D6FWZ5zTKUgpkew22EVNeqai4IXeWYKyt1Qf3ehaz9E3o1PG/bmQNIM6aQay6TD1Y4lqXI+eTVXVQev4K2fixySjFQpp9RB4UHbeA8c28yoa/cgAYHqCqlvm9uvpGMjgm/Qa4M+ZeO7NdjowfaF/wF4BQIzVFN9YRhvQ/d8WDz84B5Pr0J7pWpaX7EyC4bvdskxl6kmdNIwIRcIe4OcuIiX5Z9oO+7h/chsEVJWF4vqNIYlL9Zvyhnr0hLLhhuk2bw== root@test.one-lab.org
+"""
+private_key="""-----BEGIN RSA PRIVATE KEY-----
+MIIEogIBAAKCAQEA4jNj8yT9ieEc6nSJz/ESu4fui9WrJ2y/MCfqIZ5WcdVKhBFU
+YyIenmUaeTduMcSqvoYRQ4QnFR1BFdLG8XR9D6FWZ5zTKUgpkew22EVNeqai4IXe
+WYKyt1Qf3ehaz9E3o1PG/bmQNIM6aQay6TD1Y4lqXI+eTVXVQev4K2fixySjFQpp
+9RB4UHbeA8c28yoa/cgAYHqCqlvm9uvpGMjgm/Qa4M+ZeO7NdjowfaF/wF4BQIzV
+FN9YRhvQ/d8WDz84B5Pr0J7pWpaX7EyC4bvdskxl6kmdNIwIRcIe4OcuIiX5Z9oO
++7h/chsEVJWF4vqNIYlL9Zvyhnr0hLLhhuk2bwIBIwKCAQATY32Yf4NyN93oNd/t
+QIyTuzG0NuLI3W95J/4gI4PAnUDmv6glwRiRO92ynlnnAjqFW/LZ5sGFd4k8YoYU
+sjaa8JJgpwrJBi9y6Fx47/9Tp+ITPqyoliyTXvtqysX0jkaY+I1mNHoTITDkbknZ
+eTma0UOhiKcrMz4qOMwg+kajWsAhIplJXyf0Mio/XuyqjMT4wI/NyGZQ4bGuUjO7
+gj3p+9psOvONsRBW4MV27W5ts9c7HEXg+VJ2PSCEMs+uyzXcdnMJcTb4zQ/+tVxR
+5IMeEuR9ZzDNkDtNF6Nnw5kYcTBNoayzZbUfjcuSmsMklMXr0qJ4qcW9/ONKgBQ9
+6qhDAoGBAPkvSYuF/bxwatEiUKyF97oGDe025h/58aqK1VBD5/BBVqqvbQOeNtR5
+/LerGfFa5D9Jm+6U97gDdq3tH0j95Mo0F00LWq2+vp7U4DTQsiddepzNdbcvSrzT
+NVZ2cnOAlKTHO4hGggShm04n/M5LOzkHtI5TLcIJjw4b5iiIw9EtAoGBAOhjLTds
+Zz8UbXVTeGv8yBGhnjAeHQ5WISN6V5KenB4GIyaYCCcQUOUGqc5nCttlnPLv/GHp
+4DOJ2/0KbwDEwk7HbAtXG2Tv1OkmfcOq9RH19V9lyqynA+zvI6taisCEaMvBlafd
+k+RgXsR+NdLs96RakKt4BtgpuuADoSIryQ+LAoGBAKremNSzpq0Z4tiMjxc3Ssiz
+scc7lnxTnmZQkkWq6C+3xmZpqdaYYByra3ahNlxblTK2IcgroozPLM8I/4KCNnwG
+dmC3VB9eOZF8B3SsXOfLEj+i1GBa8WuJg6kAw4JmzFO70Qz9JfSMErk//c9Jh7IT
+6YYqaIUN3nATIXrhcFTrAoGAVlC5BfUQZ+MEFaKpEiqwthd1RRJ/0h/9rhd/nNvT
+lh+JZhs2OmUlXGGPhy2WUX2DcC1AfCOrC9Qego7YxcVsvizQW/vIWLDaDXSyXp6V
+ilQKrmejDO2Tvmdzpguv4Rs83fdyGcdUMEENQas4kCwhd49aTlEnHRbQYdV2XSY0
+vKECgYEAlhYzfSswIF2h5/hGDLETxgNJ2kD0HIZYh7aud6X6aEYNdJopbfbEhifU
+vTbf8GtvERDoxWEsk9Qp7km8xXfKWdcZtqIwsSmn/ri5d7iyvpIk591YIHSY0dr2
+BO+VyPNWF+kDNI8mSUwi7jLW6liMdhNOmDaSX0+0X8CHtK898xM=
+-----END RSA PRIVATE KEY-----
+"""
+
 def keys ():
     return [ {'name': 'key1',
+              'private' : private_key,
               'key_fields' : {'key_type':'ssh',
-                              'key':'ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA4jNj8yT9ieEc6nSJz/ESu4fui9WrJ2y/MCfqIZ5WcdVKhBFUYyIenmUaeTduMcSqvoYRQ4QnFR1BFdLG8XR9D6FWZ5zTKUgpkew22EVNeqai4IXeWYKyt1Qf3ehaz9E3o1PG/bmQNIM6aQay6TD1Y4lqXI+eTVXVQev4K2fixySjFQpp9RB4UHbeA8c28yoa/cgAYHqCqlvm9uvpGMjgm/Qa4M+ZeO7NdjowfaF/wF4BQIzVFN9YRhvQ/d8WDz84B5Pr0J7pWpaX7EyC4bvdskxl6kmdNIwIRcIe4OcuIiX5Z9oO+7h/chsEVJWF4vqNIYlL9Zvyhnr0hLLhhuk2bw== root@onelab-test.inria.fr'}}
+                              'key': public_key}}
              ]
 
 def initscripts(): 
@@ -139,25 +174,27 @@ def slices ():
                'owner' : 'pi',
                }]
     # I suspect the check_slices stuff to work improperly with 2 slices
-    return both
+#    return both
+    return [both[0]]
 
 def plc () :
     return { 
-        'name' : 'onelab-chroot',
+        'name' : 'onelab',
         # as of yet, not sure we can handle foreign hosts, but this is required though
         'hostname' : 'localhost',
-        # use this to run in a vserver
-        # 'vserver': '138.96.250.131'
+        # set these two items to run within a vserver
+        # 'vservername': '138.96.250.131'
+        # 'vserverip': '138.96.250.131'
         'role' : 'root',
-        'PLC_ROOT_USER' : 'root@onelab-test.inria.fr',
+        'PLC_ROOT_USER' : 'root@test.one-lab.org',
         'PLC_ROOT_PASSWORD' : 'test++',
         'PLC_NAME' : 'TestLab',
         'PLC_MAIL_ENABLED':'true',
         'PLC_MAIL_SUPPORT_ADDRESS' : 'mohamed-amine.chaoui@sophia.inria.fr',
-        'PLC_DB_HOST' : 'onelab-test.inria.fr',
-        'PLC_API_HOST' : 'onelab-test.inria.fr',
-        'PLC_WWW_HOST' : 'onelab-test.inria.fr',
-        'PLC_BOOT_HOST' : 'onelab-test.inria.fr',
+        'PLC_DB_HOST' : 'test.one-lab.org',
+        'PLC_API_HOST' : 'test.one-lab.org',
+        'PLC_WWW_HOST' : 'test.one-lab.org',
+        'PLC_BOOT_HOST' : 'test.one-lab.org',
         'PLC_NET_DNS1' : '138.96.0.10',
         'PLC_NET_DNS2' : '138.96.0.11',
         'sites' : sites(),
@@ -168,4 +205,3 @@ def plc () :
 
 def config (plc_specs,options):
     return plc_specs + [ plc() ]
-
index 971ff52..2219848 100644 (file)
@@ -1,7 +1,20 @@
 # $Id$
 import time
+import os
+import pprint
 
 # 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):
+    now=time.strftime("%H:%M:%S", time.localtime())
+    print ">",now,"--",message
+    pprint.PrettyPrinter(indent=6,depth=depth).pprint(spec)
+
+def system(command):
+    now=time.strftime("%H:%M:%S", time.localtime())
+    print "+",now
+    return os.system("set -x; " + command)
+