Config file processing - takes in config_file from custom path#790
Config file processing - takes in config_file from custom path#790KB-perByte wants to merge 23 commits intoansible:develfrom
Conversation
This comment was marked as outdated.
This comment was marked as outdated.
|
The CI is passing at this point! |
Jakuje
left a comment
There was a problem hiding this comment.
looks good!
(reviewing just the config part as it includes also the logging part that was actually written by me in separate PR)
|
@KB-perByte Is this variable |
The The |
|
@ganeshrn, this PR is more concerned about the config file handling from a custom path, I am testing things with the newly released version of libssh, which should do justice to JumpHost configurations from configFiles. And as I have a +1 from @Jakuje for his changes for logging here in this PR, I'll update the changelog to reflect the same and get this merged. Thanks for the reviews. |
|
Still ack. But the history now looks quite messy and is mixing 3 different things -- parsing of configuration file, logging and proxyjump. I would prefer to get the #597 merged separately (just rebased) and then rebase this + squash the fixup commits. |
|
Is this related to #479? |
@KB-perByte perhaps, just polish that PR? Or pull in their commits? Or if you go with this one, do make sure to implement https://hynek.me/til/easier-crediting-contributors-github/. |
|
@KB-perByte try to use rebasing instead of adding merge commits into topic branches since that leads to foxtrot merges in the tree. |
4eafd5d to
c127a84
Compare
- Add parse_config() to Session for parsing ~/.ssh/config or custom config files - Expose ssh_options_parse_config in libssh.pxd - Changelog fragment for config file support (fixes ansible#790) Made-with: Cursor
2f7b265 to
0cdac3a
Compare
| ) | ||
|
|
||
|
|
||
| def test_connect_config_file_none_no_parse(): |
There was a problem hiding this comment.
Seems like test_parse_config_nonexistent_raises is practically the same and they could be merged though parametrize with different error + host + file in params.
| # Parse SSH config after host is set (so Host blocks match) but before connect, | ||
| # so that options from the config (e.g. HostName, User, Port, ProxyCommand) are | ||
| # applied to this connection. Only when config_file is passed explicitly. | ||
| with _ctx.suppress(KeyError): |
There was a problem hiding this comment.
Unclear why you reverted this — the CM bit was good, the None double-check still isn't.
There was a problem hiding this comment.
I'll wait until here's responses to the questions I'd already asked before I leave any more feedback.
UPD (06.03.2026): @KB-perByte and I had a 1:1 call the other day to clear some things up and synchronize the understanding. This is now waiting for his changes which will likely happen next week as I believe we're on the same page now. Meanwhile, I'll finish up #808 and cut a release right after (hopefully today!) to make the logging improvements available early.
webknjaz
left a comment
There was a problem hiding this comment.
I did another quick pass and realized that another thing I mentioned earlier somewhere hasn't been followed up — there's an earlier PR #479 that somebody took time to file. Even though it remains unmerged, let's be nice and credit the contributor.
Inline, I've left change note-specific instructions but it'd be good to add a co-authored-by trailer to the commit changing libssh.pxd following https://hynek.me/til/easier-crediting-contributors-github/.
| ``Host`` aliases, ``ProxyCommand``, or per-host settings) before the connection is | ||
| established. See :ref:`Connecting with a custom SSH config <custom-ssh-config>` for examples. | ||
|
|
||
| -- by :user:`KB-perByte` |
There was a problem hiding this comment.
Since this includes bits of #479, let's remember to credit the contributor:
| -- by :user:`KB-perByte` | |
| -- by :user:`donnerhacke` and :user:`KB-perByte` |
There was a problem hiding this comment.
Same as with the byline, add a symlink mentioning the other PR:
$ (cd docs/changelog-fragments/ && ln -sf {790,479}.feature.rst && git add 479.feature.rst)
$ git commit -m '📝 Link PR #479 to PR #790 change note'|
|
||
|
|
||
| cdef class LibsshConfigParseException(LibsshSessionException): | ||
| """Raised when SSH config file parsing fails.""" |
There was a problem hiding this comment.
Just realized that this docstring references some external logic that may change over time in a disconnected manner. That behavior description doesn't belong here.
The docstring should instead explain what the exception represents. How about
| """Raised when SSH config file parsing fails.""" | |
| """A failure to parse or load an SSH configuration file.""" |
?
| if path is not None: | ||
| self.parse_config(path) |
There was a problem hiding this comment.
Why can't this be
| if path is not None: | |
| self.parse_config(path) | |
| self.parse_config(path) |
/
| if path is not None: | |
| self.parse_config(path) | |
| self.load_config_into_session(path) |
/
| if path is not None: | |
| self.parse_config(path) | |
| self._parse_config(path) |
/
| if path is not None: | |
| self.parse_config(path) | |
| self._load_config_into_session(path) |
?
|
@webknjaz Ithe CI is not stable, I'll get back to this PR again later. The failures are unrelated. |
|
https://github.com/ansible/pylibssh/actions/runs/22965988172/job/66671296544?pr=790
sounds like the downloads are failing due to some rate limiting ... But the failure in the following pipeline sounds related: https://github.com/ansible/pylibssh/actions/runs/22965988172/job/66671296430?pr=790#step:6:802
The error in https://github.com/ansible/pylibssh/actions/runs/22965988172/job/66671296510?pr=790 sounds related to changes in this PR too:
|
|
@Jakuje checking the same, Cython doesn't support PEP 570's positional-only parameter syntax (the / in the function signature) getting em fixed |
|
https://github.com/ansible/pylibssh/actions/runs/22989405548/job/66747015702?pr=790#step:6:802 I am not 100% sure what would the right way to fix these is, checking for the possible fixes. |
What's this mysterious "2.9"? |
| %global canonical_project_name ansible-pylibssh | ||
| %global pypi_name %canonical_project_name | ||
| %global normalized_core_packaging_metadata_project_name %(echo '%canonical_project_name' | sed --regexp-extended 's:-:_:g;s:\\.:_:g') | ||
| %global normalized_core_packaging_metadata_project_name %(echo '%canonical_project_name' | sed --regexp-extended 's:-:_:g;s:[.]:_:g') |
There was a problem hiding this comment.
It's possible that the fix will only be needed on this line. The error was caused by c94f365 somehow, it seems, not sure why. But line 8 only got changes to the var name so it's unlikely that it needs changing. I'll look into it further — it's surprising that my smoke test script doesn't fail on this locally, nor do the GHA jobs, it seems — looks like Packit might have different versions of lua or something in its env compared to the regular Fedora and UBI images.
|
|
||
| # Alternative: call parse_config() explicitly (e.g. with a pathlib.Path) | ||
| # ssh = Session(host=HOST) | ||
| # ssh.parse_config(Path(CONFIG_FILE)) # or str/bytes |
There was a problem hiding this comment.
Why do you insist on bytes of unguaranteed encoding in the API?
| if host is not None: | ||
| self.set_ssh_options('host', host) |
There was a problem hiding this comment.
This looks new.. How is it related?
There was a problem hiding this comment.
this looks like the host argument was never handled through the kwargs as the rest of the options. It should land likely at least as a separate bugfix commit, I think.
There was a problem hiding this comment.
Yeah, that's what I thought. A separate bug rather than a feature which this one is. And a separate change note.
| ids=str, | ||
| ) | ||
| def test_parse_config_valid_file_succeeds( | ||
| path_arg_type: type[bytes | str | Path], |
There was a problem hiding this comment.
This doesn't sound right. It shouldn't be a type of a union but a union of types, I think. Also, the bytes controversy in the API stands.
There was a problem hiding this comment.
I'm not seeing this surfacing in other PRs. So just drop the commit that added it when rebasing the next time.
|
FYI, I'm looking at adding linting for requiring not creating foxtrot merges automatically. |
Codecov Report❌ Patch coverage is 🚀 New features to boost your workflow:
|
for more information, see https://pre-commit.ci
|
Apologies for the delay in activity. I am trying to progress multiple items in various repos. We would need to prioritize this PR, to get the broken functionality fixed wrt to netcommon. |
SUMMARY
This patch adds support for loading and applying settings from configuration files to
libsshconnection sessions.ISSUE TYPE
ADDITIONAL INFORMATION
ansible-collections/ansible.netcommon#430
log to prove the change