From: Thierry Parmentelat Date: Tue, 27 Mar 2012 16:19:56 +0000 (+0200) Subject: more changes towards a dual vs/lxc test infra for plc's X-Git-Tag: tests-5.1-1~27 X-Git-Url: http://git.onelab.eu/?a=commitdiff_plain;h=93f5665ba1e6f7e5712c97b0d1396f037f0aa20c;p=tests.git more changes towards a dual vs/lxc test infra for plc's --- diff --git a/system/Substrate.py b/system/Substrate.py index af6c724..f260ef6 100644 --- a/system/Substrate.py +++ b/system/Substrate.py @@ -346,7 +346,7 @@ class BuildBox (Box): def reboot (self, options): if not options.soft: - self.reboot(options) + Box.reboot(self,options) else: command=['pkill','vbuild'] self.run_ssh(command,"Terminating vbuild processes",dry_run=options.dry_run) @@ -420,10 +420,10 @@ class PlcLxcInstance (PlcInstance): self.lxcname = lxcname def kill (self): - print "TODO PlcLxcInstance.kill" + print "TODO lxc PlcLxcInstance.kill ..." def line (self): - return "TODO PlcLxcInstance.line" + return "TODO lxc PlcLxcInstance.line with lxcname=%s"%(self.lxcname) ########## class PlcBox (Box): @@ -432,18 +432,8 @@ class PlcBox (Box): 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(PlcVsInstance(self,vservername,ctxid)) - - def forget (self, plc_instance): - self.plc_instances.remove(plc_instance) + def free_slots (self): + return self.max_plcs - len(self.plc_instances) # fill one slot even though this one is not started yet def add_dummy (self, plcname): @@ -451,41 +441,58 @@ class PlcVsBox (PlcBox): 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_slots(),self.uname()) - return msg - + def reboot (self, options): + if not options.soft: + self.reboot(options) + else: + self.soft_reboot (options) + def list(self): if not self.plc_instances: - header ('No vserver running on %s'%(self.line())) + header ('No plc running on %s'%(self.line())) else: header ("Active plc VMs on %s"%self.line()) self.plc_instances.sort(timestamp_sort) for p in self.plc_instances: header (p.line(),banner=False) - def free_slots (self): - return self.max_plcs - len(self.plc_instances) + def get_uname(self): + self._uname=self.backquote_ssh(['uname','-r']).strip() + # expecting sense () to have filled self._uname def uname(self): if hasattr(self,'_uname') and self._uname: return self._uname return '*undef* uname' +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(PlcVsInstance(self,vservername,ctxid)) + + def forget (self, plc_instance): + self.plc_instances.remove(plc_instance) + + def line(self): + msg="%s [max=%d,%d free, VS-based] (%s)"%(self.hostname, self.max_plcs,self.free_slots(),self.uname()) + return msg + def plc_instance_by_vservername (self, vservername): for p in self.plc_instances: if p.vservername==vservername: return p return None - def reboot (self, options): - if not options.soft: - self.reboot(options) - else: - self.run_ssh(['service','util-vserver','stop'],"Stopping all running vservers", - dry_run=options.dry_run) + def soft_reboot (self, options): + self.run_ssh(['service','util-vserver','stop'],"Stopping all running vservers", + dry_run=options.dry_run) def sense (self, options): print 'p', - self._uname=self.backquote_ssh(['uname','-r']).strip() + self.get_uname() # try to find fullname (vserver_stat truncates to a ridiculously short name) # fetch the contexts for all vservers on that box map_command=['grep','.','/etc/vservers/*/context','/dev/null',] @@ -536,20 +543,21 @@ class PlcVsBox (PlcBox): 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" + # a line describing the box + def line(self): + msg="%s [max=%d,%d free, LXC-based] (%s)"%(self.hostname, self.max_plcs,self.free_slots(),self.uname()) + return msg + + # essentially shutdown all running containers + def soft_reboot (self, options): + print "TODO lxc PlcLxcBox.soft_reboot" + # sense is expected to fill self.plc_instances with PlcLxcInstance's + # to describe the currently running VM's + # as well as to call self.get_uname() once def sense (self, options): - print "TODO PlcLxcBox.sense" + print "p(lxc) - todo (PlcLxcBox.sense)", + self.get_uname() ############################################################ diff --git a/system/TestMain.py b/system/TestMain.py index 138e1d3..f78407c 100755 --- a/system/TestMain.py +++ b/system/TestMain.py @@ -207,20 +207,24 @@ steps refer to a method in TestPlc or to a step_* module ('personality','arg-personality',"linux64",None), ('pldistro','arg-pldistro',"onelab",None), ('fcdistro','arg-fcdistro','f14',None), + ('plcs_use_lxc','arg-plcs-use-lxc',False,None), ) : # print 'handling',recname path=filename is_list = isinstance(default,list) + is_bool = isinstance(default,bool) if not getattr(self.options,recname): try: parsed=file(path).readlines() - if not is_list: # strings + if is_list: # lists + parsed=[x.strip() for x in parsed] + else: # strings and booleans if len(parsed) != 1: print "%s - error when parsing %s"%(sys.argv[1],path) sys.exit(1) parsed=parsed[0].strip() - else: # lists - parsed=[x.strip() for x in parsed] + if is_bool: + parsed = parsed.lower()=='true' setattr(self.options,recname,parsed) except: if default != "": @@ -232,11 +236,11 @@ steps refer to a method in TestPlc or to a step_* module # save for next run fsave=open(path,"w") - if not is_list: - fsave.write(getattr(self.options,recname) + "\n") - else: + if is_list: # lists for value in getattr(self.options,recname): fsave.write(value + "\n") + else: # strings and booleans - just call str() + fsave.write(str(getattr(self.options,recname)) + "\n") fsave.close() # utils.header('Saved %s into %s'%(recname,filename))