Skip to content

Allow NetworkService to be used without an explicit SSH username - #1863

Open
ozan956 wants to merge 2 commits into
labgrid-project:masterfrom
ozan956:fix/ssh-defaults
Open

Allow NetworkService to be used without an explicit SSH username#1863
ozan956 wants to merge 2 commits into
labgrid-project:masterfrom
ozan956:fix/ssh-defaults

Conversation

@ozan956

@ozan956 ozan956 commented May 7, 2026

Copy link
Copy Markdown

Allow NetworkService to be used without an explicit SSH username.

Until now, NetworkService.username was required and SSHDriver always passed
it through to ssh, scp, etc. That prevented setups where the SSH user should
come from the local SSH configuration or the default SSH user resolution.

This change makes NetworkService.username optional and updates SSHDriver to
only pass -l <username> or user@host when a username is explicitly set.

The client-side fallback path in labgrid.remote.client also no longer forces
username="root". While adding regression coverage for that path, this also
surfaced that the fallback resource creation needs name=None, which is now
passed explicitly.

I verified the change with some tests called test_run_no_username, test_put_get_no_username and test_get_ssh_no_username for the no-username paths.

Checklist

  • Documentation for the feature
  • Tests for the feature
  • PR has been tested

@ozan956
ozan956 force-pushed the fix/ssh-defaults branch from 3118e12 to 37e4cd1 Compare May 7, 2026 09:22
@codecov

codecov Bot commented May 7, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 61.1%. Comparing base (fb48582) to head (579db71).
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@           Coverage Diff            @@
##           master   #1863     +/-   ##
========================================
+ Coverage    61.0%   61.1%   +0.1%     
========================================
  Files         182     182             
  Lines       14882   14903     +21     
========================================
+ Hits         9083    9118     +35     
+ Misses       5799    5785     -14     
Flag Coverage Δ
3.10 61.1% <100.0%> (+0.1%) ⬆️
3.11 61.1% <100.0%> (+0.1%) ⬆️
3.12 61.1% <100.0%> (+0.1%) ⬆️
3.13 61.1% <100.0%> (+0.1%) ⬆️
3.14 61.1% <100.0%> (+0.1%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

@Emantor Emantor left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is going to be a breaking change for the remote infrastructure, older labgrid will expect the now optional username parameter. IMO we should still use None instead of "" which works around that.

Comment thread doc/configuration.rst Outdated
Comment thread labgrid/driver/sshdriver.py Outdated
Comment thread labgrid/driver/sshdriver.py Outdated
Comment thread labgrid/driver/sshdriver.py Outdated
Comment thread labgrid/driver/sshdriver.py Outdated
Comment thread labgrid/driver/sshdriver.py Outdated
@ozan956

ozan956 commented Jul 8, 2026

Copy link
Copy Markdown
Author

This is going to be a breaking change for the remote infrastructure, older labgrid will expect the now optional username parameter. IMO we should still use None instead of "" which works around that.

Thanks for the review! I resolved them all now. Sorry for late response.

ozan956 added 2 commits July 27, 2026 14:57
So far, `NetworkService.username` was required and `SSHDriver` always
passed it to `ssh` and `scp`. This prevented setups where the SSH
username is intentionally resolved through the user's SSH configuration
or by the default SSH user selection.

This change makes `NetworkService.username` optional and updates
`SSHDriver` to only pass `-l <username>` or `user@host` when a username
is explicitly set.

In addition, the client-side fallback `NetworkService` creation path no
longer forces `username="root"` and now instantiates the resource with
`name=None`, so ad-hoc SSH access can use the normal SSH configuration
of the user.

This improves compatibility with existing SSH setups and avoids
hardcoding a username when it is not actually required.

Add regression tests covering the no-username path in SSHDriver and the
client-side fallback NetworkService creation.

Signed-off-by: Ozan Durgut <ozan.durgut@analog.com>
Clarify that `NetworkService.username` is optional.

If no username is configured on `NetworkService` or `SSHDriver`,
labgrid lets SSH resolve the username through the local SSH
configuration or the default SSH user selection.

Signed-off-by: Ozan Durgut <ozan.durgut@analog.com>
@ozan956
ozan956 force-pushed the fix/ssh-defaults branch from 8408809 to 579db71 Compare July 27, 2026 13:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants