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