From 2bcc9dbb3a238a6ae0d3b30f1781f040df219972 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mattias=20Walstr=C3=B6m?= Date: Thu, 16 Nov 2023 16:01:09 +0100 Subject: [PATCH] vlan_ping: add some negative test Test that it works when removing interfaces. --- test/case/ietf_interfaces/vlan_ping.py | 38 ++++++++++++++++---------- 1 file changed, 24 insertions(+), 14 deletions(-) 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()