Skip to content

Commit ff894dd

Browse files
author
Robert Gartman
committed
Automate _cluster_setup
1 parent 0785207 commit ff894dd

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

mem3_helper.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,6 @@ def finish_cluster(names):
9494
else:
9595
print("This pod is intentionally skipping the call to http://127.0.0.1:5984/_cluster_setup")
9696

97-
def diff(first, second):
98-
second = set(second)
99-
return [item for item in first if item not in second]
100-
101-
10297
@backoff.on_exception(
10398
backoff.expo,
10499
requests.exceptions.ConnectionError,
@@ -126,6 +121,8 @@ def are_nodes_in_sync(names):
126121
remote_membership_uri = "http://{0}:5984/_membership".format(name)
127122
if creds[0] and creds[1]:
128123
remote_resp = requests.get(remote_membership_uri, auth=creds)
124+
else:
125+
remote_resp = requests.get(remote_membership_uri)
129126
# Compare local and remote _mebership data. Make sure the set
130127
# of nodes match. This will ensure that the remote nodes
131128
# are fully primed with nodes data before progressing with
@@ -137,14 +134,15 @@ def are_nodes_in_sync(names):
137134
if ordered(local_resp.json()) != ordered(remote_resp.json()):
138135
is_different = True
139136
print ("Fetching CouchDB node mebership from this pod: {0}".format(local_membership_uri),flush=True)
140-
records_in_local_but_not_in_remote = diff(local_resp.json().cluster_nodes, remote_resp.json().cluster_nodes)
141-
records_in_remote_but_not_in_local = diff(remote_resp.json().cluster_nodes, local_resp.json().cluster_nodes)
137+
records_in_local_but_not_in_remote = set(local_resp.json().cluster_nodes) - set(remote_resp.json().cluster_nodes)
138+
records_in_remote_but_not_in_local = set(remote_resp.json().cluster_nodes) - set(local_resp.json().cluster_nodes)
142139
if records_in_local_but_not_in_remote:
143140
print ("Cluster members in {0} not yet present in {1}: {2}".format(os.getenv("HOSTNAME"), name.split(".",1)[0], records_in_local_but_not_in_remote))
144141
if records_in_remote_but_not_in_local:
145142
print ("Cluster members in {0} not yet present in {1}: {2}".format(name.split(".",1)[0], os.getenv("HOSTNAME"), records_in_remote_but_not_in_local))
146143
else:
147144
is_different = True
145+
print('returnerar', not is_different)
148146
return not is_different
149147

150148
def sleep_forever():

0 commit comments

Comments
 (0)