attempt to fix missing method TestSsh.hostname + various redesign
authorThierry Parmentelat <thierry.parmentelat@sophia.inria.fr>
Tue, 25 Mar 2008 10:20:12 +0000 (10:20 +0000)
committerThierry Parmentelat <thierry.parmentelat@sophia.inria.fr>
Tue, 25 Mar 2008 10:20:12 +0000 (10:20 +0000)
system/TestBox.py
system/TestPlc.py
system/TestSsh.py
system/config_onelab.py
system/utils.py

index 9945f0c..b2f6ab2 100644 (file)
@@ -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"):
index 801c771..4dbfa8a 100644 (file)
@@ -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):
index dd0d324..761d5e6 100644 (file)
@@ -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):
index e456bd5..bb96298 100644 (file)
@@ -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',
index 2d30edc..c4adcb6 100644 (file)
@@ -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