diff --git a/test/case/ietf_interfaces/vlan_ping.py b/test/case/ietf_interfaces/vlan_ping.py index e20bdf41..ecfa04cb 100755 --- a/test/case/ietf_interfaces/vlan_ping.py +++ b/test/case/ietf_interfaces/vlan_ping.py @@ -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()