Example #1
0
def test_ping():
    a1 = set_pod_parser().parse_args([])
    a2 = set_ping_parser().parse_args(['0.0.0.0', str(a1.port)])

    a3 = set_ping_parser().parse_args(
        ['0.0.0.1', str(a1.port), '--timeout', '1000'])

    with pytest.raises(SystemExit) as cm:
        with PodFactory.build_pod(a1):
            NetworkChecker(a2)

    assert cm.value.code == 0

    # test with bad address
    with pytest.raises(SystemExit) as cm:
        with PodFactory.build_pod(a1):
            NetworkChecker(a3)

    assert cm.value.code == 1
def test_container_ping(docker_image_built):
    a4 = set_pea_parser().parse_args(['--uses', f'docker://{img_name}'])
    a5 = set_ping_parser().parse_args(
        ['0.0.0.0', str(a4.port_ctrl), '--print-response'])

    # test with container
    with pytest.raises(SystemExit) as cm:
        with Pea(a4):
            NetworkChecker(a5)

    assert cm.value.code == 0
Example #3
0
def test_ping():
    a1 = set_pea_parser().parse_args([])
    a2 = set_ping_parser().parse_args(
        ['0.0.0.0', str(a1.port_ctrl), '--print-response'])

    a3 = set_ping_parser().parse_args(
        ['0.0.0.1', str(a1.port_ctrl), '--timeout', '1000'])

    with pytest.raises(SystemExit) as cm:
        with Pea(a1):
            NetworkChecker(a2)

    assert cm.value.code == 0

    # test with bad address
    with pytest.raises(SystemExit) as cm:
        with Pea(a1):
            NetworkChecker(a3)

    assert cm.value.code == 1
Example #4
0
def get_main_parser():
    """The main parser for Jina

    :return: the parser
    """
    from jina.parsers.base import set_base_parser
    from jina.parsers.create import set_new_project_parser
    from jina.parsers.export_api import set_export_api_parser
    from jina.parsers.flow import set_flow_parser
    from jina.parsers.helloworld import set_hello_parser
    from jina.parsers.helper import _SHOW_ALL_ARGS, _chf
    from jina.parsers.hubble import set_hub_parser
    from jina.parsers.ping import set_ping_parser

    # create the top-level parser
    parser = set_base_parser()

    sp = parser.add_subparsers(
        dest='cli',
        required=True,
    )

    set_hello_parser(
        sp.add_parser(
            'hello',
            help='Hello Jina!',
            description='Start hello world demos.',
            formatter_class=_chf,
        ))

    set_pod_parser(
        sp.add_parser(
            'executor',
            help='Start an Executor',
            description=
            'Start an Executor. Executor is how Jina processes Document.',
            formatter_class=_chf,
        ))

    set_flow_parser(
        sp.add_parser(
            'flow',
            description=
            'Start a Flow. Flow is how Jina streamlines and distributes Executors.',
            help='Start a Flow',
            formatter_class=_chf,
        ))

    set_ping_parser(
        sp.add_parser(
            'ping',
            help='Ping an Executor',
            description='Ping a Deployment and check its network connectivity.',
            formatter_class=_chf,
        ))

    set_new_project_parser(
        sp.add_parser(
            'new',
            help='Create a new Jina project',
            description=
            'Create a new Jina toy project with the predefined template.',
            formatter_class=_chf,
        ))

    set_gateway_parser(
        sp.add_parser(
            'gateway',
            description=
            'Start a Gateway that receives client Requests via gRPC/REST interface',
            **(dict(help='Start a Gateway')) if _SHOW_ALL_ARGS else {},
            formatter_class=_chf,
        ))

    set_hub_parser(
        sp.add_parser(
            'hub',
            help='Push/pull an Executor to/from Jina Hub',
            description='Push/Pull an Executor to/from Jina Hub',
            formatter_class=_chf,
        ))

    set_help_parser(
        sp.add_parser(
            'help',
            help='Show help text of a CLI argument',
            description='Show help text of a CLI argument',
            formatter_class=_chf,
        ))
    # Below are low-level / internal / experimental CLIs, hidden from users by default

    set_pod_parser(
        sp.add_parser(
            'pod',
            description='Start a Pod. '
            'You should rarely use this directly unless you '
            'are doing low-level orchestration',
            formatter_class=_chf,
            **(dict(help='Start a Pod')) if _SHOW_ALL_ARGS else {},
        ))

    set_deployment_parser(
        sp.add_parser(
            'deployment',
            description='Start a Deployment. '
            'You should rarely use this directly unless you '
            'are doing low-level orchestration',
            formatter_class=_chf,
            **(dict(help='Start a Deployment')) if _SHOW_ALL_ARGS else {},
        ))

    set_client_cli_parser(
        sp.add_parser(
            'client',
            description=
            'Start a Python client that connects to a remote Jina gateway',
            formatter_class=_chf,
            **(dict(help='Start a Client')) if _SHOW_ALL_ARGS else {},
        ))

    set_export_api_parser(
        sp.add_parser(
            'export-api',
            description=
            'Export Jina API to JSON/YAML file for 3rd party applications',
            formatter_class=_chf,
            **(dict(help='Export Jina API to file')) if _SHOW_ALL_ARGS else {},
        ))

    return parser