aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorng0 <ng0@n0.is>2019-10-12 18:16:07 +0000
committerng0 <ng0@n0.is>2019-10-12 18:16:07 +0000
commita5f5e7ed9b07b902af4438d76087e034abcba9b2 (patch)
tree6f376f93f1c785103d0b30f54311a0f61d2bdced
parent8e827de2a1db34dfe15f5f9da2850ca469b5ecc3 (diff)
downloadgnunet-a5f5e7ed9b07b902af4438d76087e034abcba9b2.tar.gz
gnunet-a5f5e7ed9b07b902af4438d76087e034abcba9b2.zip
format python
-rwxr-xr-xcontrib/scripts/gnunet-chk.py.in23
-rw-r--r--contrib/scripts/gnunet_janitor.py.in1
-rw-r--r--contrib/scripts/gnunet_pyexpect.py.in20
-rw-r--r--contrib/scripts/pydiffer.py.in5
-rwxr-xr-xcontrib/scripts/removetrailingwhitespace.py.in1
-rw-r--r--contrib/scripts/terminate.py.in2
-rw-r--r--src/arm/test_gnunet_arm.py.in26
-rw-r--r--src/consensus/consensus-simulation.py.in15
-rw-r--r--src/dht/test_dht_tools.py.in29
-rwxr-xr-xsrc/fs/test_gnunet_fs_idx.py.in57
-rwxr-xr-xsrc/fs/test_gnunet_fs_psd.py.in75
-rwxr-xr-xsrc/fs/test_gnunet_fs_rec.py.in90
-rw-r--r--src/integration-tests/gnunet_pyexpect.py.in115
-rw-r--r--src/integration-tests/gnunet_testing.py.in100
-rwxr-xr-xsrc/integration-tests/test_integration_bootstrap_and_connect.py.in2
-rwxr-xr-xsrc/integration-tests/test_integration_clique.py.in14
-rwxr-xr-xsrc/integration-tests/test_integration_disconnect.py.in300
-rwxr-xr-xsrc/integration-tests/test_integration_disconnect_nat.py.in22
-rwxr-xr-xsrc/integration-tests/test_integration_reconnect.py.in272
-rwxr-xr-xsrc/integration-tests/test_integration_reconnect_nat.py.in25
-rwxr-xr-xsrc/peerinfo-tool/test_gnunet_peerinfo.py.in75
-rw-r--r--src/revocation/test_local_revocation.py.in31
-rw-r--r--src/statistics/test_gnunet_statistics.py.in8
23 files changed, 827 insertions, 481 deletions
diff --git a/contrib/scripts/gnunet-chk.py.in b/contrib/scripts/gnunet-chk.py.in
index 0fb591627..7d2cf73d3 100755
--- a/contrib/scripts/gnunet-chk.py.in
+++ b/contrib/scripts/gnunet-chk.py.in
@@ -29,9 +29,8 @@ import sys
29from Crypto.Cipher import AES 29from Crypto.Cipher import AES
30from functools import reduce 30from functools import reduce
31 31
32
33# Defaults 32# Defaults
34DBLOCK_SIZE = (32 * 1024) # Data block size 33DBLOCK_SIZE = (32 * 1024) # Data block size
35 34
36# Pick a multiple of 2 here to achive 8-byte alignment! We also 35# Pick a multiple of 2 here to achive 8-byte alignment! We also
37# probably want DBlocks to have (roughly) the same size as IBlocks. 36# probably want DBlocks to have (roughly) the same size as IBlocks.
@@ -39,7 +38,7 @@ DBLOCK_SIZE = (32 * 1024) # Data block size
39# byte = 2 * 512 bits). DO NOT CHANGE! 38# byte = 2 * 512 bits). DO NOT CHANGE!
40CHK_PER_INODE = 256 39CHK_PER_INODE = 256
41 40
42CHK_HASH_SIZE = 64 # SHA-512 hash = 512 bits = 64 bytes 41CHK_HASH_SIZE = 64 # SHA-512 hash = 512 bits = 64 bytes
43 42
44CHK_QUERY_SIZE = CHK_HASH_SIZE # Again a SHA-512 hash 43CHK_QUERY_SIZE = CHK_HASH_SIZE # Again a SHA-512 hash
45 44
@@ -94,11 +93,11 @@ class AESKey(object):
94 """Class for AES Keys. Contains the main key and the initialization 93 """Class for AES Keys. Contains the main key and the initialization
95 vector. """ 94 vector. """
96 95
97 key = None # The actual AES key 96 key = None # The actual AES key
98 iv = None # The initialization vector 97 iv = None # The initialization vector
99 cipher = None # The cipher object 98 cipher = None # The cipher object
100 KEY_SIZE = 32 # AES 256-bit key = 32 bytes 99 KEY_SIZE = 32 # AES 256-bit key = 32 bytes
101 IV_SIZE = AES.block_size # Initialization vector size (= AES block size) 100 IV_SIZE = AES.block_size # Initialization vector size (= AES block size)
102 101
103 def __init__(self, passphrase): 102 def __init__(self, passphrase):
104 """Creates a new AES key. 103 """Creates a new AES key.
@@ -355,13 +354,15 @@ def chkuri_from_path(path):
355 354
356def usage(): 355def usage():
357 """Prints help about using this script.""" 356 """Prints help about using this script."""
358 print(""" 357 print(
358 """
359Usage: gnunet-chk.py [options] file 359Usage: gnunet-chk.py [options] file
360Prints the Content Hash Key of given file in GNUNET-style URI. 360Prints the Content Hash Key of given file in GNUNET-style URI.
361 361
362Options: 362Options:
363 -h, --help : prints this message 363 -h, --help : prints this message
364""") 364"""
365 )
365 366
366 367
367if '__main__' == __name__: 368if '__main__' == __name__:
@@ -373,7 +374,7 @@ if '__main__' == __name__:
373 usage() 374 usage()
374 sys.exit(2) 375 sys.exit(2)
375 for option, value in opts: 376 for option, value in opts:
376 if option in("-h", "--help"): 377 if option in ("-h", "--help"):
377 usage() 378 usage()
378 sys.exit(0) 379 sys.exit(0)
379 if len(args) != 1: 380 if len(args) != 1:
diff --git a/contrib/scripts/gnunet_janitor.py.in b/contrib/scripts/gnunet_janitor.py.in
index b0b50ca76..d6834bfb4 100644
--- a/contrib/scripts/gnunet_janitor.py.in
+++ b/contrib/scripts/gnunet_janitor.py.in
@@ -31,6 +31,7 @@ import time
31import signal 31import signal
32import terminate 32import terminate
33 33
34
34def get_process_list(): 35def get_process_list():
35 result = [] 36 result = []
36 pids = [pid for pid in os.listdir('/proc') if pid.isdigit()] 37 pids = [pid for pid in os.listdir('/proc') if pid.isdigit()]
diff --git a/contrib/scripts/gnunet_pyexpect.py.in b/contrib/scripts/gnunet_pyexpect.py.in
index 188436f51..48f8acdc1 100644
--- a/contrib/scripts/gnunet_pyexpect.py.in
+++ b/contrib/scripts/gnunet_pyexpect.py.in
@@ -11,7 +11,7 @@
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# Affero General Public License for more details. 13# Affero General Public License for more details.
14# 14#
15# You should have received a copy of the GNU Affero General Public License 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/>. 16# along with this program. If not, see <http://www.gnu.org/licenses/>.
17# 17#
@@ -27,7 +27,7 @@ import shutil
27import time 27import time
28 28
29 29
30class pexpect (object): 30class pexpect(object):
31 def __init__(self): 31 def __init__(self):
32 super(pexpect, self).__init__() 32 super(pexpect, self).__init__()
33 33
@@ -54,12 +54,22 @@ class pexpect (object):
54 if len(stream) == 0: 54 if len(stream) == 0:
55 return True 55 return True
56 else: 56 else:
57 print("Failed to find `{1}' in {0}, which is `{2}' ({3})".format(s, r, stream, len(stream))) 57 print(
58 "Failed to find `{1}' in {0}, which is `{2}' ({3})".
59 format(s, r, stream, len(stream))
60 )
58 sys.exit(2) 61 sys.exit(2)
59 raise ValueError("Argument `r' should be an instance of re.RegexObject or a special string, but is `{0}'".format(r)) 62 raise ValueError(
63 "Argument `r' should be an instance of re.RegexObject or a special string, but is `{0}'"
64 .format(r)
65 )
60 m = r.search(stream.decode(), flags) 66 m = r.search(stream.decode(), flags)
61 if not m: 67 if not m:
62 print("Failed to find `{1}' in {0}, which is is `{2}'".format(s, r.pattern, stream)) 68 print(
69 "Failed to find `{1}' in {0}, which is is `{2}'".format(
70 s, r.pattern, stream
71 )
72 )
63 sys.exit(2) 73 sys.exit(2)
64 stream = stream[m.end():] 74 stream = stream[m.end():]
65 if s == 'stdout': 75 if s == 'stdout':
diff --git a/contrib/scripts/pydiffer.py.in b/contrib/scripts/pydiffer.py.in
index 35d9ffa35..08f0f4ae6 100644
--- a/contrib/scripts/pydiffer.py.in
+++ b/contrib/scripts/pydiffer.py.in
@@ -10,7 +10,10 @@ def getdiff(old, new):
10 diff = [] 10 diff = []
11 with open(old) as a: 11 with open(old) as a:
12 with open(new) as b: 12 with open(new) as b:
13 for l in difflib.unified_diff(a.read().splitlines(), b.read().splitlines()): 13 for l in difflib.unified_diff(
14 a.read().splitlines(),
15 b.read().splitlines()
16 ):
14 diff.append(l) 17 diff.append(l)
15 return diff 18 return diff
16 19
diff --git a/contrib/scripts/removetrailingwhitespace.py.in b/contrib/scripts/removetrailingwhitespace.py.in
index 5824fb591..e6c2d9014 100755
--- a/contrib/scripts/removetrailingwhitespace.py.in
+++ b/contrib/scripts/removetrailingwhitespace.py.in
@@ -3,7 +3,6 @@
3import sys 3import sys
4import re 4import re
5 5
6
7for fileName in sys.argv[1:]: 6for fileName in sys.argv[1:]:
8 f = open(fileName, 'r+') 7 f = open(fileName, 'r+')
9 fileString = f.read() 8 fileString = f.read()
diff --git a/contrib/scripts/terminate.py.in b/contrib/scripts/terminate.py.in
index f57ac6167..2cb4a13c4 100644
--- a/contrib/scripts/terminate.py.in
+++ b/contrib/scripts/terminate.py.in
@@ -26,7 +26,7 @@ import subprocess
26import os 26import os
27 27
28 28
29class dummyobj (object): 29class dummyobj(object):
30 pass 30 pass
31 31
32 32
diff --git a/src/arm/test_gnunet_arm.py.in b/src/arm/test_gnunet_arm.py.in
index 1d067b5d9..9605c4eae 100644
--- a/src/arm/test_gnunet_arm.py.in
+++ b/src/arm/test_gnunet_arm.py.in
@@ -56,25 +56,41 @@ def fail(result):
56def end_arm_failer(command, rc, stdo, stde, normal): 56def end_arm_failer(command, rc, stdo, stde, normal):
57 if normal: 57 if normal:
58 if rc != 0: 58 if rc != 0:
59 fail("FAIL: error running {}\nCommand output was:\n{}\n{}".format(command, stdo, stde)) 59 fail(
60 "FAIL: error running {}\nCommand output was:\n{}\n{}".format(
61 command, stdo, stde
62 )
63 )
60 else: 64 else:
61 if rc == 0: 65 if rc == 0:
62 fail("FAIL: expected error while running {}\nCommand output was:\n{}\n{}".format(command, stdo, stde)) 66 fail(
67 "FAIL: expected error while running {}\nCommand output was:\n{}\n{}"
68 .format(command, stdo, stde)
69 )
63 70
64 71
65def print_only_failer(command, rc, stdo, stde, normal): 72def print_only_failer(command, rc, stdo, stde, normal):
66 if normal: 73 if normal:
67 if rc != 0: 74 if rc != 0:
68 print("FAIL: error running {}\nCommand output was:\n{}\n{}".format(command, stdo, stde)) 75 print(
76 "FAIL: error running {}\nCommand output was:\n{}\n{}".format(
77 command, stdo, stde
78 )
79 )
69 sys.exit(1) 80 sys.exit(1)
70 else: 81 else:
71 if rc == 0: 82 if rc == 0:
72 print("FAIL: expected error while running {}\nCommand output was:\n{}\n{}".format(command, stdo, stde)) 83 print(
84 "FAIL: expected error while running {}\nCommand output was:\n{}\n{}"
85 .format(command, stdo, stde)
86 )
73 sys.exit(1) 87 sys.exit(1)
74 88
75 89
76def r_something(to_run, extra_args, failer=None, normal=True, **kw): 90def r_something(to_run, extra_args, failer=None, normal=True, **kw):
77 rc, stdo, stde = sub_run(to_run + extra_args, nofail=True, want_stde=True, **kw) 91 rc, stdo, stde = sub_run(
92 to_run + extra_args, nofail=True, want_stde=True, **kw
93 )
78 if failer is not None: 94 if failer is not None:
79 failer(to_run + extra_args, rc, stdo, stde, normal) 95 failer(to_run + extra_args, rc, stdo, stde, normal)
80 return (rc, stdo, stde) 96 return (rc, stdo, stde)
diff --git a/src/consensus/consensus-simulation.py.in b/src/consensus/consensus-simulation.py.in
index 39daf81c6..c6b97e63f 100644
--- a/src/consensus/consensus-simulation.py.in
+++ b/src/consensus/consensus-simulation.py.in
@@ -46,9 +46,10 @@ def simulate(k, n, verbose):
46 46
47 def done_p(): 47 def done_p():
48 for x in range(k, n): 48 for x in range(k, n):
49 if bsc(info[x]) < n-k: 49 if bsc(info[x]) < n - k:
50 return False 50 return False
51 return True 51 return True
52
52 rounds = 0 53 rounds = 0
53 while not done_p(): 54 while not done_p():
54 if verbose: 55 if verbose:
@@ -65,7 +66,10 @@ def simulate(k, n, verbose):
65 partner_physical = peers.index(partner_logical) 66 partner_physical = peers.index(partner_logical)
66 if peer_physical < k or partner_physical < k: 67 if peer_physical < k or partner_physical < k:
67 if verbose: 68 if verbose:
68 print("bad peer in connection", peer_physical, "--", partner_physical) 69 print(
70 "bad peer in connection", peer_physical, "--",
71 partner_physical
72 )
69 continue 73 continue
70 if peer_logical & arc == 0: 74 if peer_logical & arc == 0:
71 # we are outgoing 75 # we are outgoing
@@ -78,8 +82,11 @@ def simulate(k, n, verbose):
78 ghost_partner_logical = (peer_logical - arc) % n 82 ghost_partner_logical = (peer_logical - arc) % n
79 if ghost_partner_logical & arc == 0: 83 if ghost_partner_logical & arc == 0:
80 peer_type = peer_type + ", ghost incoming" 84 peer_type = peer_type + ", ghost incoming"
81 new_info[peer_physical] = new_info[peer_physical] | info[peer_physical] | info[partner_physical] 85 new_info[peer_physical] = new_info[peer_physical] | info[
82 new_info[partner_physical] = new_info[partner_physical] | info[peer_physical] | info[partner_physical] 86 peer_physical] | info[partner_physical]
87 new_info[partner_physical
88 ] = new_info[partner_physical] | info[
89 peer_physical] | info[partner_physical]
83 else: 90 else:
84 peer_type = "incoming" 91 peer_type = "incoming"
85 if verbose > 1: 92 if verbose > 1:
diff --git a/src/dht/test_dht_tools.py.in b/src/dht/test_dht_tools.py.in
index 2d9379a42..c2f95e4b5 100644
--- a/src/dht/test_dht_tools.py.in
+++ b/src/dht/test_dht_tools.py.in
@@ -94,20 +94,34 @@ def r_put(extra_args, **kw):
94def end_arm_failer(command, rc, stdo, stde, normal): 94def end_arm_failer(command, rc, stdo, stde, normal):
95 if normal: 95 if normal:
96 if rc != 0: 96 if rc != 0:
97 fail("FAIL: error running {}\nCommand output was:\n{}\n{}".format(command, stdo, stde)) 97 fail(
98 "FAIL: error running {}\nCommand output was:\n{}\n{}".format(
99 command, stdo, stde
100 )
101 )
98 else: 102 else:
99 if rc == 0: 103 if rc == 0:
100 fail("FAIL: expected error while running {}\nCommand output was:\n{}\n{}".format(command, stdo, stde)) 104 fail(
105 "FAIL: expected error while running {}\nCommand output was:\n{}\n{}"
106 .format(command, stdo, stde)
107 )
101 108
102 109
103def print_only_failer(command, rc, stdo, stde, normal): 110def print_only_failer(command, rc, stdo, stde, normal):
104 if normal: 111 if normal:
105 if rc != 0: 112 if rc != 0:
106 print("FAIL: error running {}\nCommand output was:\n{}\n{}".format(command, stdo, stde)) 113 print(
114 "FAIL: error running {}\nCommand output was:\n{}\n{}".format(
115 command, stdo, stde
116 )
117 )
107 cleanup(1) 118 cleanup(1)
108 else: 119 else:
109 if rc == 0: 120 if rc == 0:
110 print("FAIL: expected error while running {}\nCommand output was:\n{}\n{}".format(command, stdo, stde)) 121 print(
122 "FAIL: expected error while running {}\nCommand output was:\n{}\n{}"
123 .format(command, stdo, stde)
124 )
111 cleanup(1) 125 cleanup(1)
112 126
113 127
@@ -122,10 +136,13 @@ print("PASS")
122time.sleep(1) 136time.sleep(1)
123 137
124print("TEST: Testing get...", end='') 138print("TEST: Testing get...", end='')
125rc, stdo, stde = r_get(['-k', 'testkey', '-T', '50 ms', '-t', '8'], want_stdo=True, failer=end_arm_failer) 139rc, stdo, stde = r_get(['-k', 'testkey', '-T', '50 ms', '-t', '8'],
140 want_stdo=True,
141 failer=end_arm_failer)
126stdo = stdo.decode('utf-8').replace('\r', '').splitlines() 142stdo = stdo.decode('utf-8').replace('\r', '').splitlines()
127expect = "Result 0, type 8:\ntestdata".splitlines() 143expect = "Result 0, type 8:\ntestdata".splitlines()
128if len(stdo) != 2 or len(expect) != 2 or stdo[0] != expect[0] or stdo[1] != expect[1]: 144if len(stdo) != 2 or len(expect
145 ) != 2 or stdo[0] != expect[0] or stdo[1] != expect[1]:
129 fail("output `{}' differs from expected `{}'".format(stdo, expect)) 146 fail("output `{}' differs from expected `{}'".format(stdo, expect))
130print("PASS") 147print("PASS")
131 148
diff --git a/src/fs/test_gnunet_fs_idx.py.in b/src/fs/test_gnunet_fs_idx.py.in
index 4798cf503..2c8c7e8ec 100755
--- a/src/fs/test_gnunet_fs_idx.py.in
+++ b/src/fs/test_gnunet_fs_idx.py.in
@@ -11,7 +11,7 @@
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# Affero General Public License for more details. 13# Affero General Public License for more details.
14# 14#
15# You should have received a copy of the GNU Affero General Public License 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/>. 16# along with this program. If not, see <http://www.gnu.org/licenses/>.
17# 17#
@@ -43,7 +43,9 @@ elif os.name == 'nt':
43 unindex = './gnunet-unindex.exe' 43 unindex = './gnunet-unindex.exe'
44 44
45if os.name == "nt": 45if os.name == "nt":
46 shutil.rmtree(os.path.join(os.getenv("TEMP"), "gnunet-test-fs-py-idx"), True) 46 shutil.rmtree(
47 os.path.join(os.getenv("TEMP"), "gnunet-test-fs-py-idx"), True
48 )
47else: 49else:
48 shutil.rmtree("/tmp/gnunet-test-fs-py-idx", True) 50 shutil.rmtree("/tmp/gnunet-test-fs-py-idx", True)
49 51
@@ -53,22 +55,59 @@ arm.communicate()
53try: 55try:
54 pub = pexpect() 56 pub = pexpect()
55 57
56 pub.spawn(None, [publish, '-c', 'test_gnunet_fs_idx_data.conf', '-m', "description:Test archive", '-k', 'tst', 'test_gnunet_fs_rec_data.tgz'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) 58 pub.spawn(
57 pub.expect("stdout", re.compile(r"URI is `gnunet://fs/chk/2ZMHKPV74CB6GB1GFKQRR95BXJQA2SER25FN48GAW7WSBPA0GDEM5Y74V1ZJHM0NA6919TVW376BHTFDRE3RYS0KRY92M1QJVKPHFCR\.49BT3V5C10KA1695JF71FCT8ZZG4JMJSH04BD9CT22R6KEM915A7CEST17RD0QYTHXV5M4HHEGJMEZSFRDB7JAYC0EMJAN2V781E9DG\.17822'\.\r?\n")) 59 None, [
60 publish, '-c', 'test_gnunet_fs_idx_data.conf', '-m',
61 "description:Test archive", '-k', 'tst',
62 'test_gnunet_fs_rec_data.tgz'
63 ],
64 stdout=subprocess.PIPE,
65 stderr=subprocess.STDOUT
66 )
67 pub.expect(
68 "stdout",
69 re.compile(
70 r"URI is `gnunet://fs/chk/2ZMHKPV74CB6GB1GFKQRR95BXJQA2SER25FN48GAW7WSBPA0GDEM5Y74V1ZJHM0NA6919TVW376BHTFDRE3RYS0KRY92M1QJVKPHFCR\.49BT3V5C10KA1695JF71FCT8ZZG4JMJSH04BD9CT22R6KEM915A7CEST17RD0QYTHXV5M4HHEGJMEZSFRDB7JAYC0EMJAN2V781E9DG\.17822'\.\r?\n"
71 )
72 )
58 73
59 down = pexpect() 74 down = pexpect()
60 down.spawn(None, [download, '-c', 'test_gnunet_fs_idx_data.conf', '-o', 'test_gnunet_fs_rec_data.tar.gz', 'gnunet://fs/chk/2ZMHKPV74CB6GB1GFKQRR95BXJQA2SER25FN48GAW7WSBPA0GDEM5Y74V1ZJHM0NA6919TVW376BHTFDRE3RYS0KRY92M1QJVKPHFCR.49BT3V5C10KA1695JF71FCT8ZZG4JMJSH04BD9CT22R6KEM915A7CEST17RD0QYTHXV5M4HHEGJMEZSFRDB7JAYC0EMJAN2V781E9DG.17822'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) 75 down.spawn(
61 down.expect("stdout", re.compile(r"Downloading `test_gnunet_fs_rec_data.tar.gz' done (.*).\r?\n")) 76 None, [
77 download, '-c', 'test_gnunet_fs_idx_data.conf', '-o',
78 'test_gnunet_fs_rec_data.tar.gz',
79 'gnunet://fs/chk/2ZMHKPV74CB6GB1GFKQRR95BXJQA2SER25FN48GAW7WSBPA0GDEM5Y74V1ZJHM0NA6919TVW376BHTFDRE3RYS0KRY92M1QJVKPHFCR.49BT3V5C10KA1695JF71FCT8ZZG4JMJSH04BD9CT22R6KEM915A7CEST17RD0QYTHXV5M4HHEGJMEZSFRDB7JAYC0EMJAN2V781E9DG.17822'
80 ],
81 stdout=subprocess.PIPE,
82 stderr=subprocess.STDOUT
83 )
84 down.expect(
85 "stdout",
86 re.compile(
87 r"Downloading `test_gnunet_fs_rec_data.tar.gz' done (.*).\r?\n"
88 )
89 )
62 os.remove("test_gnunet_fs_rec_data.tar.gz") 90 os.remove("test_gnunet_fs_rec_data.tar.gz")
63 91
64 un = pexpect() 92 un = pexpect()
65 un.spawn(None, [unindex, '-c', 'test_gnunet_fs_idx_data.conf', 'test_gnunet_fs_rec_data.tgz'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) 93 un.spawn(
94 None, [
95 unindex, '-c', 'test_gnunet_fs_idx_data.conf',
96 'test_gnunet_fs_rec_data.tgz'
97 ],
98 stdout=subprocess.PIPE,
99 stderr=subprocess.STDOUT
100 )
66 un.expect("stdout", re.compile(r'Unindexing done\.\r?\n')) 101 un.expect("stdout", re.compile(r'Unindexing done\.\r?\n'))
67 102
68finally: 103finally:
69 arm = subprocess.Popen([gnunetarm, '-eq', '-c', 'test_gnunet_fs_idx_data.conf']) 104 arm = subprocess.Popen([
105 gnunetarm, '-eq', '-c', 'test_gnunet_fs_idx_data.conf'
106 ])
70 arm.communicate() 107 arm.communicate()
71 if os.name == "nt": 108 if os.name == "nt":
72 shutil.rmtree(os.path.join(os.getenv("TEMP"), "gnunet-test-fs-py-idx"), True) 109 shutil.rmtree(
110 os.path.join(os.getenv("TEMP"), "gnunet-test-fs-py-idx"), True
111 )
73 else: 112 else:
74 shutil.rmtree("/tmp/gnunet-test-fs-py-idx", True) 113 shutil.rmtree("/tmp/gnunet-test-fs-py-idx", True)
diff --git a/src/fs/test_gnunet_fs_psd.py.in b/src/fs/test_gnunet_fs_psd.py.in
index a1e4db9d5..abb3d0b83 100755
--- a/src/fs/test_gnunet_fs_psd.py.in
+++ b/src/fs/test_gnunet_fs_psd.py.in
@@ -11,7 +11,7 @@
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# Affero General Public License for more details. 13# Affero General Public License for more details.
14# 14#
15# You should have received a copy of the GNU Affero General Public License 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/>. 16# along with this program. If not, see <http://www.gnu.org/licenses/>.
17# 17#
@@ -38,8 +38,8 @@ except NameError:
38reload(sys) 38reload(sys)
39 39
40# Force encoding to utf-8, as this test otherwise fails 40# Force encoding to utf-8, as this test otherwise fails
41# on some systems (see #5094). In Python 3+ there is no attribute 41# on some systems (see #5094). In Python 3+ there is no attribute
42# sys.setdefaultencoding anymore. 42# sys.setdefaultencoding anymore.
43if (3 < sys.version_info[0]): 43if (3 < sys.version_info[0]):
44 sys.setdefaultencoding('utf8') 44 sys.setdefaultencoding('utf8')
45 45
@@ -68,9 +68,11 @@ if "GNUNET_PREFIX" in os.environ:
68else: 68else:
69 print("You need to export GNUNET_PREFIX") 69 print("You need to export GNUNET_PREFIX")
70 sys.exit(1) 70 sys.exit(1)
71 71
72if os.name == "nt": 72if os.name == "nt":
73 shutil.rmtree(os.path.join(os.getenv("TEMP"), "gnunet-test-fs-py-psd"), True) 73 shutil.rmtree(
74 os.path.join(os.getenv("TEMP"), "gnunet-test-fs-py-psd"), True
75 )
74else: 76else:
75 shutil.rmtree("/tmp/gnunet-test-fs-py-psd", True) 77 shutil.rmtree("/tmp/gnunet-test-fs-py-psd", True)
76 78
@@ -80,23 +82,68 @@ arm.communicate()
80# first, basic publish-search-download run 82# first, basic publish-search-download run
81try: 83try:
82 pub = pexpect() 84 pub = pexpect()
83 pub.spawn(None, [publish, '-c', 'test_gnunet_fs_psd_data.conf', '-n', '-m', "description:Test archive", '-k', 'tst', 'test_gnunet_fs_rec_data.tgz'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) 85 pub.spawn(
84 pub.expect("stdout", re.compile(r"Publishing `.+test_gnunet_fs_rec_data.tgz' done\.\r?\n")) 86 None, [
85 pub.expect("stdout", re.compile(r"URI is `gnunet://fs/chk/2ZMHKPV74CB6GB1GFKQRR95BXJQA2SER25FN48GAW7WSBPA0GDEM5Y74V1ZJHM0NA6919TVW376BHTFDRE3RYS0KRY92M1QJVKPHFCR\.49BT3V5C10KA1695JF71FCT8ZZG4JMJSH04BD9CT22R6KEM915A7CEST17RD0QYTHXV5M4HHEGJMEZSFRDB7JAYC0EMJAN2V781E9DG\.17822'\.\r?\n")) 87 publish, '-c', 'test_gnunet_fs_psd_data.conf', '-n', '-m',
88 "description:Test archive", '-k', 'tst',
89 'test_gnunet_fs_rec_data.tgz'
90 ],
91 stdout=subprocess.PIPE,
92 stderr=subprocess.STDOUT
93 )
94 pub.expect(
95 "stdout",
96 re.compile(r"Publishing `.+test_gnunet_fs_rec_data.tgz' done\.\r?\n")
97 )
98 pub.expect(
99 "stdout",
100 re.compile(
101 r"URI is `gnunet://fs/chk/2ZMHKPV74CB6GB1GFKQRR95BXJQA2SER25FN48GAW7WSBPA0GDEM5Y74V1ZJHM0NA6919TVW376BHTFDRE3RYS0KRY92M1QJVKPHFCR\.49BT3V5C10KA1695JF71FCT8ZZG4JMJSH04BD9CT22R6KEM915A7CEST17RD0QYTHXV5M4HHEGJMEZSFRDB7JAYC0EMJAN2V781E9DG\.17822'\.\r?\n"
102 )
103 )
86 104
87 s = pexpect() 105 s = pexpect()
88 s.spawn(None, [search, '-V', '-t', '1000 ms', '-N', '1', '-c', 'test_gnunet_fs_psd_data.conf', 'tst'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) 106 s.spawn(
89 s.expect("stdout", re.compile(r'gnunet-download -o "test_gnunet_fs_rec_data.tgz" gnunet://fs/chk/2ZMHKPV74CB6GB1GFKQRR95BXJQA2SER25FN48GAW7WSBPA0GDEM5Y74V1ZJHM0NA6919TVW376BHTFDRE3RYS0KRY92M1QJVKPHFCR\.49BT3V5C10KA1695JF71FCT8ZZG4JMJSH04BD9CT22R6KEM915A7CEST17RD0QYTHXV5M4HHEGJMEZSFRDB7JAYC0EMJAN2V781E9DG\.17822\r?\n')) 107 None, [
108 search, '-V', '-t', '1000 ms', '-N', '1', '-c',
109 'test_gnunet_fs_psd_data.conf', 'tst'
110 ],
111 stdout=subprocess.PIPE,
112 stderr=subprocess.STDOUT
113 )
114 s.expect(
115 "stdout",
116 re.compile(
117 r'gnunet-download -o "test_gnunet_fs_rec_data.tgz" gnunet://fs/chk/2ZMHKPV74CB6GB1GFKQRR95BXJQA2SER25FN48GAW7WSBPA0GDEM5Y74V1ZJHM0NA6919TVW376BHTFDRE3RYS0KRY92M1QJVKPHFCR\.49BT3V5C10KA1695JF71FCT8ZZG4JMJSH04BD9CT22R6KEM915A7CEST17RD0QYTHXV5M4HHEGJMEZSFRDB7JAYC0EMJAN2V781E9DG\.17822\r?\n'
118 )
119 )
90 120
91 down = pexpect() 121 down = pexpect()
92 down.spawn(None, [download, '-c', 'test_gnunet_fs_psd_data.conf', '-o', 'test_gnunet_fs_rec_data.tar.gz', 'gnunet://fs/chk/2ZMHKPV74CB6GB1GFKQRR95BXJQA2SER25FN48GAW7WSBPA0GDEM5Y74V1ZJHM0NA6919TVW376BHTFDRE3RYS0KRY92M1QJVKPHFCR.49BT3V5C10KA1695JF71FCT8ZZG4JMJSH04BD9CT22R6KEM915A7CEST17RD0QYTHXV5M4HHEGJMEZSFRDB7JAYC0EMJAN2V781E9DG.17822'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) 122 down.spawn(
93 down.expect("stdout", re.compile(r"Downloading `test_gnunet_fs_rec_data.tar.gz' done (.*).\r?\n")) 123 None, [
124 download, '-c', 'test_gnunet_fs_psd_data.conf', '-o',
125 'test_gnunet_fs_rec_data.tar.gz',
126 'gnunet://fs/chk/2ZMHKPV74CB6GB1GFKQRR95BXJQA2SER25FN48GAW7WSBPA0GDEM5Y74V1ZJHM0NA6919TVW376BHTFDRE3RYS0KRY92M1QJVKPHFCR.49BT3V5C10KA1695JF71FCT8ZZG4JMJSH04BD9CT22R6KEM915A7CEST17RD0QYTHXV5M4HHEGJMEZSFRDB7JAYC0EMJAN2V781E9DG.17822'
127 ],
128 stdout=subprocess.PIPE,
129 stderr=subprocess.STDOUT
130 )
131 down.expect(
132 "stdout",
133 re.compile(
134 r"Downloading `test_gnunet_fs_rec_data.tar.gz' done (.*).\r?\n"
135 )
136 )
94 os.remove("test_gnunet_fs_rec_data.tar.gz") 137 os.remove("test_gnunet_fs_rec_data.tar.gz")
95 138
96finally: 139finally:
97 arm = subprocess.Popen([gnunetarm, '-eq', '-c', 'test_gnunet_fs_psd_data.conf']) 140 arm = subprocess.Popen([
141 gnunetarm, '-eq', '-c', 'test_gnunet_fs_psd_data.conf'
142 ])
98 arm.communicate() 143 arm.communicate()
99 if os.name == "nt": 144 if os.name == "nt":
100 shutil.rmtree(os.path.join(os.getenv("TEMP"), "gnunet-test-fs-py-psd"), True) 145 shutil.rmtree(
146 os.path.join(os.getenv("TEMP"), "gnunet-test-fs-py-psd"), True
147 )
101 else: 148 else:
102 shutil.rmtree("/tmp/gnunet-test-fs-py-psd", True) 149 shutil.rmtree("/tmp/gnunet-test-fs-py-psd", True)
diff --git a/src/fs/test_gnunet_fs_rec.py.in b/src/fs/test_gnunet_fs_rec.py.in
index 0f881564f..0e1512b26 100755
--- a/src/fs/test_gnunet_fs_rec.py.in
+++ b/src/fs/test_gnunet_fs_rec.py.in
@@ -50,7 +50,9 @@ elif os.name == 'nt':
50 directory = './gnunet-directory.exe' 50 directory = './gnunet-directory.exe'
51 51
52if os.name == "nt": 52if os.name == "nt":
53 shutil.rmtree(os.path.join(os.getenv("TEMP"), "gnunet-test-fs-py-rec"), True) 53 shutil.rmtree(
54 os.path.join(os.getenv("TEMP"), "gnunet-test-fs-py-rec"), True
55 )
54else: 56else:
55 shutil.rmtree("/tmp/gnunet-test-fs-py-rec", True) 57 shutil.rmtree("/tmp/gnunet-test-fs-py-rec", True)
56 58
@@ -65,33 +67,83 @@ tar.extractall()
65# first, basic publish-search-download run 67# first, basic publish-search-download run
66try: 68try:
67 pub = pexpect() 69 pub = pexpect()
68 pub.spawn(None, [publish, '-c', 'test_gnunet_fs_rec_data.conf', '-k', 'testdir', 'dir/'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) 70 pub.spawn(
71 None, [
72 publish, '-c', 'test_gnunet_fs_rec_data.conf', '-k', 'testdir',
73 'dir/'
74 ],
75 stdout=subprocess.PIPE,
76 stderr=subprocess.STDOUT
77 )
69 # Can't say much for publishing, except that the last one is the toplevel directory 78 # Can't say much for publishing, except that the last one is the toplevel directory
70 pub.expect("stdout", re.compile(r"Publishing `.+' done\.\r?\n")) 79 pub.expect("stdout", re.compile(r"Publishing `.+' done\.\r?\n"))
71 pub.expect("stdout", re.compile(r"URI is `gnunet://fs/chk/[A-Z0-9]{103}\.[A-Z0-9]{103}\.\d+'\.\r?\n")) 80 pub.expect(
81 "stdout",
82 re.compile(
83 r"URI is `gnunet://fs/chk/[A-Z0-9]{103}\.[A-Z0-9]{103}\.\d+'\.\r?\n"
84 )
85 )
72 pub.expect("stdout", re.compile(r"Publishing `.+' done\.\r?\n")) 86 pub.expect("stdout", re.compile(r"Publishing `.+' done\.\r?\n"))
73 pub.expect("stdout", re.compile(r"URI is `gnunet://fs/chk/[A-Z0-9]{103}\.[A-Z0-9]{103}\.\d+'\.\r?\n")) 87 pub.expect(
88 "stdout",
89 re.compile(
90 r"URI is `gnunet://fs/chk/[A-Z0-9]{103}\.[A-Z0-9]{103}\.\d+'\.\r?\n"
91 )
92 )
74 pub.expect("stdout", re.compile(r"Publishing `.+' done\.\r?\n")) 93 pub.expect("stdout", re.compile(r"Publishing `.+' done\.\r?\n"))
75 pub.expect("stdout", re.compile(r"URI is `gnunet://fs/chk/[A-Z0-9]{103}\.[A-Z0-9]{103}\.\d+'\.\r?\n")) 94 pub.expect(
95 "stdout",
96 re.compile(
97 r"URI is `gnunet://fs/chk/[A-Z0-9]{103}\.[A-Z0-9]{103}\.\d+'\.\r?\n"
98 )
99 )
76 pub.expect("stdout", re.compile(r"Publishing `.+' done\.\r?\n")) 100 pub.expect("stdout", re.compile(r"Publishing `.+' done\.\r?\n"))
77 pub.expect("stdout", re.compile(r"URI is `gnunet://fs/chk/[A-Z0-9]{103}\.[A-Z0-9]{103}\.\d+'\.\r?\n")) 101 pub.expect(
102 "stdout",
103 re.compile(
104 r"URI is `gnunet://fs/chk/[A-Z0-9]{103}\.[A-Z0-9]{103}\.\d+'\.\r?\n"
105 )
106 )
78 pub.expect("stdout", re.compile(r"Publishing `.+' done\.\r?\n")) 107 pub.expect("stdout", re.compile(r"Publishing `.+' done\.\r?\n"))
79 pub.expect("stdout", re.compile(r"URI is `gnunet://fs/chk/[A-Z0-9]{103}\.[A-Z0-9]{103}\.\d+'\.\r?\n")) 108 pub.expect(
109 "stdout",
110 re.compile(
111 r"URI is `gnunet://fs/chk/[A-Z0-9]{103}\.[A-Z0-9]{103}\.\d+'\.\r?\n"
112 )
113 )
80 pub.expect("stdout", re.compile(r"Publishing `.+' done\.\r?\n")) 114 pub.expect("stdout", re.compile(r"Publishing `.+' done\.\r?\n"))
81 pub.expect("stdout", re.compile(r"URI is `gnunet://fs/chk/[A-Z0-9]{103}\.[A-Z0-9]{103}\.\d+'\.\r?\n")) 115 pub.expect(
82 pub.expect("stdout", re.compile(r"Publishing `.+[\\/]dir[\\/]' done\.\r?\n")) 116 "stdout",
117 re.compile(
118 r"URI is `gnunet://fs/chk/[A-Z0-9]{103}\.[A-Z0-9]{103}\.\d+'\.\r?\n"
119 )
120 )
121 pub.expect(
122 "stdout", re.compile(r"Publishing `.+[\\/]dir[\\/]' done\.\r?\n")
123 )
83 m = pub.expect("stdout", re.compile(r".+\r?\n")) 124 m = pub.expect("stdout", re.compile(r".+\r?\n"))
84 if not m: 125 if not m:
85 sys.exit(3) 126 sys.exit(3)
86 output = m.string 127 output = m.string
87 url = output[output.find("`")+1:output.find("'")] 128 url = output[output.find("`") + 1:output.find("'")]
88 129
89 down = pexpect() 130 down = pexpect()
90 down.spawn(None, [download, '-c', 'test_gnunet_fs_rec_data.conf', '-R', '-o', 'rdir.gnd', url], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) 131 down.spawn(
132 None, [
133 download, '-c', 'test_gnunet_fs_rec_data.conf', '-R', '-o',
134 'rdir.gnd', url
135 ],
136 stdout=subprocess.PIPE,
137 stderr=subprocess.STDOUT
138 )
91 down.expect("stdout", re.compile(r"Downloading `rdir.gnd' done (.*).\r?\n")) 139 down.expect("stdout", re.compile(r"Downloading `rdir.gnd' done (.*).\r?\n"))
92 140
93 d = pexpect() 141 d = pexpect()
94 d.spawn(None, [directory, '-c', 'test_gnunet_fs_rec_data.conf', 'rdir/a.gnd'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) 142 d.spawn(
143 None, [directory, '-c', 'test_gnunet_fs_rec_data.conf', 'rdir/a.gnd'],
144 stdout=subprocess.PIPE,
145 stderr=subprocess.STDOUT
146 )
95 d.expect("stdout", re.compile(r"Directory `a/' meta data:\r?\n")) 147 d.expect("stdout", re.compile(r"Directory `a/' meta data:\r?\n"))
96 d.expect("stdout", re.compile(r"Directory `a/' contents:\r?\n")) 148 d.expect("stdout", re.compile(r"Directory `a/' contents:\r?\n"))
97 d.expect("stdout", re.compile(r"COPYING (.*)\r?\n")) 149 d.expect("stdout", re.compile(r"COPYING (.*)\r?\n"))
@@ -101,14 +153,20 @@ try:
101 os.remove("rdir/a.gnd") 153 os.remove("rdir/a.gnd")
102 diff = dcdiff('dir', 'rdir') 154 diff = dcdiff('dir', 'rdir')
103 if len(diff) != 0: 155 if len(diff) != 0:
104 raise Exception("Unexpected difference between source directory and downloaded result:\n{}".format(diff)) 156 raise Exception(
105 157 "Unexpected difference between source directory and downloaded result:\n{}"
158 .format(diff)
159 )
106 160
107finally: 161finally:
108 arm = subprocess.Popen([gnunetarm, '-eq', '-c', 'test_gnunet_fs_rec_data.conf']) 162 arm = subprocess.Popen([
163 gnunetarm, '-eq', '-c', 'test_gnunet_fs_rec_data.conf'
164 ])
109 arm.communicate() 165 arm.communicate()
110 if os.name == "nt": 166 if os.name == "nt":
111 shutil.rmtree(os.path.join(os.getenv("TEMP"), "gnunet-test-fs-py-rec"), True) 167 shutil.rmtree(
168 os.path.join(os.getenv("TEMP"), "gnunet-test-fs-py-rec"), True
169 )
112 else: 170 else:
113 shutil.rmtree("/tmp/gnunet-test-fs-py-rec", True) 171 shutil.rmtree("/tmp/gnunet-test-fs-py-rec", True)
114 shutil.rmtree("dir", True) 172 shutil.rmtree("dir", True)
diff --git a/src/integration-tests/gnunet_pyexpect.py.in b/src/integration-tests/gnunet_pyexpect.py.in
index d757634a5..aad84e4f7 100644
--- a/src/integration-tests/gnunet_pyexpect.py.in
+++ b/src/integration-tests/gnunet_pyexpect.py.in
@@ -11,7 +11,7 @@
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# Affero General Public License for more details. 13# Affero General Public License for more details.
14# 14#
15# You should have received a copy of the GNU Affero General Public License 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/>. 16# along with this program. If not, see <http://www.gnu.org/licenses/>.
17# 17#
@@ -26,58 +26,69 @@ import sys
26import shutil 26import shutil
27import time 27import time
28 28
29class pexpect (object):
30 def __init__ (self):
31 super (pexpect, self).__init__ ()
32 29
33 def spawn (self, stdin, arglist, *pargs, **kwargs): 30class pexpect(object):
34 env = kwargs.pop ('env', None) 31 def __init__(self):
35 if env is None: 32 super(pexpect, self).__init__()
36 env = os.environ.copy () 33
37 # This messes up some testcases, disable log redirection 34 def spawn(self, stdin, arglist, *pargs, **kwargs):
38 env.pop ('GNUNET_FORCE_LOGFILE', None) 35 env = kwargs.pop('env', None)
39 self.proc = subprocess.Popen (arglist, *pargs, env=env, **kwargs) 36 if env is None:
40 if self.proc is None: 37 env = os.environ.copy()
41 print ("Failed to spawn a process {0}".format (arglist)) 38 # This messes up some testcases, disable log redirection
42 sys.exit (1) 39 env.pop('GNUNET_FORCE_LOGFILE', None)
43 if stdin is not None: 40 self.proc = subprocess.Popen(arglist, *pargs, env=env, **kwargs)
44 self.stdo, self.stde = self.proc.communicate (stdin) 41 if self.proc is None:
45 else: 42 print("Failed to spawn a process {0}".format(arglist))
46 self.stdo, self.stde = self.proc.communicate () 43 sys.exit(1)
47 return self.proc 44 if stdin is not None:
45 self.stdo, self.stde = self.proc.communicate(stdin)
46 else:
47 self.stdo, self.stde = self.proc.communicate()
48 return self.proc
48 49
49 def expect (self, s, r, flags=0): 50 def expect(self, s, r, flags=0):
50 stream = self.stdo if s == 'stdout' else self.stde 51 stream = self.stdo if s == 'stdout' else self.stde
51 if isinstance (r, str): 52 if isinstance(r, str):
52 if r == "EOF": 53 if r == "EOF":
53 if len (stream) == 0: 54 if len(stream) == 0:
54 return True 55 return True
56 else:
57 print(
58 "Failed to find `{1}' in {0}, which is `{2}' ({3})".
59 format(s, r, stream, len(stream))
60 )
61 sys.exit(2)
62 raise ValueError(
63 "Argument `r' should be an instance of re.RegexObject or a special string, but is `{0}'"
64 .format(r)
65 )
66 m = r.search(stream, flags)
67 if not m:
68 print(
69 "Failed to find `{1}' in {0}, which is is `{2}'".format(
70 s, r.pattern, stream
71 )
72 )
73 sys.exit(2)
74 stream = stream[m.end():]
75 if s == 'stdout':
76 self.stdo = stream
55 else: 77 else:
56 print ("Failed to find `{1}' in {0}, which is `{2}' ({3})".format (s, r, stream, len (stream))) 78 self.stde = stream
57 sys.exit (2) 79 return m
58 raise ValueError ("Argument `r' should be an instance of re.RegexObject or a special string, but is `{0}'".format (r))
59 m = r.search (stream, flags)
60 if not m:
61 print ("Failed to find `{1}' in {0}, which is is `{2}'".format (s, r.pattern, stream))
62 sys.exit (2)
63 stream = stream[m.end ():]
64 if s == 'stdout':
65 self.stdo = stream
66 else:
67 self.stde = stream
68 return m
69 80
70 def read (self, s, size=-1): 81 def read(self, s, size=-1):
71 stream = self.stdo if s == 'stdout' else self.stde 82 stream = self.stdo if s == 'stdout' else self.stde
72 result = "" 83 result = ""
73 if size < 0: 84 if size < 0:
74 result = stream 85 result = stream
75 new_stream = "" 86 new_stream = ""
76 else: 87 else:
77 result = stream[0:size] 88 result = stream[0:size]
78 new_stream = stream[size:] 89 new_stream = stream[size:]
79 if s == 'stdout': 90 if s == 'stdout':
80 self.stdo = new_stream 91 self.stdo = new_stream
81 else: 92 else:
82 self.stde = new_stream 93 self.stde = new_stream
83 return result 94 return result
diff --git a/src/integration-tests/gnunet_testing.py.in b/src/integration-tests/gnunet_testing.py.in
index c3596d232..10f9d4475 100644
--- a/src/integration-tests/gnunet_testing.py.in
+++ b/src/integration-tests/gnunet_testing.py.in
@@ -30,11 +30,13 @@ import logging
30logger = logging.getLogger() 30logger = logging.getLogger()
31handler = logging.StreamHandler() 31handler = logging.StreamHandler()
32formatter = logging.Formatter( 32formatter = logging.Formatter(
33 '%(asctime)s %(name)-12s %(levelname)-8s %(message)s') 33 '%(asctime)s %(name)-12s %(levelname)-8s %(message)s'
34)
34handler.setFormatter(formatter) 35handler.setFormatter(formatter)
35logger.addHandler(handler) 36logger.addHandler(handler)
36logger.setLevel(logging.DEBUG) 37logger.setLevel(logging.DEBUG)
37 38
39
38class Check(object): 40class Check(object):
39 def __init__(self, test): 41 def __init__(self, test):
40 self.fulfilled = False 42 self.fulfilled = False
@@ -92,7 +94,9 @@ class Check(object):
92 neg += 1 94 neg += 1
93 else: 95 else:
94 pos += 1 96 pos += 1
95 logger.debug('%s out of %s conditions fulfilled', str(pos), str(pos+neg)) 97 logger.debug(
98 '%s out of %s conditions fulfilled', str(pos), str(pos + neg)
99 )
96 return self.fulfilled 100 return self.fulfilled
97 101
98 def reset(self): 102 def reset(self):
@@ -115,9 +119,13 @@ class Condition(object):
115 119
116 def evaluate(self, failed_only): 120 def evaluate(self, failed_only):
117 if ((self.fulfilled == False) and (failed_only == True)): 121 if ((self.fulfilled == False) and (failed_only == True)):
118 logger.debug('%s condition for was %s', str(self.type), str(self.fulfilled)) 122 logger.debug(
123 '%s condition for was %s', str(self.type), str(self.fulfilled)
124 )
119 elif (failed_only == False): 125 elif (failed_only == False):
120 logger.debug('%s condition for was %s', str(self.type), str(self.fulfilled)) 126 logger.debug(
127 '%s condition for was %s', str(self.type), str(self.fulfilled)
128 )
121 return self.fulfilled 129 return self.fulfilled
122 130
123 131
@@ -140,9 +148,15 @@ class FileExistCondition(Condition):
140 148
141 def evaluate(self, failed_only): 149 def evaluate(self, failed_only):
142 if ((self.fulfilled == False) and (failed_only == True)): 150 if ((self.fulfilled == False) and (failed_only == True)):
143 logger.debug('%s confition for file %s was %s', str(self.type), self.file, str(self.fulfilled)) 151 logger.debug(
152 '%s confition for file %s was %s', str(self.type), self.file,
153 str(self.fulfilled)
154 )
144 elif (failed_only == False): 155 elif (failed_only == False):
145 logger.debug('%s confition for file %s was %s', str(self.type), self.file, str(self.fulfilled)) 156 logger.debug(
157 '%s confition for file %s was %s', str(self.type), self.file,
158 str(self.fulfilled)
159 )
146 return self.fulfilled 160 return self.fulfilled
147 161
148 162
@@ -158,7 +172,9 @@ class StatisticsCondition(Condition):
158 172
159 def check(self): 173 def check(self):
160 if (self.fulfilled == False): 174 if (self.fulfilled == False):
161 self.result = self.peer.get_statistics_value(self.subsystem, self.name) 175 self.result = self.peer.get_statistics_value(
176 self.subsystem, self.name
177 )
162 if (self.result == self.value): 178 if (self.result == self.value):
163 self.fulfilled = True 179 self.fulfilled = True
164 return True 180 return True
@@ -174,8 +190,14 @@ class StatisticsCondition(Condition):
174 else: 190 else:
175 fail = "" 191 fail = ""
176 op = " == " 192 op = " == "
177 if (((self.fulfilled == False) and (failed_only == True)) or (failed_only == False)): 193 if (((self.fulfilled == False) and (failed_only == True))
178 logger.debug('%s %s condition in subsystem %s: %s: (expected/real value) %s %s %s %s', self.peer.id[:4].decode("utf-8"), self.peer.cfg, self.subsystem.ljust(12), self.name.ljust(30), self.value, op, self.result, fail) 194 or (failed_only == False)):
195 logger.debug(
196 '%s %s condition in subsystem %s: %s: (expected/real value) %s %s %s %s',
197 self.peer.id[:4].decode("utf-8"), self.peer.cfg,
198 self.subsystem.ljust(12), self.name.ljust(30), self.value, op,
199 self.result, fail
200 )
179 return self.fulfilled 201 return self.fulfilled
180 202
181 203
@@ -195,8 +217,12 @@ class EqualStatisticsCondition(Condition):
195 217
196 def check(self): 218 def check(self):
197 if (self.fulfilled == False): 219 if (self.fulfilled == False):
198 self.result = self.peer.get_statistics_value(self.subsystem, self.name) 220 self.result = self.peer.get_statistics_value(
199 self.result2 = self.peer2.get_statistics_value(self.subsystem2, self.name2) 221 self.subsystem, self.name
222 )
223 self.result2 = self.peer2.get_statistics_value(
224 self.subsystem2, self.name2
225 )
200 if (self.result == self.result2): 226 if (self.result == self.result2):
201 self.fulfilled = True 227 self.fulfilled = True
202 return True 228 return True
@@ -206,8 +232,14 @@ class EqualStatisticsCondition(Condition):
206 return True 232 return True
207 233
208 def evaluate(self, failed_only): 234 def evaluate(self, failed_only):
209 if (((self.fulfilled == False) and (failed_only == True)) or (failed_only == False)): 235 if (((self.fulfilled == False) and (failed_only == True))
210 logger.debug('%s %s %s == %s %s %s %s %s', self.peer.id[:4], self.subsystem.ljust(12), self.name.ljust(30), self.result, self.peer2.id[:4], self.subsystem2.ljust(12), self.name2.ljust(30), self.result2) 236 or (failed_only == False)):
237 logger.debug(
238 '%s %s %s == %s %s %s %s %s', self.peer.id[:4],
239 self.subsystem.ljust(12), self.name.ljust(30), self.result,
240 self.peer2.id[:4], self.subsystem2.ljust(12),
241 self.name2.ljust(30), self.result2
242 )
211 return self.fulfilled 243 return self.fulfilled
212 244
213 245
@@ -262,19 +294,23 @@ class Peer(object):
262 # print('ERROR! Peer using cfg ' + 294 # print('ERROR! Peer using cfg ' +
263 # self.cfg + 295 # self.cfg +
264 # ' could not be stopped') 296 # ' could not be stopped')
265 logger.debug('ERROR! Peer using cfg %s could not be stopped', self.cfg) 297 logger.debug(
298 'ERROR! Peer using cfg %s could not be stopped', self.cfg
299 )
266 self.started = False 300 self.started = False
267 return ret 301 return ret
268 else: 302 else:
269 return False 303 return False
270 304
271 def start(self): 305 def start(self):
272 os.unsetenv ("XDG_CONFIG_HOME") 306 os.unsetenv("XDG_CONFIG_HOME")
273 os.unsetenv ("XDG_DATA_HOME") 307 os.unsetenv("XDG_DATA_HOME")
274 os.unsetenv ("XDG_CACHE_HOME") 308 os.unsetenv("XDG_CACHE_HOME")
275 self.test.p("Starting peer using cfg " + self.cfg) 309 self.test.p("Starting peer using cfg " + self.cfg)
276 try: 310 try:
277 server = subprocess.Popen([self.test.gnunetarm, '-sq', '-c', self.cfg]) 311 server = subprocess.Popen([
312 self.test.gnunetarm, '-sq', '-c', self.cfg
313 ])
278 server.communicate() 314 server.communicate()
279 except OSError: 315 except OSError:
280 # print("Can not start peer") 316 # print("Can not start peer")
@@ -285,7 +321,11 @@ class Peer(object):
285 test = '' 321 test = ''
286 try: 322 try:
287 server = pexpect() 323 server = pexpect()
288 server.spawn(None, [self.test.gnunetpeerinfo, '-c', self.cfg, '-s'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) 324 server.spawn(
325 None, [self.test.gnunetpeerinfo, '-c', self.cfg, '-s'],
326 stdout=subprocess.PIPE,
327 stderr=subprocess.STDOUT
328 )
289 test = server.read("stdout", 1024) 329 test = server.read("stdout", 1024)
290 except OSError: 330 except OSError:
291 # print("Can not get peer identity") 331 # print("Can not get peer identity")
@@ -299,7 +339,9 @@ class Peer(object):
299 return False 339 return False
300 self.test.p("Stopping peer using cfg " + self.cfg) 340 self.test.p("Stopping peer using cfg " + self.cfg)
301 try: 341 try:
302 server = subprocess.Popen([self.test.gnunetarm, '-eq', '-c', self.cfg]) 342 server = subprocess.Popen([
343 self.test.gnunetarm, '-eq', '-c', self.cfg
344 ])
303 server.communicate() 345 server.communicate()
304 except OSError: 346 except OSError:
305 # print("Can not stop peer") 347 # print("Can not stop peer")
@@ -310,7 +352,14 @@ class Peer(object):
310 352
311 def get_statistics_value(self, subsystem, name): 353 def get_statistics_value(self, subsystem, name):
312 server = pexpect() 354 server = pexpect()
313 server.spawn(None, [self.test.gnunetstatistics, '-c', self.cfg, '-q', '-n', name, '-s', subsystem], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) 355 server.spawn(
356 None, [
357 self.test.gnunetstatistics, '-c', self.cfg, '-q', '-n', name,
358 '-s', subsystem
359 ],
360 stdout=subprocess.PIPE,
361 stderr=subprocess.STDOUT
362 )
314 # server.expect ("stdout", re.compile (r"")) 363 # server.expect ("stdout", re.compile (r""))
315 test = server.read("stdout", 10240) 364 test = server.read("stdout", 10240)
316 tests = test.partition(b'\n') 365 tests = test.partition(b'\n')
@@ -319,9 +368,14 @@ class Peer(object):
319 tests = (tests[0][:-1], tests[1], tests[2]) 368 tests = (tests[0][:-1], tests[1], tests[2])
320 tests = tests[0] 369 tests = tests[0]
321 result = tests.decode("utf-8").strip() 370 result = tests.decode("utf-8").strip()
322 logger.debug('running gnunet-statistics %s for %s "/" %s yields %s', self.cfg, name, subsystem, result) 371 logger.debug(
372 'running gnunet-statistics %s for %s "/" %s yields %s', self.cfg,
373 name, subsystem, result
374 )
323 if (result.isdigit() == True): 375 if (result.isdigit() == True):
324 return result 376 return result
325 else: 377 else:
326 logger.debug('Invalid statistics value: %s is not a number!', result) 378 logger.debug(
379 'Invalid statistics value: %s is not a number!', result
380 )
327 return -1 381 return -1
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 4b4b35629..ddac326cd 100755
--- a/src/integration-tests/test_integration_bootstrap_and_connect.py.in
+++ b/src/integration-tests/test_integration_bootstrap_and_connect.py.in
@@ -32,7 +32,6 @@ from gnunet_testing import Check
32from gnunet_testing import Condition 32from gnunet_testing import Condition
33from gnunet_testing import * 33from gnunet_testing import *
34 34
35
36# 35#
37# 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
38# successfully connects to the server 37# successfully connects to the server
@@ -124,6 +123,7 @@ def check():
124 123
125 check.run_blocking(check_timeout, success_cont, fail_cont) 124 check.run_blocking(check_timeout, success_cont, fail_cont)
126 125
126
127# 127#
128# Test execution 128# Test execution
129# 129#
diff --git a/src/integration-tests/test_integration_clique.py.in b/src/integration-tests/test_integration_clique.py.in
index 0444cf249..a23c025ca 100755
--- a/src/integration-tests/test_integration_clique.py.in
+++ b/src/integration-tests/test_integration_clique.py.in
@@ -11,7 +11,7 @@
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# Affero General Public License for more details. 13# Affero General Public License for more details.
14# 14#
15# You should have received a copy of the GNU Affero General Public License 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/>. 16# along with this program. If not, see <http://www.gnu.org/licenses/>.
17# 17#
@@ -113,9 +113,13 @@ def check_connect():
113 check.add(StatisticsCondition(client, 'dht', '# peers connected', 2)) 113 check.add(StatisticsCondition(client, 'dht', '# peers connected', 2))
114 check.add(StatisticsCondition(client, 'fs', '# peers connected', 2)) 114 check.add(StatisticsCondition(client, 'fs', '# peers connected', 2))
115 115
116 check.add(StatisticsCondition(client_nat, 'transport', '# peers connected', 2)) 116 check.add(
117 StatisticsCondition(client_nat, 'transport', '# peers connected', 2)
118 )
117 check.add(StatisticsCondition(client_nat, 'core', '# peers connected', 2)) 119 check.add(StatisticsCondition(client_nat, 'core', '# peers connected', 2))
118 check.add(StatisticsCondition(client_nat, 'topology', '# peers connected', 2)) 120 check.add(
121 StatisticsCondition(client_nat, 'topology', '# peers connected', 2)
122 )
119 check.add(StatisticsCondition(client_nat, 'dht', '# peers connected', 2)) 123 check.add(StatisticsCondition(client_nat, 'dht', '# peers connected', 2))
120 check.add(StatisticsCondition(client_nat, 'fs', '# peers connected', 2)) 124 check.add(StatisticsCondition(client_nat, 'fs', '# peers connected', 2))
121 125
@@ -127,6 +131,7 @@ def check_connect():
127 131
128 check.run_blocking(check_timeout, success_cont, fail_cont) 132 check.run_blocking(check_timeout, success_cont, fail_cont)
129 133
134
130# 135#
131# Test execution 136# Test execution
132# 137#
@@ -199,7 +204,8 @@ def run():
199 cleanup() 204 cleanup()
200 sys.exit(success) 205 sys.exit(success)
201 206
202 if ((client.started == True) and (client_nat.started == True) and (server.started == True)): 207 if ((client.started == True) and (client_nat.started == True)
208 and (server.started == True)):
203 test.p('Peers started, running check') 209 test.p('Peers started, running check')
204 check_connect() 210 check_connect()
205 211
diff --git a/src/integration-tests/test_integration_disconnect.py.in b/src/integration-tests/test_integration_disconnect.py.in
index 737014e61..9861728c2 100755
--- a/src/integration-tests/test_integration_disconnect.py.in
+++ b/src/integration-tests/test_integration_disconnect.py.in
@@ -32,7 +32,6 @@ from gnunet_testing import Check
32from gnunet_testing import Condition 32from gnunet_testing import Condition
33from gnunet_testing import * 33from gnunet_testing import *
34 34
35
36# 35#
37# 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
38# successfully connects to the server. When both peers are connected 37# successfully connects to the server. When both peers are connected
@@ -48,158 +47,169 @@ verbose = True
48check_timeout = 180 47check_timeout = 180
49 48
50if os.name == "nt": 49if os.name == "nt":
51 tmp = os.getenv ("TEMP") 50 tmp = os.getenv("TEMP")
52 signals = [signal.SIGTERM, signal.SIGINT] 51 signals = [signal.SIGTERM, signal.SIGINT]
53else: 52else:
54 tmp = "/tmp" 53 tmp = "/tmp"
55 signals = [signal.SIGTERM, signal.SIGINT, signal.SIGHUP, signal.SIGQUIT] 54 signals = [signal.SIGTERM, signal.SIGINT, signal.SIGHUP, signal.SIGQUIT]
56 55
57def cleanup_onerror (function, path, excinfo): 56
58 import stat 57def cleanup_onerror(function, path, excinfo):
59 if not os.path.exists (path): 58 import stat
60 pass 59 if not os.path.exists(path):
61 elif not os.access(path, os.W_OK): 60 pass
62 # Is the error an access error ? 61 elif not os.access(path, os.W_OK):
63 os.chmod (path, stat.S_IWUSR) 62 # Is the error an access error ?
64 function (path) 63 os.chmod(path, stat.S_IWUSR)
65 else: 64 function(path)
66 raise 65 else:
67 66 raise
68def cleanup (): 67
69 shutil.rmtree (os.path.join (tmp, "c_bootstrap_server"), False, cleanup_onerror) 68
70 shutil.rmtree (os.path.join (tmp, "c_no_nat_client"), False, cleanup_onerror) 69def cleanup():
71 70 shutil.rmtree(
72 71 os.path.join(tmp, "c_bootstrap_server"), False, cleanup_onerror
73def success_disconnect_cont (check): 72 )
74 print('Peers disconnected successfully') 73 shutil.rmtree(os.path.join(tmp, "c_no_nat_client"), False, cleanup_onerror)
75 global success 74
76 success = True; 75
77 76def success_disconnect_cont(check):
78 77 print('Peers disconnected successfully')
79def fail_disconnect_cont (check): 78 global success
80 global success 79 success = True
81 success = False; 80
82 print('Peers failed to disconnect') 81
83 check.evaluate(True) 82def fail_disconnect_cont(check):
84 83 global success
85def check_disconnect (): 84 success = False
86 test.p ('Shutting down bootstrap server') 85 print('Peers failed to disconnect')
87 server.stop () 86 check.evaluate(True)
88 check = Check (test) 87
89 check.add (StatisticsCondition (client, 'transport', '# peers connected',0)) 88
90 check.add (StatisticsCondition (client, 'core', '# peers connected',0)) 89def check_disconnect():
91 check.add (StatisticsCondition (client, 'topology', '# peers connected',0)) 90 test.p('Shutting down bootstrap server')
92 check.add (StatisticsCondition (client, 'dht', '# peers connected',0)) 91 server.stop()
93 check.add (StatisticsCondition (client, 'fs', '# peers connected',0)) 92 check = Check(test)
94 check.run_blocking (check_timeout, success_disconnect_cont, fail_disconnect_cont) 93 check.add(StatisticsCondition(client, 'transport', '# peers connected', 0))
95 94 check.add(StatisticsCondition(client, 'core', '# peers connected', 0))
96 95 check.add(StatisticsCondition(client, 'topology', '# peers connected', 0))
97def success_connect_cont (check): 96 check.add(StatisticsCondition(client, 'dht', '# peers connected', 0))
98 print('Peers connected successfully') 97 check.add(StatisticsCondition(client, 'fs', '# peers connected', 0))
99 check_disconnect () 98 check.run_blocking(
100 99 check_timeout, success_disconnect_cont, fail_disconnect_cont
101 100 )
102def fail_connect_cont (check): 101
103 global success 102
104 success= False 103def success_connect_cont(check):
105 print('Peers failed to connected!') 104 print('Peers connected successfully')
106 check.evaluate(True) 105 check_disconnect()
107 106
108 107
109def check_connect (): 108def fail_connect_cont(check):
110 check = Check (test) 109 global success
111 check.add (StatisticsCondition (server, 'transport', '# peers connected',1)) 110 success = False
112 check.add (StatisticsCondition (server, 'core', '# peers connected',1)) 111 print('Peers failed to connected!')
113 check.add (StatisticsCondition (server, 'topology', '# peers connected',1)) 112 check.evaluate(True)
114 check.add (StatisticsCondition (server, 'dht', '# peers connected',1)) 113
115 check.add (StatisticsCondition (server, 'fs', '# peers connected',1)) 114
116 115def check_connect():
117 check.add (StatisticsCondition (client, 'transport', '# peers connected',1)) 116 check = Check(test)
118 check.add (StatisticsCondition (client, 'core', '# peers connected',1)) 117 check.add(StatisticsCondition(server, 'transport', '# peers connected', 1))
119 check.add (StatisticsCondition (client, 'topology', '# peers connected',1)) 118 check.add(StatisticsCondition(server, 'core', '# peers connected', 1))
120 check.add (StatisticsCondition (client, 'dht', '# peers connected',1)) 119 check.add(StatisticsCondition(server, 'topology', '# peers connected', 1))
121 check.add (StatisticsCondition (client, 'fs', '# peers connected',1)) 120 check.add(StatisticsCondition(server, 'dht', '# peers connected', 1))
122 121 check.add(StatisticsCondition(server, 'fs', '# peers connected', 1))
123 check.run_blocking (check_timeout, success_connect_cont, fail_connect_cont) 122
123 check.add(StatisticsCondition(client, 'transport', '# peers connected', 1))
124 check.add(StatisticsCondition(client, 'core', '# peers connected', 1))
125 check.add(StatisticsCondition(client, 'topology', '# peers connected', 1))
126 check.add(StatisticsCondition(client, 'dht', '# peers connected', 1))
127 check.add(StatisticsCondition(client, 'fs', '# peers connected', 1))
128
129 check.run_blocking(check_timeout, success_connect_cont, fail_connect_cont)
130
124 131
125# 132#
126# Test execution 133# Test execution
127# 134#
128 135
129def SigHandler(signum = None, frame = None): 136
130 global success 137def SigHandler(signum=None, frame=None):
131 global server 138 global success
132 global client 139 global server
133 140 global client
134 print('Test was aborted!') 141
135 if (None != server): 142 print('Test was aborted!')
136 server.stop () 143 if (None != server):
137 if (None != client): 144 server.stop()
138 client.stop () 145 if (None != client):
139 cleanup () 146 client.stop()
140 sys.exit(success) 147 cleanup()
141 148 sys.exit(success)
142def run (): 149
143 global success 150
144 global test 151def run():
145 global server 152 global success
146 global client 153 global test
147 154 global server
148 server = None 155 global client
149 client = None 156
150 success = False 157 server = None
151 158 client = None
152 for sig in signals: 159 success = False
153 signal.signal(sig, SigHandler) 160
154 161 for sig in signals:
155 test = Test ('test_integration_bootstrap_and_connect.py', verbose) 162 signal.signal(sig, SigHandler)
156 cleanup () 163
157 164 test = Test('test_integration_bootstrap_and_connect.py', verbose)
158 server = Peer(test, './confs/c_bootstrap_server.conf'); 165 cleanup()
159 client = Peer(test, './confs/c_no_nat_client.conf'); 166
160 167 server = Peer(test, './confs/c_bootstrap_server.conf')
161 if (True != server.start()): 168 client = Peer(test, './confs/c_no_nat_client.conf')
162 print('Failed to start server') 169
163 if (None != server): 170 if (True != server.start()):
164 server.stop () 171 print('Failed to start server')
165 cleanup () 172 if (None != server):
166 sys.exit(success) 173 server.stop()
167 174 cleanup()
168 # Give the server time to start 175 sys.exit(success)
169 time.sleep(5) 176
170 177 # Give the server time to start
171 if (True != client.start()): 178 time.sleep(5)
172 print('Failed to start client') 179
173 if (None != server): 180 if (True != client.start()):
174 server.stop () 181 print('Failed to start client')
175 if (None != client): 182 if (None != server):
176 client.stop () 183 server.stop()
177 cleanup () 184 if (None != client):
178 sys.exit(success) 185 client.stop()
179 186 cleanup()
180 if ((client.started == True) and (server.started == True)): 187 sys.exit(success)
181 test.p ('Peers started, running check') 188
182 time.sleep(5) 189 if ((client.started == True) and (server.started == True)):
183 check_connect () 190 test.p('Peers started, running check')
184 server.stop () 191 time.sleep(5)
185 client.stop () 192 check_connect()
186 193 server.stop()
187 cleanup () 194 client.stop()
188 195
189 if (success == False): 196 cleanup()
190 print ('Test failed') 197
191 return False 198 if (success == False):
192 else: 199 print('Test failed')
193 return True 200 return False
201 else:
202 return True
203
194 204
195try: 205try:
196 run () 206 run()
197except (KeyboardInterrupt, SystemExit): 207except (KeyboardInterrupt, SystemExit):
198 print('Test interrupted') 208 print('Test interrupted')
199 server.stop () 209 server.stop()
200 client.stop () 210 client.stop()
201 cleanup () 211 cleanup()
202if (success == False): 212if (success == False):
203 sys.exit(1) 213 sys.exit(1)
204else: 214else:
205 sys.exit(0) 215 sys.exit(0)
diff --git a/src/integration-tests/test_integration_disconnect_nat.py.in b/src/integration-tests/test_integration_disconnect_nat.py.in
index c3d5d8901..d3ff84ebe 100755
--- a/src/integration-tests/test_integration_disconnect_nat.py.in
+++ b/src/integration-tests/test_integration_disconnect_nat.py.in
@@ -32,7 +32,6 @@ from gnunet_testing import Check
32from gnunet_testing import Condition 32from gnunet_testing import Condition
33from gnunet_testing import * 33from gnunet_testing import *
34 34
35
36# 35#
37# 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
38# successfully connects to the server. When both peers are connected 37# successfully connects to the server. When both peers are connected
@@ -68,7 +67,9 @@ def cleanup_onerror(function, path, excinfo):
68 67
69 68
70def cleanup(): 69def cleanup():
71 shutil.rmtree(os.path.join(tmp, "c_bootstrap_server"), False, cleanup_onerror) 70 shutil.rmtree(
71 os.path.join(tmp, "c_bootstrap_server"), False, cleanup_onerror
72 )
72 shutil.rmtree(os.path.join(tmp, "c_nat_client"), False, cleanup_onerror) 73 shutil.rmtree(os.path.join(tmp, "c_nat_client"), False, cleanup_onerror)
73 74
74 75
@@ -80,7 +81,7 @@ def success_disconnect_cont(check):
80 81
81def fail_disconnect_cont(check): 82def fail_disconnect_cont(check):
82 global success 83 global success
83 success = False; 84 success = False
84 print('Peers failed to disconnect') 85 print('Peers failed to disconnect')
85 check.evaluate(True) 86 check.evaluate(True)
86 87
@@ -96,7 +97,9 @@ def check_disconnect():
96 check.add(StatisticsCondition(server, 'topology', '# peers connected', 0)) 97 check.add(StatisticsCondition(server, 'topology', '# peers connected', 0))
97 check.add(StatisticsCondition(server, 'dht', '# peers connected', 0)) 98 check.add(StatisticsCondition(server, 'dht', '# peers connected', 0))
98 check.add(StatisticsCondition(server, 'fs', '# peers connected', 0)) 99 check.add(StatisticsCondition(server, 'fs', '# peers connected', 0))
99 check.run_blocking(check_timeout, success_disconnect_cont, fail_disconnect_cont) 100 check.run_blocking(
101 check_timeout, success_disconnect_cont, fail_disconnect_cont
102 )
100 103
101 104
102def success_connect_cont(check): 105def success_connect_cont(check):
@@ -115,9 +118,13 @@ def check_connect():
115 global server 118 global server
116 global nat_client 119 global nat_client
117 check = Check(test) 120 check = Check(test)
118 check.add(StatisticsCondition(nat_client, 'transport', '# peers connected', 1)) 121 check.add(
122 StatisticsCondition(nat_client, 'transport', '# peers connected', 1)
123 )
119 check.add(StatisticsCondition(nat_client, 'core', '# peers connected', 1)) 124 check.add(StatisticsCondition(nat_client, 'core', '# peers connected', 1))
120 check.add(StatisticsCondition(nat_client, 'topology', '# peers connected', 1)) 125 check.add(
126 StatisticsCondition(nat_client, 'topology', '# peers connected', 1)
127 )
121 check.add(StatisticsCondition(nat_client, 'dht', '# peers connected', 1)) 128 check.add(StatisticsCondition(nat_client, 'dht', '# peers connected', 1))
122 check.add(StatisticsCondition(nat_client, 'fs', '# peers connected', 1)) 129 check.add(StatisticsCondition(nat_client, 'fs', '# peers connected', 1))
123 130
@@ -134,6 +141,7 @@ def check_connect():
134# Test execution 141# Test execution
135# 142#
136 143
144
137def SigHandler(signum=None, frame=None): 145def SigHandler(signum=None, frame=None):
138 global success 146 global success
139 global server 147 global server
@@ -204,7 +212,7 @@ def run():
204 212
205try: 213try:
206 run() 214 run()
207except(KeyboardInterrupt, SystemExit): 215except (KeyboardInterrupt, SystemExit):
208 print('Test interrupted') 216 print('Test interrupted')
209 server.stop() 217 server.stop()
210 nat_client.stop() 218 nat_client.stop()
diff --git a/src/integration-tests/test_integration_reconnect.py.in b/src/integration-tests/test_integration_reconnect.py.in
index 8c4193680..5bffb72e3 100755
--- a/src/integration-tests/test_integration_reconnect.py.in
+++ b/src/integration-tests/test_integration_reconnect.py.in
@@ -32,7 +32,6 @@ from gnunet_testing import Check
32from gnunet_testing import Condition 32from gnunet_testing import Condition
33from gnunet_testing import * 33from gnunet_testing import *
34 34
35
36# 35#
37# 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
38# successfully connects to the server. When both peers are connected 37# successfully connects to the server. When both peers are connected
@@ -43,195 +42,196 @@ from gnunet_testing import *
43 42
44#definitions 43#definitions
45 44
46
47testname = "test_integration_restart" 45testname = "test_integration_restart"
48verbose = True 46verbose = True
49check_timeout = 180 47check_timeout = 180
50 48
51if os.name == "nt": 49if os.name == "nt":
52 tmp = os.getenv ("TEMP") 50 tmp = os.getenv("TEMP")
53 signals = [signal.SIGTERM, signal.SIGINT] 51 signals = [signal.SIGTERM, signal.SIGINT]
54else: 52else:
55 tmp = "/tmp" 53 tmp = "/tmp"
56 signals = [signal.SIGTERM, signal.SIGINT, signal.SIGHUP, signal.SIGQUIT] 54 signals = [signal.SIGTERM, signal.SIGINT, signal.SIGHUP, signal.SIGQUIT]
57 55
58def cleanup_onerror (function, path, excinfo): 56
59 import stat 57def cleanup_onerror(function, path, excinfo):
60 if not os.path.exists (path): 58 import stat
61 pass 59 if not os.path.exists(path):
62 elif not os.access(path, os.W_OK): 60 pass
63 # Is the error an access error ? 61 elif not os.access(path, os.W_OK):
64 os.chmod (path, stat.S_IWUSR) 62 # Is the error an access error ?
65 function (path) 63 os.chmod(path, stat.S_IWUSR)
66 else: 64 function(path)
67 raise 65 else:
68 66 raise
69def cleanup (): 67
68
69def cleanup():
70 retries = 10 70 retries = 10
71 path = os.path.join (tmp, "c_bootstrap_server") 71 path = os.path.join(tmp, "c_bootstrap_server")
72 test.p ("Removing " + path) 72 test.p("Removing " + path)
73 while ((os.path.exists(path)) and (retries > 0)): 73 while ((os.path.exists(path)) and (retries > 0)):
74 shutil.rmtree ((path), False, cleanup_onerror) 74 shutil.rmtree((path), False, cleanup_onerror)
75 time.sleep (1) 75 time.sleep(1)
76 retries -= 1 76 retries -= 1
77 if (os.path.exists(path)): 77 if (os.path.exists(path)):
78 test.p ("Failed to remove " + path) 78 test.p("Failed to remove " + path)
79
80 79
81 retries = 10 80 retries = 10
82 path = os.path.join (tmp, "c_no_nat_client") 81 path = os.path.join(tmp, "c_no_nat_client")
83 test.p ("Removing " + path) 82 test.p("Removing " + path)
84 while ((os.path.exists(path)) and (retries > 0)): 83 while ((os.path.exists(path)) and (retries > 0)):
85 shutil.rmtree ((path), False, cleanup_onerror) 84 shutil.rmtree((path), False, cleanup_onerror)
86 time.sleep (1) 85 time.sleep(1)
87 retries -= 1 86 retries -= 1
88 if (os.path.exists(path)): 87 if (os.path.exists(path)):
89 test.p ("Failed to remove " + path) 88 test.p("Failed to remove " + path)
89
90 90
91def success_restart_cont (check): 91def success_restart_cont(check):
92 global success 92 global success
93 print('Peers connected successfully after restart') 93 print('Peers connected successfully after restart')
94 server.stop () 94 server.stop()
95 client.stop () 95 client.stop()
96 success = True; 96 success = True
97 97
98 98
99def fail_restart_cont (check): 99def fail_restart_cont(check):
100 global success 100 global success
101 success = False; 101 success = False
102 print('Peers failed to connect after restart') 102 print('Peers failed to connect after restart')
103 check.evaluate(True) 103 check.evaluate(True)
104 104
105 105
106def success_connect_cont (check): 106def success_connect_cont(check):
107 print('Peers connected successfully') 107 print('Peers connected successfully')
108 server.stop () 108 server.stop()
109 client.stop () 109 client.stop()
110 110
111 time.sleep(5) 111 time.sleep(5)
112 112
113 test.p ('Restarting client & server') 113 test.p('Restarting client & server')
114 server.start () 114 server.start()
115 client.start () 115 client.start()
116 116
117 check = Check (test) 117 check = Check(test)
118 check.add (StatisticsCondition (client, 'transport', '# peers connected',1)) 118 check.add(StatisticsCondition(client, 'transport', '# peers connected', 1))
119 check.add (StatisticsCondition (client, 'core', '# peers connected',1)) 119 check.add(StatisticsCondition(client, 'core', '# peers connected', 1))
120 check.add (StatisticsCondition (client, 'topology', '# peers connected',1)) 120 check.add(StatisticsCondition(client, 'topology', '# peers connected', 1))
121 check.add (StatisticsCondition (client, 'fs', '# peers connected',1)) 121 check.add(StatisticsCondition(client, 'fs', '# peers connected', 1))
122 122
123 check.add (StatisticsCondition (server, 'transport', '# peers connected',1)) 123 check.add(StatisticsCondition(server, 'transport', '# peers connected', 1))
124 check.add (StatisticsCondition (server, 'core', '# peers connected',1)) 124 check.add(StatisticsCondition(server, 'core', '# peers connected', 1))
125 check.add (StatisticsCondition (server, 'topology', '# peers connected',1)) 125 check.add(StatisticsCondition(server, 'topology', '# peers connected', 1))
126 check.add (StatisticsCondition (server, 'fs', '# peers connected',1)) 126 check.add(StatisticsCondition(server, 'fs', '# peers connected', 1))
127 127
128 check.run_blocking (check_timeout, success_restart_cont, fail_restart_cont) 128 check.run_blocking(check_timeout, success_restart_cont, fail_restart_cont)
129 129
130 130
131def fail_connect_cont (check): 131def fail_connect_cont(check):
132 global success 132 global success
133 success= False; 133 success = False
134 print('Peers failed to connect') 134 print('Peers failed to connect')
135 check.evaluate(True) 135 check.evaluate(True)
136 136
137 137
138def check_connect (): 138def check_connect():
139 check = Check (test) 139 check = Check(test)
140 check.add (StatisticsCondition (client, 'transport', '# peers connected',1)) 140 check.add(StatisticsCondition(client, 'transport', '# peers connected', 1))
141 check.add (StatisticsCondition (client, 'core', '# peers connected',1)) 141 check.add(StatisticsCondition(client, 'core', '# peers connected', 1))
142 check.add (StatisticsCondition (client, 'topology', '# peers connected',1)) 142 check.add(StatisticsCondition(client, 'topology', '# peers connected', 1))
143 check.add (StatisticsCondition (client, 'fs', '# peers connected',1)) 143 check.add(StatisticsCondition(client, 'fs', '# peers connected', 1))
144 144
145 check.add (StatisticsCondition (server, 'transport', '# peers connected',1)) 145 check.add(StatisticsCondition(server, 'transport', '# peers connected', 1))
146 check.add (StatisticsCondition (server, 'core', '# peers connected',1)) 146 check.add(StatisticsCondition(server, 'core', '# peers connected', 1))
147 check.add (StatisticsCondition (server, 'topology', '# peers connected',1)) 147 check.add(StatisticsCondition(server, 'topology', '# peers connected', 1))
148 check.add (StatisticsCondition (server, 'fs', '# peers connected',1)) 148 check.add(StatisticsCondition(server, 'fs', '# peers connected', 1))
149
150 check.run_blocking(check_timeout, success_connect_cont, fail_connect_cont)
149 151
150 check.run_blocking (check_timeout, success_connect_cont, fail_connect_cont)
151 152
152# 153#
153# Test execution 154# Test execution
154# 155#
155 156
156 157
157def SigHandler(signum = None, frame = None): 158def SigHandler(signum=None, frame=None):
158 global success 159 global success
159 global server 160 global server
160 global client 161 global client
161
162 print('Test was aborted!')
163 if (None != server):
164 server.stop ()
165 if (None != client):
166 client.stop ()
167 cleanup ()
168 sys.exit(success)
169 162
170def run (): 163 print('Test was aborted!')
171 global success 164 if (None != server):
172 global test 165 server.stop()
173 global server 166 if (None != client):
174 global client 167 client.stop()
168 cleanup()
169 sys.exit(success)
175 170
176 success = False
177 server = None
178 client = None
179 171
180 for sig in signals: 172def run():
181 signal.signal(sig, SigHandler) 173 global success
174 global test
175 global server
176 global client
182 177
178 success = False
179 server = None
180 client = None
183 181
184 test = Test ('test_integration_disconnect', verbose) 182 for sig in signals:
185 cleanup () 183 signal.signal(sig, SigHandler)
186 server = Peer(test, './confs/c_bootstrap_server.conf');
187 server.start();
188 184
189 client = Peer(test, './confs/c_no_nat_client.conf'); 185 test = Test('test_integration_disconnect', verbose)
190 client.start(); 186 cleanup()
187 server = Peer(test, './confs/c_bootstrap_server.conf')
188 server.start()
191 189
190 client = Peer(test, './confs/c_no_nat_client.conf')
191 client.start()
192 192
193 if (True != server.start()): 193 if (True != server.start()):
194 print('Failed to start server') 194 print('Failed to start server')
195 if (None != server): 195 if (None != server):
196 server.stop () 196 server.stop()
197 if (None != server): 197 if (None != server):
198 client.stop () 198 client.stop()
199 cleanup () 199 cleanup()
200 sys.exit(success) 200 sys.exit(success)
201 201
202 # Give the server time to start 202 # Give the server time to start
203 time.sleep(5) 203 time.sleep(5)
204 204
205 if (True != client.start()): 205 if (True != client.start()):
206 print('Failed to start client') 206 print('Failed to start client')
207 if (None != server): 207 if (None != server):
208 server.stop () 208 server.stop()
209 if (None != server): 209 if (None != server):
210 client.stop () 210 client.stop()
211 cleanup () 211 cleanup()
212 sys.exit(success) 212 sys.exit(success)
213 213
214 check_connect () 214 check_connect()
215 215
216 server.stop () 216 server.stop()
217 client.stop () 217 client.stop()
218 cleanup () 218 cleanup()
219 219
220 if (success == False): 220 if (success == False):
221 print ('Test failed') 221 print('Test failed')
222 return True 222 return True
223 else: 223 else:
224 return False 224 return False
225 225
226 226
227try: 227try:
228 run () 228 run()
229except (KeyboardInterrupt, SystemExit): 229except (KeyboardInterrupt, SystemExit):
230 print('Test interrupted') 230 print('Test interrupted')
231 server.stop () 231 server.stop()
232 client.stop () 232 client.stop()
233 cleanup () 233 cleanup()
234if (success == False): 234if (success == False):
235 sys.exit(1) 235 sys.exit(1)
236else: 236else:
237 sys.exit(0) 237 sys.exit(0)
diff --git a/src/integration-tests/test_integration_reconnect_nat.py.in b/src/integration-tests/test_integration_reconnect_nat.py.in
index 45626d50d..751a0484b 100755
--- a/src/integration-tests/test_integration_reconnect_nat.py.in
+++ b/src/integration-tests/test_integration_reconnect_nat.py.in
@@ -32,7 +32,6 @@ from gnunet_testing import Check
32from gnunet_testing import Condition 32from gnunet_testing import Condition
33from gnunet_testing import * 33from gnunet_testing import *
34 34
35
36# 35#
37# 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
38# successfully connects to the server. When both peers are connected 37# successfully connects to the server. When both peers are connected
@@ -43,7 +42,6 @@ from gnunet_testing import *
43 42
44# definitions 43# definitions
45 44
46
47testname = "test_integration_restart" 45testname = "test_integration_restart"
48verbose = True 46verbose = True
49check_timeout = 180 47check_timeout = 180
@@ -82,7 +80,7 @@ def cleanup():
82 retries = 10 80 retries = 10
83 path = os.path.join(tmp, "c_nat_client") 81 path = os.path.join(tmp, "c_nat_client")
84 test.p("Removing " + path) 82 test.p("Removing " + path)
85 while((os.path.exists(path)) and(retries > 0)): 83 while ((os.path.exists(path)) and (retries > 0)):
86 shutil.rmtree((path), False, cleanup_onerror) 84 shutil.rmtree((path), False, cleanup_onerror)
87 time.sleep(1) 85 time.sleep(1)
88 retries -= 1 86 retries -= 1
@@ -91,18 +89,18 @@ def cleanup():
91 89
92 90
93def success_restart_cont(check): 91def success_restart_cont(check):
94 global success 92 global success
95 print('Peers connected successfully after restart') 93 print('Peers connected successfully after restart')
96 server.stop() 94 server.stop()
97 client.stop() 95 client.stop()
98 success = True 96 success = True
99 97
100 98
101def fail_restart_cont(check): 99def fail_restart_cont(check):
102 global success 100 global success
103 success = False 101 success = False
104 print('Peers failed to connect after restart') 102 print('Peers failed to connect after restart')
105 check.evaluate(True) 103 check.evaluate(True)
106 104
107 105
108def success_connect_cont(check): 106def success_connect_cont(check):
@@ -151,6 +149,7 @@ def check_connect():
151 149
152 check.run_blocking(check_timeout, success_connect_cont, fail_connect_cont) 150 check.run_blocking(check_timeout, success_connect_cont, fail_connect_cont)
153 151
152
154# 153#
155# Test execution 154# Test execution
156# 155#
@@ -227,7 +226,7 @@ def run():
227 226
228try: 227try:
229 run() 228 run()
230except(KeyboardInterrupt, SystemExit): 229except (KeyboardInterrupt, SystemExit):
231 print('Test interrupted') 230 print('Test interrupted')
232 server.stop() 231 server.stop()
233 client.stop() 232 client.stop()
diff --git a/src/peerinfo-tool/test_gnunet_peerinfo.py.in b/src/peerinfo-tool/test_gnunet_peerinfo.py.in
index d07224b14..5d9daa930 100755
--- a/src/peerinfo-tool/test_gnunet_peerinfo.py.in
+++ b/src/peerinfo-tool/test_gnunet_peerinfo.py.in
@@ -11,7 +11,7 @@
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# Affero General Public License for more details. 13# Affero General Public License for more details.
14# 14#
15# You should have received a copy of the GNU Affero General Public License 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/>. 16# along with this program. If not, see <http://www.gnu.org/licenses/>.
17# 17#
@@ -43,53 +43,94 @@ elif os.name == 'nt':
43 43
44pinfo = pexpect() 44pinfo = pexpect()
45 45
46
47if os.name == "nt": 46if os.name == "nt":
48 shutil.rmtree(os.path.join(os.getenv("TEMP"), "gnunet-test-peerinfo"), True) 47 shutil.rmtree(os.path.join(os.getenv("TEMP"), "gnunet-test-peerinfo"), True)
49else: 48else:
50 shutil.rmtree("/tmp/gnunet-test-peerinfo", True) 49 shutil.rmtree("/tmp/gnunet-test-peerinfo", True)
51 50
52# create hostkey via testing lib # FIXME: The /tmp/ location needs to be adjusted to the TMP variable! 51# create hostkey via testing lib # FIXME: The /tmp/ location needs to be adjusted to the TMP variable!
53hkk = subprocess.Popen([gnunettesting, '-n', '1', '-c', 'test_gnunet_peerinfo_data.conf', '-k', '/tmp/gnunet-test-peerinfo/.hostkey']) 52hkk = subprocess.Popen([
53 gnunettesting, '-n', '1', '-c', 'test_gnunet_peerinfo_data.conf', '-k',
54 '/tmp/gnunet-test-peerinfo/.hostkey'
55])
54hkk.communicate() 56hkk.communicate()
55 57
56arm = subprocess.Popen([gnunetarm, '-sq', '-c', 'test_gnunet_peerinfo_data.conf']) 58arm = subprocess.Popen([
59 gnunetarm, '-sq', '-c', 'test_gnunet_peerinfo_data.conf'
60])
57arm.communicate() 61arm.communicate()
58 62
59try: 63try:
60 pinfo.spawn(None, [peerinfo, '-c', 'test_gnunet_peerinfo_data.conf', '-s'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) 64 pinfo.spawn(
65 None, [peerinfo, '-c', 'test_gnunet_peerinfo_data.conf', '-s'],
66 stdout=subprocess.PIPE,
67 stderr=subprocess.STDOUT
68 )
61 pinfo.expect("stdout", re.compile(r'I am peer `.*\'.\r?\n')) 69 pinfo.expect("stdout", re.compile(r'I am peer `.*\'.\r?\n'))
62 70
63 pinfo.spawn(None, [peerinfo, '-c', 'test_gnunet_peerinfo_data.conf', '-qs'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) 71 pinfo.spawn(
64 pinfo.expect("stdout", re.compile(r'....................................................\r?\n')) 72 None, [peerinfo, '-c', 'test_gnunet_peerinfo_data.conf', '-qs'],
65 73 stdout=subprocess.PIPE,
66 pinfo.spawn(None, [peerinfo, '-c', 'test_gnunet_peerinfo_data.conf', 'invalid'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) 74 stderr=subprocess.STDOUT
67 pinfo.expect("stdout", re.compile(r'Invalid command line argument `invalid\'\r?\n')) 75 )
68 76 pinfo.expect(
69 arm = subprocess.Popen([gnunetarm, '-q', '-i', 'transport', '-c', 'test_gnunet_peerinfo_data.conf']) 77 "stdout",
78 re.
79 compile(r'....................................................\r?\n')
80 )
81
82 pinfo.spawn(
83 None, [peerinfo, '-c', 'test_gnunet_peerinfo_data.conf', 'invalid'],
84 stdout=subprocess.PIPE,
85 stderr=subprocess.STDOUT
86 )
87 pinfo.expect(
88 "stdout", re.compile(r'Invalid command line argument `invalid\'\r?\n')
89 )
90
91 arm = subprocess.Popen([
92 gnunetarm, '-q', '-i', 'transport', '-c',
93 'test_gnunet_peerinfo_data.conf'
94 ])
70 arm.communicate() 95 arm.communicate()
71 time.sleep(1) 96 time.sleep(1)
72 97
73 pinfo.spawn(None, [peerinfo, '-i', '-c', 'test_gnunet_peerinfo_data.conf'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) 98 pinfo.spawn(
99 None, [peerinfo, '-i', '-c', 'test_gnunet_peerinfo_data.conf'],
100 stdout=subprocess.PIPE,
101 stderr=subprocess.STDOUT
102 )
74 pinfo.expect("stdout", re.compile("Peer `.*'\r?\n")) 103 pinfo.expect("stdout", re.compile("Peer `.*'\r?\n"))
75 m = pinfo.expect("stdout", re.compile("\s.*:24357\r?\n")) 104 m = pinfo.expect("stdout", re.compile("\s.*:24357\r?\n"))
76 while len(m.group(0)) > 0: 105 while len(m.group(0)) > 0:
77 m = pinfo.expect("stdout", re.compile("(\s.*:24357\r?\n|\r?\n|)")) 106 m = pinfo.expect("stdout", re.compile("(\s.*:24357\r?\n|\r?\n|)"))
78 107
79 pinfo.spawn(None, [peerinfo, '-i', '-c', 'test_gnunet_peerinfo_data.conf', '-n'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) 108 pinfo.spawn(
109 None, [peerinfo, '-i', '-c', 'test_gnunet_peerinfo_data.conf', '-n'],
110 stdout=subprocess.PIPE,
111 stderr=subprocess.STDOUT
112 )
80 pinfo.expect("stdout", re.compile("Peer `.*'\r?\n")) 113 pinfo.expect("stdout", re.compile("Peer `.*'\r?\n"))
81 m = pinfo.expect("stdout", re.compile("\s.*:24357\r?\n")) 114 m = pinfo.expect("stdout", re.compile("\s.*:24357\r?\n"))
82 while len(m.group(0)) > 0: 115 while len(m.group(0)) > 0:
83 m = pinfo.expect("stdout", re.compile("(\s.*:24357\r?\n|\r?\n|)")) 116 m = pinfo.expect("stdout", re.compile("(\s.*:24357\r?\n|\r?\n|)"))
84 117
85 pinfo.spawn(None, [peerinfo, '-c', 'test_gnunet_peerinfo_data.conf', '-qs'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) 118 pinfo.spawn(
119 None, [peerinfo, '-c', 'test_gnunet_peerinfo_data.conf', '-qs'],
120 stdout=subprocess.PIPE,
121 stderr=subprocess.STDOUT
122 )
86 pid = pinfo.read("stdout") 123 pid = pinfo.read("stdout")
87 pid.strip() 124 pid.strip()
88 125
89finally: 126finally:
90 arm = subprocess.Popen([gnunetarm, '-eq', '-c', 'test_gnunet_peerinfo_data.conf']) 127 arm = subprocess.Popen([
128 gnunetarm, '-eq', '-c', 'test_gnunet_peerinfo_data.conf'
129 ])
91 arm.communicate() 130 arm.communicate()
92 if os.name == "nt": 131 if os.name == "nt":
93 shutil.rmtree(os.path.join(os.getenv("TEMP"), "gnunet-test-peerinfo"), True) 132 shutil.rmtree(
133 os.path.join(os.getenv("TEMP"), "gnunet-test-peerinfo"), True
134 )
94 else: 135 else:
95 shutil.rmtree("/tmp/gnunet-test-peerinfo", True) 136 shutil.rmtree("/tmp/gnunet-test-peerinfo", True)
diff --git a/src/revocation/test_local_revocation.py.in b/src/revocation/test_local_revocation.py.in
index 4cc6119ca..d73d0a869 100644
--- a/src/revocation/test_local_revocation.py.in
+++ b/src/revocation/test_local_revocation.py.in
@@ -11,7 +11,7 @@
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# Affero General Public License for more details. 13# Affero General Public License for more details.
14# 14#
15# You should have received a copy of the GNU Affero General Public License 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/>. 16# along with this program. If not, see <http://www.gnu.org/licenses/>.
17# 17#
@@ -39,7 +39,10 @@ elif os.name == 'nt':
39TEST_CONFIGURATION = "test_revocation.conf" 39TEST_CONFIGURATION = "test_revocation.conf"
40TEST_REVOCATION_EGO = "revoc_test" 40TEST_REVOCATION_EGO = "revoc_test"
41 41
42get_clean = subprocess.Popen([config, '-c', TEST_CONFIGURATION, '-s', 'PATHS', '-o', 'GNUNET_HOME', '-f'], stdout=subprocess.PIPE) 42get_clean = subprocess.Popen([
43 config, '-c', TEST_CONFIGURATION, '-s', 'PATHS', '-o', 'GNUNET_HOME', '-f'
44],
45 stdout=subprocess.PIPE)
43cleandir, x = get_clean.communicate() 46cleandir, x = get_clean.communicate()
44cleandir = cleandir.decode("utf-8") 47cleandir = cleandir.decode("utf-8")
45cleandir = cleandir.rstrip('\n').rstrip('\r') 48cleandir = cleandir.rstrip('\n').rstrip('\r')
@@ -55,10 +58,15 @@ try:
55 print("Creating an ego " + TEST_REVOCATION_EGO) 58 print("Creating an ego " + TEST_REVOCATION_EGO)
56 sys.stdout.flush() 59 sys.stdout.flush()
57 sys.stderr.flush() 60 sys.stderr.flush()
58 idc = subprocess.Popen([ident, '-C', TEST_REVOCATION_EGO, '-c', TEST_CONFIGURATION]) 61 idc = subprocess.Popen([
62 ident, '-C', TEST_REVOCATION_EGO, '-c', TEST_CONFIGURATION
63 ])
59 idc.communicate() 64 idc.communicate()
60 if idc.returncode != 0: 65 if idc.returncode != 0:
61 raise Exception("gnunet-identity failed to create an ego `" + TEST_REVOCATION_EGO + "'") 66 raise Exception(
67 "gnunet-identity failed to create an ego `" + TEST_REVOCATION_EGO +
68 "'"
69 )
62 70
63 sys.stdout.flush() 71 sys.stdout.flush()
64 sys.stderr.flush() 72 sys.stderr.flush()
@@ -72,11 +80,15 @@ try:
72 print("Testing key " + rev_key) 80 print("Testing key " + rev_key)
73 sys.stdout.flush() 81 sys.stdout.flush()
74 sys.stderr.flush() 82 sys.stderr.flush()
75 tst = subprocess.Popen([revoc, '-t', rev_key, '-c', TEST_CONFIGURATION], stdout=subprocess.PIPE) 83 tst = subprocess.Popen([revoc, '-t', rev_key, '-c', TEST_CONFIGURATION],
84 stdout=subprocess.PIPE)
76 output_not_revoked, x = tst.communicate() 85 output_not_revoked, x = tst.communicate()
77 output_not_revoked = output_not_revoked.decode("utf-8") 86 output_not_revoked = output_not_revoked.decode("utf-8")
78 if tst.returncode != 0: 87 if tst.returncode != 0:
79 raise Exception("gnunet-revocation failed to test a key - " + str(tst.returncode) + ": " + output_not_revoked) 88 raise Exception(
89 "gnunet-revocation failed to test a key - " + str(tst.returncode) +
90 ": " + output_not_revoked
91 )
80 if 'valid' not in output_not_revoked: 92 if 'valid' not in output_not_revoked:
81 res = 1 93 res = 1
82 print("Key was not valid") 94 print("Key was not valid")
@@ -86,7 +98,9 @@ try:
86 print("Revoking key " + rev_key) 98 print("Revoking key " + rev_key)
87 sys.stdout.flush() 99 sys.stdout.flush()
88 sys.stderr.flush() 100 sys.stderr.flush()
89 rev = subprocess.Popen([revoc, '-R', TEST_REVOCATION_EGO, '-p', '-c', TEST_CONFIGURATION]) 101 rev = subprocess.Popen([
102 revoc, '-R', TEST_REVOCATION_EGO, '-p', '-c', TEST_CONFIGURATION
103 ])
90 rev.communicate() 104 rev.communicate()
91 if rev.returncode != 0: 105 if rev.returncode != 0:
92 raise Exception("gnunet-revocation failed to revoke a key") 106 raise Exception("gnunet-revocation failed to revoke a key")
@@ -94,7 +108,8 @@ try:
94 print("Testing revoked key " + rev_key) 108 print("Testing revoked key " + rev_key)
95 sys.stdout.flush() 109 sys.stdout.flush()
96 sys.stderr.flush() 110 sys.stderr.flush()
97 tst = subprocess.Popen([revoc, '-t', rev_key, '-c', TEST_CONFIGURATION], stdout=subprocess.PIPE) 111 tst = subprocess.Popen([revoc, '-t', rev_key, '-c', TEST_CONFIGURATION],
112 stdout=subprocess.PIPE)
98 output_revoked, x = tst.communicate() 113 output_revoked, x = tst.communicate()
99 output_revoked = output_revoked.decode("utf-8") 114 output_revoked = output_revoked.decode("utf-8")
100 if tst.returncode != 0: 115 if tst.returncode != 0:
diff --git a/src/statistics/test_gnunet_statistics.py.in b/src/statistics/test_gnunet_statistics.py.in
index b14dc9d9e..3a13c24f3 100644
--- a/src/statistics/test_gnunet_statistics.py.in
+++ b/src/statistics/test_gnunet_statistics.py.in
@@ -122,7 +122,9 @@ if len([x for x in stdo.splitlines() if re.search(b'42', x)]) != 1:
122print("PASS") 122print("PASS")
123 123
124print("TEST: Set persistent value...", end='') 124print("TEST: Set persistent value...", end='')
125rc, stdo, stde = r_st(['-n', 'lasting', '-s', 'subsystem', '40', '-p'], nofail=True, want_stdo=False) 125rc, stdo, stde = r_st(['-n', 'lasting', '-s', 'subsystem', '40', '-p'],
126 nofail=True,
127 want_stdo=False)
126rc, stdo, stde = r_st([], nofail=True, want_stdo=True) 128rc, stdo, stde = r_st([], nofail=True, want_stdo=True)
127if len([x for x in stdo.splitlines() if re.search(b'40', x)]) != 1: 129if len([x for x in stdo.splitlines() if re.search(b'40', x)]) != 1:
128 fail("FAIL: unexpected output:\n{}".format(stdo)) 130 fail("FAIL: unexpected output:\n{}".format(stdo))
@@ -137,7 +139,9 @@ if len([x for x in stdo.splitlines() if re.search(b'40', x)]) != 1:
137print("PASS") 139print("PASS")
138 140
139print("TEST: Removing persistence...", end='') 141print("TEST: Removing persistence...", end='')
140rc, stdo, stde = r_st(['-n', 'lasting', '-s', 'subsystem', '40'], nofail=True, want_stdo=False) 142rc, stdo, stde = r_st(['-n', 'lasting', '-s', 'subsystem', '40'],
143 nofail=True,
144 want_stdo=False)
141rc, stdo, stde = r_st([], nofail=True, want_stdo=True) 145rc, stdo, stde = r_st([], nofail=True, want_stdo=True)
142if len([x for x in stdo.splitlines() if re.search(b'!', x)]) != 0: 146if len([x for x in stdo.splitlines() if re.search(b'!', x)]) != 0:
143 fail("FAIL: unexpected output:\n{}".format(stdo)) 147 fail("FAIL: unexpected output:\n{}".format(stdo))