2 # This file is part of GNUnet.
3 # (C) 2010, 2018 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/>.
18 # SPDX-License-Identifier: AGPL3.0-or-later
22 # This test starts 3 peers (nated, server, no nat)and expects bootstrap
23 # and a connected clique
25 # Conditions for successful exit:
26 # Both peers have 2 connected peers in transport, core, topology, fs and dht
35 from gnunet_testing import Peer
36 from gnunet_testing import Test
37 from gnunet_testing import Check
38 from gnunet_testing import Condition
39 from gnunet_testing import *
42 tmp = os.getenv("TEMP")
48 testname = "test_integration_clique"
53 def cleanup_onerror(function, path, excinfo):
55 if not os.path.exists(path):
57 elif not os.access(path, os.W_OK):
58 # Is the error an access error ?
59 os.chmod(path, stat.S_IWUSR)
67 path = os.path.join(tmp, "c_bootstrap_server")
68 test.p("Removing " + path)
69 while ((os.path.exists(path)) and (retries > 0)):
70 shutil.rmtree((path), False, cleanup_onerror)
73 if (os.path.exists(path)):
74 test.p("Failed to remove " + path)
76 path = os.path.join(tmp, "c_no_nat_client")
77 test.p("Removing " + path)
78 while ((os.path.exists(path)) and (retries > 0)):
79 shutil.rmtree((path), False, cleanup_onerror)
82 if (os.path.exists(path)):
83 test.p("Failed to remove " + path)
85 path = os.path.join(tmp, "c_nat_client")
86 test.p("Removing " + path)
87 while ((os.path.exists(path)) and (retries > 0)):
88 shutil.rmtree((path), False, cleanup_onerror)
91 if (os.path.exists(path)):
92 test.p("Failed to remove " + path)
95 def success_cont(check):
98 print('Connected clique successfully')
101 def fail_cont(check):
105 print('Failed to connect clique')
110 check.add(StatisticsCondition(client, 'transport', '# peers connected', 2))
111 check.add(StatisticsCondition(client, 'core', '# peers connected', 2))
112 check.add(StatisticsCondition(client, 'topology', '# peers connected', 2))
113 check.add(StatisticsCondition(client, 'dht', '# peers connected', 2))
114 check.add(StatisticsCondition(client, 'fs', '# peers connected', 2))
117 StatisticsCondition(client_nat, 'transport', '# peers connected', 2)
119 check.add(StatisticsCondition(client_nat, 'core', '# peers connected', 2))
121 StatisticsCondition(client_nat, 'topology', '# peers connected', 2)
123 check.add(StatisticsCondition(client_nat, 'dht', '# peers connected', 2))
124 check.add(StatisticsCondition(client_nat, 'fs', '# peers connected', 2))
126 check.add(StatisticsCondition(server, 'transport', '# peers connected', 2))
127 check.add(StatisticsCondition(server, 'core', '# peers connected', 2))
128 check.add(StatisticsCondition(server, 'topology', '# peers connected', 2))
129 check.add(StatisticsCondition(server, 'dht', '# peers connected', 2))
130 check.add(StatisticsCondition(server, 'fs', '# peers connected', 2))
132 check.run_blocking(check_timeout, success_cont, fail_cont)
140 def SigHandler(signum=None, frame=None):
146 print('Test was aborted!')
151 if (None != client_nat):
168 test = Test('test_integration_clique', verbose)
171 server = Peer(test, './confs/c_bootstrap_server.conf')
172 if (True != server.start()):
173 print('Failed to start server')
179 # Server has to settle down
182 client = Peer(test, './confs/c_no_nat_client.conf')
183 if (True != client.start()):
184 print('Failed to start client')
192 # Server has to settle down
195 client_nat = Peer(test, './confs/c_nat_client.conf')
196 if (True != client_nat.start()):
197 print('Failed to start client_nat')
202 if (None != client_nat):
207 if ((client.started == True) and (client_nat.started == True)
208 and (server.started == True)):
209 test.p('Peers started, running check')
218 if (success == False):
227 except (KeyboardInterrupt, SystemExit):
228 print('Test interrupted')
233 if (success == False):