-
Notifications
You must be signed in to change notification settings - Fork 94
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dev: utils: Check node is reachable by using both ping and ssh #1563
Dev: utils: Check node is reachable by using both ping and ssh #1563
Conversation
b8ea58a
to
2132b3e
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files
Flags with carried forward coverage won't be shown. Click here to find out more.
☔ View full report in Codecov by Sentry. |
crmsh/utils.py
Outdated
|
||
user = userdir.getuser() | ||
rc = check_ssh(user, user, node, timeout=3) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is an overkill to check whether a node is reachable by invoking ssh command. Opening an TCP socket without sending any data is enough.
2132b3e
to
31b3392
Compare
crmsh/utils.py
Outdated
# ping failed, try to connect to ssh port by socket | ||
error_msg = f"host \"{node}\" is unreachable" | ||
try: | ||
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does not work with IPv6. Please use getaddrinfo
first.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I found we already have utils.check_port_open
, should be reused this time
crmsh/utils.py
Outdated
rc, _, err = ShellUtils().get_stdout_stderr("ping -c 1 {}".format(node)) | ||
if rc != 0: | ||
raise ValueError("host \"{}\" is unreachable: {}".format(node, err)) | ||
rc, _, _ = ShellUtils().get_stdout_stderr(f"ping -c {ping_count} {node}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add -n
to avoid triggering a reverse DNS lookup.
54e60c1
to
dc69b4d
Compare
crmsh/utils.py
Outdated
rc, _, err = ShellUtils().get_stdout_stderr("ping -c 1 {}".format(node)) | ||
if rc != 0: | ||
raise ValueError("host \"{}\" is unreachable: {}".format(node, err)) | ||
rc, _, _ = ShellUtils().get_stdout_stderr(f"ping -n -c {ping_count} {node}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
timeout
is not applied to the ping command.
crmsh/utils.py
Outdated
@@ -2460,13 +2467,18 @@ def package_is_installed(pkg, remote_addr=None): | |||
return rc == 0 | |||
|
|||
|
|||
def ping_node(node): | |||
def node_reachable_checking(node, ping_count=1, port=22, timeout=3): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"check" is a noun.
def node_reachable_checking(node, ping_count=1, port=22, timeout=3): | |
def node_reachable_check(node, ping_count=1, port=22, timeout=3): |
If both ping and socket (to ssh port) fail, the node is considered unreachable.
dc69b4d
to
3988820
Compare
If both ping and ssh fail, the node is considered unreachable.
To fix issue #1551