-
Notifications
You must be signed in to change notification settings - Fork 42
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
Enable timeouts for command execution when using Hussh #322
Merged
+2
−4
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
JacobCallahan
added
enhancement
New feature or request
0.6
Things aligned to the 0.6 release
labels
Sep 26, 2024
tpapaioa
changed the title
Enable timeouts for comment execution when using Hussh
Enable timeouts for command execution when using Hussh
Sep 26, 2024
omkarkhatavkar
approved these changes
Sep 27, 2024
ogajduse
approved these changes
Sep 27, 2024
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.
👍
tpapaioa
approved these changes
Sep 27, 2024
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.
Verified with hussh 0.1.7:
>>> my_host.execute('sleep 2; ls -la').stdout
'total 24\ndr-xr-x---. 4 root root 135 Sep 27 09:35 .\ndr-xr-xr-x. 19 root root 262 Sep 21 10:13 ..\ndrwxr-xr-x. 3 root root 17 May 9 08:14 .ansible\n-rw-r--r--. 1 root root 18 Aug 10 2021 .bash_logout\n-rw-r--r--. 1 root root 141 Aug 10 2021 .bash_profile\n-rw-r--r--. 1 root root 429 Aug 10 2021 .bashrc\n-rw-r--r--. 1 root root 100 Aug 10 2021 .cshrc\ndrwx------. 2 root root 29 Sep 27 09:36 .ssh\n-rw-r--r--. 1 root root 129 Aug 10 2021 .tcshrc\n-rw-------. 1 root root 532 May 9 08:16 .viminfo\n'
>>> my_host.session
<broker.binds.hussh.Session object at 0x7f9431595f10>
>>> my_host.execute('sleep 2; ls -la', timeout=5000).stdout
'total 24\ndr-xr-x---. 4 root root 135 Sep 27 09:35 .\ndr-xr-xr-x. 19 root root 262 Sep 21 10:13 ..\ndrwxr-xr-x. 3 root root 17 May 9 08:14 .ansible\n-rw-r--r--. 1 root root 18 Aug 10 2021 .bash_logout\n-rw-r--r--. 1 root root 141 Aug 10 2021 .bash_profile\n-rw-r--r--. 1 root root 429 Aug 10 2021 .bashrc\n-rw-r--r--. 1 root root 100 Aug 10 2021 .cshrc\ndrwx------. 2 root root 29 Sep 27 09:36 .ssh\n-rw-r--r--. 1 root root 129 Aug 10 2021 .tcshrc\n-rw-------. 1 root root 532 May 9 08:16 .viminfo\n'
>>> my_host.execute('sleep 2; ls -la', timeout="5s").stdout
'total 24\ndr-xr-x---. 4 root root 135 Sep 27 09:35 .\ndr-xr-xr-x. 19 root root 262 Sep 21 10:13 ..\ndrwxr-xr-x. 3 root root 17 May 9 08:14 .ansible\n-rw-r--r--. 1 root root 18 Aug 10 2021 .bash_logout\n-rw-r--r--. 1 root root 141 Aug 10 2021 .bash_profile\n-rw-r--r--. 1 root root 429 Aug 10 2021 .bashrc\n-rw-r--r--. 1 root root 100 Aug 10 2021 .cshrc\ndrwx------. 2 root root 29 Sep 27 09:36 .ssh\n-rw-r--r--. 1 root root 129 Aug 10 2021 .tcshrc\n-rw-------. 1 root root 532 May 9 08:16 .viminfo\n'
>>> my_host.execute('sleep 2; ls -la', timeout="1s").stdout
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/tpapaioa/git/broker/broker/hosts.py", line 166, in execute
res = self.session.run(command, timeout=timeout)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/tpapaioa/git/broker/broker/binds/hussh.py", line 94, in run
result = self.session.execute(command, timeout=helpers.translate_timeout(timeout))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TimeoutError: Timeout reading stdout: Timed out waiting on socket
>>> my_host.execute('sleep 2; ls -la', timeout=1000).stdout
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/tpapaioa/git/broker/broker/hosts.py", line 166, in execute
res = self.session.run(command, timeout=timeout)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/tpapaioa/git/broker/broker/binds/hussh.py", line 94, in run
result = self.session.execute(command, timeout=helpers.translate_timeout(timeout))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TimeoutError: Timeout reading stdout: Timed out waiting on socket
Previosuly it was impossible to set command-level timeouts when using Hussh as the backend. In fact, due to the way the Host objects acquired their Hussh connections, timeouts were always left to the default. Now, with Hussh 0.1.7, we can pass a command-specific timeout.
JacobCallahan
force-pushed
the
timeouts
branch
from
September 27, 2024 14:09
6a6ba7e
to
6091934
Compare
Merged
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Previosuly it was impossible to set command-level timeouts when using Hussh as the backend. In fact, due to the way the Host objects acquired their Hussh connections, timeouts were always left to the default. Now, with Hussh 0.1.7, we can pass a command-specific timeout.
Hussh PR for Reference: JacobCallahan/Hussh#14