def main(): """ Builds a zookeeper tree with ACLS on from a config file""" options = { 'servers':('list of zk servers', 'strlist', 'store', None) } go = simple_option(options) rpasswd, rpath = get_rootinfo(go.configfile_remainder) znodes, users = parse_zkconfig(go.configfile_remainder) logger.debug("znodes: %s" % znodes) logger.debug("users: %s" % users) # Connect to zookeeper # initial authentication credentials and acl for admin on root level acreds = [('digest', 'root:' + rpasswd)] root_acl = make_digest_acl('root', rpasswd, all=True) # Create kazoo/zookeeper connection with root credentials servers = go.options.servers zkclient = VscKazooClient(servers, auth_data=acreds) # Iterate paths for path, attrs in znodes.iteritems(): logger.debug("path %s attribs %s" % (path, attrs)) acls = dict((arg, attrs[arg]) for arg in attrs if arg not in ('value', 'ephemeral', 'sequence', 'makepath')) acl_list = parse_acls(acls, users, root_acl) kwargs = dict((arg, attrs[arg]) for arg in attrs if arg in ('ephemeral', 'sequence', 'makepath')) if not zkclient.exists_znode(path): zkclient.make_znode(path, value=attrs.get('value', ''), acl=acl_list, **kwargs) else: logger.warning('node %s already exists' % path) zkclient.znode_acls(path, acl_list) zkclient.exit()
def main(): """ Builds a zookeeper tree with ACLS on from a config file""" options = {'servers': ('list of zk servers', 'strlist', 'store', None)} go = simple_option(options) rpasswd, _ = get_rootinfo(go.configfile_remainder) znodes, users = parse_zkconfig(go.configfile_remainder) logger.debug("znodes: %s", znodes) logger.debug("users: %s", users) # Connect to zookeeper # initial authentication credentials and acl for admin on root level acreds = [('digest', 'root:' + rpasswd)] root_acl = make_digest_acl('root', rpasswd, all=True) # Create kazoo/zookeeper connection with root credentials servers = go.options.servers zkclient = VscKazooClient(servers, auth_data=acreds) # Iterate paths for path, attrs in znodes.iteritems(): logger.debug("path %s attribs %s", path, attrs) acls = dict( (arg, attrs[arg]) for arg in attrs if arg not in ('value', 'ephemeral', 'sequence', 'makepath')) acl_list = parse_acls(acls, users, root_acl) kwargs = dict((arg, attrs[arg]) for arg in attrs if arg in ('ephemeral', 'sequence', 'makepath')) if not zkclient.exists_znode(path): zkclient.make_znode(path, value=attrs.get('value', ''), acl=acl_list, **kwargs) else: logger.warning('node %s already exists', path) zkclient.znode_acls(path, acl_list) zkclient.exit()
def test_set_is_ready(self): """ Test the ready function """ zkclient = VscKazooClient('mocked') self.assertFalse(zkclient.is_ready()) zkclient.set_ready() self.assertTrue(zkclient.is_ready())
def test_znode_path(self): """ Test the correct creation of a zookeeper path """ zkclient = VscKazooClient('mocked') self.assertEqual(zkclient.znode_path('test'), '/admin/test') self.assertEqual(zkclient.znode_path('/admin/test'), '/admin/test') self.assertRaises(Exception, zkclient.znode_path, '/other/test')