Beispiel #1
0
    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")
Beispiel #2
0
    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")
    def test_dispatch_types(self):
        """
        Test all the various dispatch mechanisms internal to the module.
        """
        def dispatch_callback(*args, **kwargs):
            self.callback_flag = True

        self.ensureCreated("/zk-python-dispatch-test")
        self.callback_harness(
            lambda: zookeeper.adelete(
                self.handle, "/zk-python-dispatch-test", -1,
                self.create_callback(dispatch_callback)), lambda: self.
            assertEqual(True, self.callback_flag, "Void dispatch not fired"))

        self.ensureCreated("/zk-python-dispatch-test")
        self.callback_harness(
            lambda: zookeeper.aexists(
                self.handle, "/zk-python-dispatch-test", None,
                self.create_callback(dispatch_callback)), lambda: self.
            assertEqual(True, self.callback_flag, "Stat dispatch not fired"))

        self.callback_harness(
            lambda: zookeeper.aget(
                self.handle, "/zk-python-dispatch-test", None,
                self.create_callback(dispatch_callback)), lambda: self.
            assertEqual(True, self.callback_flag, "Data dispatch not fired"))

        self.callback_harness(
            lambda: zookeeper.aget_children(
                self.handle, "/", None, self.
                create_callback(dispatch_callback)), lambda: self.assertEqual(
                    True, self.callback_flag, "Strings dispatch not fired"))

        self.callback_harness(
            lambda: getattr(zookeeper, 'async')
            (self.handle, "/", self.create_callback(dispatch_callback)),
            lambda: self.assertEqual(True, self.callback_flag,
                                     "String dispatch not fired"))

        self.callback_harness(
            lambda: zookeeper.aget_acl(
                self.handle, "/", self.create_callback(dispatch_callback)),
            lambda: self.assertEqual(True, self.callback_flag,
                                     "ACL dispatch not fired"))
 def get_acl(self, path):
     """
     Gets the acl associated with a node.
 
     path: the name of the node. Expressed as a file name with slashes 
     separating ancestors of the node.
     
     Return:
     (acl, stat)
     """
     results = []
     pc = utils.PipeCondition()
     ok = zookeeper.aget_acl(self._zhandle, path, functools.partial(generic_completion, pc, results))
     assert ok == zookeeper.OK
     pc.wait()
     # unpack result as acl_completion
     handle, rc, acl, stat = results
     assert handle == self._zhandle
     if rc == zookeeper.OK:
         return (acl, stat)
     self._raise_exception(rc)
Beispiel #5
0
    def get_acl(self, path):
        """
        Get the list of acls that apply to node with the give path.

        Each acl is a dictionary containing keys/values for scheme, id,
        and perms.

        @param path: The path of the node whose acl will be retrieved.
        """
        d = defer.Deferred()
        if self._check_connected(d):
            return d

        def _cb_get_acl(result_code, acls, stat):
            if self._check_result(result_code, d, path=path):
                return
            d.callback((acls, stat))

        callback = self._zk_thread_callback(_cb_get_acl)
        result = zookeeper.aget_acl(self.handle, path, callback)
        self._check_result(result, d, path=path)
        return d
 def get_acl(self, path):
     """
     Gets the acl associated with a node.
 
     path: the name of the node. Expressed as a file name with slashes 
     separating ancestors of the node.
     
     Return:
     (acl, stat)
     """
     results = []
     pc = utils.PipeCondition()
     ok = zookeeper.aget_acl(
         self._zhandle, path,
         functools.partial(generic_completion, pc, results))
     assert ok == zookeeper.OK
     pc.wait()
     #unpack result as acl_completion
     handle, rc, acl, stat = results
     assert handle == self._zhandle
     if rc == zookeeper.OK:
         return (acl, stat)
     self._raise_exception(rc)
Beispiel #7
0
 def aget_acl(self, path, callback):
     return zookeeper.aget_acl(self.handle, path, callback)