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.
22 # This test starts 3 peers (1 bootstrap server, 1 not nat'ed peer, 1 nat'ed peer)
23 # and expects bootstrap and a connected clique
25 # Conditions for successful exit:
26 # Both peers have 1 connected peer in transport, core, topology, fs
34 from gnunet_testing import Peer
35 from gnunet_testing import Test
36 from gnunet_testing import Check
37 from gnunet_testing import Condition
38 from gnunet_testing import *
41 tmp = os.getenv ("TEMP")
46 testname = "test_integration_clique_nat"
53 path = os.path.join (tmp, "c_bootstrap_server")
54 test.p ("Removing " + path)
55 while ((os.path.exists(path)) and (retries > 0)):
56 shutil.rmtree ((path), False)
59 if (os.path.exists(path)):
60 test.p ("Failed to remove " + path)
63 path = os.path.join (tmp, "c_no_nat_client")
64 test.p ("Removing " + path)
65 while ((os.path.exists(path)) and (retries > 0)):
66 shutil.rmtree ((path), False)
69 if (os.path.exists(path)):
70 test.p ("Failed to remove " + path)
72 path = os.path.join (tmp, "c_nat_client")
73 test.p ("Removing " + path)
74 while ((os.path.exists(path)) and (retries > 0)):
75 shutil.rmtree ((path), False)
78 if (os.path.exists(path)):
79 test.p ("Failed to remove " + path)
82 def success_cont (check):
86 def fail_cont (check):
92 def check_disconnect_client ():
93 test.p ('Shutting down bootstrap client')
97 check.add (StatisticsCondition (client2, 'transport', '# peers connected',0))
98 check.add (StatisticsCondition (client2, 'core', '# neighbour entries allocated',0))
99 check.add (StatisticsCondition (client2, 'core', '# peers connected',0))
100 check.add (StatisticsCondition (client2, 'topology', '# peers connected',0))
101 check.add (StatisticsCondition (client2, 'fs', '# peers connected',0))
103 check.run_blocking (check_timeout, success_cont, fail_cont)
106 def success_disconnect_server_cont (check):
107 check_disconnect_client ()
110 def fail_disconnect_server_cont (check):
113 check.evaluate(False)
116 def check_disconnect_server ():
117 test.p ('Shutting down bootstrap server')
120 check.add (StatisticsCondition (client, 'transport', '# peers connected',1))
121 check.add (StatisticsCondition (client, 'core', '# neighbour entries allocated',1))
122 check.add (StatisticsCondition (client, 'core', '# peers connected',1))
123 check.add (StatisticsCondition (client, 'topology', '# peers connected',1))
124 check.add (StatisticsCondition (client, 'fs', '# peers connected',1))
126 check.add (StatisticsCondition (client2, 'transport', '# peers connected',1))
127 check.add (StatisticsCondition (client2, 'core', '# neighbour entries allocated',1))
128 check.add (StatisticsCondition (client2, 'core', '# peers connected',1))
129 check.add (StatisticsCondition (client2, 'topology', '# peers connected',1))
130 check.add (StatisticsCondition (client2, 'fs', '# peers connected',1))
132 check.run_blocking (check_timeout, success_disconnect_server_cont, fail_disconnect_server_cont)
135 def success_connect_cont (check):
136 check_disconnect_server ()
139 def fail_connect_cont (check):
142 check.evaluate(False)
145 def check_connect ():
147 check.add (StatisticsCondition (client, 'transport', '# peers connected',2))
148 check.add (StatisticsCondition (client, 'core', '# neighbour entries allocated',2))
149 check.add (StatisticsCondition (client, 'core', '# peers connected',2))
150 check.add (StatisticsCondition (client, 'topology', '# peers connected',2))
151 check.add (StatisticsCondition (client, 'fs', '# peers connected',2))
153 check.add (StatisticsCondition (client2, 'transport', '# peers connected',2))
154 check.add (StatisticsCondition (client2, 'core', '# neighbour entries allocated',2))
155 check.add (StatisticsCondition (client2, 'core', '# peers connected',2))
156 check.add (StatisticsCondition (client2, 'topology', '# peers connected',2))
157 check.add (StatisticsCondition (client2, 'fs', '# peers connected',2))
159 check.add (StatisticsCondition (server, 'transport', '# peers connected',2))
160 check.add (StatisticsCondition (server, 'core', '# neighbour entries allocated',2))
161 check.add (StatisticsCondition (server, 'core', '# peers connected',2))
162 check.add (StatisticsCondition (server, 'topology', '# peers connected',2))
163 check.add (StatisticsCondition (server, 'fs', '# peers connected',2))
165 check.run_blocking (check_timeout, success_connect_cont, fail_connect_cont)
179 test = Test ('test_integration_disconnect', verbose)
181 server = Peer(test, './confs/c_bootstrap_server.conf');
184 client = Peer(test, './confs/c_no_nat_client.conf');
187 client2 = Peer(test, './confs/c_nat_client.conf');
190 if ((client.started == True) and (client2.started == True) and (server.started == True)):
191 test.p ('Peers started, running check')
200 if (success == False):
201 print ('Test failed')
209 except (KeyboardInterrupt, SystemExit):
210 print 'Test interrupted'
215 if (success == False):