Beispiel #1
0
    def build_pod(args: 'Namespace') -> Type['BasePod']:
        """Build an implementation of a `BasePod` interface

        :param args: deployment arguments parsed from the CLI.

        :return: the created BaseDeployment
        """
        # copy to update but forward original
        cargs = deepcopy(args)
        if cargs.host != __default_host__ and not cargs.disable_remote:
            cargs.timeout_ready = -1
            return JinaDPod(cargs)

        if is_valid_huburi(cargs.uses):
            _hub_args = deepcopy(args)
            _hub_args.uri = args.uses
            _hub_args.no_usage = True
            cargs.uses = HubIO(_hub_args).pull()

        if (
            cargs.pod_role != PodRoleType.HEAD
            and cargs.uses
            and cargs.uses.startswith('docker://')
        ):
            return ContainerPod(cargs)
        else:
            return Pod(args)
Beispiel #2
0
def test_non_gateway_runtimes(runtime_cls):
    args = set_pod_parser().parse_args([
        '--runtime-cls',
        runtime_cls,
    ])

    with Pod(args) as p:
        assert p.runtime_cls.__name__ == runtime_cls
Beispiel #3
0
def _create_worker_pod(port, name='', executor=None):
    args = set_pod_parser().parse_args([])
    args.port = port
    args.name = name
    args.no_block_on_start = True
    if executor:
        args.uses = executor
    return Pod(args)
Beispiel #4
0
def test_failing_executor():
    args = set_pod_parser().parse_args([
        '--uses',
        'RaisingExecutor',
    ])

    with pytest.raises(RuntimeFailToStart):
        with Pod(args):
            pass
Beispiel #5
0
def _create_gateway_pod(graph_description, pod_addresses, port):
    return Pod(set_gateway_parser().parse_args([
        '--graph-description',
        graph_description,
        '--deployments-addresses',
        pod_addresses,
        '--port',
        str(port),
    ]))
Beispiel #6
0
def test_failing_head():
    args = set_pod_parser().parse_args([
        '--runtime-cls',
        'HeadRuntime',
    ])
    args.port = None

    with pytest.raises(RuntimeFailToStart):
        with Pod(args):
            pass
Beispiel #7
0
def test_gateway_args(protocol, expected):
    args = set_gateway_parser().parse_args([
        '--host',
        'jina-custom-gateway',
        '--port',
        '23456',
        '--protocol',
        protocol,
    ])
    p = Pod(args)
    assert p.runtime_cls.__name__ == expected
Beispiel #8
0
def test_gateway_runtimes(protocol, expected):
    args = set_gateway_parser().parse_args([
        '--graph-description',
        '{"start-gateway": ["pod0"], "pod0": ["end-gateway"]}',
        '--deployments-addresses',
        '{"pod0": ["0.0.0.0:1234"]}',
        '--protocol',
        protocol,
    ])

    with Pod(args) as p:
        assert p.runtime_cls.__name__ == expected
Beispiel #9
0
def test_failing_gateway_runtimes(protocol, expected):
    args = set_gateway_parser().parse_args([
        '--graph-description',
        '{"start-gateway": ["pod0"], "pod0": ["end-gateway"]}',
        '--deployments-addresses',
        '{_INVALIDJSONINTENTIONALLY_pod0": ["0.0.0.0:1234"]}',
        '--protocol',
        protocol,
    ])

    with pytest.raises(RuntimeFailToStart):
        with Pod(args):
            pass
Beispiel #10
0
def _create_head_pod(port, name='', polling='ANY', uses_before=None, uses_after=None):
    args = set_pod_parser().parse_args([])
    args.port = port
    args.name = name
    args.pod_cls = 'HeadRuntime'
    args.pod_role = PodRoleType.HEAD
    args.no_block_on_start = True
    args.polling = PollingType.ANY if polling == 'ANY' else PollingType.ALL
    if uses_before:
        args.uses_before_address = uses_before
    if uses_after:
        args.uses_after_address = uses_after

    return Pod(args)
Beispiel #11
0
def _create_gateway_pod(graph_description, pod_addresses, port_expose):
    return Pod(
        set_gateway_parser().parse_args(
            [
                '--graph-description',
                graph_description,
                '--deployments-addresses',
                pod_addresses,
                '--port-expose',
                str(port_expose),
                '--noblock-on-start',
            ]
        )
    )
Beispiel #12
0
def test_pod_runtime_env_setting(fake_env):
    with Pod(set_pod_parser().parse_args([
            '--uses',
            'EnvChecker1',
            '--env',
            'key1=value1',
            '--env',
            'key2=value2',
    ])):
        pass

    # should not affect the main process
    assert 'key1' not in os.environ
    assert 'key2' not in os.environ
    assert 'key_parent' in os.environ
Beispiel #13
0
def _create_gateway_pod(graph_description,
                        pod_addresses,
                        port,
                        protocol='grpc'):
    return Pod(set_gateway_parser().parse_args([
        '--graph-description',
        graph_description,
        '--deployments-addresses',
        pod_addresses,
        '--port',
        str(port),
        '--noblock-on-start',
        '--protocol',
        protocol,
    ]))
Beispiel #14
0
def test_pod_runtime_env_setting_in_thread(fake_env):
    os.environ['key_parent'] = 'value3'

    with Pod(set_pod_parser().parse_args([
            '--uses',
            'EnvChecker2',
            '--env',
            'key1=value1',
            '--env',
            'key2=value2',
            '--runtime-backend',
            'thread',
    ])):
        pass

    # should not affect the main process
    assert 'key1' not in os.environ
    assert 'key2' not in os.environ
    assert 'key_parent' in os.environ
    os.environ.pop('key_parent')
Beispiel #15
0
def test_close_before_start_slow_enter(monkeypatch):
    class SlowFakeRuntime:
        def __init__(self, *args, **kwargs):
            pass

        def __enter__(self):
            time.sleep(5.0)

        def __exit__(self, exc_type, exc_val, exc_tb):
            pass

        def run_forever(self):
            pass

    monkeypatch.setattr(
        runtimes,
        'get_runtime',
        lambda *args, **kwargs: SlowFakeRuntime,
    )
    pod = Pod(set_pod_parser().parse_args(['--noblock-on-start']))
    pod.start()
    pod.close()