Esempio n. 1
0
    def test_bundle_http_port(self):
        port_number = 1111
        getenv_mock = MagicMock(return_value=port_number)
        with patch('os.getenv', getenv_mock):
            result = sandbox_common.bundle_http_port()

        self.assertEqual(result, port_number)
        getenv_mock.assert_called_with('BUNDLE_HTTP_PORT', 9000)
Esempio n. 2
0
    def test_bundle_http_port(self):
        port_number = 1111
        getenv_mock = MagicMock(return_value=port_number)
        with patch('os.getenv', getenv_mock):
            result = sandbox_common.bundle_http_port()

        self.assertEqual(result, port_number)
        getenv_mock.assert_called_with('BUNDLE_HTTP_PORT', 9000)
Esempio n. 3
0
def build_parser():
    # Main argument parser
    parser = argparse.ArgumentParser('sandbox')
    subparsers = parser.add_subparsers(
        title='commands', help='Use one of the following sub commands')

    # Sub-parser for `run` sub-command
    run_parser = subparsers.add_parser(
        'run',
        help='Run ConductR sandbox cluster',
        usage='%(prog)s IMAGE_VERSION [ARGS]',
        formatter_class=argparse.RawTextHelpFormatter)
    add_default_arguments(run_parser)
    run_parser.add_argument(
        'image_version',
        nargs='?',
        help='Version of the ConductR docker image to use.\n'
        'To obtain the current version and additional information, please visit the \n'
        'http://www.typesafe.com/product/conductr/developer page on Typesafe.com.'
    )
    run_parser.add_argument(
        '-r',
        '--conductr-role',
        dest='conductr_roles',
        action='append',
        nargs='*',
        default=[],
        help='Set additional roles allowed per ConductR node.\n'
        'Multiple roles per node are separated by a whitespace.\n'
        'Example: sandbox run IMAGE_VERSION -r role1 role2 -r role3\n'
        'In this example the roles role1 and role2 are assigned to the first node and\n'
        'role3 is assigned to the second node.\n'
        'Afterwards the specified roles are subsequently applied to the remaining nodes.\n'
        'Defaults to [].',
        metavar='')
    run_parser.add_argument(
        '-e',
        '--env',
        dest='envs',
        action='append',
        default=[],
        help=
        'Set additional environment variables for each ConductR container. Defaults to [].',
        metavar='')
    run_parser.add_argument('-i',
                            '--image',
                            default=CONDUCTR_DEV_IMAGE,
                            help='Docker image to use.\n'
                            'Defaults to `{}`.'.format(CONDUCTR_DEV_IMAGE),
                            metavar='')
    log_levels = ['debug', 'info', 'warning']
    run_parser.add_argument(
        '-l',
        '--log-level',
        default='info',
        help='Log level of ConductR.\n'
        'Defaults to `info`.\n'
        'You can observe ConductRs logging via the `docker logs` command. \n'
        'For example `docker logs -f cond-0` will follow the logs of the first '
        'ConductR container.\n'
        'Available log levels: ' + ', '.join(log_levels),
        choices=log_levels,
        metavar='')
    run_parser.add_argument('-n',
                            '--nr-of-containers',
                            type=int,
                            default=1,
                            help='Number of ConductR nodes. Defaults to 1.',
                            metavar='')
    run_parser.add_argument(
        '-p',
        '--port',
        dest='ports',
        action='append',
        type=int,
        default=[],
        help=
        'Set additional ports to be made public by each of the ConductR containers.',
        metavar='')
    run_parser.add_argument(
        '--bundle-http-port',
        dest='bundle_http_port',
        type=int,
        default=sandbox_common.bundle_http_port(),
        help='Set default frontend port for proxying HTTP based request ACLs.',
        metavar='')
    features = ['visualization', 'logging', 'monitoring']
    run_parser.add_argument('-f',
                            '--feature',
                            dest='features',
                            action='append',
                            default=[],
                            help='Features to be enabled.\n'
                            'Available features: ' + ', '.join(features),
                            choices=features,
                            metavar='')
    run_parser.set_defaults(func=sandbox_run.run)

    # Sub-parser for `debug` sub-command
    debug_parser = subparsers.add_parser(
        'debug', help='Not supported. Use \'sbt-conductr-sandbox\' instead.')
    add_resolve_ip(debug_parser, False)
    debug_parser.set_defaults(func='debug')

    # Sub-parser for `stop` sub-command
    stop_parser = subparsers.add_parser('stop',
                                        help='Stop ConductR sandbox cluster')
    add_default_arguments(stop_parser)
    stop_parser.set_defaults(func=sandbox_stop.stop)

    # Sub-parser for `init` sub-command
    init_parser = subparsers.add_parser(
        'init', help='Initializes ConductR sandbox environment')
    add_resolve_ip(init_parser, False)
    init_parser.set_defaults(func=sandbox_init.init)
    return parser
