simple.py 2.17 KB
Newer Older
1 2
#!/usr/bin/env python
#
3
# Copyright (C) 2011-2019  Nexedi SA
4
#
5
# This program is free software; you can redistribute it and/or
6 7 8 9 10 11
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 14 15
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
16
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
17

18
import argparse, inspect, random
19
from logging import getLogger, INFO
20
from neo.lib import logging
21
from neo.tests import functional
22 23
logging.backlog()
del logging.default_root_handler.handle
24 25 26 27

def main():
    args, _, _, defaults = inspect.getargspec(functional.NEOCluster.__init__)
    option_list = zip(args[-len(defaults):], defaults)
28
    parser = argparse.ArgumentParser(
29
        description="Quickly setup a simple NEO cluster for testing purpose.")
30
    parser.add_argument('--seed', help="settings like node ports/uuids and"
31 32 33 34 35 36 37 38 39 40
        " cluster name are random: pass any string to initialize the RNG")
    defaults = {}
    for option, default in sorted(option_list):
        kw = {}
        if type(default) is bool:
            kw['action'] = "store_true"
            defaults[option] = False
        elif default is not None:
            defaults[option] = default
            if isinstance(default, int):
41 42
                kw['type'] = int
        parser.add_argument('--' + option, **kw)
43
    parser.set_defaults(**defaults)
44 45 46 47
    parser.add_argument('db', nargs='+')
    args = parser.parse_args()
    if args.seed:
        functional.random = random.Random(args.seed)
48
    getLogger().setLevel(INFO)
49 50
    cluster = functional.NEOCluster(args.db, **{x: getattr(args, x)
                                                for x, _ in option_list})
51
    try:
52
        cluster.run()
53
        logging.info("Cluster running ...")
54
        cluster.waitAll()
55 56 57 58
    finally:
        cluster.stop()

if __name__ == "__main__":
59
    main()