summaryrefslogtreecommitdiff
path: root/tests/cloud_tests/__main__.py
blob: 260ddb3fb943f4f7ec89635d55c7f081db8add58 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# This file is part of cloud-init. See LICENSE file for license information.

"""Main entry point."""

import argparse
import logging
import sys

from tests.cloud_tests import args, bddeb, collect, manage, run_funcs, verify
from tests.cloud_tests import LOG


def configure_log(args):
    """Configure logging."""
    level = logging.INFO
    if args.verbose:
        level = logging.DEBUG
    elif args.quiet:
        level = logging.WARN
    LOG.setLevel(level)


def main():
    """Entry point for cloud test suite."""
    # configure parser
    parser = argparse.ArgumentParser(prog='cloud_tests')
    subparsers = parser.add_subparsers(dest="subcmd")
    subparsers.required = True

    def add_subparser(name, description, arg_sets):
        """Add arguments to subparser."""
        subparser = subparsers.add_parser(name, help=description)
        for (_args, _kwargs) in (a for arg_set in arg_sets for a in arg_set):
            subparser.add_argument(*_args, **_kwargs)

    # configure subparsers
    for (name, (description, arg_sets)) in args.SUBCMDS.items():
        add_subparser(name, description,
                      [args.ARG_SETS[arg_set] for arg_set in arg_sets])

    # parse arguments
    parsed = parser.parse_args()

    # process arguments
    configure_log(parsed)
    (_, arg_sets) = args.SUBCMDS[parsed.subcmd]
    for normalizer in [args.NORMALIZERS[arg_set] for arg_set in arg_sets]:
        parsed = normalizer(parsed)
        if not parsed:
            return -1

    # run handler
    LOG.debug('running with args: %s\n', parsed)
    return {
        'bddeb': bddeb.bddeb,
        'collect': collect.collect,
        'create': manage.create,
        'run': run_funcs.run,
        'tree_collect': run_funcs.tree_collect,
        'tree_run': run_funcs.tree_run,
        'verify': verify.verify,
    }[parsed.subcmd](parsed)


if __name__ == "__main__":
    sys.exit(main())

# vi: ts=4 expandtab