step by step
[oweals/gnunet.git] / src / integration-tests / test_integration_bootstrap_and_connect.py.in
1 #!@PYTHON@
2 #    This file is part of GNUnet.
3 #    (C) 2010 Christian Grothoff (and other contributing authors)
4 #
5 #    GNUnet is free software; you can redistribute it and/or modify
6 #    it under the terms of the GNU General Public License as published
7 #    by the Free Software Foundation; either version 2, or (at your
8 #    option) any later version.
9 #
10 #    GNUnet is distributed in the hope that it will be useful, but
11 #    WITHOUT ANY WARRANTY; without even the implied warranty of
12 #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13 #    General Public License for more details.
14 #
15 #    You should have received a copy of the GNU General Public License
16 #    along with GNUnet; see the file COPYING.  If not, write to the
17 #    Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 #    Boston, MA 02111-1307, USA.
19 #
20
21 import sys
22 import os
23 import subprocess
24 import re
25 import shutil
26
27 #
28 # This test tests if a fresh peer bootstraps from a hostlist server and then
29 # successfully connects to the server 
30 #
31
32 #definitions
33
34 def vpfrint (msg):
35     if verbose == True:
36         print msg
37
38
39 testname = "test_integration_bootstrap_and_connect"
40 verbose = True
41
42 # setup
43
44 srcdir = "../.."
45 gnunet_pyexpect_dir = os.path.join (srcdir, "contrib")
46 if gnunet_pyexpect_dir not in sys.path:
47   sys.path.append (gnunet_pyexpect_dir)
48
49 from gnunet_pyexpect import pexpect
50
51 if os.name == 'posix':
52   gnunetarm = 'gnunet-arm'
53 elif os.name == 'nt':
54   gnunetarm = 'gnunet-arm.exe'
55
56 if os.name == "nt":
57   shutil.rmtree (os.path.join (os.getenv ("TEMP"), testname), True)
58 else:
59   shutil.rmtree ("/tmp/" + testname, True)
60
61 vpfrint ("Running " + testname)
62
63
64
65 # start nodes
66
67 vpfrint ("Starting bootstrap server & client")
68 try:
69     server = subprocess.Popen ([gnunetarm, '-sq', '-c', './confs/c_bootstrap_server.conf'])
70     server.communicate ()    
71 except OSError:
72     print "Can not start bootstrap server, exiting..."
73     exit (1)
74 try:
75     client = subprocess.Popen ([gnunetarm, '-sq', '-c', 'confs/c_no_nat_client.conf'])
76     client.communicate ()    
77 except OSError:
78     print "Can not start bootstrap client, exiting..."
79     exit (1)
80 vpfrint ("Bootstrap server & client started")
81
82
83 import time
84 time.sleep(5)
85
86 # shutdown
87 vpfrint ("Shutting down bootstrap server")
88 try:
89     server = subprocess.Popen ([gnunetarm, '-eq', '-c', './confs/c_bootstrap_server.conf'])
90     server.communicate ()    
91 except OSError:
92     print "Can not stop bootstrap server, exiting..."
93     exit (1)
94 try:
95     client = subprocess.Popen ([gnunetarm, '-eq', '-c', 'confs/c_no_nat_client.conf'])
96     client.communicate ()    
97 except OSError:
98     print "Can not stop bootstrap client, exiting..."
99     exit (1)
100 vpfrint ("Bootstrap server & client stopped")
101
102 # clean up
103
104 if os.name == "nt":
105     shutil.rmtree (os.path.join (os.getenv ("TEMP"), "gnunet-test-fs-py-ns"), True)
106 else:
107     shutil.rmtree ("/tmp/gnunet-test-fs-py-ns", True)
108
109 exit (0)
110