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
28 from __future__ import print_function
36 from gnunet_testing import Peer
37 from gnunet_testing import Test
38 from gnunet_testing import Check
39 from gnunet_testing import Condition
40 from gnunet_testing import *
43 tmp = os.getenv("TEMP")
49 testname = "test_integration_clique"
54 def cleanup_onerror(function, path, excinfo):
56 if not os.path.exists(path):
58 elif not os.access(path, os.W_OK):
59 # Is the error an access error ?
60 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)
77 path = os.path.join(tmp, "c_no_nat_client")
78 test.p("Removing " + path)
79 while ((os.path.exists(path)) and (retries > 0)):
80 shutil.rmtree((path), False, cleanup_onerror)
83 if (os.path.exists(path)):
84 test.p("Failed to remove " + path)
86 path = os.path.join(tmp, "c_nat_client")
87 test.p("Removing " + path)
88 while ((os.path.exists(path)) and (retries > 0)):
89 shutil.rmtree((path), False, cleanup_onerror)
92 if (os.path.exists(path)):
93 test.p("Failed to remove " + path)
96 def success_cont(check):
99 print('Connected clique successfully')
102 def fail_cont(check):
106 print('Failed to connect clique')
111 check.add(StatisticsCondition(client, 'transport', '# peers connected', 2))
112 check.add(StatisticsCondition(client, 'core', '# peers connected', 2))
113 check.add(StatisticsCondition(client, 'topology', '# peers connected', 2))
114 check.add(StatisticsCondition(client, 'dht', '# peers connected', 2))
115 check.add(StatisticsCondition(client, 'fs', '# peers connected', 2))
117 check.add(StatisticsCondition(client_nat, 'transport', '# peers connected', 2))
118 check.add(StatisticsCondition(client_nat, 'core', '# peers connected', 2))
119 check.add(StatisticsCondition(client_nat, 'topology', '# peers connected', 2))
120 check.add(StatisticsCondition(client_nat, 'dht', '# peers connected', 2))
121 check.add(StatisticsCondition(client_nat, 'fs', '# peers connected', 2))
123 check.add(StatisticsCondition(server, 'transport', '# peers connected', 2))
124 check.add(StatisticsCondition(server, 'core', '# peers connected', 2))
125 check.add(StatisticsCondition(server, 'topology', '# peers connected', 2))
126 check.add(StatisticsCondition(server, 'dht', '# peers connected', 2))
127 check.add(StatisticsCondition(server, 'fs', '# peers connected', 2))
129 check.run_blocking(check_timeout, success_cont, fail_cont)
136 def SigHandler(signum=None, frame=None):
142 print('Test was aborted!')
147 if (None != client_nat):
164 test = Test('test_integration_clique', verbose)
167 server = Peer(test, './confs/c_bootstrap_server.conf')
168 if (True != server.start()):
169 print('Failed to start server')
175 # Server has to settle down
178 client = Peer(test, './confs/c_no_nat_client.conf')
179 if (True != client.start()):
180 print('Failed to start client')
188 # Server has to settle down
191 client_nat = Peer(test, './confs/c_nat_client.conf')
192 if (True != client_nat.start()):
193 print('Failed to start client_nat')
198 if (None != client_nat):
203 if ((client.started == True) and (client_nat.started == True) and (server.started == True)):
204 test.p('Peers started, running check')
213 if (success == False):
222 except (KeyboardInterrupt, SystemExit):
223 print('Test interrupted')
228 if (success == False):