use new connecT API
[oweals/gnunet.git] / src / integration-tests / test_integration_bootstrap_and_connect.py.in
index afc55ca40ad53764868f5cd7ae5e7e04908a6e3f..73fb0b3bfb7da17d084bc874917af056f4ad9753 100755 (executable)
@@ -14,8 +14,8 @@
 #
 #    You should have received a copy of the GNU General Public License
 #    along with GNUnet; see the file COPYING.  If not, write to the
-#    Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-#    Boston, MA 02111-1307, USA.
+#    Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+#    Boston, MA 02110-1301, USA.
 #
 # 
 import signal
@@ -54,15 +54,28 @@ check_timeout = 180
 
 if os.name == "nt":
   tmp = os.getenv ("TEMP")
+  signals = [signal.SIGTERM, signal.SIGINT]
 else:
   tmp = "/tmp"
+  signals = [signal.SIGTERM, signal.SIGINT, signal.SIGHUP, signal.SIGQUIT]
+
+def cleanup_onerror (function, path, excinfo):
+  import stat
+  if not os.path.exists (path):
+    pass
+  elif not os.access(path, os.W_OK):
+    # Is the error an access error ?
+    os.chmod (path, stat.S_IWUSR)
+    function (path)
+  else:
+    raise
 
 def cleanup ():
     retries = 10
     path = os.path.join (tmp, "c_bootstrap_server")  
     test.p ("Removing " + path)      
     while ((os.path.exists(path)) and (retries > 0)):
-        shutil.rmtree ((path), False)
+        shutil.rmtree ((path), False, cleanup_onerror)
         time.sleep (1)
         retries -= 1
     if (os.path.exists(path)):
@@ -73,7 +86,7 @@ def cleanup ():
     path = os.path.join (tmp, "c_no_nat_client")    
     test.p ("Removing " + path)    
     while ((os.path.exists(path)) and (retries > 0)):
-        shutil.rmtree ((path), False)
+        shutil.rmtree ((path), False, cleanup_onerror)
         time.sleep (1)
         retries -= 1
     if (os.path.exists(path)):
@@ -120,7 +133,7 @@ def SigHandler(signum = None, frame = None):
        print 'Test was aborted!'
        if (None != server):
                server.stop ()
-       if (None != server):            
+       if (None != client):            
                client.stop ()
        cleanup ()
        sys.exit(success)
@@ -135,7 +148,7 @@ def run ():
        client = None
        success = False  
        
-       for sig in [signal.SIGTERM, signal.SIGINT, signal.SIGHUP, signal.SIGQUIT]:
+       for sig in signals:
                signal.signal(sig, SigHandler)
 
        test = Test ('test_integration_bootstrap_and_connect.py', verbose)
@@ -144,8 +157,26 @@ def run ():
        server = Peer(test, './confs/c_bootstrap_server.conf');
        client = Peer(test, './confs/c_no_nat_client.conf');
        
-       assert (True == server.start());
-       assert (True == client.start());
+       if (True != server.start()):
+               print 'Failed to start server'
+               if (None != server):
+                       server.stop ()
+               if (None != server):            
+                       client.stop ()
+               cleanup ()
+               sys.exit(success)
+               
+       # Give the server time to start
+       time.sleep(5)
+       
+       if (True != client.start()):
+               print 'Failed to start client'
+               if (None != server):
+                       server.stop ()
+               if (None != server):            
+                       client.stop ()
+               cleanup ()
+               sys.exit(success)
        
        if ((client.started == True) and (server.started == True)):
                test.p ('Peers started, running check')