Skip to content

Commit

Permalink
refactor(mongodb_replicaset): Count voting members (#615)
Browse files Browse the repository at this point in the history
Count voting members based on the sum of "votes" and using a comprehension
list (improves #614).

Signed-off-by: Julien Riou <[email protected]>
  • Loading branch information
jouir authored Nov 27, 2023
1 parent 9124598 commit 764a82b
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions plugins/modules/mongodb_replicaset.py
Original file line number Diff line number Diff line change
Expand Up @@ -554,13 +554,11 @@ def main():
debug = module.params['debug']
cluster_cmd = module.params['cluster_cmd']

voting_members = []
for member in members:
if ("votes" in member and member["votes"]) or "votes" not in member:
voting_members.append(member)
# Count voting members
voting_members = sum([1 if not isinstance(m, dict) or m.get("votes", 1) == 1 else 0 for m in members])

if validate and reconfigure is False:
if len(members) <= 2 or len(voting_members) % 2 == 0:
if len(members) <= 2 or voting_members % 2 == 0:
module.fail_json(msg="MongoDB Replicaset validation failed. Invalid number of replicaset members.")
if arbiter_at_index is not None and len(members) - 1 < arbiter_at_index:
module.fail_json(msg="MongoDB Replicaset validation failed. Invalid arbiter index.")
Expand Down

0 comments on commit 764a82b

Please sign in to comment.