summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCharles-Henri de Boysson <ceache@users.noreply.github.com>2020-04-15 00:10:05 -0400
committerCharles-Henri de Boysson <ceache@users.noreply.github.com>2020-04-15 00:13:44 -0400
commitcbde70ac87435afbbacc9806c675184c7f778343 (patch)
tree65e665a4699cab092d8fd3cfbdbd9e89e7404416
parentf2ee3058c2178dfe52a2ce327a6db115d299bad4 (diff)
downloadkazoo-cbde70ac87435afbbacc9806c675184c7f778343.tar.gz
fix(core): sync() return should be unchrooted
Resolves #601
-rw-r--r--kazoo/client.py18
-rw-r--r--kazoo/tests/test_client.py17
2 files changed, 26 insertions, 9 deletions
diff --git a/kazoo/client.py b/kazoo/client.py
index a5bdae4..25baa68 100644
--- a/kazoo/client.py
+++ b/kazoo/client.py
@@ -826,7 +826,8 @@ class KazooClient(object):
"""Strip the chroot if applicable from the path."""
if not self.chroot:
return path
-
+ if self.chroot == path:
+ return "/"
if path.startswith(self.chroot):
return path[len(self.chroot):]
else:
@@ -839,7 +840,20 @@ class KazooClient(object):
"""
async_result = self.handler.async_result()
- self._call(Sync(_prefix_root(self.chroot, path)), async_result)
+
+ @wrap(async_result)
+ def _sync_completion(result):
+ return self.unchroot(result.get())
+
+ def _do_sync():
+ result = self.handler.async_result()
+ self._call(
+ Sync(_prefix_root(self.chroot, path)),
+ result
+ )
+ result.rawlink(_sync_completion)
+
+ _do_sync()
return async_result
def sync(self, path):
diff --git a/kazoo/tests/test_client.py b/kazoo/tests/test_client.py
index 1800c57..45ec009 100644
--- a/kazoo/tests/test_client.py
+++ b/kazoo/tests/test_client.py
@@ -190,8 +190,8 @@ class TestAuthentication(KazooTestCase):
client.close()
def test_unicode_auth(self):
- username = u("xe4/\hm")
- password = u("/\xe4hm")
+ username = u(r"xe4/\hm")
+ password = u(r"/\xe4hm")
digest_auth = "%s:%s" % (username, password)
acl = self._makeAuth(username, password, all=True)
@@ -774,10 +774,11 @@ class TestClient(KazooTestCase):
client.ensure_path("/1/2/3/4")
assert client.exists("/1/2/3/4")
- @pytest.mark.skip("BUG: sync() call is not chroot'd")
def test_sync(self):
client = self.client
- assert client.sync('/') == '/'
+ assert client.sync("/") == "/"
+ # Albeit surprising, you can sync anything, even what does not exist.
+ assert client.sync("/not_there") == "/not_there"
def test_exists(self):
nodepath = "/" + uuid.uuid4().hex
@@ -1366,9 +1367,11 @@ class TestNonChrootClient(KazooTestCase):
def test_unchroot(self):
client = self._get_nonchroot_client()
- client.chroot = '/a'
- assert client.unchroot('/a/b') == '/b'
- assert client.unchroot('/b/c') == '/b/c'
+ client.chroot = "/a"
+ # Unchroot'ing the chroot path should return "/"
+ assert client.unchroot("/a") == "/"
+ assert client.unchroot("/a/b") == "/b"
+ assert client.unchroot("/b/c") == "/b/c"
class TestReconfig(KazooTestCase):