diff --git a/.code-samples.meilisearch.yaml b/.code-samples.meilisearch.yaml index bf7062f3..d119b7bb 100644 --- a/.code-samples.meilisearch.yaml +++ b/.code-samples.meilisearch.yaml @@ -3,6 +3,18 @@ # the documentation on build # You can read more on https://github.com/meilisearch/documentation/tree/master/.vuepress/code-samples --- +get_network_1: |- + client.get_all_networks() + +update_network_1: |- + client.add_or_update_networks({ + "remotes": { + "http://localhost:7700": { + "searchApiKey": "masterKey" + } + }, + "leader": None + }) get_one_index_1: |- client.get_index('movies') list_all_indexes_1: |- diff --git a/meilisearch/client.py b/meilisearch/client.py index 99f8a5da..d50a5724 100644 --- a/meilisearch/client.py +++ b/meilisearch/client.py @@ -898,12 +898,14 @@ def generate_tenant_token( return jwt_token def add_or_update_networks(self, body: Union[MutableMapping[str, Any], None]) -> Dict[str, str]: - """Set all the Remote Networks + """Configure the network topology Parameters ---------- body: - Remote networks that are allowed + The network configuration dictionary. must contain either: + - 'remotes': A dictionary of instances in the network + - 'leader': The leader instance (should be a key in the `remotes` dictionary) Returns ------- diff --git a/tests/client/test_client_network.py b/tests/client/test_client_network.py index adf4dec0..f7dfcf6d 100644 --- a/tests/client/test_client_network.py +++ b/tests/client/test_client_network.py @@ -16,7 +16,6 @@ def test_get_all_networks(client): def test_add_or_update_networks(client): """Tests upsert network remote instance.""" body = { - "self": REMOTE_MS_1, "remotes": { REMOTE_MS_1: { "url": "http://localhost:7700", @@ -33,9 +32,29 @@ def test_add_or_update_networks(client): response = client.add_or_update_networks(body=body) assert isinstance(response, dict) - assert response["self"] == REMOTE_MS_1 assert len(response["remotes"]) >= 2 assert REMOTE_MS_2 in response["remotes"] assert REMOTE_MS_1 in response["remotes"] reset_network_config(client) + + +@pytest.mark.usefixtures("enable_network_options") +def test_configure_as_leader(client): + """Test configuring the current instance as a Leader with one follower.""" + body = { + "remotes": { + REMOTE_MS_1: { + "url": "http://localhost:7701", + "searchApiKey": "remoteSearchKey", + } + }, + "leader": None, + } + response = client.add_or_update_networks(body) + + assert isinstance(response, dict) + assert REMOTE_MS_1 in response["remotes"] + assert response.get("leader") is None + + reset_network_config(client) diff --git a/tests/settings/test_settings_embedders.py b/tests/settings/test_settings_embedders.py index 178106ef..0265d6c3 100644 --- a/tests/settings/test_settings_embedders.py +++ b/tests/settings/test_settings_embedders.py @@ -95,7 +95,7 @@ def test_huggingface_embedder_format(empty_index): } } response = index.update_embedders(huggingface_embedder) - index.wait_for_task(response.task_uid, timeout_in_ms=60000) # embedder config can take longer. + index.wait_for_task(response.task_uid, timeout_in_ms=60000) # embedder config can take longer. embedders = index.get_embedders() assert embedders.embedders["huggingface"].source == "huggingFace" assert embedders.embedders["huggingface"].model == "BAAI/bge-base-en-v1.5"