Example #1
0
    def get_children(self, path, watcher=None):
	"""Return the list of the children of the node of the given path.

        If the `watcher` function is provided and the call is successful (no
	exception is thrown), a watch will be left on the node with the given
	path. The watch will be triggered by a successful operation that
	deletes the node of the given path or creates/delete a child under the
	node.

        The list of children returned is not sorted and no guarantee is
	provided as to its natural or lexical order.

        :Parameters:
	    - `path`: path to node
	    - `watcher`: (optional) watcher function to call when changes occur

        :Return:
	    list of children nodes

	:Exceptions:
	    - `NoNodeException`: if node does not exist
        """
	if watcher:
	    watcher = self._wrap_watcher(watcher)
	children = _zookeeper.get_children(self.zk_handle, path, watcher)
	assert isinstance(children, list)
	return children
Example #2
0
    def test_sync_delete(self):
        ZOO_OPEN_ACL_UNSAFE = {"perms":0x1f, "scheme":"world", "id" :"anyone"}
        self.assertEqual(self.connected, True)
        ret = zookeeper.create(self.handle, "/zk-python-deletetest", "nodecontents", [ZOO_OPEN_ACL_UNSAFE], zookeeper.EPHEMERAL)
        self.assertEqual(ret, "/zk-python-deletetest")
        ret = zookeeper.delete(self.handle,"/zk-python-deletetest")
        self.assertEqual(ret, zookeeper.OK)
        children = zookeeper.get_children(self.handle, "/")
        self.assertEqual(False, "zk-python-deletetest" in children)

        # test exception
        self.assertRaises(zookeeper.NoNodeException,
                          zookeeper.delete,
                          self.handle,
                          "/zk-python-deletetest")
Example #3
0
 def test_sync_getchildren(self):
     self.ensureCreated("/zk-python-getchildrentest", flags=0)
     self.ensureCreated("/zk-python-getchildrentest/child")
     children = zookeeper.get_children(self.handle, "/zk-python-getchildrentest")
     self.assertEqual(len(children), 1, "Expected to find 1 child, got " + str(len(children)))