From: Thierry Parmentelat Date: Tue, 1 Apr 2008 15:57:00 +0000 (+0000) Subject: remote chroot-myplc and remote qemu testbox should almost work X-Git-Tag: tests-4.2-4~111 X-Git-Url: http://git.onelab.eu/?a=commitdiff_plain;h=2b0ea6d27b0f551871288079a7aea90483992db3;p=tests.git remote chroot-myplc and remote qemu testbox should almost work --- diff --git a/system/TestKey.py b/system/TestKey.py index d411a90..4df0b48 100644 --- a/system/TestKey.py +++ b/system/TestKey.py @@ -23,11 +23,11 @@ class TestKey: priv=self.privatepath() utils.header("Storing key %s in %s into %s "%(self.name(),pub,hostname)) dir=os.path.dirname(pub) - utils.system(self.test_ssh.to_host("mkdir %s"%dir)) - utils.system(self.test_ssh.to_host("cat %s >> %s"%(self.key_spec['key_fields']['key'],pub))) - utils.system(self.test_ssh.to_host("cat %s >> %s"%(self.key_spec['private'],priv))) - utils.system(self.test_ssh.to_host("chmod %s 0400"%priv)) - utils.system(self.test_ssh.to_host("chmod %s 0444"%pub)) + self.test_ssh.run("mkdir %s"%dir) + self.test_ssh.run("cat %s >> %s"%(self.key_spec['key_fields']['key'],pub)) + self.test_ssh.run("cat %s >> %s"%(self.key_spec['private'],priv)) + self.test_ssh.run("chmod %s 0400"%priv) + self.test_ssh.run("chmod %s 0444"%pub) def store_key(self): pub=self.publicpath() diff --git a/system/TestMain.py b/system/TestMain.py index 089ee1b..1135845 100755 --- a/system/TestMain.py +++ b/system/TestMain.py @@ -179,10 +179,7 @@ steps refer to a method in TestPlc or to a step_* module # 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] - # expose to the various objects - for (spec,obj) in all_plcs: - obj.options=self.options + all_plcs = [ (x, TestPlc(x,self.options)) for x in all_plc_specs] overall_result = True testplc_method_dict = __import__("TestPlc").__dict__['TestPlc'].__dict__ diff --git a/system/TestNode.py b/system/TestNode.py index d44a159..0624269 100644 --- a/system/TestNode.py +++ b/system/TestNode.py @@ -30,7 +30,7 @@ class TestNode: def buildname(self): return self.test_plc.options.buildname - def areaname (self): + def nodedir (self): if self.is_qemu(): return "qemu-%s"%self.name() else: @@ -103,12 +103,12 @@ class TestNode: # Do most of the stuff locally - will be pushed on host_box - *not* the plc - later if needed def prepare_area(self): - utils.system("rm -rf %s"%self.areaname()) - utils.system("mkdir %s"%self.areaname()) + utils.system("rm -rf %s"%self.nodedir()) + utils.system("mkdir %s"%self.nodedir()) #create the tar log file utils.system("rm -rf nodeslogs && mkdir nodeslogs") if self.is_qemu(): - utils.system("rsync -v -a --exclude .svn template-qemu/ %s/"%self.areaname()) + utils.system("rsync -v -a --exclude .svn template-qemu/ %s/"%self.nodedir()) def create_boot_cd(self): utils.header("Calling GetBootMedium for %s"%self.name()) @@ -119,7 +119,7 @@ class TestNode: if (encoded == ''): raise Exception, 'GetBootmedium failed' - filename="%s/%s.iso"%(self.areaname(),self.name()) + filename="%s/%s.iso"%(self.nodedir(),self.name()) utils.header('Storing boot medium into %s'%filename) file(filename,'w').write(base64.b64decode(encoded)) @@ -128,7 +128,7 @@ class TestNode: return mac=self.node_spec['network_fields']['mac'] hostname=self.node_spec['node_fields']['hostname'] - conf_filename="%s/qemu.conf"%(self.areaname()) + conf_filename="%s/qemu.conf"%(self.nodedir()) utils.header('Storing qemu config for %s in %s'%(self.name(),conf_filename)) file=open(conf_filename,'w') file.write('MACADDR=%s\n'%mac) @@ -139,10 +139,9 @@ class TestNode: # if relevant, push the qemu area onto the host box if ( not self.test_box().is_local()): utils.header ("Transferring configuration files for node %s onto %s"%(self.name(),self.host_box())) - self.test_box().clean_dir(self.buildname()) - self.test_box().mkdir(self.buildname()) +# self.test_box().clean_dir(self.buildname()) self.test_box().mkdir("nodeslogs") - self.test_box().copy(self.areaname(),recursive=True) + self.test_box().copy(self.nodedir(),recursive=True) def start_node (self,options): diff --git a/system/TestPlc.py b/system/TestPlc.py index fe7bd44..b7da2f8 100644 --- a/system/TestPlc.py +++ b/system/TestPlc.py @@ -21,9 +21,9 @@ from TestSsh import TestSsh # step methods must take (self, options) and return a boolean def standby(minutes): - utils.header('Entering StandBy for %d mn'%minutes) - time.sleep(60*minutes) - return True + utils.header('Entering StandBy for %d mn'%minutes) + time.sleep(60*minutes) + return True def standby_generic (func): def actual(self,options): @@ -33,10 +33,10 @@ def standby_generic (func): class TestPlc: - def __init__ (self,plc_spec): + def __init__ (self,plc_spec,options): self.plc_spec=plc_spec - self.path=os.path.dirname(sys.argv[0]) - self.test_ssh=TestSsh(self.plc_spec['hostname'],self.path) + self.options=options + self.test_ssh=TestSsh(self.plc_spec['hostname'],self.options.buildname) try: self.vserverip=plc_spec['vserverip'] self.vservername=plc_spec['vservername'] @@ -66,14 +66,11 @@ class TestPlc: def connect (self): pass - def full_command(self,command): - return self.test_ssh.to_host(self.host_to_guest(command)) - def run_in_guest (self,command): - return utils.system(self.full_command(command)) + return self.test_ssh.run(self.host_to_guest(command)) def run_in_host (self,command): - return utils.system(self.test_ssh.to_host(command)) + return self.test_ssh.run_in_buildname(command) #command gets run in the chroot/vserver def host_to_guest(self,command): @@ -102,8 +99,7 @@ class TestPlc: # xxx quick n dirty def run_in_guest_piped (self,local,remote): - return utils.system(local+" | "+self.full_command(remote)) - + return utils.system(local+" | "+self.test_ssh.actual_command(self.host_to_guest(remote))) def auth_root (self): return {'Username':self.plc_spec['PLC_ROOT_USER'], @@ -215,7 +211,7 @@ class TestPlc: ##### Clean up the /plc directory self.run_in_host('rm -rf /plc/data') ##### stop any running vservers - self.run_in_host('for vserver in $(ls /vservers/* | sed -e s,/vservers/,,) ; do vserver $vserver stop ; done') + self.run_in_host('for vserver in $(ls -d /vservers/* | sed -e s,/vservers/,,) ; do case $vserver in vtest*) echo Shutting down vserver $vserver ; vserver $vserver stop ;; esac ; done') return True def uninstall_vserver(self,options): @@ -242,7 +238,7 @@ class TestPlc: # we need build dir for vtest-init-vserver if self.is_local(): # a full path for the local calls - build_dir=self.path+"/build" + build_dir=os.path(sys.argv[0])+"/build" else: # use a standard name - will be relative to HOME build_dir="options.buildname" @@ -268,19 +264,16 @@ class TestPlc: return self.install_chroot(options) ### install_rpm - def cache_rpm(self,url): - self.run_in_host('rm -rf *.rpm') - utils.header('Curling rpm from %s'%url) - id= self.run_in_host('curl -O '+url) + def cache_rpm(self,url,rpm): + cache_fetch="pwd;if [ -f %(rpm)s ] ; then echo Using cached rpm %(rpm)s ; else echo Fetching %(url)s ; curl -O %(url)s; fi"%locals() + id = self.run_in_host(cache_fetch) if (id != 0): - raise Exception,"Could not get rpm from %s"%url - return False - return True + raise Exception,"Could not get rpm from %s"%url def install_rpm_chroot(self,options): - rpm = os.path.basename(options.myplc_url) - if (not os.path.isfile(rpm)): - self.cache_rpm(options.myplc_url) + url = self.options.myplc_url + rpm = os.path.basename(url) + self.cache_rpm(url,rpm) utils.header('Installing the : %s'%rpm) self.run_in_host('rpm -Uvh '+rpm) self.run_in_host('service plc mount') @@ -342,7 +335,7 @@ class TestPlc: return True def clean_keys(self, options): - utils.system("rm -rf %s/keys/"%self.path) + utils.system("rm -rf %s/keys/"%os.path(sys.argv[0])) def sites (self,options): return self.do_sites(options) @@ -526,7 +519,7 @@ class TestPlc: test_node.configure_qemu() return True - def do_check_intiscripts(self): + def do_check_initscripts(self): for site_spec in self.plc_spec['sites']: test_site = TestSite (self,site_spec) test_node = TestNode (self,test_site,site_spec['nodes']) @@ -539,7 +532,7 @@ class TestPlc: return init_status def check_initscripts(self, options): - return self.do_check_intiscripts() + return self.do_check_initscripts() def initscripts (self, options): for initscript in self.plc_spec['initscripts']: @@ -588,13 +581,13 @@ class TestPlc: return True def check_tcp (self, options): - #we just need to create a sliver object nothing else - test_sliver=TestSliver(self, - TestNode(self, TestSite(self,self.plc_spec['sites'][0]), - self.plc_spec['sites'][0]['nodes'][0]), - TestSlice(self,TestSite(self,self.plc_spec['sites'][0]), - self.plc_spec['slices'])) - return test_sliver.do_check_tcp(self.plc_spec['tcp_param'],options) + # we just need to create a sliver object nothing else + test_sliver=TestSliver(self, + TestNode(self, TestSite(self,self.plc_spec['sites'][0]), + self.plc_spec['sites'][0]['nodes'][0]), + TestSlice(self,TestSite(self,self.plc_spec['sites'][0]), + self.plc_spec['slices'])) + return test_sliver.do_check_tcp(self.plc_spec['tcp_param'],options) # returns the filename to use for sql dump/restore, using options.dbname if set def dbfile (self, database, options): diff --git a/system/TestSsh.py b/system/TestSsh.py index 38d514b..603b63e 100644 --- a/system/TestSsh.py +++ b/system/TestSsh.py @@ -38,44 +38,69 @@ class TestSsh: self.buildname=buildname self.key=key - def is_local(self): return TestSsh.is_local_hostname(self.hostname) + std_options="-o StrictHostKeyChecking=no -o BatchMode=yes " + + def key_part (self): + if not self.key: + return "" + return "-i %s.rsa "%self.key + # command gets run on the right box - def to_host(self,command): + def actual_command (self, command): if self.is_local(): return command - else: - return "ssh %s %s"%(self.hostname,TestSsh.backslash_shell_specials(command)) + ssh_command = "ssh " + ssh_command += TestSsh.std_options + ssh_command += self.key_part() + ssh_command += "%s %s" %(self.hostname,TestSsh.backslash_shell_specials(command)) + return ssh_command + + def run(self, command): + return utils.system(self.actual_command(command)) def clean_dir (self,dirname): if self.is_local(): return 0 - return utils.system(self.to_host("rm -rf %s"%dirname)) + return self.run("rm -rf %s"%dirname) - def mkdir (self,dirname): + def mkdir (self,dirname=None): if self.is_local(): + if dirname: + return os.path.mkdir(dirname) return 0 - return utils.system(self.to_host("mkdir %s"%dirname)) + if dirname: + dirname="%s/%s"%(self.buildname,dirname) + else: + dirname=self.buildname + return self.run("mkdir %s"%dirname) + + def create_buildname_once (self): + if self.is_local(): + return + # create remote buildname on demand + try: + self.buildname_created + except: + self.mkdir() + self.buildname_created=True def run_in_buildname (self,command): if self.is_local(): return utils.system(command) - ssh_command="ssh -o StrictHostKeyChecking=no -o BatchMode=yes " - if self.key: - ssh_command += "-i %s.rsa "%(self.key) - ssh_command += "%s %s/%s"%(self.hostname,self.buildname,TestSsh.backslash_shell_specials(command)) - return utils.system(ssh_command) + self.create_buildname_once() + return self.run("cd %s ; %s"%(self.buildname,command)) def copy (self,local_file,recursive=False): if self.is_local(): return 0 - command="scp " - if recursive: command += "-r " - if self.key: - command += "-i %s.rsa " - command +="%s %s:%s/%s"%(local_file,self.hostname,self.buildname, - os.path.basename(local_file) or ".") - return utils.system(command) + self.create_buildname_once() + scp_command="scp " + if recursive: scp_command += "-r " + scp_command += self.key_part() + scp_command += "%s %s:%s/%s"%(local_file,self.hostname,self.buildname, + os.path.basename(local_file) or ".") + return utils.system(scp_command)