Skip to content

Commit

Permalink
Dev: scripts: Filter out unreachable nodes in cluster health
Browse files Browse the repository at this point in the history
So that the cluster health check can be continued even if some nodes are
unreachable.
  • Loading branch information
liangxin1300 committed Sep 29, 2024
1 parent 113b211 commit 4c07bb7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
15 changes: 11 additions & 4 deletions crmsh/scripts.py
Original file line number Diff line number Diff line change
Expand Up @@ -1257,10 +1257,17 @@ def _filter_nodes(nodes, user, port):
nodes = nodes.replace(',', ' ').split()
else:
nodes = utils.list_cluster_nodes()
if not nodes:
raise ValueError("No hosts")
nodes = [(node, port or None, user or None) for node in nodes]
return nodes

reachable_nodes = []
for node in nodes:
try:
utils.node_reachable_check(node)
reachable_nodes.append((node, port or None, user or None))
except ValueError:
logger.warning("Node %s is unreachable", node)

Check warning on line 1267 in crmsh/scripts.py

View check run for this annotation

Codecov / codecov/patch

crmsh/scripts.py#L1266-L1267

Added lines #L1266 - L1267 were not covered by tests
if not reachable_nodes:
raise ValueError("No reachable hosts")

Check warning on line 1269 in crmsh/scripts.py

View check run for this annotation

Codecov / codecov/patch

crmsh/scripts.py#L1269

Added line #L1269 was not covered by tests
return reachable_nodes


def _scoped_param(context, name):
Expand Down
2 changes: 2 additions & 0 deletions crmsh/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2471,6 +2471,8 @@ def node_reachable_check(node, ping_count=1, port=22, timeout=3):
"""
Check if node is reachable by using ping and socket to ssh port
"""
if options.regression_tests:
return True
rc, _, _ = ShellUtils().get_stdout_stderr(f"ping -n -c {ping_count} -W {timeout} {node}")
if rc == 0:
return True
Expand Down

0 comments on commit 4c07bb7

Please sign in to comment.