From: Thierry Parmentelat Date: Tue, 25 Mar 2008 14:48:49 +0000 (+0000) Subject: first step towards a cleaner TestSsh, buildname provided to constructor X-Git-Tag: tests-4.2-4~172 X-Git-Url: http://git.onelab.eu/?a=commitdiff_plain;h=591216968031ba65140a04ae261e3a755ced4dce;p=tests.git first step towards a cleaner TestSsh, buildname provided to constructor --- diff --git a/system/TestBox.py b/system/TestBox.py index 6c24959..fe17923 100644 --- a/system/TestBox.py +++ b/system/TestBox.py @@ -11,7 +11,7 @@ class TestBox: self.hostname_value=hostname self.buildname=buildname self.key=key - self.test_ssh=TestSsh(self) + self.test_ssh=TestSsh(self,buildname) def hostname (self): return self.hostname_value diff --git a/system/TestSsh.py b/system/TestSsh.py index 86bb28e..0e9495d 100644 --- a/system/TestSsh.py +++ b/system/TestSsh.py @@ -35,15 +35,16 @@ class TestSsh: utils.header("WARNING : something wrong in is_local_hostname with hostname=%s"%hostname) return False - def __init__(self,caller): + # buildname is the name of a directory that we can use in $hostname's homedir (/root) + def __init__(self,caller,buildname=None,key=None): self.caller=caller + self.buildname=buildname + self._key=key def hostname(self): return self.caller.hostname() def is_local(self): return TestSsh.is_local_hostname(self.hostname()) - def buildname(self): - return self.caller.buildname() # command gets run on the right box def to_host(self,command): @@ -66,22 +67,28 @@ class TestSsh: return utils.system(local+" | "+self.full_command(remote)) def run_in_buildname (self,command): + if not self.buildname: + utils.header ("WARNING : TestSsh.run_in_buildname without a buildname") + return 1 if self.is_local(): return utils.system(command) ssh_command="ssh " if self.caller.key: ssh_command += "-i %s.rsa "%(self.caller.key) - ssh_command += "%s/%s"%(self.buildname(),TestSsh.backslash_shell_specials(command)) + ssh_command += "%s/%s"%(self.buildname,TestSsh.backslash_shell_specials(command)) return utils.system(ssh_command) def copy (self,local_file,recursive=False): + if not self.buildname: + utils.header ("WARNING : TestSsh.copy without a buildname") + return 1 if self.is_local(): return 0 command="scp " if recursive: command += "-r " if self.caller.key: command += "-i %s.rsa " - command +="%s %s:%s/%s"%(local_file,self.hostname(),self.buildname(), + command +="%s %s:%s/%s"%(local_file,self.hostname(),self.buildname, os.path.basename(local_file) or ".") return utils.system(command)