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
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,
# 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)
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
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:
else:
return 1
except:
+ traceback.print_exc()
return 2
if __name__ == "__main__":
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)
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',