diff --git a/labgrid/driver/shelldriver.py b/labgrid/driver/shelldriver.py index c8b748d5e..c9766387e 100644 --- a/labgrid/driver/shelldriver.py +++ b/labgrid/driver/shelldriver.py @@ -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""" diff --git a/tests/test_shelldriver.py b/tests/test_shelldriver.py index 0f24928ad..697ec9157 100644 --- a/tests/test_shelldriver.py +++ b/tests/test_shelldriver.py @@ -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): @@ -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 = """ +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")