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. When both peers are connected
32 # in transport, core, topology, fs, the server is shutdown
34 # Conditions for successful exit:
35 # Both peers have 0 connected peer in transport, core, topology, fs
39 testname = "test_integration_disconnect"
55 gnunet_pyexpect_dir = os.path.join (srcdir, "contrib")
56 if gnunet_pyexpect_dir not in sys.path:
57 sys.path.append (gnunet_pyexpect_dir)
58 from gnunet_pyexpect import pexpect
60 global gnunetstatistics
61 if os.name == 'posix':
62 gnunetarm = 'gnunet-arm'
63 gnunetstatistics = 'gnunet-statistics'
65 gnunetarm = 'gnunet-arm.exe'
66 gnunetstatistics = 'gnunet-statistics.exe'
68 shutil.rmtree (os.path.join (os.getenv ("TEMP"), testname), True)
70 shutil.rmtree ("/tmp/" + testname, True)
73 vprintf ("Starting bootstrap server & client")
75 server = subprocess.Popen ([gnunetarm, '-sq', '-c', './confs/c_bootstrap_server.conf'])
78 print "Can not start bootstrap server, exiting..."
81 client = subprocess.Popen ([gnunetarm, '-sq', '-c', 'confs/c_no_nat_client.conf'])
84 print "Can not start bootstrap client, exiting..."
86 vprintf ("Bootstrap server & client started")
90 client = subprocess.Popen ([gnunetarm, '-eq', '-c', 'confs/c_no_nat_client.conf'])
93 print "Can not stop bootstrap client, exiting..."
95 vprintf ("Bootstrap client stopped")
100 shutil.rmtree (os.path.join (os.getenv ("TEMP"), "gnunet-test-fs-py-ns"), True)
101 shutil.rmtree (os.path.join (os.getenv ("TEMP"), "c_no_nat_client"), True)
103 shutil.rmtree ("/tmp/c_bootstrap_server/", True)
104 shutil.rmtree ("/tmp/c_no_nat_client/", True)
106 def check_statistics (conf, subsystem, name, value):
107 from gnunet_pyexpect import pexpect
109 server.spawn (None, [gnunetstatistics, '-c', conf ,'-q','-n', name, '-s', subsystem ], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
110 #server.expect ("stdout", re.compile (r""))
111 test = server.read("stdout", 10240)
112 if (test.find(str(value)) == -1):
119 def check_connect ():
120 server_transport_connected = False
121 server_topology_connected = False
122 server_core_connected = False
123 server_core_session_map = False
124 server_fs_connected = False
125 client_transport_connected = False
126 client_topology_connected = False
127 client_core_connected = False
128 client_core_session_map = False
129 client_fs_connected = False
133 while ((connected == False) and (count <= timeout)):
135 if ((False == server_transport_connected) and (True == check_statistics ('./confs/c_bootstrap_server.conf', 'transport', '# peers connected',1))):
136 server_transport_connected = True
137 vprintf ('Server transport services is connected')
139 if ((False == client_transport_connected) and (True == check_statistics ('./confs/c_no_nat_client.conf', 'transport', '# peers connected',1))):
140 client_transport_connected = True
141 vprintf ('Client transport services is connected')
143 if ((False == server_core_connected) and (True == check_statistics ('./confs/c_bootstrap_server.conf', 'core', '# neighbour entries allocated',1))):
144 server_core_connected = True
145 vprintf ('Server core services is connected')
147 if ((False == client_core_connected) and (True == check_statistics ('./confs/c_no_nat_client.conf', 'core', '# neighbour entries allocated',1))):
148 client_core_connected = True
149 vprintf ('Client core services is connected')
151 if ((False == client_core_session_map) and (True == check_statistics ('./confs/c_bootstrap_server.conf', 'core', '# entries in session map',1))):
152 client_core_session_map = True
153 vprintf ('Server core services is connected')
155 if ((False == server_core_session_map) and (True == check_statistics ('./confs/c_no_nat_client.conf', 'core', '# entries in session map',1))):
156 server_core_session_map = True
157 vprintf ('Client core notifies about connected')
159 if ((False == server_topology_connected) and (True == check_statistics ('./confs/c_bootstrap_server.conf', 'topology', '# peers connected',1))):
160 server_topology_connected = True
161 vprintf ('Server topology services is connected')
163 if ((False == client_topology_connected) and (True == check_statistics ('./confs/c_no_nat_client.conf', 'topology', '# peers connected',1))):
164 client_topology_connected = True
165 vprintf ('Client topology services is connected')
167 if ((False == client_fs_connected) and (True == check_statistics ('./confs/c_no_nat_client.conf', 'fs', '# peers connected',1))):
168 client_fs_connected = True
169 vprintf ('Client fs services is connected')
170 if ((False == server_fs_connected) and (True == check_statistics ('./confs/c_bootstrap_server.conf', 'fs', '# peers connected',1))):
171 server_fs_connected = True
172 vprintf ('Server fs services is connected')
174 # Check if conditions fulfilled
175 if ((True == client_transport_connected) and (True == server_transport_connected) and
176 (True == client_topology_connected) and (True == server_topology_connected) and
177 (True == client_core_connected) and (True == server_core_connected) and
178 (True == client_core_session_map) and (True == server_core_session_map) and
179 (True == client_fs_connected) and (True == server_fs_connected)):
185 if (connected == False):
187 if (client_transport_connected == False):
188 print ('Client transport was NOT connected')
189 if (server_transport_connected == False):
190 print ('Server transport was NOT connected')
191 if (client_topology_connected == False):
192 print ('Client topology was NOT connected')
193 if (server_topology_connected == False):
194 print ('Server topology was NOT connected')
195 if (client_core_connected == False):
196 print ('Client core was NOT connected')
197 if (server_core_connected == False):
198 print ('Server core was NOT connected')
199 if (client_core_session_map == False):
200 print ('Client core sessions did NOT increase')
201 if (server_core_session_map == False):
202 print ('Server core sessions did NOT increase')
207 def check_disconnect ():
208 vprintf ("Shutting down bootstrap server")
210 server = subprocess.Popen ([gnunetarm, '-eq', '-c', './confs/c_bootstrap_server.conf'])
211 server.communicate ()
213 print "Can not stop bootstrap server, exiting..."
216 client_transport_disconnected = False
217 client_topology_disconnected = False
218 client_core_disconnected = False
219 client_core_session_map = False
220 client_fs_disconnected = False
224 while ((disconnected == False) and (count <= timeout)):
225 if ((False == client_transport_disconnected) and (True == check_statistics ('./confs/c_no_nat_client.conf', 'transport', '# peers connected',0))):
226 client_transport_disconnected = True
227 vprintf ('Client transport services is disconnected')
229 if ((False == client_core_disconnected) and (True == check_statistics ('./confs/c_no_nat_client.conf', 'core', '# neighbour entries allocated',0))):
230 client_core_disconnected = True
231 vprintf ('Client core services is disconnected')
233 if ((False == client_core_session_map) and (True == check_statistics ('./confs/c_no_nat_client.conf', 'core', '# entries in session map',0))):
234 client_core_session_map = True
235 vprintf ('Client core notifies about disconnected')
237 if ((False == client_topology_disconnected) and (True == check_statistics ('./confs/c_no_nat_client.conf', 'topology', '# peers connected',0))):
238 client_topology_disconnected = True
239 vprintf ('Client topology services is disconnected')
241 if ((False == client_fs_disconnected) and (True == check_statistics ('./confs/c_no_nat_client.conf', 'fs', '# peers connected',0))):
242 client_fs_disconnected = True
243 vprintf ('Client fs services is disconnected')
245 # Check if conditions fulfilled
246 if ((True == client_transport_disconnected) and
247 (True == client_topology_disconnected) and
248 (True == client_core_disconnected) and
249 (True == client_core_session_map) and
250 (True == client_fs_disconnected)):
256 if (disconnected == False):
258 if (client_transport_disconnected == False):
259 print ('Client transport was NOT disconnected')
260 if (client_topology_disconnected == False):
261 print ('Client topology was NOT disconnected')
262 if (client_core_disconnected == False):
263 print ('Client core was NOT disconnected')
264 if (server_core_session_map == False):
265 print ('Server core sessions did NOT increase')
274 vprintf ("Running " + testname)
278 ret = check_connect ()
280 vprintf ('Peers connected')
281 if (True == check_disconnect ()):
289 if (success == False):
290 print ('Test failed')