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