Skip to content

Commit

Permalink
testinfra/modules/interface: Implement link property
Browse files Browse the repository at this point in the history
On Linux, implement `host.interface(iface).link()`, which returns the output of

```shell
ip --json link show $iface
```

Signed-off-by: Benoît Knecht <bknecht@protonmail.ch>
  • Loading branch information
BenoitKnecht authored and philpep committed Feb 15, 2024
1 parent 7abe568 commit c7f5462
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions testinfra/modules/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -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").
Expand Down Expand Up @@ -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"

Expand Down

0 comments on commit c7f5462

Please sign in to comment.