Skip to content

Commit

Permalink
tests: amalgamate check_ping
Browse files Browse the repository at this point in the history
❌✂️📋

Signed-off-by: Quentin Young <qlyoung@qlyoung.net>
  • Loading branch information
qlyoung committed Aug 9, 2023
1 parent df04c23 commit de6bbd1
Show file tree
Hide file tree
Showing 7 changed files with 167 additions and 244 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
from lib.topogen import Topogen, TopoRouter, get_topogen
from lib.topolog import logger
from lib.common_config import required_linux_kernel_version
from lib.checkping import check_ping

pytestmark = [pytest.mark.bgpd]

Expand Down Expand Up @@ -101,31 +102,15 @@ def teardown_module(mod):
tgen.stop_topology()


def check_ping4(name, dest_addr, expected):
def _check(name, dest_addr, match):
tgen = get_topogen()
output = tgen.gears[name].run("ping {} -c 1 -w 1".format(dest_addr))
logger.info(output)
if match not in output:
return "ping fail"

match = ", {} packet loss".format("0%" if expected else "100%")
logger.info("[+] check {} {} {}".format(name, dest_addr, match))
tgen = get_topogen()
func = functools.partial(_check, name, dest_addr, match)
success, result = topotest.run_and_expect(func, None, count=10, wait=1)
assert result is None, "Failed"


def test_ping():
tgen = get_topogen()

check_ping4("c11", "192.168.2.1", True)
check_ping4("c11", "192.168.3.1", True)
check_ping4("c12", "192.168.2.1", True)
check_ping4("c12", "192.168.3.1", True)
check_ping4("c21", "192.168.3.1", True)
check_ping4("c22", "192.168.3.1", True)
check_ping("c11", "192.168.2.1", True, 10, 1)
check_ping("c11", "192.168.3.1", True, 10, 1)
check_ping("c12", "192.168.2.1", True, 10, 1)
check_ping("c12", "192.168.3.1", True, 10, 1)
check_ping("c21", "192.168.3.1", True, 10, 1)
check_ping("c22", "192.168.3.1", True, 10, 1)


if __name__ == "__main__":
Expand Down
81 changes: 33 additions & 48 deletions tests/topotests/bgp_srv6l3vpn_sid/test_bgp_srv6l3vpn_sid.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
from lib.topogen import Topogen, TopoRouter, get_topogen
from lib.topolog import logger
from lib.common_config import required_linux_kernel_version
from lib.checkping import check_ping


def build_topo(tgen):
Expand Down Expand Up @@ -167,22 +168,6 @@ def open_json_file(filename):
assert False, "Could not read file {}".format(filename)


def check_ping(name, dest_addr, expect_connected):
def _check(name, dest_addr, match):
tgen = get_topogen()
output = tgen.gears[name].run("ping {} -c 1 -w 1".format(dest_addr))
logger.info(output)
if match not in output:
return True

match = ", {} packet loss".format("0%" if expect_connected else "100%")
logger.info("[+] check {} {} {}".format(name, dest_addr, match))
tgen = get_topogen()
func = functools.partial(_check, name, dest_addr, match)
success, result = topotest.run_and_expect(func, None, count=10, wait=0.5)
assert result is None, "Failed"


def check_rib(name, cmd, expected_file):
def _check(name, cmd, expected_file):
logger.info("polling")
Expand Down Expand Up @@ -215,21 +200,21 @@ def test_rib():


def test_ping():
check_ping("ce1", "2001:2::2", True)
check_ping("ce1", "2001:3::2", True)
check_ping("ce1", "2001:4::2", False)
check_ping("ce1", "2001:5::2", False)
check_ping("ce1", "2001:6::2", False)
check_ping("ce4", "2001:1::2", False)
check_ping("ce4", "2001:2::2", False)
check_ping("ce4", "2001:3::2", False)
check_ping("ce4", "2001:5::2", True)
check_ping("ce4", "2001:6::2", True)
check_ping("ce1", "2001:2::2", True, 10, 0.5)
check_ping("ce1", "2001:3::2", True, 10, 0.5)
check_ping("ce1", "2001:4::2", False, 10, 0.5)
check_ping("ce1", "2001:5::2", False, 10, 0.5)
check_ping("ce1", "2001:6::2", False, 10, 0.5)
check_ping("ce4", "2001:1::2", False, 10, 0.5)
check_ping("ce4", "2001:2::2", False, 10, 0.5)
check_ping("ce4", "2001:3::2", False, 10, 0.5)
check_ping("ce4", "2001:5::2", True, 10, 0.5)
check_ping("ce4", "2001:6::2", True, 10, 0.5)


