Ejemplo n.º 1
0
def test_flow_api(monkeypatch, partial_flow_client):
    flow_model = FlowModel()
    flow_model.uses = f'{cur_dir}/good_flow_dummy.yml'
    create_response = partial_flow_client.post(
        api, json={'flow': flow_model.dict(exclude={'log_config'})}
    )

    get_response = partial_flow_client.get(api)

    endpoint_responses = Client(port=56789).post(
        on='/any_endpoint', inputs=Document(), return_results=True
    )

    rolling_update_response = partial_flow_client.put(
        f'{api}/rolling_update',
        params={
            'pod_name': 'dummy_executor',
            'uses_with': {},
        },
    )

    delete_response = partial_flow_client.delete(api)

    assert create_response
    assert get_response
    assert get_response.json()['arguments']['port_expose'] == 56789
    assert endpoint_responses[0].docs[0].content == 'https://jina.ai'
    assert rolling_update_response.status_code == 200
    assert delete_response
Ejemplo n.º 2
0
def test_flow_api(monkeypatch, partial_flow_client):
    flow_model = FlowModel()
    flow_model.uses = f'{cur_dir}/good_flow_dummy.yml'
    response = partial_flow_client.post(
        api,
        json=flow_model.dict(exclude={'log_config'}),
        params={'port_expose': 56789})
    assert response

    response = partial_flow_client.get(api)
    assert response
    print(response.json())
    assert response.json()['arguments']['port_expose'] == 56789

    def response_checker(response):
        assert response.docs[0].content == 'https://jina.ai'

    Client(port_expose=56789).post(on='/any_endpoint',
                                   inputs=Document(),
                                   on_done=response_checker)

    # the pod used in this flow is not a compound pod and does not support ROLLING_UPDATE
    response = partial_flow_client.put(
        api,
        params={
            'kind': UpdateOperation.ROLLING_UPDATE,
            'dump_path': '',
            'pod_name': 'dummy_executor',
            'shards': 1,
        },
    )
    assert response.status_code == 400

    response = partial_flow_client.delete(api)
    assert response
Ejemplo n.º 3
0
def test_no_exceptions():
    FlowModel()
    # this gets executed while verifying inputs
    FlowModel().dict()
    # this gets executed while creating docs
    FlowModel().schema()
    with pytest.raises(AttributeError):
        FlowModel().abc
Ejemplo n.º 4
0
def test_flowstore_add(monkeypatch, partial_flow_store):
    flow_model = FlowModel()
    flow_model.uses = f'{cur_dir}/flow.yml'
    args = ArgNamespace.kwargs2namespace(flow_model.dict(), set_flow_parser())
    partial_store_item = partial_flow_store.add(args)

    assert partial_store_item
    assert isinstance(partial_flow_store.object, Flow)
    assert 'executor1' in partial_store_item.yaml_source
    assert partial_flow_store.object.port_expose == 12345
Ejemplo n.º 5
0
def test_no_exceptions():
    FlowModel()
    # this gets executed while verifying inputs
    FlowModel().dict()
    # this gets executed while creating docs
    FlowModel().schema()
    # Flow parser doesn't contain identity by default. It is passed during model building
    FlowModel().identity
    with pytest.raises(AttributeError):
        FlowModel().abc
Ejemplo n.º 6
0
def test_flowstore_scale(partial_flow_store, mocker):
    flow_model = FlowModel()
    flow_model.uses = f'{cur_dir}/flow.yml'
    args = ArgNamespace.kwargs2namespace(flow_model.dict(), set_flow_parser())

    partial_flow_store.add(args)

    scale_mock = mocker.Mock()
    partial_flow_store.object.scale = scale_mock

    partial_flow_store.scale(pod_name='executor1', replicas=2)
    scale_mock.assert_called()
Ejemplo n.º 7
0
def test_flowstore_rolling_update(partial_flow_store, mocker):
    flow_model = FlowModel()
    flow_model.uses = f'{cur_dir}/flow.yml'
    args = ArgNamespace.kwargs2namespace(flow_model.dict(), set_flow_parser())

    partial_flow_store.add(args)

    rolling_update_mock = mocker.Mock()
    partial_flow_store.object.rolling_update = rolling_update_mock

    partial_flow_store.rolling_update(pod_name='executor1', uses_with={})
    rolling_update_mock.assert_called()
Ejemplo n.º 8
0
async def test_flowstore_scale(partial_flow_store, mocker):
    flow_model = FlowModel()
    flow_model.uses = f'{cur_dir}/flow.yml'
    args = ArgNamespace.kwargs2namespace(flow_model.dict(), set_flow_parser())

    partial_flow_store.add(args)

    future = asyncio.Future()
    future.set_result(PartialStoreItem())
    mocker.patch('daemon.stores.partial.PartialFlowStore.scale',
                 return_value=future)
    resp = await partial_flow_store.scale(deployment_name='executor1',
                                          replicas=2)
    assert resp
Ejemplo n.º 9
0
def test_flowstore_update(partial_flow_store, mocker):
    flow_model = FlowModel()
    flow_model.uses = f'{cur_dir}/flow.yml'
    port_expose = helper.random_port()
    args = ArgNamespace.kwargs2namespace(flow_model.dict(), set_flow_parser())

    partial_flow_store.add(args, port_expose)

    update_mock = mocker.Mock()
    partial_flow_store.object.rolling_update = update_mock

    partial_flow_store.update(kind=UpdateOperation.ROLLING_UPDATE,
                              dump_path='',
                              pod_name='pod1',
                              shards=1)

    update_mock.assert_called()
Ejemplo n.º 10
0
async def test_flow_store(workspace):
    store = FlowStore()
    flow_id = DaemonID('jflow')
    flow_model = FlowModel()
    flow_model.uses = f'flow.yml'

    await store.add(
        id=flow_id,
        workspace_id=workspace,
        params=flow_model,
        ports={},
        port_expose=56789,
    )
    assert len(store) == 1
    assert flow_id in store
    await store.delete(flow_id)
    assert flow_id not in store
    assert not store
Ejemplo n.º 11
0
 def __init__(
     self,
     workspace_id: DaemonID,
     filename: str,
     envs: Environment = Depends(Environment),
 ) -> None:
     self.workspace_id = workspace_id
     self.filename = filename
     self.id = DaemonID('jflow')
     self.params = FlowModel(uses=self.filename, workspace_id=self.workspace_id.jid)
     self.envs = envs.vars
     self._ports = {}
     self.load_and_dump()
     # Unlike `PodModel` / `DeploymentModel`, `gpus` arg doesn't exist in FlowModel
     # We try assigning `all` gpus to the Flow container by default.
     self.device_requests = get_gpu_device_requests('all')
Ejemplo n.º 12
0
Archivo: flows.py Proyecto: srbhr/jina
async def _fetch_flow_params():
    return FlowModel.schema()['properties']
Ejemplo n.º 13
0
def test_no_exceptions():
    FlowModel()
    # this gets executed while verifying inputs
    FlowModel().dict()
    # this gets executed while creating docs
    FlowModel().schema()