def test_sync_acl(self): self.assertEqual(self.connected, True) ret = zookeeper.create(self.handle, "/zk-python-acltest", "nodecontents", [ZOO_OPEN_ACL_UNSAFE], zookeeper.EPHEMERAL) acls = zookeeper.get_acl(self.handle, "/zk-python-acltest") self.assertEqual(acls[1], [ZOO_OPEN_ACL_UNSAFE]) self.assertRaises(zookeeper.InvalidACLException,zookeeper.set_acl,self.handle, "/zk-python-acltest", -1, ZOO_ACL_READ) zookeeper.set_acl(self.handle, "/zk-python-acltest", -1, [ZOO_ACL_READ]) acls = zookeeper.get_acl(self.handle, "/zk-python-acltest") self.assertEqual(acls[1], [ZOO_ACL_READ])
def get_acl(self, path): """Return the ACL and stat of the node of the given path. :Parameters: - `path`: the given path for the node :Returns: (Stat object, acl list) for the node :Exceptions: - `NoNodeException` if the node does not exist. """ stat_dict, acl_list = _zookeeper.get_acl(self.zk_handle, path) # Pack into ACL objects. acl_list = [ACL(a['perms'], Id(a['scheme'], a['id'])) for a in acl_list] return Stat(**stat_dict), acl_list
def test_async_acl(self): self.cv = threading.Condition() self.cv = threading.Condition() def aget_callback(handle, rc, acl, stat): self.cv.acquire() self.callback_flag = True self.rc = rc self.acl = acl self.stat = stat self.cv.notify() self.cv.release() def aset_callback(handle, rc): self.cv.acquire() self.callback_flag = True self.rc = rc self.cv.notify() self.cv.release() self.assertEqual(self.connected, True, "Not connected!") ret = zookeeper.create(self.handle, "/zk-python-aacltest", "nodecontents", [ZOO_OPEN_ACL_UNSAFE], zookeeper.EPHEMERAL) self.cv.acquire() zookeeper.aget_acl(self.handle, "/zk-python-aacltest", aget_callback) self.cv.wait(15) self.cv.release() self.assertEqual(self.callback_flag, True, "aget_acl timed out") self.assertEqual(self.rc, zookeeper.OK, "aget failed") self.assertEqual(self.acl, [ZOO_OPEN_ACL_UNSAFE], "Wrong ACL returned from aget") self.cv.acquire() self.callback_flag = False zookeeper.aset_acl(self.handle, "/zk-python-aacltest", -1, [ZOO_ACL_READ], aset_callback) self.cv.wait(15) self.cv.release() self.assertEqual(self.callback_flag, True, "aset_acl timed out") self.assertEqual(self.rc, zookeeper.OK, "aset failed") acls = zookeeper.get_acl(self.handle, "/zk-python-aacltest") self.assertEqual(acls[1], [ZOO_ACL_READ], "Wrong ACL returned from get when aset")