simple.py 2.19 KB
Newer Older
1 2
#!/usr/bin/env python
#
3
# Copyright (C) 2011-2015  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 inspect, random, signal, sys
19
from logging import getLogger, INFO
20
from optparse import OptionParser
21
from neo.lib import logging
22
from neo.tests import functional
23 24
logging.backlog()
del logging.default_root_handler.handle
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47

def main():
    args, _, _, defaults = inspect.getargspec(functional.NEOCluster.__init__)
    option_list = zip(args[-len(defaults):], defaults)
    parser = OptionParser(usage="%prog [options] [db...]",
        description="Quickly setup a simple NEO cluster for testing purpose.")
    parser.add_option('--seed', help="settings like node ports/uuids and"
        " 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):
                kw['type'] = "int"
        parser.add_option('--' + option, **kw)
    parser.set_defaults(**defaults)
    options, args = parser.parse_args()
    if options.seed:
        functional.random = random.Random(options.seed)
48
    getLogger().setLevel(INFO)
49 50
    cluster = functional.NEOCluster(args, **{x: getattr(options, 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()