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_core_session_map = False
52 server_fs_connected = False
54 client_transport_connected = False
55 client_topology_connected = False
56 client_core_connected = False
57 client_core_session_map = False
58 client_fs_connected = False
66 gnunet_pyexpect_dir = os.path.join (srcdir, "contrib")
67 if gnunet_pyexpect_dir not in sys.path:
68 sys.path.append (gnunet_pyexpect_dir)
69 from gnunet_pyexpect import pexpect
71 global gnunetstatistics
72 if os.name == 'posix':
73 gnunetarm = 'gnunet-arm'
74 gnunetstatistics = 'gnunet-statistics'
76 gnunetarm = 'gnunet-arm.exe'
77 gnunetstatistics = 'gnunet-statistics.exe'
79 shutil.rmtree (os.path.join (os.getenv ("TEMP"), testname), True)
81 shutil.rmtree ("/tmp/" + testname, True)
84 vprintf ("Starting bootstrap server & client")
86 server = subprocess.Popen ([gnunetarm, '-sq', '-c', './confs/c_bootstrap_server.conf'])
89 print "Can not start bootstrap server, exiting..."
92 client = subprocess.Popen ([gnunetarm, '-sq', '-c', 'confs/c_no_nat_client.conf'])
95 print "Can not start bootstrap client, exiting..."
97 vprintf ("Bootstrap server & client started")
100 vprintf ("Shutting down bootstrap server")
102 server = subprocess.Popen ([gnunetarm, '-eq', '-c', './confs/c_bootstrap_server.conf'])
103 server.communicate ()
105 print "Can not stop bootstrap server, exiting..."
108 client = subprocess.Popen ([gnunetarm, '-eq', '-c', 'confs/c_no_nat_client.conf'])
109 client.communicate ()
111 print "Can not stop bootstrap client, exiting..."
113 vprintf ("Bootstrap server & client stopped")
118 shutil.rmtree (os.path.join (os.getenv ("TEMP"), "gnunet-test-fs-py-ns"), True)
119 shutil.rmtree (os.path.join (os.getenv ("TEMP"), "c_no_nat_client"), True)
121 shutil.rmtree ("/tmp/c_bootstrap_server/", True)
122 shutil.rmtree ("/tmp/c_no_nat_client/", True)
124 def check_statistics (conf, subsystem, name, value):
125 from gnunet_pyexpect import pexpect
127 server.spawn (None, [gnunetstatistics, '-c', conf ,'-q','-n', name, '-s', subsystem ], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
128 #server.expect ("stdout", re.compile (r""))
129 test = server.read("stdout", 10240)
130 if (test.find(str(value)) == -1):
141 global server_transport_connected
142 global server_topology_connected
143 global server_core_connected
144 global server_core_session_map
145 global server_fs_connected
147 global client_transport_connected
148 global client_topology_connected
149 global client_core_connected
150 global client_core_session_map
151 global client_fs_connected
154 while ((success == False) and (count <= timeout)):
156 if ((False == server_transport_connected) and (True == check_statistics ('./confs/c_bootstrap_server.conf', 'transport', '# peers connected',1))):
157 server_transport_connected = True
158 vprintf ('Server transport services is connected')
160 if ((False == client_transport_connected) and (True == check_statistics ('./confs/c_no_nat_client.conf', 'transport', '# peers connected',1))):
161 client_transport_connected = True
162 vprintf ('Client transport services is connected')
164 if ((False == server_core_connected) and (True == check_statistics ('./confs/c_bootstrap_server.conf', 'core', '# neighbour entries allocated',1))):
165 server_core_connected = True
166 vprintf ('Server core services is connected')
168 if ((False == client_core_connected) and (True == check_statistics ('./confs/c_no_nat_client.conf', 'core', '# neighbour entries allocated',1))):
169 client_core_connected = True
170 vprintf ('Client core services is connected')
172 if ((False == server_core_session_map) and (True == check_statistics ('./confs/c_bootstrap_server.conf', 'core', '# entries in session map',1))):
173 server_core_session_map = True
174 vprintf ('Server core services is connected')
176 if ((False == client_core_session_map) and (True == check_statistics ('./confs/c_no_nat_client.conf', 'core', '# entries in session map',1))):
177 client_core_session_map = True
178 vprintf ('Client core notifies about connected')
180 if ((False == server_topology_connected) and (True == check_statistics ('./confs/c_bootstrap_server.conf', 'topology', '# peers connected',1))):
181 server_topology_connected = True
182 vprintf ('Server topology services is connected')
184 if ((False == client_topology_connected) and (True == check_statistics ('./confs/c_no_nat_client.conf', 'topology', '# peers connected',1))):
185 client_topology_connected = True
186 vprintf ('Client topology services is connected')
188 if ((False == client_fs_connected) and (True == check_statistics ('./confs/c_no_nat_client.conf', 'fs', '# peers connected',1))):
189 client_fs_connected = True
190 vprintf ('Client fs services is connected')
191 if ((False == server_fs_connected) and (True == check_statistics ('./confs/c_bootstrap_server.conf', 'fs', '# peers connected',1))):
192 server_fs_connected = True
193 vprintf ('Server fs services is connected')
195 # Check if conditions fulfilled
196 if ((True == client_transport_connected) and (True == server_transport_connected) and
197 (True == client_topology_connected) and (True == server_topology_connected) and
198 (True == client_core_connected) and (True == server_core_connected) and
199 (True == client_core_session_map) and (True == server_core_session_map) and
200 (True == client_fs_connected) and (True == server_fs_connected)):
206 if (success == False):
208 if (client_transport_connected == False):
209 print ('Client transport was NOT connected')
210 if (server_transport_connected == False):
211 print ('Server transport was NOT connected')
212 if (client_topology_connected == False):
213 print ('Client topology was NOT connected')
214 if (server_topology_connected == False):
215 print ('Server topology was NOT connected')
216 if (client_core_connected == False):
217 print ('Client core was NOT connected')
218 if (server_core_connected == False):
219 print ('Server core was NOT connected')
220 if (client_core_session_map == False):
221 print ('Client core sessions did NOT increase')
222 if (server_core_session_map == False):
223 print ('Server core sessions did NOT increase')
229 vprintf ("Running " + testname)
238 if (success == False):
239 print ('Test failed')