Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests: iproute2 VRF capability check for topotests #8253

Merged
merged 3 commits into from
Mar 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@
# Import topogen and topotest helpers
from lib.topogen import Topogen, get_topogen
from mininet.topo import Topo

from lib.topotest import iproute2_is_vrf_capable
from lib.common_config import (
step,
verify_rib,
Expand Down Expand Up @@ -215,6 +215,10 @@ def setup_module(mod):
if result is not True:
pytest.skip("Kernel requirements are not met")

# iproute2 needs to support VRFs for this suite to run.
if not iproute2_is_vrf_capable():
pytest.skip("Installed iproute2 version does not support VRFs")

testsuite_run_time = time.asctime(time.localtime(time.time()))
logger.info("Testsuite start time: {}".format(testsuite_run_time))
logger.info("=" * 40)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
# Import topogen and topotest helpers
from lib.topogen import Topogen, get_topogen
from mininet.topo import Topo

from lib.topotest import iproute2_is_vrf_capable
from lib.common_config import (
step,
verify_rib,
Expand Down Expand Up @@ -164,6 +164,10 @@ def setup_module(mod):
if result is not True:
pytest.skip("Kernel requirements are not met")

# iproute2 needs to support VRFs for this suite to run.
if not iproute2_is_vrf_capable():
pytest.skip("Installed iproute2 version does not support VRFs")

testsuite_run_time = time.asctime(time.localtime(time.time()))
logger.info("Testsuite start time: {}".format(testsuite_run_time))
logger.info("=" * 40)
Expand Down
32 changes: 20 additions & 12 deletions tests/topotests/isis-topo1-vrf/test_isis_topo1_vrf.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
from lib import topotest
from lib.topogen import Topogen, TopoRouter, get_topogen
from lib.topolog import logger
from lib.topotest import iproute2_is_vrf_capable
from lib.common_config import required_linux_kernel_version

from mininet.topo import Topo

Expand Down Expand Up @@ -193,18 +195,21 @@ def test_isis_route_installation():


def test_isis_linux_route_installation():

dist = platform.dist()

if dist[1] == "16.04":
pytest.skip("Kernel not supported for vrf")

"Check whether all expected routes are present and installed in the OS"
tgen = get_topogen()
# Don't run this test if we have any failure.
if tgen.routers_have_failure():
pytest.skip(tgen.errors)

# Required linux kernel version for this suite to run.
result = required_linux_kernel_version("4.15")
if result is not True:
pytest.skip("Kernel requirements are not met")

# iproute2 needs to support VRFs for this suite to run.
if not iproute2_is_vrf_capable():
pytest.skip("Installed iproute2 version does not support VRFs")

logger.info("Checking routers for installed ISIS vrf routes in OS")
# Check for routes in `ip route show vrf {}-cust1`
for rname, router in tgen.routers().items():
Expand Down Expand Up @@ -236,18 +241,21 @@ def test_isis_route6_installation():


def test_isis_linux_route6_installation():

dist = platform.dist()

if dist[1] == "16.04":
pytest.skip("Kernel not supported for vrf")

"Check whether all expected routes are present and installed in the OS"
tgen = get_topogen()
# Don't run this test if we have any failure.
if tgen.routers_have_failure():
pytest.skip(tgen.errors)

# Required linux kernel version for this suite to run.
result = required_linux_kernel_version("4.15")
if result is not True:
pytest.skip("Kernel requirements are not met")

# iproute2 needs to support VRFs for this suite to run.
if not iproute2_is_vrf_capable():
pytest.skip("Installed iproute2 version does not support VRFs")

logger.info("Checking routers for installed ISIS vrf IPv6 routes in OS")
# Check for routes in `ip -6 route show vrf {}-cust1`
for rname, router in tgen.routers().items():
Expand Down
38 changes: 38 additions & 0 deletions tests/topotests/lib/topotest.py
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,44 @@ def normalize_text(text):
return text


def is_linux():
"""
Parses unix name output to check if running on GNU/Linux.

Returns True if running on Linux, returns False otherwise.
"""

if os.uname()[0] == "Linux":
return True
return False


def iproute2_is_vrf_capable():
"""
Checks if the iproute2 version installed on the system is capable of
handling VRFs by interpreting the output of the 'ip' utility found in PATH.

Returns True if capability can be detected, returns False otherwise.
"""

if is_linux():
try:
subp = subprocess.Popen(
["ip", "route", "show", "vrf"],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
stdin=subprocess.PIPE,
encoding="utf-8"
)
iproute2_err = subp.communicate()[1].splitlines()[0].split()[0]

if iproute2_err != "Error:":
return True
except Exception:
pass
return False


def module_present_linux(module, load):
"""
Returns whether `module` is present.
Expand Down