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