rework check-tcp so that we first wait for the network to be ready in the sliver
[tests.git] / system / TestSliver.py
index cde09e8..f69e4c5 100644 (file)
@@ -1,3 +1,6 @@
+# Thierry Parmentelat <thierry.parmentelat@inria.fr>
+# Copyright (C) 2010 INRIA 
+#
 import utils
 import os, os.path
 import datetime
@@ -21,31 +24,43 @@ class TestSliver:
             print str(e)
             
     def create_test_ssh(self):
-        (found,privatekey) = self.get_privateKey()
-        if not found:
+        private_key = self.test_slice.locate_private_key()
+        if not private_key:
             raise Exception,"Cannot find the private key for slice %s"%self.test_slice.name()
-        return TestSsh (self.test_node.name(),key=privatekey,username=self.test_slice.name(),
+        return TestSsh (self.test_node.name(),key=private_key,username=self.test_slice.name(),
                         # so that copies end up in the home dir
                         buildname=".")
 
-    def name (self):
+    def name(self):
         return "%s@%s"%(self.test_slice.name(),self.test_node.name())
 
-    def check_initscript(self,initscript):
-        slice_spec=self.test_slice.slice_spec
-        initscript = slice_spec['initscriptname']
-        utils.header("Checking initscript %s on sliver %s"%(initscript,self.name()))
-        return self.test_ssh.run("ls -l /tmp/%s.stamp"%initscript)==0
+    def check_initscript_stamp(self, stamp):
+        utils.header("Checking for initscript stamp %s on sliver %s"%(stamp, self.name()))
+        return self.test_ssh.run("ls -l /var/tmp/%s.stamp"%stamp)==0
     
-    def run_tcp_server (self,port,timeout=10):
-        server_command = "./tcptest.py server -p %d -t %d"%(port,timeout)
-        return self.test_ssh.copy("tcptest.py")==0 and \
-            self.test_ssh.run(server_command,background=True)==0
+    def run_tcp_server (self, port, timeout=10):
+        server_command = "./tcptest.py server -p %d -t %d"%(port, timeout)
+        return self.test_ssh.copy("tcptest.py") == 0 and \
+            self.test_ssh.run(server_command, background=True)==0
+
+    def check_tcp_ready (self, port):
+        server_command = "./tcptest.py ready -p %d"%(port)
+        return self.test_ssh.copy("tcptest.py") == 0 and \
+            self.test_ssh.run(server_command) == 0
 
-    def run_tcp_client (self,servername,port):
-        client_command="./tcptest.py client -a %s -p %d"%(servername,port)
-        return self.test_ssh.copy("tcptest.py")==0 and \
-            self.test_ssh.run(client_command,background=True)==0
+    def run_tcp_client (self, servername, port, retry=5):
+        client_command="./tcptest.py client -a %s -p %d"%(servername, port)
+        if self.test_ssh.copy("tcptest.py") != 0:
+            return False
+        # allow for 2 attempts
+        attempts = 2
+        for attempt in range (attempts):
+            if attempt != 0:
+                time.sleep(retry)
+            utils.header ("tcp client - attempt # %s" % (attempt+1))
+            if self.test_ssh.run(client_command) == 0:
+                return True
+        return False
 
     # use the node's main ssh root entrance, as the slice entrance might be down
     #def tar_var_logs (self):