Skip to content
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
merged 1 commit into from
Sep 27, 2024

Conversation

JacobCallahan
Copy link
Member

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

@JacobCallahan JacobCallahan added enhancement New feature or request 0.6 Things aligned to the 0.6 release labels Sep 26, 2024
@tpapaioa tpapaioa changed the title Enable timeouts for comment execution when using Hussh Enable timeouts for command execution when using Hussh Sep 26, 2024
Copy link
Member

@ogajduse ogajduse left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Copy link
Collaborator

@tpapaioa tpapaioa left a 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 JacobCallahan merged commit d9fc28f into SatelliteQE:0.6 Sep 27, 2024
4 checks passed
@JacobCallahan JacobCallahan deleted the timeouts branch September 27, 2024 14:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
0.6 Things aligned to the 0.6 release enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants