2 # This file is part of GNUnet.
3 # (C) 2010 Christian Grothoff (and other contributing authors)
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.
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.
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.
30 # This test tests if a fresh peer bootstraps from a hostlist server and then
31 # successfully connects to the server
33 # Conditions for successful exit:
34 # Both peers have 1 connected peer in transport, core, topology, fs
38 testname = "test_integration_bootstrap_and_connect"
48 server_transport_connected = False
49 server_topology_connected = False
50 server_core_connected = False
51 server_fs_connected = False
53 client_transport_connected = False
54 client_topology_connected = False
55 client_core_connected = False
56 client_fs_connected = False
64 gnunet_pyexpect_dir = os.path.join (srcdir, "contrib")
65 if gnunet_pyexpect_dir not in sys.path:
66 sys.path.append (gnunet_pyexpect_dir)
67 from gnunet_pyexpect import pexpect
69 global gnunetstatistics
70 if os.name == 'posix':
71 gnunetarm = 'gnunet-arm'
72 gnunetstatistics = 'gnunet-statistics'
74 gnunetarm = 'gnunet-arm.exe'
75 gnunetstatistics = 'gnunet-statistics.exe'
77 shutil.rmtree (os.path.join (os.getenv ("TEMP"), testname), True)
79 shutil.rmtree ("/tmp/" + testname, True)
82 vprintf ("Starting bootstrap server & client")
84 server = subprocess.Popen ([gnunetarm, '-sq', '-c', './confs/c_bootstrap_server.conf'])
87 print "Can not start bootstrap server, exiting..."
90 client = subprocess.Popen ([gnunetarm, '-sq', '-c', 'confs/c_no_nat_client.conf'])
93 print "Can not start bootstrap client, exiting..."
95 vprintf ("Bootstrap server & client started")
98 vprintf ("Shutting down bootstrap server")
100 server = subprocess.Popen ([gnunetarm, '-eq', '-c', './confs/c_bootstrap_server.conf'])
101 server.communicate ()
103 print "Can not stop bootstrap server, exiting..."
106 client = subprocess.Popen ([gnunetarm, '-eq', '-c', 'confs/c_no_nat_client.conf'])
107 client.communicate ()
109 print "Can not stop bootstrap client, exiting..."
111 vprintf ("Bootstrap server & client stopped")
116 shutil.rmtree (os.path.join (os.getenv ("TEMP"), "gnunet-test-fs-py-ns"), True)
117 shutil.rmtree (os.path.join (os.getenv ("TEMP"), "c_no_nat_client"), True)
119 shutil.rmtree ("/tmp/c_bootstrap_server/", True)
120 shutil.rmtree ("/tmp/c_no_nat_client/", True)
122 def check_statistics (conf, subsystem, name, value):
123 from gnunet_pyexpect import pexpect
125 server.spawn (None, [gnunetstatistics, '-c', conf ,'-q','-n', name, '-s', subsystem ], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
126 #server.expect ("stdout", re.compile (r""))
127 test = server.read("stdout", 10240)
128 if (test.find(str(value)) == -1):
139 global server_transport_connected
140 global server_topology_connected
141 global server_core_connected
142 global server_fs_connected
144 global client_transport_connected
145 global client_topology_connected
146 global client_core_connected
147 global client_fs_connected
150 while ((success == False) and (count <= timeout)):
152 if ((False == server_transport_connected) and (True == check_statistics ('./confs/c_bootstrap_server.conf', 'transport', '# peers connected',1))):
153 server_transport_connected = True
154 vprintf ('Server transport services is connected')
156 if ((False == client_transport_connected) and (True == check_statistics ('./confs/c_no_nat_client.conf', 'transport', '# peers connected',1))):
157 client_transport_connected = True
158 vprintf ('Client transport services is connected')
160 if ((False == server_core_connected) and (True == check_statistics ('./confs/c_bootstrap_server.conf', 'core', '# neighbour entries allocated',1))):
161 server_core_connected = True
162 vprintf ('Server core services is connected')
164 if ((False == client_core_connected) and (True == check_statistics ('./confs/c_no_nat_client.conf', 'core', '# neighbour entries allocated',1))):
165 client_core_connected = True
166 vprintf ('Client core services is connected')
168 if ((False == server_topology_connected) and (True == check_statistics ('./confs/c_bootstrap_server.conf', 'topology', '# peers connected',1))):
169 server_topology_connected = True
170 vprintf ('Server topology services is connected')
172 if ((False == client_topology_connected) and (True == check_statistics ('./confs/c_no_nat_client.conf', 'topology', '# peers connected',1))):
173 client_topology_connected = True
174 vprintf ('Client topology services is connected')
176 if ((False == client_fs_connected) and (True == check_statistics ('./confs/c_no_nat_client.conf', 'fs', '# peers connected',1))):
177 client_fs_connected = True
178 vprintf ('Client fs services is connected')
179 if ((False == server_fs_connected) and (True == check_statistics ('./confs/c_bootstrap_server.conf', 'fs', '# peers connected',1))):
180 server_fs_connected = True
181 vprintf ('Server fs services is connected')
183 # Check if conditions fulfilled
184 if ((True == client_transport_connected) and (True == server_transport_connected) and
185 (True == client_topology_connected) and (True == server_topology_connected) and
186 (True == client_core_connected) and (True == server_core_connected) and
187 (True == client_fs_connected) and (True == server_fs_connected)):
193 if (success == False):
194 if (client_transport_connected == False):
195 print ('Client transport was NOT connected')
196 if (server_transport_connected == False):
197 print ('Server transport was NOT connected')
198 if (client_topology_connected == False):
199 print ('Client topology was NOT connected')
200 if (server_topology_connected == False):
201 print ('Server topology was NOT connected')
202 if (client_core_connected == False):
203 print ('Client core was NOT connected')
204 if (server_core_connected == False):
205 print ('Server core was NOT connected')
211 vprintf ("Running " + testname)
220 if (success == False):
221 print ('Test failed')
224 print ('Test successful')