Skip to content

Commit 35d568c

Browse files
costasdphilpep
authored andcommitted
iproute2: filtering in tunnels, more tests for netns & tunnels
1 parent 0d82bec commit 35d568c

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

test/test_modules.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -707,7 +707,16 @@ def test_iproute2_tunnels(host):
707707
assert host.iproute2.exists
708708

709709
tunnels = host.iproute2.tunnels()
710-
assert len(tunnels) == 0
710+
assert len(tunnels) > 0
711+
712+
cmd = host.run("ip tunnel add test mode ipip remote 127.0.0.1")
713+
assert cmd.exit_status == 0, f"{cmd.stdout}\n{cmd.stderr}"
714+
715+
tunnels = host.iproute2.tunnels(ifname="test")
716+
assert len(tunnels) > 0
717+
assert tunnels[0].get("ifname") == "test"
718+
assert tunnels[0].get("mode") == "ip/ip"
719+
assert tunnels[0].get("remote") == "127.0.0.1"
711720

712721

713722
def test_iproute2_vrfs(host):
@@ -722,3 +731,10 @@ def test_iproute2_netns(host):
722731

723732
namespaces = host.iproute2.netns()
724733
assert len(namespaces) == 0
734+
735+
cmd = host.run("ip netns add test")
736+
assert cmd.exit_status == 0, f"{cmd.stdout}\n{cmd.stderr}"
737+
738+
namespaces = host.iproute2.netns()
739+
assert len(namespaces) == 1
740+
assert namespaces[0].get("name") == "test"

testinfra/modules/iproute2.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,9 +161,15 @@ def rules(
161161
out = self.check_output(cmd)
162162
return json.loads(out)
163163

164-
def tunnels(self):
164+
def tunnels(self, ifname=None):
165165
"""Return all configured tunnels"""
166-
cmd = f"{self._ip} --json tunnel show"
166+
cmd = f"{self._ip} --json tunnel show "
167+
168+
options = []
169+
if ifname is not None:
170+
options += [ifname]
171+
172+
cmd += " ".join(options)
167173
out = self.check_output(cmd)
168174
return json.loads(out)
169175

0 commit comments

Comments
 (0)