diff --git a/testinfra/modules/interface.py b/testinfra/modules/interface.py index d5caec2f..ce6b3a3b 100644 --- a/testinfra/modules/interface.py +++ b/testinfra/modules/interface.py @@ -51,6 +51,26 @@ def addresses(self): """ raise NotImplementedError + @property + def link(self): + """Return the link properties associated with the interface. + + >>> host.interface("lo").link + {'address': '00:00:00:00:00:00', + 'broadcast': '00:00:00:00:00:00', + 'flags': ['LOOPBACK', 'UP', 'LOWER_UP'], + 'group': 'default', + 'ifindex': 1, + 'ifname': 'lo', + 'link_type': 'loopback', + 'linkmode': 'DEFAULT', + 'mtu': 65536, + 'operstate': 'UNKNOWN', + 'qdisc': 'noqueue', + 'txqlen': 1000} + """ + raise NotImplementedError + def routes(self, scope=None): """Return the routes associated with the interface, optionally filtered by scope ("host", "link" or "global"). @@ -132,6 +152,12 @@ def addresses(self): addrs.append(splitted[1].split("/", 1)[0]) return addrs + @property + def link(self): + return json.loads( + self.check_output(f"{self._ip} --json link show %s", self.name) + ) + def routes(self, scope=None): cmd = f"{self._ip} --json route list dev %s"