Пример #1
0
def set_gateway_parser(parser=None):
    """Set the parser for the gateway arguments

    :param parser: an optional existing parser to build upon
    :return: the parser
    """
    if not parser:
        from jina.parsers.base import set_base_parser

        parser = set_base_parser()

    from jina.parsers.orchestrate.base import mixin_base_ppr_parser
    from jina.parsers.orchestrate.runtimes.worker import mixin_worker_runtime_parser
    from jina.parsers.orchestrate.runtimes.remote import (
        mixin_gateway_parser,
        mixin_prefetch_parser,
        mixin_http_gateway_parser,
        mixin_compressor_parser,
    )
    from jina.parsers.orchestrate.deployment import mixin_base_deployment_parser
    from jina.parsers.orchestrate.pod import mixin_pod_parser

    mixin_base_ppr_parser(parser)
    mixin_worker_runtime_parser(parser)
    mixin_prefetch_parser(parser)
    mixin_http_gateway_parser(parser)
    mixin_compressor_parser(parser)
    mixin_comm_protocol_parser(parser)
    mixin_gateway_parser(parser)
    mixin_pod_parser(parser)
    mixin_head_parser(parser)

    from jina.enums import DeploymentRoleType

    parser.set_defaults(
        name='gateway',
        runtime_cls='GRPCGatewayRuntime',
        deployment_role=DeploymentRoleType.GATEWAY,
    )

    return parser
Пример #2
0
def test_runtime_parser():
    parser = argparse.ArgumentParser(epilog=f'Test',
                                     description='Test Command Line Interface')

    mixin_http_gateway_parser(parser)

    args = parser.parse_args([])
    assert args.uvicorn_kwargs is None

    args = parser.parse_args(
        ['--uvicorn-kwargs', 'ssl_keyfile: /tmp/cert.pem'])
    assert args.uvicorn_kwargs == {'ssl_keyfile': '/tmp/cert.pem'}

    args = parser.parse_args([
        '--uvicorn-kwargs',
        'ssl_keyfile: /tmp/cert.pem',
        'ssl_keyfile_password: 1234e',
    ])
    assert args.uvicorn_kwargs == {
        'ssl_keyfile': '/tmp/cert.pem',
        'ssl_keyfile_password': '******',
    }