Commit b5802865 authored by Tom Niget's avatar Tom Niget

Merge branch 'zdimension/re6st-py3-test' of...

Merge branch 'zdimension/re6st-py3-test' of https://lab.nexedi.com/nexedi/re6stnet into zdimension/re6st-py3-test
parents d8594f79 1a85418a
...@@ -35,13 +35,11 @@ RENEW_PERIOD = 30 * 86400 ...@@ -35,13 +35,11 @@ RENEW_PERIOD = 30 * 86400
BABEL_HMAC = 'babel_hmac0', 'babel_hmac1', 'babel_hmac2' BABEL_HMAC = 'babel_hmac0', 'babel_hmac1', 'babel_hmac2'
def rpc(f): def rpc(f):
args, varargs, varkw, defaults = inspect.getargspec(f) argspec = inspect.getfullargspec(f)
assert not (varargs or varkw), f assert not (argspec.varargs or argspec.varkw), f
if not defaults: sig = inspect.signature(f)
defaults = () sig = sig.replace(parameters=[*sig.parameters.values()][1:])
i = len(args) - len(defaults) f.getcallargs = eval("lambda %s: locals()" % str(sig)[1:-1])
f.getcallargs = eval("lambda %s: locals()" % ','.join(args[1:i]
+ list(map("%s=%r".__mod__, list(zip(args[i:], defaults))))))
return f return f
def rpc_private(f): def rpc_private(f):
...@@ -818,7 +816,7 @@ class RegistryClient(object): ...@@ -818,7 +816,7 @@ class RegistryClient(object):
kw = getcallargs(*args, **kw) kw = getcallargs(*args, **kw)
query = '/' + name query = '/' + name
if kw: if kw:
if any(type(v) is not str for v in kw.values()): if any(not isinstance(v, (str, bytes)) for v in kw.values()):
raise TypeError(kw) raise TypeError(kw)
query += '?' + urlencode(kw) query += '?' + urlencode(kw)
url = self._path + query url = self._path + query
......
...@@ -70,7 +70,7 @@ class TestRegistryClientInteract(unittest.TestCase): ...@@ -70,7 +70,7 @@ class TestRegistryClientInteract(unittest.TestCase):
self.fail("Request token failed, no token in database") self.fail("Request token failed, no token in database")
# token: tuple[unicode,] # token: tuple[unicode,]
token = str(token[0]) token = str(token[0])
self.assertEqual(client.isToken(token), "1") self.assertEqual(client.isToken(token).decode(), "1")
# request ca # request ca
ca = client.getCa() ca = client.getCa()
...@@ -78,7 +78,7 @@ class TestRegistryClientInteract(unittest.TestCase): ...@@ -78,7 +78,7 @@ class TestRegistryClientInteract(unittest.TestCase):
# request a cert and get cn # request a cert and get cn
key, csr = tools.generate_csr() key, csr = tools.generate_csr()
cert = client.requestCertificate(token, csr) cert = client.requestCertificate(token, csr)
self.assertEqual(client.isToken(token), '', "token should be deleted") self.assertEqual(client.isToken(token).decode(), '', "token should be deleted")
# creat x509.cert object # creat x509.cert object
def write_to_temp(text): def write_to_temp(text):
...@@ -97,18 +97,19 @@ class TestRegistryClientInteract(unittest.TestCase): ...@@ -97,18 +97,19 @@ class TestRegistryClientInteract(unittest.TestCase):
# verfiy cn and prefix # verfiy cn and prefix
prefix = client.cert.prefix prefix = client.cert.prefix
cn = client.getNodePrefix(email) cn = client.getNodePrefix(email).decode()
self.assertEqual(tools.prefix2cn(prefix), cn) self.assertEqual(tools.prefix2cn(prefix), cn)
# simulate the process in cache # simulate the process in cache
# just prove works # just prove works
net_config = client.getNetworkConfig(prefix) net_config = client.getNetworkConfig(prefix)
self.assertIsNotNone(net_config)
net_config = json.loads(zlib.decompress(net_config)) net_config = json.loads(zlib.decompress(net_config))
self.assertEqual(net_config[u'max_clients'], self.max_clients) self.assertEqual(net_config[u'max_clients'], self.max_clients)
# no re6stnet, empty result # no re6stnet, empty result
bootpeer = client.getBootstrapPeer(prefix) bootpeer = client.getBootstrapPeer(prefix)
self.assertEqual(bootpeer, "") self.assertEqual(bootpeer.decode(), "")
# server should not die # server should not die
self.assertIsNone(self.server.proc.poll()) self.assertIsNone(self.server.proc.poll())
......
...@@ -8,8 +8,7 @@ import logging ...@@ -8,8 +8,7 @@ import logging
import random import random
from pathlib import Path from pathlib import Path
import network_build from re6st.tests.test_network import network_build, re6st_wrap
import re6st_wrap
PING_PATH = str(Path(__file__).parent.resolve() / "ping.py") PING_PATH = str(Path(__file__).parent.resolve() / "ping.py")
......
...@@ -15,10 +15,10 @@ def copy_file(self, infile, outfile, *args, **kw): ...@@ -15,10 +15,10 @@ def copy_file(self, infile, outfile, *args, **kw):
if infile == version["__file__"]: if infile == version["__file__"]:
if not self.dry_run: if not self.dry_run:
log.info("generating %s -> %s", infile, outfile) log.info("generating %s -> %s", infile, outfile)
with open(outfile, "w", encoding="utf-8") as f: with open(outfile, "wb") as f:
for x in sorted(version.items()): for x in sorted(version.items()):
if not x[0].startswith("_"): if not x[0].startswith("_"):
f.write("%s = %r\n" % x) f.write(("%s = %r\n" % x).encode())
return outfile, 1 return outfile, 1
elif isinstance(self, build_py) and \ elif isinstance(self, build_py) and \
os.stat(infile).st_mode & stat.S_IEXEC: os.stat(infile).st_mode & stat.S_IEXEC:
...@@ -27,14 +27,17 @@ def copy_file(self, infile, outfile, *args, **kw): ...@@ -27,14 +27,17 @@ def copy_file(self, infile, outfile, *args, **kw):
# Adjust interpreter of OpenVPN hooks. # Adjust interpreter of OpenVPN hooks.
with open(infile) as src: with open(infile) as src:
first_line = src.readline() first_line = src.readline()
m = first_line_re.match(first_line) m = first_line_re.match(first_line.encode())
if m and not self.dry_run: if m and not self.dry_run:
log.info("copying and adjusting %s -> %s", infile, outfile) log.info("copying and adjusting %s -> %s", infile, outfile)
executable = self.distribution.command_obj['build'].executable executable = self.distribution.command_obj['build'].executable
patched = "#!%s%s\n" % (executable, m.group(1) or '') patched = "#!%s%s\n" % (executable, m.group(1) or '')
patched += src.read() patched += src.read()
with open(outfile, "w") as dst: dst = os.open(outfile, os.O_CREAT | os.O_WRONLY | os.O_TRUNC)
dst.write(patched) try:
os.write(dst, patched.encode())
finally:
os.close(dst)
return outfile, 1 return outfile, 1
cls, = self.__class__.__bases__ cls, = self.__class__.__bases__
return cls.copy_file(self, infile, outfile, *args, **kw) return cls.copy_file(self, infile, outfile, *args, **kw)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment