diff --git a/kazoo/client.py b/kazoo/client.py index a5bdae42..25baa683 100644 --- a/kazoo/client.py +++ b/kazoo/client.py @@ -826,7 +826,8 @@ def unchroot(self, path): """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 @@ def sync_async(self, path): """ 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 1800c574..45ec0092 100644 --- a/kazoo/tests/test_client.py +++ b/kazoo/tests/test_client.py @@ -190,8 +190,8 @@ def test_connect_auth(self): 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 @@ def test_ensure_path(self): 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 @@ def test_create(self): 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):