-
-
Couldn't load subscription status.
- Fork 35
Retry on libssh SSH_AGAIN return code
#756
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
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| Added a ``pylibsshext.session.connect()`` parameter | ||
| ``open_session_retries`` -- by :user:`justin-stephenson`. | ||
|
|
||
| The ``open_session_retries`` session ``connect()`` | ||
| parameter allows a configurable number of retries if | ||
| libssh ``ssh_channel_open_session()`` returns ``SSH_AGAIN``. | ||
| The default option value is 0, no retries will be | ||
| attempted. |
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| Added a ``pylibsshext.session.connect()`` parameter | ||
| ``timeout_usec`` to set ``SSH_OPTIONS_TIMEOUT_USEC``. | ||
|
|
||
| This allows setting the ``SSH_OPTIONS_TIMEOUT_USEC`` | ||
| ssh option, though ``SSH_OPTIONS_TIMEOUT`` is a more | ||
| practical option. | ||
|
|
||
| -- by :user:`justin-stephenson` | ||
This file contains hidden or 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
webknjaz marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,12 +8,17 @@ | |
|
|
||
| import pytest | ||
|
|
||
| from pylibsshext.errors import LibsshChannelException | ||
| from pylibsshext.session import Session | ||
|
|
||
|
|
||
| COMMAND_TIMEOUT = 30 | ||
| POLL_EXIT_CODE_TIMEOUT = 5 | ||
| POLL_TIMEOUT = 5000 | ||
| # Lowest possible timeout_usec is 1000 because timeout_usec / 1000 must be > 0, | ||
| # otherwise libssh sets timeout to 10000 | ||
| SMALL_TIMEOUT_USEC = 1000 | ||
| LARGE_TIMEOUT_SEC = 10 | ||
|
|
||
|
|
||
| @pytest.fixture | ||
|
|
@@ -33,6 +38,42 @@ def ssh_channel(ssh_client_session): | |
| chan.close() | ||
|
|
||
|
|
||
| def test_open_session_small_timeout(ssh_session_connect): | ||
| """Test opening a new channel with a small timeout value. | ||
|
|
||
| This generates an exception from ``ssh_channel_open_session()`` | ||
| returning ``SSH_AGAIN`` with the ``usec`` timeout and default | ||
| ``open_session_retries`` value of ``0``. | ||
| """ | ||
| ssh_session = Session() | ||
webknjaz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ssh_session_connect(ssh_session) | ||
| ssh_session.set_ssh_options('timeout_usec', SMALL_TIMEOUT_USEC) | ||
| error_msg = '^Failed to open_session' | ||
| with pytest.raises(LibsshChannelException, match=error_msg): | ||
| ssh_session.new_channel() | ||
| ssh_session.close() | ||
|
|
||
|
|
||
| def test_open_session_large_timeout(ssh_session_connect): | ||
| """Test opening a new channel with a large timeout value.""" | ||
| ssh_session = Session() | ||
| ssh_session_connect(ssh_session) | ||
| ssh_session.set_ssh_options('timeout', LARGE_TIMEOUT_SEC) | ||
| ssh_channel = ssh_session.new_channel() | ||
| ssh_channel.close() | ||
| ssh_session.close() | ||
|
|
||
|
|
||
| def test_open_session_small_timeout_with_retries(ssh_session_connect_retries): | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @justin-stephenson this test failed at least on one occasion post-merge: https://github.com/ansible/pylibssh/actions/runs/18431666269#summary-52519922027 |
||
| """Test with a small timeout value and retries set.""" | ||
| ssh_session = Session() | ||
| ssh_session_connect_retries(ssh_session) | ||
| ssh_session.set_ssh_options('timeout_usec', SMALL_TIMEOUT_USEC) | ||
| ssh_channel = ssh_session.new_channel() | ||
| ssh_channel.close() | ||
| ssh_session.close() | ||
|
|
||
|
|
||
| def exec_second_command(ssh_channel): | ||
| """Check the standard output of ``exec_command()`` as a string.""" | ||
| u_cmd = ssh_channel.exec_command('echo -n Hello Again') | ||
|
|
||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.