From bd7ea8da228bc28d602518dc8946f6fd568fc325 Mon Sep 17 00:00:00 2001 From: naveen Date: Wed, 12 Aug 2020 11:15:57 +0530 Subject: [PATCH] tests: Kernel version check for topojson scripts. 1. Added linux kernel version check to avoid failures in CI systems if matching kernel version not found. Signed-off-by: naveen --- .../test_bgp_basic_functionality.py | 6 ++++ .../bgp-ecmp-topo2/test_ebgp_ecmp_topo2.py | 6 ++++ .../bgp-ecmp-topo2/test_ibgp_ecmp_topo2.py | 6 ++++ .../bgp_as_allow_in/test_bgp_as_allow_in.py | 6 ++++ .../test_bgp_communities.py | 6 ++++ .../test_bgp_gr_functionality_topo1.py | 6 ++++ .../test_bgp_gr_functionality_topo2.py | 6 ++++ .../test_bgp_large_community_topo_1.py | 6 ++++ .../test_bgp_large_community_topo_2.py | 6 ++++ .../test_bgp_multi_vrf_topo1.py | 5 +++ .../test_bgp_multi_vrf_topo2.py | 5 +++ tests/topotests/lib/common_config.py | 31 ++++++++++++++++++- 12 files changed, 94 insertions(+), 1 deletion(-) diff --git a/tests/topotests/bgp-basic-functionality-topo1/test_bgp_basic_functionality.py b/tests/topotests/bgp-basic-functionality-topo1/test_bgp_basic_functionality.py index 69e050caed..41fa7c0a09 100755 --- a/tests/topotests/bgp-basic-functionality-topo1/test_bgp_basic_functionality.py +++ b/tests/topotests/bgp-basic-functionality-topo1/test_bgp_basic_functionality.py @@ -76,6 +76,7 @@ from lib.common_config import ( create_prefix_lists, create_route_maps, verify_bgp_community, + required_linux_kernel_version ) from lib.topolog import logger from lib.bgp import ( @@ -137,6 +138,11 @@ def setup_module(mod): * `mod`: module name """ + # 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") + testsuite_run_time = time.asctime(time.localtime(time.time())) logger.info("Testsuite start time: {}".format(testsuite_run_time)) logger.info("=" * 40) diff --git a/tests/topotests/bgp-ecmp-topo2/test_ebgp_ecmp_topo2.py b/tests/topotests/bgp-ecmp-topo2/test_ebgp_ecmp_topo2.py index 948f641afb..6068f5f831 100755 --- a/tests/topotests/bgp-ecmp-topo2/test_ebgp_ecmp_topo2.py +++ b/tests/topotests/bgp-ecmp-topo2/test_ebgp_ecmp_topo2.py @@ -61,6 +61,7 @@ from lib.common_config import ( check_address_types, interface_status, reset_config_on_routers, + required_linux_kernel_version ) from lib.topolog import logger from lib.bgp import verify_bgp_convergence, create_router_bgp, clear_bgp @@ -108,6 +109,11 @@ def setup_module(mod): global NEXT_HOPS, INTF_LIST_R3, INTF_LIST_R2, TEST_STATIC global ADDR_TYPES + # 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") + testsuite_run_time = time.asctime(time.localtime(time.time())) logger.info("Testsuite start time: {}".format(testsuite_run_time)) logger.info("=" * 40) diff --git a/tests/topotests/bgp-ecmp-topo2/test_ibgp_ecmp_topo2.py b/tests/topotests/bgp-ecmp-topo2/test_ibgp_ecmp_topo2.py index 5b997fdd16..ae54019a0f 100755 --- a/tests/topotests/bgp-ecmp-topo2/test_ibgp_ecmp_topo2.py +++ b/tests/topotests/bgp-ecmp-topo2/test_ibgp_ecmp_topo2.py @@ -61,6 +61,7 @@ from lib.common_config import ( check_address_types, interface_status, reset_config_on_routers, + required_linux_kernel_version ) from lib.topolog import logger from lib.bgp import verify_bgp_convergence, create_router_bgp, clear_bgp @@ -108,6 +109,11 @@ def setup_module(mod): global NEXT_HOPS, INTF_LIST_R3, INTF_LIST_R2, TEST_STATIC global ADDR_TYPES + # 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") + testsuite_run_time = time.asctime(time.localtime(time.time())) logger.info("Testsuite start time: {}".format(testsuite_run_time)) logger.info("=" * 40) diff --git a/tests/topotests/bgp_as_allow_in/test_bgp_as_allow_in.py b/tests/topotests/bgp_as_allow_in/test_bgp_as_allow_in.py index 89b15c46d3..f9d22a3a36 100755 --- a/tests/topotests/bgp_as_allow_in/test_bgp_as_allow_in.py +++ b/tests/topotests/bgp_as_allow_in/test_bgp_as_allow_in.py @@ -65,6 +65,7 @@ from lib.common_config import ( create_route_maps, check_address_types, step, + required_linux_kernel_version ) from lib.topolog import logger from lib.bgp import ( @@ -112,6 +113,11 @@ def setup_module(mod): * `mod`: module name """ + # 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") + testsuite_run_time = time.asctime(time.localtime(time.time())) logger.info("Testsuite start time: {}".format(testsuite_run_time)) logger.info("=" * 40) diff --git a/tests/topotests/bgp_communities_topo1/test_bgp_communities.py b/tests/topotests/bgp_communities_topo1/test_bgp_communities.py index 7d960d6916..57e8e0d34a 100644 --- a/tests/topotests/bgp_communities_topo1/test_bgp_communities.py +++ b/tests/topotests/bgp_communities_topo1/test_bgp_communities.py @@ -54,6 +54,7 @@ from lib.common_config import ( create_route_maps, create_prefix_lists, create_route_maps, + required_linux_kernel_version ) from lib.topolog import logger from lib.bgp import ( @@ -102,6 +103,11 @@ def setup_module(mod): * `mod`: module name """ + # 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") + testsuite_run_time = time.asctime(time.localtime(time.time())) logger.info("Testsuite start time: {}".format(testsuite_run_time)) logger.info("=" * 40) diff --git a/tests/topotests/bgp_gr_functionality_topo1/test_bgp_gr_functionality_topo1.py b/tests/topotests/bgp_gr_functionality_topo1/test_bgp_gr_functionality_topo1.py index fdc1bed522..fdbd317093 100755 --- a/tests/topotests/bgp_gr_functionality_topo1/test_bgp_gr_functionality_topo1.py +++ b/tests/topotests/bgp_gr_functionality_topo1/test_bgp_gr_functionality_topo1.py @@ -135,6 +135,7 @@ from lib.common_config import ( kill_mininet_routers_process, get_frr_ipv6_linklocal, create_route_maps, + required_linux_kernel_version ) # Reading the data from JSON File for topology and configuration creation @@ -186,6 +187,11 @@ def setup_module(mod): global ADDR_TYPES + # 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") + testsuite_run_time = time.asctime(time.localtime(time.time())) logger.info("Testsuite start time: {}".format(testsuite_run_time)) logger.info("=" * 40) diff --git a/tests/topotests/bgp_gr_functionality_topo2/test_bgp_gr_functionality_topo2.py b/tests/topotests/bgp_gr_functionality_topo2/test_bgp_gr_functionality_topo2.py index 83a04f491f..e1ec0ea81b 100755 --- a/tests/topotests/bgp_gr_functionality_topo2/test_bgp_gr_functionality_topo2.py +++ b/tests/topotests/bgp_gr_functionality_topo2/test_bgp_gr_functionality_topo2.py @@ -135,6 +135,7 @@ from lib.common_config import ( kill_mininet_routers_process, get_frr_ipv6_linklocal, create_route_maps, + required_linux_kernel_version ) # Reading the data from JSON File for topology and configuration creation @@ -183,6 +184,11 @@ def setup_module(mod): * `mod`: module name """ + # 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") + global ADDR_TYPES testsuite_run_time = time.asctime(time.localtime(time.time())) diff --git a/tests/topotests/bgp_large_community/test_bgp_large_community_topo_1.py b/tests/topotests/bgp_large_community/test_bgp_large_community_topo_1.py index 334aaebb4b..dc06b7131a 100755 --- a/tests/topotests/bgp_large_community/test_bgp_large_community_topo_1.py +++ b/tests/topotests/bgp_large_community/test_bgp_large_community_topo_1.py @@ -67,6 +67,7 @@ from lib.common_config import ( verify_bgp_community, step, check_address_types, + required_linux_kernel_version ) from lib.topolog import logger from lib.bgp import verify_bgp_convergence, create_router_bgp, clear_bgp_and_verify @@ -142,6 +143,11 @@ def setup_module(mod): * `mod`: module name """ + # 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") + global ADDR_TYPES testsuite_run_time = time.asctime(time.localtime(time.time())) logger.info("Testsuite start time: {}".format(testsuite_run_time)) diff --git a/tests/topotests/bgp_large_community/test_bgp_large_community_topo_2.py b/tests/topotests/bgp_large_community/test_bgp_large_community_topo_2.py index 502a9a9ec4..bb88e47415 100755 --- a/tests/topotests/bgp_large_community/test_bgp_large_community_topo_2.py +++ b/tests/topotests/bgp_large_community/test_bgp_large_community_topo_2.py @@ -91,6 +91,7 @@ from lib.common_config import ( verify_route_maps, create_static_routes, check_address_types, + required_linux_kernel_version ) from lib.topolog import logger from lib.bgp import verify_bgp_convergence, create_router_bgp, clear_bgp_and_verify @@ -133,6 +134,11 @@ def setup_module(mod): * `mod`: module name """ + # 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") + testsuite_run_time = time.asctime(time.localtime(time.time())) logger.info("Testsuite start time: {}".format(testsuite_run_time)) logger.info("=" * 40) diff --git a/tests/topotests/bgp_multi_vrf_topo1/test_bgp_multi_vrf_topo1.py b/tests/topotests/bgp_multi_vrf_topo1/test_bgp_multi_vrf_topo1.py index a37e3f36a3..c15b88d371 100755 --- a/tests/topotests/bgp_multi_vrf_topo1/test_bgp_multi_vrf_topo1.py +++ b/tests/topotests/bgp_multi_vrf_topo1/test_bgp_multi_vrf_topo1.py @@ -132,6 +132,7 @@ from lib.common_config import ( create_bgp_community_lists, check_router_status, apply_raw_config, + required_linux_kernel_version ) from lib.topolog import logger @@ -209,6 +210,10 @@ def setup_module(mod): * `mod`: module name """ + # 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") testsuite_run_time = time.asctime(time.localtime(time.time())) logger.info("Testsuite start time: {}".format(testsuite_run_time)) diff --git a/tests/topotests/bgp_multi_vrf_topo2/test_bgp_multi_vrf_topo2.py b/tests/topotests/bgp_multi_vrf_topo2/test_bgp_multi_vrf_topo2.py index c36e66a60e..bb13d54019 100755 --- a/tests/topotests/bgp_multi_vrf_topo2/test_bgp_multi_vrf_topo2.py +++ b/tests/topotests/bgp_multi_vrf_topo2/test_bgp_multi_vrf_topo2.py @@ -78,6 +78,7 @@ from lib.common_config import ( get_frr_ipv6_linklocal, check_router_status, apply_raw_config, + required_linux_kernel_version ) from lib.topolog import logger @@ -141,6 +142,10 @@ def setup_module(mod): * `mod`: module name """ + # 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") testsuite_run_time = time.asctime(time.localtime(time.time())) logger.info("Testsuite start time: {}".format(testsuite_run_time)) diff --git a/tests/topotests/lib/common_config.py b/tests/topotests/lib/common_config.py index 1846d43138..a5385b0fcb 100644 --- a/tests/topotests/lib/common_config.py +++ b/tests/topotests/lib/common_config.py @@ -36,6 +36,8 @@ import ConfigParser import traceback import socket import ipaddress +import platform + if sys.version_info[0] > 2: import io @@ -46,7 +48,7 @@ else: from lib.topolog import logger, logger_config from lib.topogen import TopoRouter, get_topogen -from lib.topotest import interface_set_status +from lib.topotest import interface_set_status, version_cmp FRRCFG_FILE = "frr_json.conf" FRRCFG_BKUP_FILE = "frr_json_initial.conf" @@ -3973,3 +3975,30 @@ def verify_vrf_vni(tgen, input_dict): logger.debug("Exiting lib API: {}".format(sys._getframe().f_code.co_name)) return False + + +def required_linux_kernel_version(required_version): + """ + This API is used to check linux version compatibility of the test suite. + If version mentioned in required_version is higher than the linux kernel + of the system, test suite will be skipped. This API returns true or errormsg. + + Parameters + ---------- + * `required_version` : Kernel version required for the suites to run. + + Usage + ----- + result = linux_kernel_version_lowerthan('4.15') + + Returns + ------- + errormsg(str) or True + """ + system_kernel = platform.release() + if version_cmp(system_kernel, required_version) < 0: + error_msg = ('These tests will not run on kernel "{}", ' + 'they require kernel >= {})'.format(system_kernel, + required_version )) + return error_msg + return True -- 2.39.5