From 3dfd384ec4f3d7cdcc43373c6ff6c197fe81c81b Mon Sep 17 00:00:00 2001 From: naveen Date: Tue, 18 Aug 2020 19:52:45 +0530 Subject: [PATCH] tests: Moving kernel version check to API. Signed-off-by: naveen --- .../test_bgp_basic_functionality.py | 12 +++++-- .../bgp-ecmp-topo2/test_ebgp_ecmp_topo2.py | 15 ++++----- .../bgp-ecmp-topo2/test_ibgp_ecmp_topo2.py | 15 ++++----- .../bgp_as_allow_in/test_bgp_as_allow_in.py | 15 ++++----- .../test_bgp_communities.py | 14 ++++----- .../test_bgp_gr_functionality_topo1.py | 14 ++++----- .../test_bgp_gr_functionality_topo2.py | 14 ++++----- .../test_bgp_large_community_topo_1.py | 14 ++++----- .../test_bgp_large_community_topo_2.py | 15 ++++----- .../test_bgp_multi_vrf_topo1.py | 13 ++++---- .../test_bgp_multi_vrf_topo2.py | 13 ++++---- tests/topotests/lib/common_config.py | 31 ++++++++++++++++++- 12 files changed, 112 insertions(+), 73 deletions(-) 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 7e7155e8fa..b34c001ca2 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 @@ -46,9 +46,8 @@ import sys import json import time import pytest -import platform from copy import deepcopy -from lib.topotest import version_cmp + # Save the Current Working Directory to find configuration files. CWD = os.path.dirname(os.path.realpath(__file__)) sys.path.append(os.path.join(CWD, "../")) @@ -70,6 +69,7 @@ from lib.common_config import ( create_static_routes, verify_rib, verify_admin_distance_for_static_routes, +<<<<<<< ff9ae8fbb8f14b1cf5679d3278341edd09e7d8bf check_address_types, apply_raw_config, addKernelRoute, @@ -77,6 +77,9 @@ from lib.common_config import ( create_prefix_lists, create_route_maps, verify_bgp_community, +======= + required_linux_kernel_version +>>>>>>> tests: Moving kernel version check to API. ) from lib.topolog import logger from lib.bgp import ( @@ -138,6 +141,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: + pytest.skip(result) + 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 6059060729..63e5a9f9b2 100755 --- a/tests/topotests/bgp-ecmp-topo2/test_ebgp_ecmp_topo2.py +++ b/tests/topotests/bgp-ecmp-topo2/test_ebgp_ecmp_topo2.py @@ -41,7 +41,7 @@ import sys import time import json import pytest -import platform + # Save the Current Working Directory to find configuration files. CWD = os.path.dirname(os.path.realpath(__file__)) sys.path.append(os.path.join(CWD, "../")) @@ -51,7 +51,7 @@ sys.path.append(os.path.join(CWD, "../../")) # Import topogen and topotest helpers from lib.topogen import Topogen, get_topogen from mininet.topo import Topo -from lib.topotest import version_cmp + from lib.common_config import ( start_topology, write_test_header, @@ -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: + pytest.skip(result) + testsuite_run_time = time.asctime(time.localtime(time.time())) logger.info("Testsuite start time: {}".format(testsuite_run_time)) logger.info("=" * 40) @@ -124,11 +130,6 @@ def setup_module(mod): # Creating configuration from JSON build_config_from_json(tgen, topo) - if version_cmp(platform.release(), '4.19') < 0: - error_msg = ('These tests will not run. (have kernel "{}", ' - 'requires kernel >= 4.19)'.format(platform.release())) - pytest.skip(error_msg) - # Don't run this test if we have any failure. if tgen.routers_have_failure(): pytest.skip(tgen.errors) 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 81486dd2a1..883dc92438 100755 --- a/tests/topotests/bgp-ecmp-topo2/test_ibgp_ecmp_topo2.py +++ b/tests/topotests/bgp-ecmp-topo2/test_ibgp_ecmp_topo2.py @@ -41,7 +41,7 @@ import sys import time import json import pytest -import platform + # Save the Current Working Directory to find configuration files. CWD = os.path.dirname(os.path.realpath(__file__)) sys.path.append(os.path.join(CWD, "../")) @@ -51,7 +51,7 @@ sys.path.append(os.path.join(CWD, "../../")) # Import topogen and topotest helpers from lib.topogen import Topogen, get_topogen from mininet.topo import Topo -from lib.topotest import version_cmp + from lib.common_config import ( start_topology, write_test_header, @@ -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: + pytest.skip(result) + testsuite_run_time = time.asctime(time.localtime(time.time())) logger.info("Testsuite start time: {}".format(testsuite_run_time)) logger.info("=" * 40) @@ -124,11 +130,6 @@ def setup_module(mod): # Creating configuration from JSON build_config_from_json(tgen, topo) - if version_cmp(platform.release(), '4.19') < 0: - error_msg = ('These tests will not run. (have kernel "{}", ' - 'requires kernel >= 4.19)'.format(platform.release())) - pytest.skip(error_msg) - # Don't run this test if we have any failure. if tgen.routers_have_failure(): pytest.skip(tgen.errors) 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 197a2619aa..4db4d1a8b9 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 @@ -43,7 +43,7 @@ import sys import time import json import pytest -import platform + # Save the Current Working Directory to find configuration files. CWD = os.path.dirname(os.path.realpath(__file__)) sys.path.append(os.path.join(CWD, "../")) @@ -53,7 +53,7 @@ sys.path.append(os.path.join(CWD, "../lib/")) # Import topogen and topotest helpers from mininet.topo import Topo from lib.topogen import Topogen, get_topogen -from lib.topotest import version_cmp + # Import topoJson from lib, to create topology and initial configuration from lib.common_config import ( start_topology, @@ -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: + pytest.skip(result) + testsuite_run_time = time.asctime(time.localtime(time.time())) logger.info("Testsuite start time: {}".format(testsuite_run_time)) logger.info("=" * 40) @@ -129,11 +135,6 @@ def setup_module(mod): # Creating configuration from JSON build_config_from_json(tgen, topo) - if version_cmp(platform.release(), '4.19') < 0: - error_msg = ('These tests will not run. (have kernel "{}", ' - 'requires kernel >= 4.19)'.format(platform.release())) - pytest.skip(error_msg) - # Checking BGP convergence global BGP_CONVERGENCE global ADDR_TYPES diff --git a/tests/topotests/bgp_communities_topo1/test_bgp_communities.py b/tests/topotests/bgp_communities_topo1/test_bgp_communities.py index 2726f65ad9..88c5e0df19 100644 --- a/tests/topotests/bgp_communities_topo1/test_bgp_communities.py +++ b/tests/topotests/bgp_communities_topo1/test_bgp_communities.py @@ -31,7 +31,6 @@ import sys import time import json import pytest -import platform # Save the Current Working Directory to find configuration files. CWD = os.path.dirname(os.path.realpath(__file__)) @@ -41,7 +40,7 @@ sys.path.append(os.path.join(CWD, "../")) # Import topogen and topotest helpers from mininet.topo import Topo from lib.topogen import Topogen, get_topogen -from lib.topotest import version_cmp + # Import topoJson from lib, to create topology and initial configuration from lib.common_config import ( start_topology, @@ -55,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 ( @@ -103,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: + pytest.skip(result) + testsuite_run_time = time.asctime(time.localtime(time.time())) logger.info("Testsuite start time: {}".format(testsuite_run_time)) logger.info("=" * 40) @@ -120,11 +125,6 @@ def setup_module(mod): # Creating configuration from JSON build_config_from_json(tgen, topo) - if version_cmp(platform.release(), '4.19') < 0: - error_msg = ('These tests will not run. (have kernel "{}", ' - 'requires kernel >= 4.19)'.format(platform.release())) - pytest.skip(error_msg) - # Checking BGP convergence global BGP_CONVERGENCE global ADDR_TYPES 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 fc6c528f71..30757809c4 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 @@ -91,7 +91,6 @@ import json import time import inspect import pytest -import platform from time import sleep # Save the Current Working Directory to find configuration files. @@ -104,7 +103,7 @@ sys.path.append(os.path.join("../lib/")) from lib import topotest from lib.topogen import Topogen, TopoRouter, get_topogen from lib.topolog import logger -from lib.topotest import version_cmp + # Required to instantiate the topology builder class. from mininet.topo import Topo @@ -136,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 @@ -187,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: + pytest.skip(result) + testsuite_run_time = time.asctime(time.localtime(time.time())) logger.info("Testsuite start time: {}".format(testsuite_run_time)) logger.info("=" * 40) @@ -207,11 +212,6 @@ def setup_module(mod): # Creating configuration from JSON build_config_from_json(tgen, topo) - if version_cmp(platform.release(), '4.19') < 0: - error_msg = ('These tests will not run. (have kernel "{}", ' - 'requires kernel >= 4.19)'.format(platform.release())) - pytest.skip(error_msg) - # Don't run this test if we have any failure. if tgen.routers_have_failure(): pytest.skip(tgen.errors) 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 49045f2bb6..8bec22c577 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 @@ -87,7 +87,6 @@ import sys import json import time import pytest -import platform from time import sleep from copy import deepcopy @@ -101,7 +100,7 @@ sys.path.append(os.path.join("../lib/")) from lib import topotest from lib.topogen import Topogen, TopoRouter, get_topogen from lib.topolog import logger -from lib.topotest import version_cmp + # Required to instantiate the topology builder class. from mininet.topo import Topo @@ -136,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 @@ -184,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: + pytest.skip(result) + global ADDR_TYPES testsuite_run_time = time.asctime(time.localtime(time.time())) @@ -203,11 +208,6 @@ def setup_module(mod): # Creating configuration from JSON build_config_from_json(tgen, topo) - if version_cmp(platform.release(), '4.19') < 0: - error_msg = ('These tests will not run. (have kernel "{}", ' - 'requires kernel >= 4.19)'.format(platform.release())) - pytest.skip(error_msg) - # Api call verify whether BGP is converged ADDR_TYPES = check_address_types() 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 baa0653dc2..fe9e8504ad 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 @@ -51,8 +51,7 @@ import time from os import path as os_path import sys from json import load as json_load -import platform -from lib.topotest import version_cmp + # Required to instantiate the topology builder class. from lib.topogen import Topogen, get_topogen from mininet.topo import Topo @@ -68,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 @@ -143,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: + pytest.skip(result) + global ADDR_TYPES testsuite_run_time = time.asctime(time.localtime(time.time())) logger.info("Testsuite start time: {}".format(testsuite_run_time)) @@ -161,11 +166,6 @@ def setup_module(mod): # Creating configuration from JSON build_config_from_json(tgen, topo) - if version_cmp(platform.release(), '4.19') < 0: - error_msg = ('These tests will not run. (have kernel "{}", ' - 'requires kernel >= 4.19)'.format(platform.release())) - pytest.skip(error_msg) - # Checking BGP convergence global bgp_convergence 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 5ec663c633..d890fe127d 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 @@ -64,7 +64,7 @@ import sys import json import pytest import time -import platform + # Save the Current Working Directory to find configuration files. CWD = os.path.dirname(os.path.realpath(__file__)) sys.path.append(os.path.join(CWD, "../")) @@ -75,7 +75,7 @@ sys.path.append(os.path.join(CWD, "../lib/")) # Import topoJson from lib, to create topology and initial configuration from lib.topogen import Topogen, get_topogen from mininet.topo import Topo -from lib.topotest import version_cmp + from lib.common_config import ( start_topology, write_test_header, @@ -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: + pytest.skip(result) + testsuite_run_time = time.asctime(time.localtime(time.time())) logger.info("Testsuite start time: {}".format(testsuite_run_time)) logger.info("=" * 40) @@ -150,11 +156,6 @@ def setup_module(mod): # Creating configuration from JSON build_config_from_json(tgen, topo) - if version_cmp(platform.release(), '4.19') < 0: - error_msg = ('These tests will not run. (have kernel "{}", ' - 'requires kernel >= 4.19)'.format(platform.release())) - pytest.skip(error_msg) - # Checking BGP convergence global bgp_convergence, ADDR_TYPES 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 74cbda6a25..6ecc11119f 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 @@ -102,7 +102,6 @@ import sys import json import time import pytest -import platform from copy import deepcopy # Save the Current Working Directory to find configuration files. @@ -116,7 +115,7 @@ sys.path.append(os.path.join(CWD, "../lib/")) # Import topogen and topotest helpers from lib.topogen import Topogen, get_topogen from mininet.topo import Topo -from lib.topotest import version_cmp + from lib.common_config import ( step, verify_rib, @@ -133,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 @@ -210,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.19') + if result: + pytest.skip(result) testsuite_run_time = time.asctime(time.localtime(time.time())) logger.info("Testsuite start time: {}".format(testsuite_run_time)) @@ -231,11 +235,6 @@ def setup_module(mod): # Creating configuration from JSON build_config_from_json(tgen, topo) - if version_cmp(platform.release(), '4.19') < 0: - error_msg = ('These tests will not run. (have kernel "{}", ' - 'requires kernel >= 4.19)'.format(platform.release())) - pytest.skip(error_msg) - global BGP_CONVERGENCE global ADDR_TYPES ADDR_TYPES = check_address_types() 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 f1522c2a99..18c4a5dc75 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 @@ -43,10 +43,9 @@ import sys import json import time import pytest -import platform from copy import deepcopy from time import sleep -from lib.topotest import version_cmp + # Save the Current Working Directory to find configuration files. CWD = os.path.dirname(os.path.realpath(__file__)) @@ -79,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 @@ -142,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.19') + if result: + pytest.skip(result) testsuite_run_time = time.asctime(time.localtime(time.time())) logger.info("Testsuite start time: {}".format(testsuite_run_time)) @@ -163,11 +167,6 @@ def setup_module(mod): # Creating configuration from JSON build_config_from_json(tgen, topo) - if version_cmp(platform.release(), '4.19') < 0: - error_msg = ('These tests will not run. (have kernel "{}", ' - 'requires kernel >= 4.19)'.format(platform.release())) - pytest.skip(error_msg) - global BGP_CONVERGENCE global ADDR_TYPES ADDR_TYPES = check_address_types() diff --git a/tests/topotests/lib/common_config.py b/tests/topotests/lib/common_config.py index 1846d43138..5a6d3f3899 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 \ No newline at end of file