示例#1
0
def test_to_k8s_yaml(tmpdir, exec_type):
    Executor.to_k8s_yaml(
        output_base_path=tmpdir,
        port_expose=2020,
        uses='jinahub+docker://DummyHubExecutor',
        executor_type=exec_type,
    )

    with open(os.path.join(tmpdir, 'executor0', 'executor0.yml')) as f:
        exec_yaml = list(yaml.safe_load_all(f))[-1]
        assert exec_yaml['spec']['template']['spec']['containers'][0][
            'image'].startswith('jinahub/')

    if exec_type == Executor.StandaloneExecutorType.SHARED:
        assert set(os.listdir(tmpdir)) == {
            'executor0',
        }
    else:
        assert set(os.listdir(tmpdir)) == {
            'executor0',
            'gateway',
        }

        with open(os.path.join(tmpdir, 'gateway', 'gateway.yml')) as f:
            gatewayyaml = list(yaml.safe_load_all(f))[-1]
            assert (gatewayyaml['spec']['template']['spec']['containers'][0]
                    ['ports'][0]['containerPort'] == 2020)
            gateway_args = gatewayyaml['spec']['template']['spec'][
                'containers'][0]['args']
            assert gateway_args[gateway_args.index('--port') + 1] == '2020'
示例#2
0
def test_executor_workspace_simple_workspace(tmpdir):
    workspace = os.path.join(tmpdir, 'some_folder')
    name = 'test_meta'

    executor = Executor(metas={'name': name, 'workspace': workspace})
    assert executor.workspace == os.path.abspath(os.path.join(workspace, name))

    executor = Executor(metas={'name': name}, runtime_args={'workspace': workspace})
    assert executor.workspace == os.path.abspath(os.path.join(workspace, name))

    # metas before runtime_args
    executor = Executor(
        metas={'name': name, 'workspace': workspace},
        runtime_args={'workspace': 'test2'},
    )
    assert executor.workspace == os.path.abspath(os.path.join(workspace, name))

    executor = Executor(
        metas={'name': name, 'workspace': workspace},
        runtime_args={'shard_id': 1},
    )
    assert executor.workspace == os.path.abspath(os.path.join(workspace, name, '1'))

    executor = Executor(
        metas={'name': name},
        runtime_args={'workspace': workspace, 'shard_id': 1},
    )
    assert executor.workspace == os.path.abspath(os.path.join(workspace, name, '1'))
示例#3
0
def test_executor_load_from_hub():
    exec = Executor.from_hub('jinahub://DummyHubExecutor',
                             uses_metas={'name': 'hello123'})
    da = DocumentArray([Document()])
    exec.foo(da)
    assert da.texts == ['hello']
    assert exec.metas.name == 'hello123'
示例#4
0
def test_executor_workspace_simple(test_metas_workspace_simple):
    executor = Executor(metas=test_metas_workspace_simple)
    assert executor.workspace == os.path.abspath(
        os.path.join(
            test_metas_workspace_simple['workspace'],
            test_metas_workspace_simple['name'],
        ))
示例#5
0
def test_load_save_yml(tmp_path):
    m = Executor.load_config(y)
    m.save_config(os.path.join(tmp_path, 'a.yml'))

    assert m.bar == 'hello'
    assert m.bar2 == 1
    assert m.metas.name == 'my-awesomeness'
    for k in ('/default', '/foo_endpoint', '/random_endpoint'):
        assert k in m.requests
示例#6
0
def test_executor_workspace_parent_noreplica_nopea(
        test_metas_workspace_replica_peas, replica_id, pea_id):
    executor = Executor(
        metas={'name': test_metas_workspace_replica_peas['name']},
        runtime_args=test_metas_workspace_replica_peas,
    )
    assert executor.workspace == os.path.abspath(
        os.path.join(
            test_metas_workspace_replica_peas['workspace'],
            test_metas_workspace_replica_peas['name'],
        ))
示例#7
0
def test_to_docker_compose_yaml(tmpdir, exec_type):
    compose_file = os.path.join(tmpdir, 'compose.yml')
    Executor.to_docker_compose_yaml(
        output_path=compose_file,
        port_expose=2020,
        uses='jinahub+docker://DummyHubExecutor',
        executor_type=exec_type,
    )

    with open(compose_file) as f:
        services = list(yaml.safe_load_all(f))[0]['services']
        assert services['executor0']['image'].startswith('jinahub/')

        if exec_type == Executor.StandaloneExecutorType.SHARED:
            assert len(services) == 1
        else:
            assert len(services) == 2
            assert services['gateway']['ports'][0] == '2020:2020'
            gateway_args = services['gateway']['command']
            assert gateway_args[gateway_args.index('--port') + 1] == '2020'
示例#8
0
def test_executor_workspace_parent_noreplica_pod(
        test_metas_workspace_replica_pods, shard_id):
    executor = Executor(
        metas={'name': test_metas_workspace_replica_pods['name']},
        runtime_args=test_metas_workspace_replica_pods,
    )
    assert executor.workspace == os.path.abspath(
        os.path.join(
            test_metas_workspace_replica_pods['workspace'],
            test_metas_workspace_replica_pods['name'],
            str(shard_id),
        ))
示例#9
0
def test_executor_import_with_external_dependencies(capsys):
    ex = Executor.load_config('../hubble-executor/config.yml')
    assert ex.bar == 123
    ex.foo()
    out, err = capsys.readouterr()
    assert 'hello' in out