コード例 #1
0
ファイル: configparser.py プロジェクト: hpcugent/vsc-zk
 def test_parse_zkconfig(self):
     """ Checks if configuration file got parsed correctly"""
     res = (
         {
             "/admin": {
                 "rwcd": ["user1"],
                 "c": ["user3"],
                 "rw": ["user4", "user3"],
                 "r": ["user5"],
                 "cd": ["user2"],
             },
             "/admin/user1": {"all": ["user1"], "r": ["user2", "user3"], "rw": ["user4"]},
             "/admin/tools": {"all": ["sys"]},
             "/admin/rsync": {"rwcd": ["rsync", "kwaegema"]},
         },
         {
             "user4": {"passwd": ["bla"]},
             "user5": {"passwd": ["bla"]},
             "user2": {"passwd": ["bar"]},
             "user3": {"passwd": ["bla"]},
             "user1": {"passwd": ["xyz"]},
             "rsync": {"passwd": ["w00f"]},
             "sys": {"passwd": ["sis"]},
             "kwaegema": {"passwd": ["w00f"]},
         },
     )
     cp.get_rootinfo(self.cfgremainder)
     self.assertEqual(cp.parse_zkconfig(self.cfgremainder), res)
コード例 #2
0
ファイル: zkinitree.py プロジェクト: kwaegema/vsc-zk
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()
コード例 #3
0
ファイル: configparser.py プロジェクト: hpcugent/vsc-zk
 def test_rootinfo(self):
     """Checks if root info got parsed correctly"""
     self.assertEqual(cp.get_rootinfo(self.cfgremainder), ("admin", "/"))