mirror of
https://github.com/kernelkit/infix.git
synced 2026-07-31 21:13:00 +02:00
vlan_ping: add some negative test
Test that it works when removing interfaces.
This commit is contained in:
committed by
Joachim Wiberg
parent
171824c570
commit
2bcc9dbb3a
@@ -1,6 +1,22 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import infamy
|
||||
import copy
|
||||
def test_ping(hport, should_pass):
|
||||
with infamy.IsolatedMacVlan(hport) as ns:
|
||||
pingtest = ns.runsh("""
|
||||
set -ex
|
||||
|
||||
ip link set iface up
|
||||
ip link add dev vlan10 link iface up type vlan id 10
|
||||
ip addr add 10.0.0.1/24 dev vlan10
|
||||
|
||||
ping -c1 -w5 10.0.0.2 || exit 1
|
||||
""")
|
||||
|
||||
if (pingtest.returncode and should_pass) or (not pingtest.returncode and not should_pass):
|
||||
print(pingtest.stdout)
|
||||
test.fail()
|
||||
|
||||
with infamy.Test() as test:
|
||||
with test.step("Initialize"):
|
||||
@@ -41,20 +57,14 @@ with infamy.Test() as test:
|
||||
|
||||
with test.step("Ping 10.0.0.2 from VLAN 10 on host:data with IP 10.0.0.1"):
|
||||
_, hport = env.ltop.xlate("host", "data")
|
||||
test_ping(hport,True)
|
||||
|
||||
with infamy.IsolatedMacVlan(hport) as ns:
|
||||
pingtest = ns.runsh("""
|
||||
set -ex
|
||||
|
||||
ip link set iface up
|
||||
ip link add dev vlan10 link iface up type vlan id 10
|
||||
ip addr add 10.0.0.1/24 dev vlan10
|
||||
|
||||
ping -c1 -w5 10.0.0.2 || exit 1
|
||||
""")
|
||||
|
||||
if pingtest.returncode:
|
||||
print(pingtest.stdout)
|
||||
test.fail()
|
||||
with test.step("Remove VLAN interface, and test again (should not be able to ping)"):
|
||||
running = target.get_config_dict("/ietf-interfaces:interfaces")
|
||||
new = copy.deepcopy(running)
|
||||
new["interfaces"]["interface"] = [d for d in new["interfaces"]["interface"] if not (d["name"] == f"{tport}.10")]
|
||||
target.put_diff_dicts("ietf-interfaces",running,new)
|
||||
_, hport = env.ltop.xlate("host", "data")
|
||||
test_ping(hport,False)
|
||||
|
||||
test.succeed()
|
||||
|
||||
Reference in New Issue
Block a user