Skip to content

Commit 525bde4

Browse files
BenoitKnechtphilpep
authored andcommitted
testinfra/modules/interface: Implement link property
On Linux, implement `host.interface(iface).link()`, which returns the output of ```shell ip --json link show $iface ``` Signed-off-by: Benoît Knecht <[email protected]>
1 parent 7abe568 commit 525bde4

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

testinfra/modules/interface.py

+26
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,26 @@ def addresses(self):
5151
"""
5252
raise NotImplementedError
5353

54+
@property
55+
def link(self):
56+
"""Return the link properties associated with the interface.
57+
58+
>>> host.interface("lo").link
59+
{'address': '00:00:00:00:00:00',
60+
'broadcast': '00:00:00:00:00:00',
61+
'flags': ['LOOPBACK', 'UP', 'LOWER_UP'],
62+
'group': 'default',
63+
'ifindex': 1,
64+
'ifname': 'lo',
65+
'link_type': 'loopback',
66+
'linkmode': 'DEFAULT',
67+
'mtu': 65536,
68+
'operstate': 'UNKNOWN',
69+
'qdisc': 'noqueue',
70+
'txqlen': 1000}
71+
"""
72+
raise NotImplementedError
73+
5474
def routes(self, scope=None):
5575
"""Return the routes associated with the interface, optionally filtered by scope
5676
("host", "link" or "global").
@@ -132,6 +152,12 @@ def addresses(self):
132152
addrs.append(splitted[1].split("/", 1)[0])
133153
return addrs
134154

155+
@property
156+
def link(self):
157+
return json.loads(
158+
self.check_output(f"{self._ip} --json link show %s", self.name)
159+
)
160+
135161
def routes(self, scope=None):
136162
cmd = f"{self._ip} --json route list dev %s"
137163

0 commit comments

Comments
 (0)