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