Skip to content

Commit

Permalink
test: vlan_ping: Improve test step description and structure
Browse files Browse the repository at this point in the history
Initially done as a workaround for the MACVLAN create/remove race. But
even though the old version of this test now works, this refactor
provides better test step descriptions, making it easier to follow for
anyone looking to manually verify the functionality.
  • Loading branch information
wkz committed Nov 4, 2024
1 parent 8c3ea90 commit 9ce3980
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 27 deletions.
8 changes: 5 additions & 3 deletions test/case/ietf_interfaces/vlan_ping/Readme.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@ endif::testgroup[]
endif::topdoc[]
==== Test sequence
. Set up topology and attach to target DUT
. Set up VLAN interface on host:data with IP 10.0.0.1
. Configure VLAN 10 interface on target:data with IP 10.0.0.2
. Waiting for links to come up
. Ping 10.0.0.2 from VLAN 10 on host:data with IP 10.0.0.1
. Remove VLAN interface from target:data, and test again (should not be able to ping)
. Wait for links to come up
. Verify that host:data can reach 10.0.0.2
. Remove VLAN interface from target:data
. Verify that host:data can no longer reach 10.0.0.2


<<<
Expand Down
40 changes: 16 additions & 24 deletions test/case/ietf_interfaces/vlan_ping/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,31 +10,21 @@

from infamy import until

def test_ping(hport, should_pass):
with infamy.IsolatedMacVlan(hport) as ns:
try:
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
""")

if should_pass:
ns.must_reach("10.0.0.2")
else:
ns.must_not_reach("10.0.0.2")

except Exception as e:
print(f"An error occurred during the VLAN setup or ping test: {e}")
raise

with infamy.Test() as test:
with test.step("Set up topology and attach to target DUT"):
env = infamy.Env()
target = env.attach("target", "mgmt")
_, tport = env.ltop.xlate("target", "data")

with test.step("Set up VLAN interface on host:data with IP 10.0.0.1"):
_, hport = env.ltop.xlate("host", "data")
datanet = infamy.IsolatedMacVlan(hport).start()
datanet.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
""")

with test.step("Configure VLAN 10 interface on target:data with IP 10.0.0.2"):
target.put_config_dict("ietf-interfaces", {
Expand Down Expand Up @@ -64,16 +54,18 @@ def test_ping(hport, should_pass):
}
})

with test.step("Waiting for links to come up"):
with test.step("Wait for links to come up"):
until(lambda: iface.get_param(target, tport, "oper-status") == "up")

with test.step("Ping 10.0.0.2 from VLAN 10 on host:data with IP 10.0.0.1"):
with test.step("Verify that host:data can reach 10.0.0.2"):
_, hport = env.ltop.xlate("host", "data")
test_ping(hport,True)
datanet.must_reach("10.0.0.2")

with test.step("Remove VLAN interface from target:data, and test again (should not be able to ping)"):
with test.step("Remove VLAN interface from target:data"):
target.delete_xpath(f"/ietf-interfaces:interfaces/interface[name='{tport}.10']")

with test.step("Verify that host:data can no longer reach 10.0.0.2"):
_, hport = env.ltop.xlate("host", "data")
test_ping(hport,False)
datanet.must_not_reach("10.0.0.2")

test.succeed()

0 comments on commit 9ce3980

Please sign in to comment.