From e53dac069a417485200df6f6683386ee333de068 Mon Sep 17 00:00:00 2001 From: Thierry Parmentelat Date: Tue, 20 Mar 2012 11:33:59 +0100 Subject: [PATCH] scaffolding for lxc-based plcs run -X to use this (uncomplete) feature local substrate definition declares vs- and lxc- enabled boxes --- system/LocalSubstrate.inria.py | 7 ++- system/Substrate.py | 80 +++++++++++++++++++++++++++------- system/TestMain.py | 3 ++ 3 files changed, 73 insertions(+), 17 deletions(-) diff --git a/system/LocalSubstrate.inria.py b/system/LocalSubstrate.inria.py index 97772f0..1dcd262 100755 --- a/system/LocalSubstrate.inria.py +++ b/system/LocalSubstrate.inria.py @@ -23,10 +23,15 @@ class OnelabSubstrate (Substrate): return [ 'liquid', 'reed', 'velvet', ] # the vs-capable box for PLCs - def plc_boxes_spec (self): + def plc_vs_boxes_spec (self): return [ ('vs64-1', 35), # how many plcs max in this box ] + # the lxc-capable box for PLCs + def plc_lxc_boxes_spec (self): + return [ ('lxc64-1', 35), # how many plcs max in this box + ] + # vplc01 to 40 def vplc_ips (self): return [ ( 'vplc%02d'%i, # DNS name diff --git a/system/Substrate.py b/system/Substrate.py index 36b321b..e912133 100644 --- a/system/Substrate.py +++ b/system/Substrate.py @@ -379,17 +379,21 @@ class BuildBox (Box): ############################################################ class PlcInstance: - def __init__ (self, vservername, ctxid, plcbox): - self.vservername=vservername - self.ctxid=ctxid + def __init__ (self, plcbox): self.plc_box=plcbox # unknown yet self.timestamp=0 - + def set_timestamp (self,timestamp): self.timestamp=timestamp def set_now (self): self.timestamp=int(time.time()) def pretty_timestamp (self): return time.strftime("%Y-%m-%d:%H-%M",time.localtime(self.timestamp)) +class PlcVsInstance (PlcInstance): + def __init__ (self, plcbox, vservername, ctxid): + PlcInstance.__init__(self,plcbox) + self.vservername=vservername + self.ctxid=ctxid + def vplcname (self): return self.vservername.split('-')[-1] def buildname (self): @@ -409,31 +413,46 @@ class PlcInstance: self.plc_box.run_ssh(['vserver',self.vservername,'stop'],msg) self.plc_box.forget(self) +class PlcLxcInstance (PlcInstance): + # does lxc have a context id of any kind ? + def __init__ (self, plcbox, lxcname): + PlcInstance.__init__(self, plcbox) + self.lxcname = lxcname + + def kill (self): + print "TODO PlcLxcInstance.kill" + + def line (self): + return "TODO PlcLxcInstance.line" + +########## class PlcBox (Box): def __init__ (self, hostname, max_plcs): Box.__init__(self,hostname) self.plc_instances=[] self.max_plcs=max_plcs +class PlcVsBox (PlcBox): + def add_vserver (self,vservername,ctxid): for plc in self.plc_instances: if plc.vservername==vservername: header("WARNING, duplicate myplc %s running on %s"%\ (vservername,self.hostname),banner=False) return - self.plc_instances.append(PlcInstance(vservername,ctxid,self)) + self.plc_instances.append(PlcVsInstance(self,vservername,ctxid)) def forget (self, plc_instance): self.plc_instances.remove(plc_instance) # fill one slot even though this one is not started yet def add_dummy (self, plcname): - dummy=PlcInstance('dummy_'+plcname,0,self) + dummy=PlcVsInstance(self,'dummy_'+plcname,0) dummy.set_now() self.plc_instances.append(dummy) def line(self): - msg="%s [max=%d,%d free] (%s)"%(self.hostname, self.max_plcs,self.free_spots(),self.uname()) + msg="%s [max=%d,%d free] (%s)"%(self.hostname, self.max_plcs,self.free_slots(),self.uname()) return msg def list(self): @@ -445,7 +464,7 @@ class PlcBox (Box): for p in self.plc_instances: header (p.line(),banner=False) - def free_spots (self): + def free_slots (self): return self.max_plcs - len(self.plc_instances) def uname(self): @@ -515,6 +534,22 @@ class PlcBox (Box): except: print 'WARNING, could not parse ts line',ts_line +class PlcLxcBox (PlcBox): + + def add_dummy (self, plcname): + print "TODO PlcLxcBox.add_dummy" + + def free_slots (self): + print "TODO PlcLxcBox.free_slots" + + def list (self): + print "TODO PlcLxcBox.list" + + def reboot (self, options): + print "TODO PlcLxcBox.reboot" + + def sense (self, options): + print "TODO PlcLxcBox.sense" ############################################################ @@ -574,7 +609,7 @@ class QemuBox (Box): self.qemu_instances.append(dummy) def line (self): - msg="%s [max=%d,%d free] (%s)"%(self.hostname, self.max_qemus,self.free_spots(),self.driver()) + msg="%s [max=%d,%d free] (%s)"%(self.hostname, self.max_qemus,self.free_slots(),self.driver()) return msg def list(self): @@ -586,7 +621,7 @@ class QemuBox (Box): for q in self.qemu_instances: header (q.line(),banner=False) - def free_spots (self): + def free_slots (self): return self.max_qemus - len(self.qemu_instances) def driver(self): @@ -824,7 +859,7 @@ class Options: pass class Substrate: - def __init__ (self): + def __init__ (self, use_plc_vs_boxes=True, use_plc_lxc_boxes=False): self.options=Options() self.options.dry_run=False self.options.verbose=False @@ -832,14 +867,22 @@ class Substrate: self.options.soft=False self.test_box = TestBox (self.test_box_spec()) self.build_boxes = [ BuildBox(h) for h in self.build_boxes_spec() ] - self.plc_boxes = [ PlcBox (h,m) for (h,m) in self.plc_boxes_spec ()] + self.plc_vs_boxes = [ PlcVsBox (h,m) for (h,m) in self.plc_vs_boxes_spec ()] + self.plc_lxc_boxes = [ PlcLxcBox (h,m) for (h,m) in self.plc_lxc_boxes_spec ()] self.qemu_boxes = [ QemuBox (h,m) for (h,m) in self.qemu_boxes_spec ()] - self.default_boxes = self.plc_boxes + self.qemu_boxes - self.all_boxes = self.build_boxes + [ self.test_box ] + self.plc_boxes + self.qemu_boxes self._sensed=False self.vplc_pool = Pool (self.vplc_ips(),"for vplcs",self) self.vnode_pool = Pool (self.vnode_ips(),"for vnodes",self) + + self.rescope (use_plc_vs_boxes, use_plc_lxc_boxes) + + def rescope(self, plcs_on_vs, plcs_on_lxc): + self.plc_boxes=[] + if plcs_on_vs: self.plc_boxes += self.plc_vs_boxes + if plcs_on_lxc: self.plc_boxes += self.plc_lxc_boxes + self.default_boxes = self.plc_boxes + self.qemu_boxes + self.all_boxes = self.build_boxes + [ self.test_box ] + self.plc_boxes + self.qemu_boxes def fqdn (self, hostname): if hostname.find('.')<0: return "%s.%s"%(hostname,self.domain()) @@ -922,7 +965,7 @@ class Substrate: max_free=0 # use the box that has max free spots for load balancing for pb in self.plc_boxes: - free=pb.free_spots() + free=pb.free_slots() if free>max_free: plc_boxname=pb.hostname max_free=free @@ -1017,7 +1060,7 @@ class Substrate: max_free=0 # use the box that has max free spots for load balancing for qb in self.qemu_boxes: - free=qb.free_spots() + free=qb.free_slots() if free>max_free: qemu_boxname=qb.hostname max_free=free @@ -1122,6 +1165,8 @@ class Substrate: help='add build boxes') parser.add_option ('-p',"--plc",action='store_true',dest='plcs',default=False, help='add plc boxes') + parser.add_option ('-X', "--lxc",action='store_true',dest='plcs_use_lxc', + help='use lxc-enabled plc boxes instead of vs-enabled ones') parser.add_option ('-q',"--qemu",action='store_true',dest='qemus',default=False, help='add qemu boxes') parser.add_option ('-a',"--all",action='store_true',dest='all',default=False, @@ -1132,6 +1177,9 @@ class Substrate: help='dry run mode') (self.options,args)=parser.parse_args() + if self.options.plcs_use_lxc: + self.rescope (plcs_on_vs=False, plcs_on_lxc=True) + boxes=args if self.options.testbox: boxes += [self.test_box] if self.options.builds: boxes += self.build_boxes diff --git a/system/TestMain.py b/system/TestMain.py index 33d6aba..138e1d3 100755 --- a/system/TestMain.py +++ b/system/TestMain.py @@ -155,6 +155,8 @@ steps refer to a method in TestPlc or to a step_* module help="Specify the set of hostnames for the boxes that host the nodes") parser.add_option("-N","--nodes",action="append", dest="ips_vnode", default=[], help="Specify the set of hostname/IP's to use for vnodes") + parser.add_option ('-X', "--lxc",action='store_true',dest='plcs_use_lxc', + help='use lxc-enabled plc boxes instead of vs-enabled ones') parser.add_option("-s","--size",action="store",type="int",dest="size",default=1, help="sets test size in # of plcs - default is 1") parser.add_option("-q","--qualifier",action="store",type="int",dest="qualifier",default=None, @@ -300,6 +302,7 @@ steps refer to a method in TestPlc or to a step_* module raise # provision on local substrate + if self.options.plcs_use_lxc: LocalSubstrate.local_substrate.rescope (plcs_on_vs=False, plcs_on_lxc=True) all_plc_specs = LocalSubstrate.local_substrate.provision(all_plc_specs,self.options) # remember substrate IP address(es) for next run -- 2.43.0