Skip to content

Commit be88ba3

Browse files
authored
Merge pull request #1187 from orbin123/feat/1185-update-network-api-compat
fix/[v1.30] Update Network API compatibility enhancement
2 parents 54b5e34 + 05036e5 commit be88ba3

3 files changed

Lines changed: 37 additions & 4 deletions

File tree

.code-samples.meilisearch.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,18 @@
33
# the documentation on build
44
# You can read more on https://github.com/meilisearch/documentation/tree/master/.vuepress/code-samples
55
---
6+
get_network_1: |-
7+
client.get_all_networks()
8+
9+
update_network_1: |-
10+
client.add_or_update_networks({
11+
"remotes": {
12+
"http://localhost:7700": {
13+
"searchApiKey": "masterKey"
14+
}
15+
},
16+
"leader": None
17+
})
618
get_one_index_1: |-
719
client.get_index('movies')
820
list_all_indexes_1: |-

meilisearch/client.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -898,12 +898,14 @@ def generate_tenant_token(
898898
return jwt_token
899899

900900
def add_or_update_networks(self, body: Union[MutableMapping[str, Any], None]) -> Dict[str, str]:
901-
"""Set all the Remote Networks
901+
"""Configure the network topology
902902
903903
Parameters
904904
----------
905905
body:
906-
Remote networks that are allowed
906+
The network configuration dictionary. must contain either:
907+
- 'remotes': A dictionary of instances in the network
908+
- 'leader': The leader instance (should be a key in the `remotes` dictionary)
907909
908910
Returns
909911
-------

tests/client/test_client_network.py

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ def test_get_all_networks(client):
1616
def test_add_or_update_networks(client):
1717
"""Tests upsert network remote instance."""
1818
body = {
19-
"self": REMOTE_MS_1,
2019
"remotes": {
2120
REMOTE_MS_1: {
2221
"url": "http://localhost:7700",
@@ -33,9 +32,29 @@ def test_add_or_update_networks(client):
3332
response = client.add_or_update_networks(body=body)
3433

3534
assert isinstance(response, dict)
36-
assert response["self"] == REMOTE_MS_1
3735
assert len(response["remotes"]) >= 2
3836
assert REMOTE_MS_2 in response["remotes"]
3937
assert REMOTE_MS_1 in response["remotes"]
4038

4139
reset_network_config(client)
40+
41+
42+
@pytest.mark.usefixtures("enable_network_options")
43+
def test_configure_as_leader(client):
44+
"""Test configuring the current instance as a Leader with one follower."""
45+
body = {
46+
"remotes": {
47+
REMOTE_MS_1: {
48+
"url": "http://localhost:7701",
49+
"searchApiKey": "remoteSearchKey",
50+
}
51+
},
52+
"leader": None,
53+
}
54+
response = client.add_or_update_networks(body)
55+
56+
assert isinstance(response, dict)
57+
assert REMOTE_MS_1 in response["remotes"]
58+
assert response.get("leader") is None
59+
60+
reset_network_config(client)

0 commit comments

Comments
 (0)