2 # This file is part of GNUnet.
3 # (C) 2010, 2017 Christian Grothoff (and other contributing authors)
5 # GNUnet is free software: you can redistribute it and/or modify it
6 # under the terms of the GNU Affero General Public License as published
7 # by the Free Software Foundation, either version 3 of the License,
8 # or (at your 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 # Affero General Public License for more details.
15 # You should have received a copy of the GNU Affero General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
26 from gnunet_testing import Peer
27 from gnunet_testing import Test
28 from gnunet_testing import Check
29 from gnunet_testing import Condition
30 from gnunet_testing import *
34 # This test tests if a fresh peer bootstraps from a hostlist server and then
35 # successfully connects to the server. When both peers are connected
36 # in transport, core, topology, fs, botth peers are shutdown and restarted
38 # Conditions for successful exit:
39 # Both peers have 1 connected peer in transport, core, topology, fs after restart
44 testname = "test_integration_restart"
49 tmp = os.getenv ("TEMP")
50 signals = [signal.SIGTERM, signal.SIGINT]
53 signals = [signal.SIGTERM, signal.SIGINT, signal.SIGHUP, signal.SIGQUIT]
55 def cleanup_onerror (function, path, excinfo):
57 if not os.path.exists (path):
59 elif not os.access(path, os.W_OK):
60 # Is the error an access error ?
61 os.chmod (path, stat.S_IWUSR)
68 path = os.path.join (tmp, "c_bootstrap_server")
69 test.p ("Removing " + path)
70 while ((os.path.exists(path)) and (retries > 0)):
71 shutil.rmtree ((path), False, cleanup_onerror)
74 if (os.path.exists(path)):
75 test.p ("Failed to remove " + path)
79 path = os.path.join (tmp, "c_no_nat_client")
80 test.p ("Removing " + path)
81 while ((os.path.exists(path)) and (retries > 0)):
82 shutil.rmtree ((path), False, cleanup_onerror)
85 if (os.path.exists(path)):
86 test.p ("Failed to remove " + path)
88 def success_restart_cont (check):
90 print('Peers connected successfully after restart')
96 def fail_restart_cont (check):
99 print('Peers failed to connect after restart')
103 def success_connect_cont (check):
104 print('Peers connected successfully')
110 test.p ('Restarting client & server')
115 check.add (StatisticsCondition (client, 'transport', '# peers connected',1))
116 check.add (StatisticsCondition (client, 'core', '# peers connected',1))
117 check.add (StatisticsCondition (client, 'topology', '# peers connected',1))
118 check.add (StatisticsCondition (client, 'fs', '# peers connected',1))
120 check.add (StatisticsCondition (server, 'transport', '# peers connected',1))
121 check.add (StatisticsCondition (server, 'core', '# peers connected',1))
122 check.add (StatisticsCondition (server, 'topology', '# peers connected',1))
123 check.add (StatisticsCondition (server, 'fs', '# peers connected',1))
125 check.run_blocking (check_timeout, success_restart_cont, fail_restart_cont)
128 def fail_connect_cont (check):
131 print('Peers failed to connect')
135 def check_connect ():
137 check.add (StatisticsCondition (client, 'transport', '# peers connected',1))
138 check.add (StatisticsCondition (client, 'core', '# peers connected',1))
139 check.add (StatisticsCondition (client, 'topology', '# peers connected',1))
140 check.add (StatisticsCondition (client, 'fs', '# peers connected',1))
142 check.add (StatisticsCondition (server, 'transport', '# peers connected',1))
143 check.add (StatisticsCondition (server, 'core', '# peers connected',1))
144 check.add (StatisticsCondition (server, 'topology', '# peers connected',1))
145 check.add (StatisticsCondition (server, 'fs', '# peers connected',1))
147 check.run_blocking (check_timeout, success_connect_cont, fail_connect_cont)
154 def SigHandler(signum = None, frame = None):
159 print('Test was aborted!')
178 signal.signal(sig, SigHandler)
181 test = Test ('test_integration_disconnect', verbose)
183 server = Peer(test, './confs/c_bootstrap_server.conf');
186 client = Peer(test, './confs/c_no_nat_client.conf');
190 if (True != server.start()):
191 print('Failed to start server')
199 # Give the server time to start
202 if (True != client.start()):
203 print('Failed to start client')
217 if (success == False):
218 print ('Test failed')
226 except (KeyboardInterrupt, SystemExit):
227 print('Test interrupted')
231 if (success == False):