aboutsummaryrefslogtreecommitdiff
path: root/src/integration-tests/test_integration_clique.py.in
diff options
context:
space:
mode:
Diffstat (limited to 'src/integration-tests/test_integration_clique.py.in')
-rwxr-xr-xsrc/integration-tests/test_integration_clique.py.in339
1 files changed, 170 insertions, 169 deletions
diff --git a/src/integration-tests/test_integration_clique.py.in b/src/integration-tests/test_integration_clique.py.in
index f8b60f33d..c2228da41 100755
--- a/src/integration-tests/test_integration_clique.py.in
+++ b/src/integration-tests/test_integration_clique.py.in
@@ -2,28 +2,26 @@
2# This file is part of GNUnet. 2# This file is part of GNUnet.
3# (C) 2010, 2018 Christian Grothoff (and other contributing authors) 3# (C) 2010, 2018 Christian Grothoff (and other contributing authors)
4# 4#
5# GNUnet is free software; you can redistribute it and/or modify 5# GNUnet is free software: you can redistribute it and/or modify it
6# it under the terms of the GNU General Public License as published 6# under the terms of the GNU Affero General Public License as published
7# by the Free Software Foundation; either version 2, or (at your 7# by the Free Software Foundation, either version 3 of the License,
8# option) any later version. 8# or (at your option) any later version.
9# 9#
10# GNUnet is distributed in the hope that it will be useful, but 10# GNUnet is distributed in the hope that it will be useful, but
11# WITHOUT ANY WARRANTY; without even the implied warranty of 11# WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13# General Public License for more details. 13# Affero General Public License for more details.
14#
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/>.
14# 17#
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., 51 Franklin Street, Fifth Floor,
18# Boston, MA 02110-1301, USA.
19# 18#
20#
21# 19#
22# This test starts 3 peers (nated, server, no nat)and expects bootstrap 20# This test starts 3 peers (nated, server, no nat)and expects bootstrap
23# and a connected clique 21# and a connected clique
24# 22#
25# Conditions for successful exit: 23# Conditions for successful exit:
26# Both peers have 2 connected peers in transport, core, topology, fs and dht 24# Both peers have 2 connected peers in transport, core, topology, fs and dht
27 25
28import sys 26import sys
29import signal 27import signal
@@ -36,192 +34,195 @@ from gnunet_testing import Peer
36from gnunet_testing import Test 34from gnunet_testing import Test
37from gnunet_testing import Check 35from gnunet_testing import Check
38from gnunet_testing import Condition 36from gnunet_testing import Condition
39from gnunet_testing import * 37from gnunet_testing import *
40 38
41if os.name == "nt": 39if os.name == "nt":
42 tmp = os.getenv ("TEMP") 40 tmp = os.getenv("TEMP")
43else: 41else:
44 tmp = "/tmp" 42 tmp = "/tmp"
45 43
46#definitions 44# definitions
47 45
48testname = "test_integration_clique" 46testname = "test_integration_clique"
49verbose = True 47verbose = True
50check_timeout = 180 48check_timeout = 180
51 49
52def cleanup_onerror (function, path, excinfo): 50
53 import stat 51def cleanup_onerror(function, path, excinfo):
54 if not os.path.exists (path): 52 import stat
55 pass 53 if not os.path.exists(path):
56 elif not os.access(path, os.W_OK): 54 pass
57 # Is the error an access error ? 55 elif not os.access(path, os.W_OK):
58 os.chmod (path, stat.S_IWUSR) 56 # Is the error an access error ?
59 function (path) 57 os.chmod(path, stat.S_IWUSR)
60 else: 58 function(path)
61 raise 59 else:
62 60 raise
63def cleanup (): 61
62
63def cleanup():
64 retries = 10 64 retries = 10
65 path = os.path.join (tmp, "c_bootstrap_server") 65 path = os.path.join(tmp, "c_bootstrap_server")
66 test.p ("Removing " + path) 66 test.p("Removing " + path)
67 while ((os.path.exists(path)) and (retries > 0)): 67 while ((os.path.exists(path)) and (retries > 0)):
68 shutil.rmtree ((path), False, cleanup_onerror) 68 shutil.rmtree((path), False, cleanup_onerror)
69 time.sleep (1) 69 time.sleep(1)
70 retries -= 1 70 retries -= 1
71 if (os.path.exists(path)): 71 if (os.path.exists(path)):
72 test.p ("Failed to remove " + path) 72 test.p("Failed to remove " + path)
73 retries = 10 73 retries = 10
74 path = os.path.join (tmp, "c_no_nat_client") 74 path = os.path.join(tmp, "c_no_nat_client")
75 test.p ("Removing " + path) 75 test.p("Removing " + path)
76 while ((os.path.exists(path)) and (retries > 0)): 76 while ((os.path.exists(path)) and (retries > 0)):
77 shutil.rmtree ((path), False, cleanup_onerror) 77 shutil.rmtree((path), False, cleanup_onerror)
78 time.sleep (1) 78 time.sleep(1)
79 retries -= 1 79 retries -= 1
80 if (os.path.exists(path)): 80 if (os.path.exists(path)):
81 test.p ("Failed to remove " + path) 81 test.p("Failed to remove " + path)
82 retries = 10 82 retries = 10
83 path = os.path.join (tmp, "c_nat_client") 83 path = os.path.join(tmp, "c_nat_client")
84 test.p ("Removing " + path) 84 test.p("Removing " + path)
85 while ((os.path.exists(path)) and (retries > 0)): 85 while ((os.path.exists(path)) and (retries > 0)):
86 shutil.rmtree ((path), False, cleanup_onerror) 86 shutil.rmtree((path), False, cleanup_onerror)
87 time.sleep (1) 87 time.sleep(1)
88 retries -= 1 88 retries -= 1
89 if (os.path.exists(path)): 89 if (os.path.exists(path)):
90 test.p ("Failed to remove " + path) 90 test.p("Failed to remove " + path)
91 91
92 92
93def success_cont (check): 93def success_cont(check):
94 global success 94 global success
95 success = True; 95 success = True
96 print('Connected clique successfully') 96 print('Connected clique successfully')
97 97
98def fail_cont (check): 98
99 global success 99def fail_cont(check):
100 success= False; 100 global success
101 success = False
101 check.evaluate(True) 102 check.evaluate(True)
102 print('Failed to connect clique') 103 print('Failed to connect clique')
103 104
104def check_connect (): 105
105 check = Check (test) 106def check_connect():
106 check.add (StatisticsCondition (client, 'transport', '# peers connected',2)) 107 check = Check(test)
107 check.add (StatisticsCondition (client, 'core', '# peers connected',2)) 108 check.add(StatisticsCondition(client, 'transport', '# peers connected', 2))
108 check.add (StatisticsCondition (client, 'topology', '# peers connected',2)) 109 check.add(StatisticsCondition(client, 'core', '# peers connected', 2))
109 check.add (StatisticsCondition (client, 'dht', '# peers connected',2)) 110 check.add(StatisticsCondition(client, 'topology', '# peers connected', 2))
110 check.add (StatisticsCondition (client, 'fs', '# peers connected',2)) 111 check.add(StatisticsCondition(client, 'dht', '# peers connected', 2))
111 112 check.add(StatisticsCondition(client, 'fs', '# peers connected', 2))
112 check.add (StatisticsCondition (client_nat, 'transport', '# peers connected',2)) 113
113 check.add (StatisticsCondition (client_nat, 'core', '# peers connected',2)) 114 check.add(StatisticsCondition(client_nat, 'transport', '# peers connected', 2))
114 check.add (StatisticsCondition (client_nat, 'topology', '# peers connected',2)) 115 check.add(StatisticsCondition(client_nat, 'core', '# peers connected', 2))
115 check.add (StatisticsCondition (client_nat, 'dht', '# peers connected',2)) 116 check.add(StatisticsCondition(client_nat, 'topology', '# peers connected', 2))
116 check.add (StatisticsCondition (client_nat, 'fs', '# peers connected',2)) 117 check.add(StatisticsCondition(client_nat, 'dht', '# peers connected', 2))
117 118 check.add(StatisticsCondition(client_nat, 'fs', '# peers connected', 2))
118 check.add (StatisticsCondition (server, 'transport', '# peers connected',2)) 119
119 check.add (StatisticsCondition (server, 'core', '# peers connected',2)) 120 check.add(StatisticsCondition(server, 'transport', '# peers connected', 2))
120 check.add (StatisticsCondition (server, 'topology', '# peers connected',2)) 121 check.add(StatisticsCondition(server, 'core', '# peers connected', 2))
121 check.add (StatisticsCondition (server, 'dht', '# peers connected',2)) 122 check.add(StatisticsCondition(server, 'topology', '# peers connected', 2))
122 check.add (StatisticsCondition (server, 'fs', '# peers connected',2)) 123 check.add(StatisticsCondition(server, 'dht', '# peers connected', 2))
123 124 check.add(StatisticsCondition(server, 'fs', '# peers connected', 2))
124 check.run_blocking (check_timeout, success_cont, fail_cont) 125
125 126 check.run_blocking(check_timeout, success_cont, fail_cont)
126# 127
128#
127# Test execution 129# Test execution
128# 130#
129 131
130def SigHandler(signum = None, frame = None): 132
131 global success 133def SigHandler(signum=None, frame=None):
132 global server 134 global success
133 global client 135 global server
134 global client_nat 136 global client
135 137 global client_nat
136 print('Test was aborted!') 138
137 if (None != server): 139 print('Test was aborted!')
138 server.stop () 140 if (None != server):
139 if (None != client): 141 server.stop()
140 client.stop () 142 if (None != client):
141 if (None != client_nat): 143 client.stop()
142 client_nat.stop () 144 if (None != client_nat):
143 cleanup () 145 client_nat.stop()
144 sys.exit(success) 146 cleanup()
145 147 sys.exit(success)
146def run (): 148
147 global success 149
148 global test 150def run():
149 global server 151 global success
150 global client 152 global test
151 global client_nat 153 global server
152 154 global client
153 success = False 155 global client_nat
154 server = None 156
155 client = None 157 success = False
156 client_nat = None 158 server = None
157 test = Test ('test_integration_clique', verbose) 159 client = None
158 cleanup () 160 client_nat = None
159 161 test = Test('test_integration_clique', verbose)
160 server = Peer(test, './confs/c_bootstrap_server.conf'); 162 cleanup()
161 if (True != server.start()): 163
162 print('Failed to start server') 164 server = Peer(test, './confs/c_bootstrap_server.conf')
163 if (None != server): 165 if (True != server.start()):
164 server.stop () 166 print('Failed to start server')
165 cleanup () 167 if (None != server):
166 sys.exit(success) 168 server.stop()
167 169 cleanup()
168 # Server has to settle down 170 sys.exit(success)
169 time.sleep(5) 171
170 172 # Server has to settle down
171 client = Peer(test, './confs/c_no_nat_client.conf'); 173 time.sleep(5)
172 if (True != client.start()): 174
173 print('Failed to start client') 175 client = Peer(test, './confs/c_no_nat_client.conf')
174 if (None != server): 176 if (True != client.start()):
175 server.stop () 177 print('Failed to start client')
176 if (None != client): 178 if (None != server):
177 client.stop () 179 server.stop()
178 cleanup () 180 if (None != client):
179 sys.exit(success) 181 client.stop()
180 182 cleanup()
181 # Server has to settle down 183 sys.exit(success)
182 time.sleep(5) 184
183 185 # Server has to settle down
184 186 time.sleep(5)
185 client_nat = Peer(test, './confs/c_nat_client.conf'); 187
186 if (True != client_nat.start()): 188 client_nat = Peer(test, './confs/c_nat_client.conf')
187 print('Failed to start client_nat') 189 if (True != client_nat.start()):
188 if (None != server): 190 print('Failed to start client_nat')
189 server.stop () 191 if (None != server):
190 if (None != client): 192 server.stop()
191 client.stop () 193 if (None != client):
192 if (None != client_nat): 194 client.stop()
193 client_nat.stop () 195 if (None != client_nat):
194 cleanup () 196 client_nat.stop()
195 sys.exit(success) 197 cleanup()
196 198 sys.exit(success)
197 if ((client.started == True) and (client_nat.started == True) and (server.started == True)): 199
198 test.p ('Peers started, running check') 200 if ((client.started == True) and (client_nat.started == True) and (server.started == True)):
199 check_connect () 201 test.p('Peers started, running check')
200 202 check_connect()
201 server.stop () 203
202 client.stop () 204 server.stop()
203 client_nat.stop () 205 client.stop()
204 206 client_nat.stop()
205 cleanup () 207
206 208 cleanup()
207 if (success == False): 209
208 print ('Test failed') 210 if (success == False):
209 return False 211 print('Test failed')
210 else: 212 return False
211 return True 213 else:
212 214 return True
213 215
216
214try: 217try:
215 run () 218 run()
216except (KeyboardInterrupt, SystemExit): 219except (KeyboardInterrupt, SystemExit):
217 print('Test interrupted') 220 print('Test interrupted')
218 server.stop () 221 server.stop()
219 client.stop () 222 client.stop()
220 client_nat.stop () 223 client_nat.stop()
221 cleanup () 224 cleanup()
222if (success == False): 225if (success == False):
223 sys.exit(1) 226 sys.exit(1)
224else: 227else:
225 sys.exit(0) 228 sys.exit(0)
226
227