def test_is_zookeeper_enabled(self): config = {} assert not zkutil.is_zookeeper_enabled(config) config = {"server": {}} assert not zkutil.is_zookeeper_enabled(config) config = {"server": {"zookeeper": {}}} assert not zkutil.is_zookeeper_enabled(config) config = {"server": {"zookeeper": {"hosts": "localhost:2181", "path": "/hats"}}} assert zkutil.is_zookeeper_enabled(config) config = {"server": {"zookeeper": {"enabled": True, "hosts": "localhost:2181", "path": "/hats"}}} assert zkutil.is_zookeeper_enabled(config) config = {"server": {"zookeeper": {"enabled": "True", "hosts": "localhost:2181", "path": "/hats"}}} assert zkutil.is_zookeeper_enabled(config) config = {"server": {"zookeeper": {"enabled": False, "hosts": "localhost:2181", "path": "/hats"}}} assert not zkutil.is_zookeeper_enabled(config) config = {"server": {"zookeeper": {"enabled": "False", "hosts": "localhost:2181", "path": "/hats"}}} assert not zkutil.is_zookeeper_enabled(config) config = {"server": {"zookeeper": {"enabled": "false", "hosts": "localhost:2181", "path": "/hats"}}} assert not zkutil.is_zookeeper_enabled(config)
def main(args=None): parser = argparse.ArgumentParser(description='EPU ZooKeeper management utility') parser.add_argument('--config', '-c', metavar="config.yml", type=argparse.FileType('r'), required=True) subparsers = parser.add_subparsers() setup_parser = subparsers.add_parser("setup", description=cmd_setup.__doc__, help="prepare path for system launch") setup_parser.add_argument("path", help="ZooKeeper base path", nargs='?') setup_parser.add_argument("--clean", help="Remove existing contents of path", action="store_true") setup_parser.add_argument("--clean-epu", help="Remove EPU-layer data", action="store_true") setup_parser.set_defaults(func=cmd_setup) destroy_parser = subparsers.add_parser("destroy", description=cmd_destroy.__doc__, help="delete path") destroy_parser.add_argument("path", help="ZooKeeper base path", nargs='?') destroy_parser.set_defaults(func=cmd_destroy) args = parser.parse_args(args=args) config = yaml.load(args.config) if not zkutil.is_zookeeper_enabled(config): print >>sys.stderr, "ZooKeeper is not enabled in config. Doing nothing." return zk_config = zkutil.get_zookeeper_config(config) try: args.func(zk_config, args) except CliError, e: parser.error(str(e))
def get_provisioner_store(config, use_gevent=False, proc_name=None): """Instantiate Provisioner store object for the given configuration """ if zkutil.is_zookeeper_enabled(config): zookeeper = zkutil.get_zookeeper_config(config) log.info("Using ZooKeeper Provisioner store") store = ProvisionerZooKeeperStore(zookeeper['hosts'], zookeeper['path'], username=zookeeper.get('username'), password=zookeeper.get('password'), timeout=zookeeper.get('timeout'), proc_name=proc_name, use_gevent=use_gevent) else: log.info("Using in-memory Provisioner store") store = ProvisionerStore() return store
def get_dtrs_store(config, use_gevent=False): """Instantiate DTRS store object for the given configuration """ if zkutil.is_zookeeper_enabled(config): zookeeper = zkutil.get_zookeeper_config(config) log.info("Using ZooKeeper DTRS store") store = DTRSZooKeeperStore(zookeeper['hosts'], zookeeper['path'], username=zookeeper.get('username'), password=zookeeper.get('password'), timeout=zookeeper.get('timeout'), use_gevent=use_gevent) else: log.info("Using in-memory DTRS store") store = DTRSStore() return store