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

shelldriver: allow dashes and dots in device names #1373

Merged
merged 1 commit into from
Apr 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion labgrid/driver/shelldriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -596,7 +596,7 @@ def get_ip_addresses(self, device=None):
device = self.get_default_interface_device_name()

regex = r"""\d+: # leading number
\s+\w+ # interface name
\s+[\w\.-]+ # interface name
\s+inet6?\s+(\S+) # IP address, prefix
.*global # global scope, not host scope"""

Expand Down
17 changes: 17 additions & 0 deletions tests/test_shelldriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
from labgrid.driver import ShellDriver, ExecutionError
from labgrid.exceptions import NoDriverFoundError

from ipaddress import IPv4Interface


class TestShellDriver:
def test_instance(self, target, serial_driver):
Expand Down Expand Up @@ -45,3 +47,18 @@ def test_run_with_timeout(self, target_with_fakeconsole, mocker):
assert res == ['success']
res = d.run("test")
assert res == (['success'], [], 0)

def test_get_ip_addresses(self, target_with_fakeconsole, mocker):
fake_ip_addr_show = r"""
18: br-lan.42 inet 192.168.42.1/24 brd 192.168.42.255 scope global br-lan.42\ valid_lft forever preferred_lft forever
18: br-lan.42 inet6 fe80::9683:c4ff:fea6:fb6b/64 scope link \ valid_lft forever preferred_lft forever
"""

t = target_with_fakeconsole
d = ShellDriver(t, "shell", prompt='dummy', login_prompt='dummy', username='dummy')
d.on_activate = mocker.MagicMock()
d = t.get_driver('ShellDriver')
d._run = mocker.MagicMock(return_value=([fake_ip_addr_show], [], 0))

res = d.get_ip_addresses("br-lan.42")
assert res[0] == IPv4Interface("192.168.42.1/24")
Loading