aboutsummaryrefslogtreecommitdiff
path: root/src/integration-tests/test_integration_disconnect_nat.py.in
diff options
context:
space:
mode:
Diffstat (limited to 'src/integration-tests/test_integration_disconnect_nat.py.in')
-rwxr-xr-xsrc/integration-tests/test_integration_disconnect_nat.py.in340
1 files changed, 170 insertions, 170 deletions
diff --git a/src/integration-tests/test_integration_disconnect_nat.py.in b/src/integration-tests/test_integration_disconnect_nat.py.in
index 611255a09..69d670663 100755
--- a/src/integration-tests/test_integration_disconnect_nat.py.in
+++ b/src/integration-tests/test_integration_disconnect_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#
21import sys 19import sys
22import signal 20import signal
23import os 21import os
@@ -29,8 +27,8 @@ from gnunet_testing import Peer
29from gnunet_testing import Test 27from gnunet_testing import Test
30from gnunet_testing import Check 28from gnunet_testing import Check
31from gnunet_testing import Condition 29from gnunet_testing import Condition
32from gnunet_testing import * 30from 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
@@ -40,173 +38,175 @@ from gnunet_testing import *
40# Conditions for successful exit: 38# Conditions for successful exit:
41# Client peer has 0 connected peer in transport, core, topology, dht, fs 39# Client peer has 0 connected peer in transport, core, topology, dht, fs
42 40
43#definitions 41# definitions
44 42
45testname = "test_integration_disconnect" 43testname = "test_integration_disconnect"
46verbose = True 44verbose = True
47check_timeout = 180 45check_timeout = 180
48 46
49if os.name == "nt": 47if os.name == "nt":
50 tmp = os.getenv ("TEMP") 48 tmp = os.getenv("TEMP")
51 signals = [signal.SIGTERM, signal.SIGINT] 49 signals = [signal.SIGTERM, signal.SIGINT]
52else: 50else:
53 tmp = "/tmp" 51 tmp = "/tmp"
54 signals = [signal.SIGTERM, signal.SIGINT, signal.SIGHUP, signal.SIGQUIT] 52 signals = [signal.SIGTERM, signal.SIGINT, signal.SIGHUP, signal.SIGQUIT]
55 53
56def cleanup_onerror (function, path, excinfo): 54
57 import stat 55def cleanup_onerror(function, path, excinfo):
58 if not os.path.exists (path): 56 import stat
59 pass 57 if not os.path.exists(path):
60 elif not os.access(path, os.W_OK): 58 pass
61 # Is the error an access error ? 59 elif not os.access(path, os.W_OK):
62 os.chmod (path, stat.S_IWUSR) 60 # Is the error an access error ?
63 function (path) 61 os.chmod(path, stat.S_IWUSR)
64 else: 62 function(path)
65 raise 63 else:
66 64 raise
67def cleanup (): 65
68 shutil.rmtree (os.path.join (tmp, "c_bootstrap_server"), False, cleanup_onerror) 66
69 shutil.rmtree (os.path.join (tmp, "c_nat_client"), False, cleanup_onerror) 67def cleanup():
70 68 shutil.rmtree(os.path.join(tmp, "c_bootstrap_server"), False, cleanup_onerror)
71 69 shutil.rmtree(os.path.join(tmp, "c_nat_client"), False, cleanup_onerror)
72def success_disconnect_cont (check): 70
73 print('Peers disconnected successfully') 71
74 global success 72def success_disconnect_cont(check):
75 success = True; 73 print('Peers disconnected successfully')
76 74 global success
77 75 success = True
78def fail_disconnect_cont (check): 76
79 global success 77
80 success = False; 78def fail_disconnect_cont(check):
81 print('Peers failed to disconnect') 79 global success
82 check.evaluate(True) 80 success = False;
83 81 print('Peers failed to disconnect')
84def check_disconnect (): 82 check.evaluate(True)
85 global server 83
86 global nat_client 84
87 test.p ('Shutting down nat client') 85def check_disconnect():
88 nat_client.stop () 86 global server
89 check = Check (test) 87 global nat_client
90 check.add (StatisticsCondition (server, 'transport', '# peers connected',0)) 88 test.p('Shutting down nat client')
91 check.add (StatisticsCondition (server, 'core', '# peers connected',0)) 89 nat_client.stop()
92 check.add (StatisticsCondition (server, 'topology', '# peers connected',0)) 90 check = Check(test)
93 check.add (StatisticsCondition (server, 'dht', '# peers connected',0)) 91 check.add(StatisticsCondition(server, 'transport', '# peers connected', 0))
94 check.add (StatisticsCondition (server, 'fs', '# peers connected',0)) 92 check.add(StatisticsCondition(server, 'core', '# peers connected', 0))
95 check.run_blocking (check_timeout, success_disconnect_cont, fail_disconnect_cont) 93 check.add(StatisticsCondition(server, 'topology', '# peers connected', 0))
96 94 check.add(StatisticsCondition(server, 'dht', '# peers connected', 0))
97 95 check.add(StatisticsCondition(server, 'fs', '# peers connected', 0))
98def success_connect_cont (check): 96 check.run_blocking(check_timeout, success_disconnect_cont, fail_disconnect_cont)
99 print('Peers connected successfully') 97
100 check_disconnect () 98
101 99def success_connect_cont(check):
102 100 print('Peers connected successfully')
103def fail_connect_cont (check): 101 check_disconnect()
104 global success 102
105 success= False 103
106 print('Peers failed to connected!') 104def fail_connect_cont(check):
107 check.evaluate(True) 105 global success
108 106 success = False
109 107 print('Peers failed to connected!')
110def check_connect (): 108 check.evaluate(True)
111 global server 109
112 global nat_client 110
113 check = Check (test) 111def check_connect():
114 check.add (StatisticsCondition (nat_client, 'transport', '# peers connected',1)) 112 global server
115 check.add (StatisticsCondition (nat_client, 'core', '# peers connected',1)) 113 global nat_client
116 check.add (StatisticsCondition (nat_client, 'topology', '# peers connected',1)) 114 check = Check(test)
117 check.add (StatisticsCondition (nat_client, 'dht', '# peers connected',1)) 115 check.add(StatisticsCondition(nat_client, 'transport', '# peers connected', 1))
118 check.add (StatisticsCondition (nat_client, 'fs', '# peers connected',1)) 116 check.add(StatisticsCondition(nat_client, 'core', '# peers connected', 1))
119 117 check.add(StatisticsCondition(nat_client, 'topology', '# peers connected', 1))
120 check.add (StatisticsCondition (server, 'transport', '# peers connected',1)) 118 check.add(StatisticsCondition(nat_client, 'dht', '# peers connected', 1))
121 check.add (StatisticsCondition (server, 'core', '# peers connected',1)) 119 check.add(StatisticsCondition(nat_client, 'fs', '# peers connected', 1))
122 check.add (StatisticsCondition (server, 'topology', '# peers connected',1)) 120
123 check.add (StatisticsCondition (server, 'dht', '# peers connected',1)) 121 check.add(StatisticsCondition(server, 'transport', '# peers connected', 1))
124 check.add (StatisticsCondition (server, 'fs', '# peers connected',1)) 122 check.add(StatisticsCondition(server, 'core', '# peers connected', 1))
125 123 check.add(StatisticsCondition(server, 'topology', '# peers connected', 1))
126 check.run_blocking (check_timeout, success_connect_cont, fail_connect_cont) 124 check.add(StatisticsCondition(server, 'dht', '# peers connected', 1))
127 125 check.add(StatisticsCondition(server, 'fs', '# peers connected', 1))
128# 126
127 check.run_blocking(check_timeout, success_connect_cont, fail_connect_cont)
128
129
130#
129# Test execution 131# Test execution
130# 132#
131 133
132def SigHandler(signum = None, frame = None): 134def SigHandler(signum=None, frame=None):
133 global success 135 global success
134 global server 136 global server
135 global nat_client 137 global nat_client
136 138
137 print('Test was aborted!') 139 print('Test was aborted!')
138 if (None != server): 140 if (None != server):
139 server.stop () 141 server.stop()
140 if (None != nat_client): 142 if (None != nat_client):
141 nat_client.stop () 143 nat_client.stop()
142 cleanup () 144 cleanup()
143 sys.exit(success) 145 sys.exit(success)
144 146
145def run (): 147
146 global success 148def run():
147 global test 149 global success
148 global server 150 global test
149 global nat_client 151 global server
150 152 global nat_client
151 server = None 153
152 nat_client = None 154 server = None
153 success = False 155 nat_client = None
154 156 success = False
155 for sig in signals: 157
156 signal.signal(sig, SigHandler) 158 for sig in signals:
157 159 signal.signal(sig, SigHandler)
158 test = Test ('test_integration_bootstrap_and_connect.py', verbose) 160
159 cleanup () 161 test = Test('test_integration_bootstrap_and_connect.py', verbose)
160 162 cleanup()
161 server = Peer(test, './confs/c_bootstrap_server.conf'); 163
162 nat_client = Peer(test, './confs/c_nat_client.conf'); 164 server = Peer(test, './confs/c_bootstrap_server.conf')
163 165 nat_client = Peer(test, './confs/c_nat_client.conf')
164 if (True != server.start()): 166
165 print('Failed to start server') 167 if (True != server.start()):
166 if (None != server): 168 print('Failed to start server')
167 server.stop () 169 if (None != server):
168 cleanup () 170 server.stop()
169 sys.exit(success) 171 cleanup()
170 172 sys.exit(success)
171 # Give the server time to start 173
172 time.sleep(5) 174 # Give the server time to start
173 175 time.sleep(5)
174 if (True != nat_client.start()): 176
175 print('Failed to start nat_client') 177 if (True != nat_client.start()):
176 if (None != server): 178 print('Failed to start nat_client')
177 server.stop () 179 if (None != server):
178 if (None != nat_client): 180 server.stop()
179 nat_client.stop () 181 if (None != nat_client):
180 cleanup () 182 nat_client.stop()
181 sys.exit(success) 183 cleanup()
182 184 sys.exit(success)
183 if ((nat_client.started == True) and (server.started == True)): 185
184 test.p ('Peers started, running check') 186 if ((nat_client.started == True) and (server.started == True)):
185 time.sleep(5) 187 test.p('Peers started, running check')
186 check_connect () 188 time.sleep(5)
187 server.stop () 189 check_connect()
188 nat_client.stop () 190 server.stop()
189 191 nat_client.stop()
190 cleanup () 192
191 193 cleanup()
192 if (success == False): 194
193 print ('Test failed') 195 if (success == False):
194 return False 196 print('Test failed')
195 else: 197 return False
196 return True 198 else:
199 return True
200
197 201
198try: 202try:
199 run () 203 run()
200except (KeyboardInterrupt, SystemExit): 204except(KeyboardInterrupt, SystemExit):
201 print('Test interrupted') 205 print('Test interrupted')
202 server.stop () 206 server.stop()
203 nat_client.stop () 207 nat_client.stop()
204 cleanup () 208 cleanup()
205if (success == False): 209if (success == False):
206 sys.exit(1) 210 sys.exit(1)
207else: 211else:
208 sys.exit(0) 212 sys.exit(0)
209
210
211
212