Esempio n. 4
0
def build_parser():
    # Main argument parser
    parser = argparse.ArgumentParser('sandbox')
    subparsers = parser.add_subparsers(title='commands',
                                       help='Use one of the following sub commands')

    # Sub-parser for `version` sub-command
    version_parser = subparsers.add_parser('version',
                                           help='print version')
    version_parser.set_defaults(func=version.version)

    # Sub-parser for `run` sub-command
    run_parser = subparsers.add_parser('run',
                                       help='Run ConductR sandbox cluster',
                                       usage='%(prog)s IMAGE_VERSION [ARGS]',
                                       formatter_class=argparse.RawTextHelpFormatter)
    add_default_arguments(run_parser)
    add_image_dir(run_parser)
    run_parser.add_argument('image_version',
                            nargs='?',
                            help='Version of the ConductR docker image to use.\n'
                                 'To obtain the current version and additional information, please visit \n'
                                 'http://lightbend.com/product/conductr/developer')
    run_parser.add_argument('-r', '--conductr-role',
                            dest='conductr_roles',
                            action='append',
                            nargs='*',
                            default=[],
                            help='Set additional roles allowed per ConductR node.\n'
                                 'Multiple roles per node are separated by a whitespace.\n'
                                 'Example: sandbox run IMAGE_VERSION -r role1 role2 -r role3\n'
                                 'In this example the roles role1 and role2 are assigned to the first node and\n'
                                 'role3 is assigned to the second node.\n'
                                 'Afterwards the specified roles are subsequently applied to the remaining nodes.\n'
                                 'Defaults to [].',
                            metavar='')
    run_parser.add_argument('-e', '--env',
                            dest='envs',
                            action='append',
                            default=[],
                            help='Set additional environment variables for each ConductR container. Defaults to [].',
                            metavar='')
    run_parser.add_argument('-i', '--image',
                            default=CONDUCTR_DEV_IMAGE,
                            help='Docker image to use.\n'
                                 'Defaults to `{}`.'.format(CONDUCTR_DEV_IMAGE),
                            metavar='')
    log_levels = ['debug', 'info', 'warning']
    run_parser.add_argument('-l', '--log-level',
                            default='info',
                            help='Log level of ConductR.\n'
                                 'Defaults to `info`.\n'
                                 'ConductR logs can be inspected via the `sandbox logs` command.\n'
                                 'Available log levels: ' + ', '.join(log_levels),
                            choices=log_levels,
                            metavar='')
    run_parser.add_argument('-n', '--nr-of-containers', '--nr-of-instances',
                            type=nr_of_instances,
                            default='1',
                            dest='nr_of_instances',
                            help='Number of ConductR core and agent instances. Defaults to 1.\n'
                                 'Also accepts `x:y` format: `x` is a number of core instances, '
                                 'and y is a number of agent instances\n'
                                 'If a number instead of the `x:y` format is specified, then the value correlates '
                                 'to the number of agent instances.\n'
                                 'The core instance will then be 1.\n'
                                 'Example: -n 3 converts to -n 1:3\n'
                                 'For ConductR 1.x, this corresponds to the number of nodes.',
                            metavar='')
    run_parser.add_argument('--offline',
                            default=DEFAULT_OFFLINE_MODE,
                            dest='offline_mode',
                            action='store_true',
                            help='Enables offline mode to resolve bundles only locally '
                                 'either by file uri or from the cache directory. '
                                 'Defaults to environment variable CONDUCTR_OFFLINE_MODE. '
                                 'If not set the default is False.')
    run_parser.add_argument('-p', '--port',
                            dest='ports',
                            action='append',
                            type=int,
                            default=[],
                            help='Set additional ports to be made public by each of the ConductR containers.',
                            metavar='')
    run_parser.add_argument('--bundle-http-port',
                            dest='bundle_http_port',
                            type=int,
                            default=sandbox_common.bundle_http_port(),
                            help='Set default frontend port for proxying HTTP based request ACLs.',
                            metavar='')
    run_parser.add_argument('-f', '--feature',
                            dest='features',
                            action='append',
                            nargs='*',
                            default=[],
                            help='Features to be enabled.\n'
                                 'Available features: ' + ', '.join(feature_names),
                            metavar='')
    run_parser.add_argument('--no-wait',
                            help='Disables waiting for ConductR to be started in the sandbox.',
                            default=False,
                            dest='no_wait',
                            action='store_true')
    run_parser.add_argument('--addr-range',
                            type=addr_range,
                            default=DEFAULT_SANDBOX_ADDR_RANGE,
                            help='Range of address which will be used by ConductR Sandbox to bind to.\n'
                                 'The address range is specified using CIDR notation, i.e. 192.168.1.0/24')
    run_parser.set_defaults(func=sandbox_run.run)

    # Sub-parser for `stop` sub-command
    stop_parser = subparsers.add_parser('stop',
                                        help='Stop ConductR sandbox cluster')
    add_image_dir(stop_parser)
    add_default_arguments(stop_parser)
    stop_parser.set_defaults(func=sandbox_stop.stop)

    # Sub-parser for `ps` sub-command
    ps_parser = subparsers.add_parser('ps',
                                      help='List the pids for ConductR core and agent sandbox processes')
    add_image_dir(ps_parser)
    add_default_arguments(ps_parser)
    ps_parser.add_argument('--core',
                           help='Displays ConductR core sandbox process only.',
                           default=False,
                           dest='is_filter_core',
                           action='store_true')
    ps_parser.add_argument('--agent',
                           help='Displays ConductR agent sandbox process only.',
                           default=False,
                           dest='is_filter_agent',
                           action='store_true')
    ps_parser.add_argument('-q', '--quiet',
                           help='Displays only the pids without the column headers.',
                           default=False,
                           dest='is_quiet',
                           action='store_true')
    ps_parser.set_defaults(func=sandbox_ps.ps)

    # Sub-parser for `logs` sub-command
    logs_parser = subparsers.add_parser('logs',
                                        help='Fetches the logs of ConductR core and agent processes')
    add_image_dir(logs_parser)
    add_default_arguments(logs_parser)
    logs_parser.add_argument('-f', '--follow',
                             help='Output appended as the log files grow',
                             default=False,
                             dest='follow',
                             action='store_true')
    logs_parser.set_defaults(func=sandbox_logs.logs)

    return parser
