-
Notifications
You must be signed in to change notification settings - Fork 343
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
Resolved some issues where execution could not be voluntarily stopped #5654
Conversation
…top. Signed-off-by: zuohanxu <[email protected]>
@richtja @clebergnu Some commands cannot be automatically stopped during execution. We can add the parameter timeout to terminate the command. What do you think |
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.
Hi @zuohanxu,
First of all, I apologize for taking so long to answer this.
Now, the idea is good, but I'm afraid there's something missing. I wrote this reproducer:
import time
from avocado.utils.ssh import Session
with Session("host", user="root", key="/path/to/key") as s:
# baseline case
time_start = time.monotonic()
s.cmd("sleep 10")
total_time = time.monotonic() - time_start
print(total_time)
assert total_time >= 10
# check of timeout enforcement
time_start = time.monotonic()
s.cmd("sleep 10", timeout=1)
total_time = time.monotonic() - time_start
print(total_time)
assert total_time <= 10
In my case, the second assertion fails. I suspect process.run()
is either failing to enforce the timeout or the way it enforces the timeout is not sufficiently effective for an ssh command.
Let me know if you can reproduce what I found, and we can work together on a solution.
Hi @clebergnu , def cmd(self, command, ignore_status=True, timeout=None):
try:
if timeout:
command_argument = f"timeout --foreground {timeout} {command}"
else:
command_argument = command
return process.run(
self.get_raw_ssh_command(command_argument),
ignore_status=ignore_status,
)
except process.CmdError as exc:
if exc.result.exit_status == 255:
exc.additional_text = "SSH connection failed"
else:
exc.additional_text = f"Command '{command}' failed"
exc.stderr = exc.result.stderr
exc.stdout = exc.result.stdout
raise exc |
@clebergnu @richtja Do you think this idea is OK with me? If you have any questions, please help me point out, thank you |
Hi @zuohanxu , Yes, I think your approach is sound. I'll be on the lookout for the actual implementation. Thanks! |
Hi @clebergnu |
Hi @clebergnu @richtja |
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.
Hello @zuohanxu,
thank you for your recent contributions. The code LGTM and I'm quite satisfied with the changes you've made. I do have a few suggestions concerning the organization of commits, though.
Firstly, could you please exclude the commit d35b1e5? It appears to be a remnant from the development phase and is no longer necessary.
Additionally, I'd like to propose combining the Modify static check
commits with the ones that alter the behavior. This way, we can maintain a coherent and seamless progression of changes. My preference is to retain only the commits fa4ec66 and be04d70, as they adhere to the appropriate style.
If you will need any help with that, don't hesitate to ask.
Thank you once again for your valuable contributions.
Signed-off-by: zuohanxu <[email protected]>
Hi @clebergnu |
No description provided.