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