def test_sid_per_afv6_auto():
check_rib("r1", "show ipv6 route vrf vrf10 json", "r1/vrf10_afv6_auto_sid_rib.json")
check_ping("ce1", "2001:2::2", True)
check_ping("ce1", "2001:2::2", True, 10, 0.5)
get_topogen().gears["r2"].vtysh_cmd(
"""
configure terminal
Expand All @@ -241,7 +226,7 @@ def test_sid_per_afv6_auto():
check_rib(
"r1", "show ipv6 route vrf vrf10 json", "r1/vrf10_afv6_auto_no_sid_rib.json"
)
check_ping("ce1", "2001:2::2", False)
check_ping("ce1", "2001:2::2", False, 10, 0.5)

get_topogen().gears["r2"].vtysh_cmd(
"""
Expand All @@ -252,7 +237,7 @@ def test_sid_per_afv6_auto():
"""
)
check_rib("r1", "show ipv6 route vrf vrf10 json", "r1/vrf10_afv6_auto_sid_rib.json")
check_ping("ce1", "2001:2::2", True)
check_ping("ce1", "2001:2::2", True, 10, 0.5)

get_topogen().gears["r2"].vtysh_cmd(
"""
Expand All @@ -265,14 +250,14 @@ def test_sid_per_afv6_auto():
check_rib(
"r1", "show ipv6 route vrf vrf10 json", "r1/vrf10_afv6_auto_no_sid_rib.json"
)
check_ping("ce1", "2001:2::2", False)
check_ping("ce1", "2001:2::2", False, 10, 0.5)


def test_sid_per_afv6_manual():
check_rib(
"r1", "show ipv6 route vrf vrf10 json", "r1/vrf10_afv6_manual_no_sid_rib.json"
)
check_ping("ce1", "2001:2::2", False)
check_ping("ce1", "2001:2::2", False, 10, 0.5)

get_topogen().gears["r2"].vtysh_cmd(
"""
Expand All @@ -286,7 +271,7 @@ def test_sid_per_afv6_manual():
check_rib(
"r1", "show ipv6 route vrf vrf10 json", "r1/vrf10_afv6_manual_sid_rib.json"
)
check_ping("ce1", "2001:2::2", True)
check_ping("ce1", "2001:2::2", True, 10, 0.5)

get_topogen().gears["r2"].vtysh_cmd(
"""
Expand All @@ -299,12 +284,12 @@ def test_sid_per_afv6_manual():
check_rib(
"r1", "show ipv6 route vrf vrf10 json", "r1/vrf10_afv6_manual_no_sid_rib.json"
)
check_ping("ce1", "2001:2::2", False)
check_ping("ce1", "2001:2::2", False, 10, 0.5)


def test_sid_per_afv4_auto():
check_rib("r1", "show ip route vrf vrf10 json", "r1/vrf10_afv4_auto_sid_rib.json")
check_ping("ce1", "192.168.2.2", True)
check_ping("ce1", "192.168.2.2", True, 10, 0.5)
get_topogen().gears["r2"].vtysh_cmd(
"""
configure terminal
Expand All @@ -317,7 +302,7 @@ def test_sid_per_afv4_auto():
check_rib(
"r1", "show ip route vrf vrf10 json", "r1/vrf10_afv4_auto_no_sid_rib.json"
)
check_ping("ce1", "192.168.2.2", False)
check_ping("ce1", "192.168.2.2", False, 10, 0.5)

get_topogen().gears["r2"].vtysh_cmd(
"""
Expand All @@ -329,7 +314,7 @@ def test_sid_per_afv4_auto():
)

check_rib("r1", "show ip route vrf vrf10 json", "r1/vrf10_afv4_auto_sid_rib.json")
check_ping("ce1", "192.168.2.2", True)
check_ping("ce1", "192.168.2.2", True, 10, 0.5)

get_topogen().gears["r2"].vtysh_cmd(
"""
Expand All @@ -342,14 +327,14 @@ def test_sid_per_afv4_auto():
check_rib(
"r1", "show ip route vrf vrf10 json", "r1/vrf10_afv4_auto_no_sid_rib.json"
)
check_ping("ce1", "192.168.2.2", False)
check_ping("ce1", "192.168.2.2", False, 10, 0.5)


def test_sid_per_afv4_manual():
check_rib(
"r1", "show ip route vrf vrf10 json", "r1/vrf10_afv4_manual_no_sid_rib.json"
)
check_ping("ce1", "192.168.2.2", False)
check_ping("ce1", "192.168.2.2", False, 10, 0.5)
get_topogen().gears["r2"].vtysh_cmd(
"""
configure terminal
Expand All @@ -360,7 +345,7 @@ def test_sid_per_afv4_manual():
)

check_rib("r1", "show ip route vrf vrf10 json", "r1/vrf10_afv4_manual_sid_rib.json")
check_ping("ce1", "192.168.2.2", True)
check_ping("ce1", "192.168.2.2", True, 10, 0.5)

get_topogen().gears["r2"].vtysh_cmd(
"""
Expand All @@ -370,7 +355,7 @@ def test_sid_per_afv4_manual():
no sid vpn export 8
"""
)
check_ping("ce1", "192.168.2.2", False)
check_ping("ce1", "192.168.2.2", False, 10, 0.5)
check_rib(
"r1", "show ip route vrf vrf10 json", "r1/vrf10_afv4_manual_no_sid_rib.json"
)
Expand All @@ -380,7 +365,7 @@ def test_sid_per_vrf_auto():
check_rib(
"r1", "show ipv6 route vrf vrf10 json", "r1/vrf10_pervrf_auto_no_sid_rib.json"
)
check_ping("ce1", "2001:2::2", False)
check_ping("ce1", "2001:2::2", False, 10, 0.5)
get_topogen().gears["r2"].vtysh_cmd(
"""
configure terminal
Expand All @@ -392,11 +377,11 @@ def test_sid_per_vrf_auto():
check_rib(
"r1", "show ipv6 route vrf vrf10 json", "r1/vrf10_pervrf6_auto_sid_rib.json"
)
check_ping("ce1", "2001:2::2", True)
check_ping("ce1", "2001:2::2", True, 10, 0.5)
check_rib(
"r1", "show ip route vrf vrf10 json", "r1/vrf10_pervrf4_auto_sid_rib.json"
)
check_ping("ce1", "192.168.2.2", True)
check_ping("ce1", "192.168.2.2", True, 10, 0.5)

get_topogen().gears["r2"].vtysh_cmd(
"""
Expand All @@ -409,14 +394,14 @@ def test_sid_per_vrf_auto():
check_rib(
"r1", "show ipv6 route vrf vrf10 json", "r1/vrf10_pervrf_auto_no_sid_rib.json"
)
check_ping("ce1", "2001:2::2", False)
check_ping("ce1", "2001:2::2", False, 10, 0.5)


def test_sid_per_vrf_manual():
check_rib(
"r1", "show ip route vrf vrf10 json", "r1/vrf10_pervrf_manual_no_sid_rib.json"
)
check_ping("ce1", "192.168.2.2", False)
check_ping("ce1", "192.168.2.2", False, 10, 0.5)
get_topogen().gears["r2"].vtysh_cmd(
"""
configure terminal
Expand All @@ -428,11 +413,11 @@ def test_sid_per_vrf_manual():
check_rib(
"r1", "show ipv6 route vrf vrf10 json", "r1/vrf10_pervrf6_manual_sid_rib.json"
)
check_ping("ce1", "2001:2::2", True)
check_ping("ce1", "2001:2::2", True, 10, 0.5)
check_rib(
"r1", "show ip route vrf vrf10 json", "r1/vrf10_pervrf4_manual_sid_rib.json"
)
check_ping("ce1", "192.168.2.2", True)
check_ping("ce1", "192.168.2.2", True, 10, 0.5)

get_topogen().gears["r2"].vtysh_cmd(
"""
Expand All @@ -445,7 +430,7 @@ def test_sid_per_vrf_manual():
check_rib(
"r1", "show ip route vrf vrf10 json", "r1/vrf10_pervrf_manual_no_sid_rib.json"
)
check_ping("ce1", "192.168.2.2", False)
check_ping("ce1", "192.168.2.2", False, 10, 0.5)


if __name__ == "__main__":
Expand Down
Loading

0 comments on commit de6bbd1

Please sign in to comment.