From: Thierry Parmentelat Date: Tue, 25 Mar 2008 10:20:12 +0000 (+0000) Subject: attempt to fix missing method TestSsh.hostname + various redesign X-Git-Tag: tests-4.2-4~180 X-Git-Url: http://git.onelab.eu/?a=commitdiff_plain;h=d2cac6fc8ecef992022fe39890408e713e0945b4;p=tests.git attempt to fix missing method TestSsh.hostname + various redesign --- diff --git a/system/TestBox.py b/system/TestBox.py index 9945f0c..b2f6ab2 100644 --- a/system/TestBox.py +++ b/system/TestBox.py @@ -17,7 +17,7 @@ class TestBox: return self.hostname_value def is_local(self): - return utils.is_local (self.hostname()) + return TestSsh.is_local (self.hostname()) def tar_logs(self): if os.path.isdir("nodeslogs"): diff --git a/system/TestPlc.py b/system/TestPlc.py index 801c771..4dbfa8a 100644 --- a/system/TestPlc.py +++ b/system/TestPlc.py @@ -59,7 +59,7 @@ class TestPlc: return self.plc_spec['hostname'] def is_local (self): - return utils.is_local(self.hostname()) + return TestSsh.is_local(self.hostname()) # define the API methods on this object through xmlrpc # would help, but not strictly necessary @@ -71,7 +71,7 @@ class TestPlc: if self.vserver: return "vserver %s exec %s"%(self.vservername,command) else: - return "chroot /plc/root %s"%utils.backslash_shell_specials(command) + return "chroot /plc/root %s"%TestSsh.backslash_shell_specials(command) # copy a file to the myplc root image - pass in_data=True if the file must go in /plc/data def copy_in_guest (self, localfile, remotefile, in_data=False): diff --git a/system/TestSsh.py b/system/TestSsh.py index dd0d324..761d5e6 100644 --- a/system/TestSsh.py +++ b/system/TestSsh.py @@ -9,11 +9,36 @@ import utils class TestSsh: + # inserts a backslash before each occurence of the following chars + # \ " ' < > & | ; ( ) $ * ~ + @staticmethod + def backslash_shell_specials (command): + result='' + for char in command: + if char in "\\\"'<>&|;()$*~": + result +='\\'+char + else: + result +=char + return result + + # check main IP address against the provided hostname + @staticmethod + def is_local (hostname): + if hostname == "localhost": + return True + import socket + try: + local_ip = socket.gethostbyname(socket.gethostname()) + remote_ip = socket.gethostbyname(hostname) + return local_ip==remote_ip + except: + header("WARNING : something wrong in is_local with hostname=%s"%hostname) + return False + def __init__(self,caller): self.caller=caller - - def hostanme(self): + def hostname(self): return self.caller.hostname() def is_local(self): return self.caller.is_local() @@ -25,7 +50,7 @@ class TestSsh: if self.caller.is_local(): return command else: - return "ssh %s %s"%(self.hostname(),utils.backslash_shell_specials(command)) + return "ssh %s %s"%(self.hostname(),TestSsh.backslash_shell_specials(command)) def full_command(self,command): return self.to_host(self.caller.host_to_guest(command)) @@ -46,7 +71,7 @@ class TestSsh: ssh_comand="ssh " if self.caller.key: ssh_comand += "-i %s.rsa "%(self.caller.key) - ssh_command += "%s/%s"%(self.buildname,utils.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): diff --git a/system/config_onelab.py b/system/config_onelab.py index e456bd5..bb96298 100644 --- a/system/config_onelab.py +++ b/system/config_onelab.py @@ -11,7 +11,7 @@ onelab="one-lab.org" def nodes(): nodes= [{'node_fields': {'hostname': 'lysithea.inria.fr', 'model':'qemu/minhw', } , - 'host_box': 'test.one-lab.org', + 'host_box': 'testbox1.one-lab.org', 'owner' : 'pi', 'network_fields': { 'method':'static', 'type':'ipv4', @@ -27,7 +27,7 @@ def nodes(): }, {'node_fields': {'hostname': 'pluton.inria.fr', 'model':'qemu/minhw', } , - 'host_box': 'test.one-lab.org', + 'host_box': 'testbox1.one-lab.org', 'owner' : 'pi', 'network_fields': { 'method':'static', 'type':'ipv4', diff --git a/system/utils.py b/system/utils.py index 2d30edc..c4adcb6 100644 --- a/system/utils.py +++ b/system/utils.py @@ -114,27 +114,4 @@ def check_ping (hostname): (status,output) = commands.getstatusoutput(command) return status == 0 -# inserts a backslash before each occurence of the following chars -# \ " ' < > & | ; ( ) $ * ~ -def backslash_shell_specials (command): - result='' - for char in command: - if char in "\\\"'<>&|;()$*~": - result +='\\'+char - else: - result +=char - return result - -# check main IP address against the provided hostname -def is_local (hostname): - if hostname == "localhost": - return True - import socket - try: - local_ip = socket.gethostbyname(socket.gethostname()) - remote_ip = socket.gethostbyname(hostname) - return local_ip==remote_ip - except: - header("WARNING : something wrong in is_local with hostname=%s"%hostname) - return False