diff options
Diffstat (limited to 'src/integration-tests/test_integration_reconnect_nat.py.in')
-rwxr-xr-x | src/integration-tests/test_integration_reconnect_nat.py.in | 375 |
1 files changed, 186 insertions, 189 deletions
diff --git a/src/integration-tests/test_integration_reconnect_nat.py.in b/src/integration-tests/test_integration_reconnect_nat.py.in index 78c75c335..f175554fb 100755 --- a/src/integration-tests/test_integration_reconnect_nat.py.in +++ b/src/integration-tests/test_integration_reconnect_nat.py.in | |||
@@ -2,22 +2,20 @@ | |||
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 | import sys | 19 | import sys |
22 | import os | 20 | import os |
23 | import subprocess | 21 | import subprocess |
@@ -29,18 +27,18 @@ from gnunet_testing import Peer | |||
29 | from gnunet_testing import Test | 27 | from gnunet_testing import Test |
30 | from gnunet_testing import Check | 28 | from gnunet_testing import Check |
31 | from gnunet_testing import Condition | 29 | from gnunet_testing import Condition |
32 | from gnunet_testing import * | 30 | from gnunet_testing import * |
33 | 31 | ||
34 | 32 | ||
35 | # | 33 | # |
36 | # This test tests if a fresh peer bootstraps from a hostlist server and then | 34 | # This test tests if a fresh peer bootstraps from a hostlist server and then |
37 | # successfully connects to the server. When both peers are connected | 35 | # successfully connects to the server. When both peers are connected |
38 | # in transport, core, topology, fs, botth peers are shutdown and restarted | 36 | # in transport, core, topology, fs, botth peers are shutdown and restarted |
39 | # | 37 | # |
40 | # Conditions for successful exit: | 38 | # Conditions for successful exit: |
41 | # Both peers have 1 connected peer in transport, core, topology, fs after restart | 39 | # Both peers have 1 connected peer in transport, core, topology, fs after restart |
42 | 40 | ||
43 | #definitions | 41 | # definitions |
44 | 42 | ||
45 | 43 | ||
46 | testname = "test_integration_restart" | 44 | testname = "test_integration_restart" |
@@ -48,191 +46,190 @@ verbose = True | |||
48 | check_timeout = 180 | 46 | check_timeout = 180 |
49 | 47 | ||
50 | if os.name == "nt": | 48 | if os.name == "nt": |
51 | tmp = os.getenv ("TEMP") | 49 | tmp = os.getenv("TEMP") |
52 | signals = [signal.SIGTERM, signal.SIGINT] | 50 | signals = [signal.SIGTERM, signal.SIGINT] |
53 | else: | 51 | else: |
54 | tmp = "/tmp" | 52 | tmp = "/tmp" |
55 | signals = [signal.SIGTERM, signal.SIGINT, signal.SIGHUP, signal.SIGQUIT] | 53 | signals = [signal.SIGTERM, signal.SIGINT, signal.SIGHUP, signal.SIGQUIT] |
56 | 54 | ||
57 | def cleanup_onerror (function, path, excinfo): | 55 | |
58 | import stat | 56 | def cleanup_onerror(function, path, excinfo): |
59 | if not os.path.exists (path): | 57 | import stat |
60 | pass | 58 | if not os.path.exists(path): |
61 | elif not os.access(path, os.W_OK): | 59 | pass |
62 | # Is the error an access error ? | 60 | elif not os.access(path, os.W_OK): |
63 | os.chmod (path, stat.S_IWUSR) | 61 | # Is the error an access error ? |
64 | function (path) | 62 | os.chmod(path, stat.S_IWUSR) |
65 | else: | 63 | function(path) |
66 | raise | 64 | else: |
67 | 65 | raise | |
68 | def cleanup (): | 66 | |
67 | |||
68 | def cleanup(): | ||
69 | retries = 10 | 69 | retries = 10 |
70 | path = os.path.join (tmp, "c_bootstrap_server") | 70 | path = os.path.join(tmp, "c_bootstrap_server") |
71 | test.p ("Removing " + path) | 71 | test.p("Removing " + path) |
72 | while ((os.path.exists(path)) and (retries > 0)): | 72 | while ((os.path.exists(path)) and (retries > 0)): |
73 | shutil.rmtree ((path), False, cleanup_onerror) | 73 | shutil.rmtree((path), False, cleanup_onerror) |
74 | time.sleep (1) | 74 | time.sleep(1) |
75 | retries -= 1 | 75 | retries -= 1 |
76 | if (os.path.exists(path)): | 76 | if (os.path.exists(path)): |
77 | test.p ("Failed to remove " + path) | 77 | test.p("Failed to remove " + path) |
78 | 78 | ||
79 | |||
80 | retries = 10 | 79 | retries = 10 |
81 | path = os.path.join (tmp, "c_nat_client") | 80 | path = os.path.join(tmp, "c_nat_client") |
82 | test.p ("Removing " + path) | 81 | test.p("Removing " + path) |
83 | while ((os.path.exists(path)) and (retries > 0)): | 82 | while((os.path.exists(path)) and(retries > 0)): |
84 | shutil.rmtree ((path), False, cleanup_onerror) | 83 | shutil.rmtree((path), False, cleanup_onerror) |
85 | time.sleep (1) | 84 | time.sleep(1) |
86 | retries -= 1 | 85 | retries -= 1 |
87 | if (os.path.exists(path)): | 86 | if (os.path.exists(path)): |
88 | test.p ("Failed to remove " + path) | 87 | test.p("Failed to remove " + path) |
89 | 88 | ||
90 | def success_restart_cont (check): | 89 | |
91 | global success | 90 | def success_restart_cont(check): |
92 | print('Peers connected successfully after restart') | 91 | global success |
93 | server.stop () | 92 | print('Peers connected successfully after restart') |
94 | client.stop () | 93 | server.stop() |
95 | success = True; | 94 | client.stop() |
96 | 95 | success = True | |
97 | 96 | ||
98 | def fail_restart_cont (check): | 97 | |
99 | global success | 98 | def fail_restart_cont(check): |
100 | success = False; | 99 | global success |
101 | print('Peers failed to connect after restart') | 100 | success = False |
102 | check.evaluate(True) | 101 | print('Peers failed to connect after restart') |
103 | 102 | check.evaluate(True) | |
104 | 103 | ||
105 | def success_connect_cont (check): | 104 | |
106 | print('Peers connected successfully') | 105 | def success_connect_cont(check): |
107 | server.stop () | 106 | print('Peers connected successfully') |
108 | client.stop () | 107 | server.stop() |
109 | 108 | client.stop() | |
110 | time.sleep(5) | 109 | |
111 | 110 | time.sleep(5) | |
112 | test.p ('Restarting client & server') | 111 | |
113 | server.start () | 112 | test.p('Restarting client & server') |
114 | client.start () | 113 | server.start() |
115 | 114 | client.start() | |
116 | check = Check (test) | 115 | |
117 | check.add (StatisticsCondition (client, 'transport', '# peers connected',1)) | 116 | check = Check(test) |
118 | check.add (StatisticsCondition (client, 'core', '# peers connected',1)) | 117 | check.add(StatisticsCondition(client, 'transport', '# peers connected', 1)) |
119 | check.add (StatisticsCondition (client, 'topology', '# peers connected',1)) | 118 | check.add(StatisticsCondition(client, 'core', '# peers connected', 1)) |
120 | check.add (StatisticsCondition (client, 'fs', '# peers connected',1)) | 119 | check.add(StatisticsCondition(client, 'topology', '# peers connected', 1)) |
121 | 120 | check.add(StatisticsCondition(client, 'fs', '# peers connected', 1)) | |
122 | check.add (StatisticsCondition (server, 'transport', '# peers connected',1)) | 121 | |
123 | check.add (StatisticsCondition (server, 'core', '# peers connected',1)) | 122 | check.add(StatisticsCondition(server, 'transport', '# peers connected', 1)) |
124 | check.add (StatisticsCondition (server, 'topology', '# peers connected',1)) | 123 | check.add(StatisticsCondition(server, 'core', '# peers connected', 1)) |
125 | check.add (StatisticsCondition (server, 'fs', '# peers connected',1)) | 124 | check.add(StatisticsCondition(server, 'topology', '# peers connected', 1)) |
126 | 125 | check.add(StatisticsCondition(server, 'fs', '# peers connected', 1)) | |
127 | check.run_blocking (check_timeout, success_restart_cont, fail_restart_cont) | 126 | |
128 | 127 | check.run_blocking(check_timeout, success_restart_cont, fail_restart_cont) | |
129 | 128 | ||
130 | def fail_connect_cont (check): | 129 | |
131 | global success | 130 | def fail_connect_cont(check): |
132 | success= False; | 131 | global success |
133 | print('Peers failed to connect') | 132 | success = False |
134 | check.evaluate(True) | 133 | print('Peers failed to connect') |
135 | 134 | check.evaluate(True) | |
136 | 135 | ||
137 | def check_connect (): | 136 | |
138 | check = Check (test) | 137 | def check_connect(): |
139 | check.add (StatisticsCondition (client, 'transport', '# peers connected',1)) | 138 | check = Check(test) |
140 | check.add (StatisticsCondition (client, 'core', '# peers connected',1)) | 139 | check.add(StatisticsCondition(client, 'transport', '# peers connected', 1)) |
141 | check.add (StatisticsCondition (client, 'topology', '# peers connected',1)) | 140 | check.add(StatisticsCondition(client, 'core', '# peers connected', 1)) |
142 | check.add (StatisticsCondition (client, 'fs', '# peers connected',1)) | 141 | check.add(StatisticsCondition(client, 'topology', '# peers connected', 1)) |
143 | 142 | check.add(StatisticsCondition(client, 'fs', '# peers connected', 1)) | |
144 | check.add (StatisticsCondition (server, 'transport', '# peers connected',1)) | 143 | |
145 | check.add (StatisticsCondition (server, 'core', '# peers connected',1)) | 144 | check.add(StatisticsCondition(server, 'transport', '# peers connected', 1)) |
146 | check.add (StatisticsCondition (server, 'topology', '# peers connected',1)) | 145 | check.add(StatisticsCondition(server, 'core', '# peers connected', 1)) |
147 | check.add (StatisticsCondition (server, 'fs', '# peers connected',1)) | 146 | check.add(StatisticsCondition(server, 'topology', '# peers connected', 1)) |
148 | 147 | check.add(StatisticsCondition(server, 'fs', '# peers connected', 1)) | |
149 | check.run_blocking (check_timeout, success_connect_cont, fail_connect_cont) | 148 | |
150 | 149 | check.run_blocking(check_timeout, success_connect_cont, fail_connect_cont) | |
151 | # | 150 | |
151 | # | ||
152 | # Test execution | 152 | # Test execution |
153 | # | 153 | # |
154 | 154 | ||
155 | 155 | ||
156 | def SigHandler(signum = None, frame = None): | 156 | def SigHandler(signum=None, frame=None): |
157 | global success | 157 | global success |
158 | global server | 158 | global server |
159 | global client | 159 | global client |
160 | 160 | ||
161 | print('Test was aborted!') | 161 | print('Test was aborted!') |
162 | if (None != server): | 162 | if (None != server): |
163 | server.stop () | 163 | server.stop() |
164 | if (None != client): | 164 | if (None != client): |
165 | client.stop () | 165 | client.stop() |
166 | cleanup () | 166 | cleanup() |
167 | sys.exit(success) | 167 | sys.exit(success) |
168 | 168 | ||
169 | def run (): | 169 | |
170 | global success | 170 | def run(): |
171 | global test | 171 | global success |
172 | global server | 172 | global test |
173 | global client | 173 | global server |
174 | 174 | global client | |
175 | success = False | 175 | |
176 | server = None | 176 | success = False |
177 | client = None | 177 | server = None |
178 | 178 | client = None | |
179 | for sig in signals: | 179 | |
180 | signal.signal(sig, SigHandler) | 180 | for sig in signals: |
181 | 181 | signal.signal(sig, SigHandler) | |
182 | 182 | ||
183 | test = Test ('test_integration_disconnect', verbose) | 183 | test = Test('test_integration_disconnect', verbose) |
184 | cleanup () | 184 | cleanup() |
185 | server = Peer(test, './confs/c_bootstrap_server.conf'); | 185 | server = Peer(test, './confs/c_bootstrap_server.conf') |
186 | server.start(); | 186 | server.start() |
187 | 187 | ||
188 | client = Peer(test, './confs/c_nat_client.conf'); | 188 | client = Peer(test, './confs/c_nat_client.conf') |
189 | client.start(); | 189 | client.start() |
190 | 190 | ||
191 | 191 | if (True != server.start()): | |
192 | if (True != server.start()): | 192 | print('Failed to start server') |
193 | print('Failed to start server') | 193 | if (None != server): |
194 | if (None != server): | 194 | server.stop() |
195 | server.stop () | 195 | if (None != server): |
196 | if (None != server): | 196 | client.stop() |
197 | client.stop () | 197 | cleanup() |
198 | cleanup () | 198 | sys.exit(success) |
199 | sys.exit(success) | 199 | |
200 | 200 | # Give the server time to start | |
201 | # Give the server time to start | 201 | time.sleep(5) |
202 | time.sleep(5) | 202 | |
203 | 203 | if (True != client.start()): | |
204 | if (True != client.start()): | 204 | print('Failed to start client') |
205 | print('Failed to start client') | 205 | if (None != server): |
206 | if (None != server): | 206 | server.stop() |
207 | server.stop () | 207 | if (None != server): |
208 | if (None != server): | 208 | client.stop() |
209 | client.stop () | 209 | cleanup() |
210 | cleanup () | 210 | sys.exit(success) |
211 | sys.exit(success) | 211 | |
212 | 212 | check_connect() | |
213 | check_connect () | 213 | |
214 | 214 | server.stop() | |
215 | server.stop () | 215 | client.stop() |
216 | client.stop () | 216 | cleanup() |
217 | cleanup () | 217 | |
218 | 218 | if (success == False): | |
219 | if (success == False): | 219 | print('Test failed') |
220 | print ('Test failed') | 220 | return True |
221 | return True | 221 | else: |
222 | else: | 222 | return False |
223 | return False | 223 | |
224 | 224 | ||
225 | |||
226 | try: | 225 | try: |
227 | run () | 226 | run() |
228 | except (KeyboardInterrupt, SystemExit): | 227 | except(KeyboardInterrupt, SystemExit): |
229 | print('Test interrupted') | 228 | print('Test interrupted') |
230 | server.stop () | 229 | server.stop() |
231 | client.stop () | 230 | client.stop() |
232 | cleanup () | 231 | cleanup() |
233 | if (success == False): | 232 | if (success == False): |
234 | sys.exit(1) | 233 | sys.exit(1) |
235 | else: | 234 | else: |
236 | sys.exit(0) | 235 | sys.exit(0) |
237 | |||
238 | |||