Esempio n. 5
0
def build_parser():
    # Main argument parser
    parser = argparse.ArgumentParser('sandbox')
    subparsers = parser.add_subparsers(title='commands',
                                       help='Use one of the following sub commands')

    # Sub-parser for `version` sub-command
    version_parser = subparsers.add_parser('version',
                                           help='print version')
    version_parser.set_defaults(func=version.version)

    # Sub-parser for `run` sub-command
    run_parser = subparsers.add_parser('run',
                                       help='Run ConductR sandbox cluster',
                                       usage='%(prog)s IMAGE_VERSION [ARGS]',
                                       formatter_class=argparse.RawTextHelpFormatter)
    add_default_arguments(run_parser)
    run_parser.add_argument('image_version',
                            nargs='?',
                            help='Version of the ConductR docker image to use.\n'
                                 'To obtain the current version and additional information, please visit \n'
                                 'http://lightbend.com/product/conductr/developer')
    run_parser.add_argument('-r', '--conductr-role',
                            dest='conductr_roles',
                            action='append',
                            nargs='*',
                            default=[],
                            help='Set additional roles allowed per ConductR node.\n'
                                 'Multiple roles per node are separated by a whitespace.\n'
                                 'Example: sandbox run IMAGE_VERSION -r role1 role2 -r role3\n'
                                 'In this example the roles role1 and role2 are assigned to the first node and\n'
                                 'role3 is assigned to the second node.\n'
                                 'Afterwards the specified roles are subsequently applied to the remaining nodes.\n'
                                 'Defaults to [].',
                            metavar='')
    run_parser.add_argument('-e', '--env',
                            dest='envs',
                            action='append',
                            default=[],
                            help='Set additional environment variables for each ConductR container. Defaults to [].',
                            metavar='')
    run_parser.add_argument('-i', '--image',
                            default=CONDUCTR_DEV_IMAGE,
                            help='Docker image to use.\n'
                                 'Defaults to `{}`.'.format(CONDUCTR_DEV_IMAGE),
                            metavar='')
    log_levels = ['debug', 'info', 'warning']
    run_parser.add_argument('-l', '--log-level',
                            default='info',
                            help='Log level of ConductR.\n'
                                 'Defaults to `info`.\n'
                                 'You can observe ConductRs logging via the `docker logs` command. \n'
                                 'For example `docker logs -f cond-0` will follow the logs of the first '
                                 'ConductR container.\n'
                                 'Available log levels: ' + ', '.join(log_levels),
                            choices=log_levels,
                            metavar='')
    run_parser.add_argument('-n', '--nr-of-containers',
                            type=int,
                            default=1,
                            help='Number of ConductR nodes. Defaults to 1.',
                            metavar='')
    run_parser.add_argument('-p', '--port',
                            dest='ports',
                            action='append',
                            type=int,
                            default=[],
                            help='Set additional ports to be made public by each of the ConductR containers.',
                            metavar='')
    run_parser.add_argument('--bundle-http-port',
                            dest='bundle_http_port',
                            type=int,
                            default=sandbox_common.bundle_http_port(),
                            help='Set default frontend port for proxying HTTP based request ACLs.',
                            metavar='')
    run_parser.add_argument('-f', '--feature',
                            dest='features',
                            action='append',
                            nargs='*',
                            default=[],
                            help='Features to be enabled.\n'
                                 'Available features: ' + ', '.join(feature_names),
                            metavar='')
    run_parser.add_argument('--no-wait',
                            help='Disables waiting for ConductR to be started in the sandbox',
                            default=False,
                            dest='no_wait',
                            action='store_true')
    run_parser.set_defaults(func=sandbox_run.run)

    # Sub-parser for `stop` sub-command
    stop_parser = subparsers.add_parser('stop',
                                        help='Stop ConductR sandbox cluster')
    add_default_arguments(stop_parser)
    stop_parser.set_defaults(func=sandbox_stop.stop)
    return parser