allow to set IP addresses - useful when running steps manually
authorThierry Parmentelat <thierry.parmentelat@sophia.inria.fr>
Fri, 18 Jan 2008 10:37:28 +0000 (10:37 +0000)
committerThierry Parmentelat <thierry.parmentelat@sophia.inria.fr>
Fri, 18 Jan 2008 10:37:28 +0000 (10:37 +0000)
system/TestMain.py
system/TestPlc.py
system/config_onelab_vserver.py

index c4be4c8..32ea7a0 100755 (executable)
@@ -48,6 +48,8 @@ build-url defaults to the last value used, as stored in BUILD-URL,
    or %s
 config defaults to the last value used, as stored in CONFIG,
    or %r
+ips defaults to the last value used, as stored in IPS,
+   default is to use IP scanning
 steps refer to a method in TestPlc or to a step_* module"""%(TestMain.default_build_url,TestMain.default_config)
         usage += "\n  Defaut steps are %r"%TestMain.default_steps
         usage += "\n  Other useful steps are %r"%TestMain.other_steps
@@ -65,6 +67,9 @@ steps refer to a method in TestPlc or to a step_* module"""%(TestMain.default_bu
                            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("-i","--ip",action="callback", callback=TestMain.optparse_list, dest="ips",
+                          nargs=1,type="string",
+                          help="allows to specify the set of IP addresses to use in vserver mode (disable scanning)")
         parser.add_option("-v","--verbose", action="store_true", dest="verbose", default=False, 
                           help="Run in verbose mode")
         parser.add_option("-n","--dry-run", action="store_true", dest="dry_run", default=False,
@@ -89,6 +94,7 @@ steps refer to a method in TestPlc or to a step_* module"""%(TestMain.default_bu
         # handle defaults and option persistence
         for (recname,filename,default) in ( ('myplc_url','MYPLC-URL',"") , 
                                             ('build_url','BUILD-URL',TestMain.default_build_url) ,
+                                            ('ips','IPS',[]) , 
                                             ('config','CONFIG',TestMain.default_config) , ) :
             print 'handling',recname
             path="%s/%s"%(self.path,filename)
@@ -105,7 +111,7 @@ steps refer to a method in TestPlc or to a step_* module"""%(TestMain.default_bu
                         parsed=[x.strip() for x in parsed]
                     setattr(self.options,recname,parsed)
                 except:
-                    if default:
+                    if default != "":
                         setattr(self.options,recname,default)
                     else:
                         print "Cannot determine",recname
@@ -178,7 +184,7 @@ steps refer to a method in TestPlc or to a step_* module"""%(TestMain.default_bu
             
         if self.options.dry_run:
             self.show_env(self.options,"Dry run")
-            sys.exit(0)
+            return 0
             
         # do all steps on all plcs
         for (name,method) in all_step_infos:
@@ -209,6 +215,7 @@ steps refer to a method in TestPlc or to a step_* module"""%(TestMain.default_bu
             else:
                 return 1 
         except:
+            traceback.print_exc()
             return 2
 
 if __name__ == "__main__":
index 08dd6c2..75c8205 100644 (file)
@@ -146,7 +146,7 @@ class TestPlc:
     def install(self,options):
         if self.vserver:
             return self.install_vserver_create(options)
-            return self.install_vserver_yum(options)
+            return self.install_vserver_native(options)
         else:
             return self.install_chroot(options)
 
index 88d7640..c1cef44 100644 (file)
@@ -1,32 +1,53 @@
 import utils
 import os.path
 
+# the pool of IP addresses available
 # from 01 to 09
-available = [ ( i, 'vnode%02d.inria.fr'%i, '138.96.250.13%d'%i) for i in range(1,10) ]
+available = [ ( 'vnode%02d.inria.fr'%i, '138.96.250.13%d'%i) for i in range(1,10) ]
+
+# let's be flexible
+def locate (user_provided):
+    global available
+    for (hostname,ip) in available:
+        if hostname.find(user_provided) >=0 or ip.find(user_provided) >=0:
+            return (hostname,ip)
 
 def config (plcs,options):
+    global available
     available.reverse()
+    if len(options.ips) != 0:
+        options.ips.reverse()
     plc_counter=0
     for plc in plcs:
-        ### locating the next available hostname (using ping)
-        while True:
-            try:
-                (i,hostname,ip)=available.pop()
-                if not utils.check_ping(hostname):
-                    break
-            except:
-                raise Exception('Cannot find an available IP for %s - exiting'%plc['name'])
+        if len(options.ips) != 0:
+            utils.header('ips=%r'%options.ips)
+            user_provided = options.ips.pop()
+            utils.header('vserver IP assignment : using user-provided %s'%user_provided)
+            (hostname,ip) = locate(user_provided)
+        else:
+            ### locating the next available hostname (using ping)
+            while True:
+                try:
+                    (hostname,ip)=available.pop()
+                    utils.header('vserver IP assignment : scanning IP %s'%ip)
+                    if not utils.check_ping(hostname):
+                        utils.header('IP %s is OK'%ip)
+                        break
+                except:
+                    raise Exception('Cannot find an available IP for %s - exiting'%plc['name'])
         # compute a helpful vserver name
         plc_counter += 1
+        simplehostname=hostname.split('.')[0]
         vservername = os.path.basename(options.myplc_url)
         vservername = vservername.replace(".rpm","")
+        vservername = vservername.replace("myplc","vtest")
         if len(plcs) == 1 :
-            vservername = "%s-%s" % (vservername,ip)
+            vservername = "%s-%s" % (vservername,simplehostname)
         else:
-            vservername = "%s-%d-%s" % (vservername,plc_counter,ip)
+            vservername = "%s-%d-%s" % (vservername,plc_counter,simplehostname)
         plc['vservername']=vservername
         plc['vserverip']=ip
-        plc['name'] = "%s_%02d"%(plc['name'],i)
+        plc['name'] = "%s_%s"%(plc['name'],simplehostname)
         utils.header("Attaching plc %s to vserver %s (%s)"%\
                          (plc['name'],plc['vservername'],plc['vserverip']))
         for key in [ 'PLC_DB_HOST',