diff --git a/tests/topotests/bgp_default_originate/test_default_orginate_vrf.py b/tests/topotests/bgp_default_originate/test_default_orginate_vrf.py index 95bb96f9a0f6..1b842e5f4716 100644 --- a/tests/topotests/bgp_default_originate/test_default_orginate_vrf.py +++ b/tests/topotests/bgp_default_originate/test_default_orginate_vrf.py @@ -76,8 +76,8 @@ # Save the Current Working Directory to find configuration files. CWD = os.path.dirname(os.path.realpath(__file__)) -sys.path.append(os.path.join(CWD, '../')) -sys.path.append(os.path.join(CWD, '../lib/')) +sys.path.append(os.path.join(CWD, "../")) +sys.path.append(os.path.join(CWD, "../lib/")) # Required to instantiate the topology builder class. @@ -146,6 +146,7 @@ r4_connected_address_ipv4 = "192.168.3.0/24" r4_connected_address_ipv6 = "fd00:0:0:3::/64" + def setup_module(mod): """ Sets up the pytest environment @@ -320,6 +321,7 @@ def setup_module(mod): logger.info("Running setup_module() done") + def teardown_module(): """Teardown the pytest environment""" @@ -335,6 +337,7 @@ def teardown_module(): ) logger.info("=" * 40) + ##################################################### # # Testcases @@ -348,7 +351,7 @@ def test_verify_default_originate_route_with_non_default_VRF_p1(request): global BGP_CONVERGENCE if BGP_CONVERGENCE != True: - pytest.skip('skipped because of BGP Convergence failure') + pytest.skip("skipped because of BGP Convergence failure") # test case name tc_name = request.node.name write_test_header(tc_name) @@ -356,16 +359,21 @@ def test_verify_default_originate_route_with_non_default_VRF_p1(request): check_router_status(tgen) reset_config_on_routers(tgen) - #these steps are implemented as base toplopgy setup + # these steps are implemented as base toplopgy setup step("Configure IPV4 and IPV6 IBGP between R1 and R2 default VRF") step("Configure IPV4 and IPV6 EBGP between R2 to R3 non-default VRF (RED)") - step("Configure IPv4 and IP6 loopback address on R1 default and R3 non-default (RED) VRF") + step( + "Configure IPv4 and IP6 loopback address on R1 default and R3 non-default (RED) VRF" + ) step("After changing the BGP AS Path Verify the BGP Convergence") BGP_CONVERGENCE = verify_bgp_convergence(tgen, topo) assert BGP_CONVERGENCE is True, "setup_module :Failed \n Error: {}".format( - BGP_CONVERGENCE) - step("Configure IPv4 and IPv6 static route on R1 default and R3 non-default (RED) VRF with nexthop as Null ( different static route on each side)") + BGP_CONVERGENCE + ) + step( + "Configure IPv4 and IPv6 static route on R1 default and R3 non-default (RED) VRF with nexthop as Null ( different static route on each side)" + ) for addr_type in ADDR_TYPES: static_routes_input = { "r1": { @@ -378,8 +386,11 @@ def test_verify_default_originate_route_with_non_default_VRF_p1(request): } } result = create_static_routes(tgen, static_routes_input) - assert result is True, "Testcase {} : Failed to configure the static routes in router R1 default vrf \n Error: {}".format( - tc_name, result) + assert ( + result is True + ), "Testcase {} : Failed to configure the static routes in router R1 default vrf \n Error: {}".format( + tc_name, result + ) for addr_type in ADDR_TYPES: static_routes_input = { @@ -388,16 +399,21 @@ def test_verify_default_originate_route_with_non_default_VRF_p1(request): { "network": [NETWORK2_1[addr_type]], "next_hop": NEXT_HOP_IP[addr_type], - "vrf":"RED" + "vrf": "RED", } ] } } result = create_static_routes(tgen, static_routes_input) - assert result is True, "Testcase {} : Failed to configure static route in R3 non default vrf RED \n Error: {}".format( - tc_name, result) + assert ( + result is True + ), "Testcase {} : Failed to configure static route in R3 non default vrf RED \n Error: {}".format( + tc_name, result + ) - step("Verify IPv4 and IPv6 static route configured on R1 default vrf and R3 non-default (RED) vrf") + step( + "Verify IPv4 and IPv6 static route configured on R1 default vrf and R3 non-default (RED) vrf" + ) for addr_type in ADDR_TYPES: static_routes_input = { "r1": { @@ -410,8 +426,11 @@ def test_verify_default_originate_route_with_non_default_VRF_p1(request): } } result = verify_rib(tgen, addr_type, "r1", static_routes_input) - assert result is True, "Testcase {} : Failed: Routes configured on vrf is not seen in R1 default VRF FIB \n Error: {}".format( - tc_name, result) + assert ( + result is True + ), "Testcase {} : Failed: Routes configured on vrf is not seen in R1 default VRF FIB \n Error: {}".format( + tc_name, result + ) for addr_type in ADDR_TYPES: static_routes_input = { @@ -420,39 +439,41 @@ def test_verify_default_originate_route_with_non_default_VRF_p1(request): { "network": [NETWORK2_1[addr_type]], "next_hop": NEXT_HOP_IP[addr_type], - "vrf":"RED" + "vrf": "RED", } ] } } result = verify_rib(tgen, addr_type, "r3", static_routes_input) - assert result is True, "Testcase {} : Failed : Routes configured in non-defaul vrf in R3 FIB is \n Error: {}".format( - tc_name, result) + assert ( + result is True + ), "Testcase {} : Failed : Routes configured in non-defaul vrf in R3 FIB is \n Error: {}".format( + tc_name, result + ) - step("Configure redistribute connected and static on R1 (R1-R2) and on R3 ( R2-R3 RED VRF) IPv4 and IPv6 address family ") + step( + "Configure redistribute connected and static on R1 (R1-R2) and on R3 ( R2-R3 RED VRF) IPv4 and IPv6 address family " + ) redistribute_static = { "r1": { "bgp": { "address_family": { "ipv4": { "unicast": { - "redistribute": [{ - "redist_type": "static" - }, - { - "redist_type": "connected" - }] + "redistribute": [ + {"redist_type": "static"}, + {"redist_type": "connected"}, + ] } - }, "ipv6": { + }, + "ipv6": { "unicast": { - "redistribute": [{ - "redist_type": "static" - }, - { - "redist_type": "connected" - }] + "redistribute": [ + {"redist_type": "static"}, + {"redist_type": "connected"}, + ] } - } + }, } } }, @@ -463,32 +484,34 @@ def test_verify_default_originate_route_with_non_default_VRF_p1(request): "address_family": { "ipv4": { "unicast": { - "redistribute": [{ - "redist_type": "static" - }, - { - "redist_type": "connected" - }] + "redistribute": [ + {"redist_type": "static"}, + {"redist_type": "connected"}, + ] } - }, "ipv6": { + }, + "ipv6": { "unicast": { - "redistribute": [{ - "redist_type": "static" - }, - { - "redist_type": "connected" - }] + "redistribute": [ + {"redist_type": "static"}, + {"redist_type": "connected"}, + ] } - } - } + }, + }, } - } + }, } result = create_router_bgp(tgen, topo, redistribute_static) - assert result is True, "Testcase {} : Failed to configure the redistribute on R1 and R3 \n Error: {}".format( - tc_name, result) + assert ( + result is True + ), "Testcase {} : Failed to configure the redistribute on R1 and R3 \n Error: {}".format( + tc_name, result + ) - step("Verify IPv4 and IPv6 static route configured on R1 received as BGP routes on R2 default VRF ") + step( + "Verify IPv4 and IPv6 static route configured on R1 received as BGP routes on R2 default VRF " + ) for addr_type in ADDR_TYPES: static_routes_input = { "r2": { @@ -504,15 +527,17 @@ def test_verify_default_originate_route_with_non_default_VRF_p1(request): { "network": [R1_NETWORK_CONNECTED[addr_type]], "next_hop": R1_NETWORK_CONNECTED_NXTHOP[addr_type], - } - + }, ] } } result = verify_bgp_rib(tgen, addr_type, "r2", static_routes_input) assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) - step("Verify IPv4 and IPv6 static route configured on R3 received as BGP routes on R2 non-default VRF ") + tc_name, result + ) + step( + "Verify IPv4 and IPv6 static route configured on R3 received as BGP routes on R2 non-default VRF " + ) for addr_type in ADDR_TYPES: static_routes_input = { "r3": { @@ -520,63 +545,51 @@ def test_verify_default_originate_route_with_non_default_VRF_p1(request): { "network": [NETWORK2_1[addr_type]], "next_hop": NEXT_HOP_IP[addr_type], - "vrf":"RED" + "vrf": "RED", }, { "network": [R3_NETWORK_CONNECTED[addr_type]], "next_hop": R3_NETWORK_CONNECTED_NXTHOP[addr_type], - "vrf":"RED" - } + "vrf": "RED", + }, ] } } result = verify_bgp_rib(tgen, addr_type, "r2", static_routes_input) assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) - + tc_name, result + ) - step("Configure default-originate on R1 for R1 to R2 neighbor for IPv4 and IPv6 peer") + step( + "Configure default-originate on R1 for R1 to R2 neighbor for IPv4 and IPv6 peer" + ) local_as = get_dut_as_number(tgen, dut="r1") default_originate_config = { "r1": { "bgp": { "local_as": local_as, "address_family": { - "ipv4": { - "unicast": { - "default_originate":{ - "r2":{ - - } - - } - - } - }, "ipv6": { - "unicast": { - "default_originate":{ - "r2":{ - - } - - } - } - } - } + "ipv4": {"unicast": {"default_originate": {"r2": {}}}}, + "ipv6": {"unicast": {"default_originate": {"r2": {}}}}, + }, } } } result = create_router_bgp(tgen, topo, default_originate_config) - assert result is True, "Testcase {} : Failed to configure the default originate \n Error: {}".format( - tc_name, result) + assert ( + result is True + ), "Testcase {} : Failed to configure the default originate \n Error: {}".format( + tc_name, result + ) - step("After configuring default-originate command , verify default routes are advertised on R2 ") + step( + "After configuring default-originate command , verify default routes are advertised on R2 " + ) DEFAULT_ROUTES = {"ipv4": "0.0.0.0/0", "ipv6": "0::0/0"} for addr_type in ADDR_TYPES: static_routes_input = { "r2": { "static_routes": [ - { "network": [DEFAULT_ROUTES[addr_type]], "next_hop": DEFAULT_ROUTE_NXT_HOP_R1[addr_type], @@ -585,13 +598,27 @@ def test_verify_default_originate_route_with_non_default_VRF_p1(request): } } - result = verify_rib(tgen, addr_type, "r2", static_routes_input,next_hop=DEFAULT_ROUTE_NXT_HOP_R1[addr_type]) + result = verify_rib( + tgen, + addr_type, + "r2", + static_routes_input, + next_hop=DEFAULT_ROUTE_NXT_HOP_R1[addr_type], + ) assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + tc_name, result + ) - result = verify_bgp_rib(tgen, addr_type, "r2", static_routes_input,next_hop=DEFAULT_ROUTE_NXT_HOP_R1[addr_type]) + result = verify_bgp_rib( + tgen, + addr_type, + "r2", + static_routes_input, + next_hop=DEFAULT_ROUTE_NXT_HOP_R1[addr_type], + ) assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + tc_name, result + ) for addr_type in ADDR_TYPES: static_routes_input = { @@ -608,22 +635,38 @@ def test_verify_default_originate_route_with_non_default_VRF_p1(request): { "network": [R1_NETWORK_CONNECTED[addr_type]], "next_hop": R1_NETWORK_CONNECTED_NXTHOP[addr_type], - } + }, ] } } - result = verify_bgp_rib(tgen, addr_type, "r2", static_routes_input,next_hop=DEFAULT_ROUTE_NXT_HOP_R1[addr_type]) + result = verify_bgp_rib( + tgen, + addr_type, + "r2", + static_routes_input, + next_hop=DEFAULT_ROUTE_NXT_HOP_R1[addr_type], + ) assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + tc_name, result + ) - result = verify_rib(tgen, addr_type, "r2", static_routes_input,next_hop=DEFAULT_ROUTE_NXT_HOP_R1[addr_type]) + result = verify_rib( + tgen, + addr_type, + "r2", + static_routes_input, + next_hop=DEFAULT_ROUTE_NXT_HOP_R1[addr_type], + ) assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + tc_name, result + ) - snapshot1 = get_prefix_count_route(tgen, topo, dut="r2", peer="r3",vrf="RED") + snapshot1 = get_prefix_count_route(tgen, topo, dut="r2", peer="r3", vrf="RED") - step("Configure default-originate on R3 for R3 to R2 neighbor (RED VRF) for IPv4 and IPv6 peer") + step( + "Configure default-originate on R3 for R3 to R2 neighbor (RED VRF) for IPv4 and IPv6 peer" + ) default_originate_config = { "r3": { @@ -631,37 +674,18 @@ def test_verify_default_originate_route_with_non_default_VRF_p1(request): "local_as": "3000", "vrf": "RED", "address_family": { - "ipv4": { - "unicast": { - "default_originate":{ - "r2":{ - - - } - - } - - } - }, "ipv6": { - "unicast": { - "default_originate":{ - "r2":{ - - } - - } - } - } - } + "ipv4": {"unicast": {"default_originate": {"r2": {}}}}, + "ipv6": {"unicast": {"default_originate": {"r2": {}}}}, + }, } } } result = create_router_bgp(tgen, topo, default_originate_config) - assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) - + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) - step("Verify IPv4 and IPv6 bgp default route and static route received on R2 VRF red nexthop as R3") + step( + "Verify IPv4 and IPv6 bgp default route and static route received on R2 VRF red nexthop as R3" + ) DEFAULT_ROUTES = {"ipv4": "0.0.0.0/0", "ipv6": "0::0/0"} for addr_type in ADDR_TYPES: static_routes_input = { @@ -670,25 +694,39 @@ def test_verify_default_originate_route_with_non_default_VRF_p1(request): { "network": [NETWORK2_1[addr_type]], "next_hop": NEXT_HOP_IP[addr_type], - "vrf":"RED" + "vrf": "RED", }, { "network": [DEFAULT_ROUTES[addr_type]], "next_hop": DEFAULT_ROUTE_NXT_HOP_R3[addr_type], - "vrf":"RED" - } + "vrf": "RED", + }, ] } } - result = verify_rib(tgen, addr_type, "r2", static_routes_input,next_hop=DEFAULT_ROUTE_NXT_HOP_R3[addr_type] ) + result = verify_rib( + tgen, + addr_type, + "r2", + static_routes_input, + next_hop=DEFAULT_ROUTE_NXT_HOP_R3[addr_type], + ) assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) - result = verify_bgp_rib(tgen, addr_type, "r2", static_routes_input ,next_hop=DEFAULT_ROUTE_NXT_HOP_R3[addr_type]) + tc_name, result + ) + result = verify_bgp_rib( + tgen, + addr_type, + "r2", + static_routes_input, + next_hop=DEFAULT_ROUTE_NXT_HOP_R3[addr_type], + ) assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + tc_name, result + ) step("verify Out-prefix count incremented for IPv4/IPv6 default route on VRF red") - snapshot2 = get_prefix_count_route(tgen, topo, dut="r2", peer="r3",vrf="RED") + snapshot2 = get_prefix_count_route(tgen, topo, dut="r2", peer="r3", vrf="RED") step("verifying the prefix count incrementing or not ") isIPv4prefix_incremented = False isIPv6prefix_incremented = False @@ -712,22 +750,18 @@ def test_verify_default_originate_route_with_non_default_VRF_p1(request): { "local_as": local_as, "address_family": { - "ipv4": { - "unicast": {"import": {"vrf": "RED" }} - }, - "ipv6": { - "unicast": {"import": {"vrf": "RED" }} - } + "ipv4": {"unicast": {"import": {"vrf": "RED"}}}, + "ipv6": {"unicast": {"import": {"vrf": "RED"}}}, }, } ] } } result = create_router_bgp(tgen, topo, input_import_vrf) - assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) + step( + "Verify VRF RED IPv4 and IPv6, default-originate, \n static and loopback route are imported to R2 default VRF table ,\n default-originate route coming from VRF red should not active on R2 default VRF table" ) - step("Verify VRF RED IPv4 and IPv6, default-originate, \n static and loopback route are imported to R2 default VRF table ,\n default-originate route coming from VRF red should not active on R2 default VRF table") step("verifying the static routes connected and loop back routes") for addr_type in ADDR_TYPES: static_routes_input = { @@ -736,7 +770,8 @@ def test_verify_default_originate_route_with_non_default_VRF_p1(request): { "network": [NETWORK1_1[addr_type]], "next_hop": NEXT_HOP_IP[addr_type], - }, { + }, + { "network": [NETWORK2_1[addr_type]], "next_hop": NEXT_HOP_IP[addr_type], }, @@ -751,21 +786,22 @@ def test_verify_default_originate_route_with_non_default_VRF_p1(request): { "network": [R3_NETWORK_CONNECTED[addr_type]], "next_hop": R3_NETWORK_CONNECTED_NXTHOP[addr_type], - } + }, ] } } result = verify_rib(tgen, addr_type, "r2", static_routes_input) assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + tc_name, result + ) result = verify_bgp_rib(tgen, addr_type, "r2", static_routes_input) assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) - + tc_name, result + ) - STEP=""" After importing non defualt VRF into default vrf . + STEP = """ After importing non defualt VRF into default vrf . verify that the default originate from R1 --> R2(non -default) is preffered over R3 --> R2 because the Default Route prefers iBGP over eBGP over Default Route from R1 Should be present in BGP RIB and FIB @@ -777,7 +813,6 @@ def test_verify_default_originate_route_with_non_default_VRF_p1(request): static_routes_input = { "r2": { "static_routes": [ - { "network": [DEFAULT_ROUTES[addr_type]], "next_hop": DEFAULT_ROUTE_NXT_HOP_R1[addr_type], @@ -788,7 +823,8 @@ def test_verify_default_originate_route_with_non_default_VRF_p1(request): result = verify_rib(tgen, addr_type, "r2", static_routes_input) assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + tc_name, result + ) static_routes_input = { "r2": { @@ -796,19 +832,22 @@ def test_verify_default_originate_route_with_non_default_VRF_p1(request): { "network": [DEFAULT_ROUTES[addr_type]], "next_hop": DEFAULT_ROUTE_NXT_HOP_R3[addr_type], - } , + }, { "network": [DEFAULT_ROUTES[addr_type]], "next_hop": DEFAULT_ROUTE_NXT_HOP_R1[addr_type], - } + }, ] } } result = verify_bgp_rib(tgen, addr_type, "r2", static_routes_input) assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) - step("Configure import VRF default on R2 (R2-R3) RED VRF for IPV4 and IPV6 BGP peer") + tc_name, result + ) + step( + "Configure import VRF default on R2 (R2-R3) RED VRF for IPV4 and IPV6 BGP peer" + ) step("Importing the default vrf in non-default VRF ") local_as = "2000" input_import_vrf = { @@ -816,24 +855,20 @@ def test_verify_default_originate_route_with_non_default_VRF_p1(request): "bgp": [ { "local_as": local_as, - "vrf":"RED", + "vrf": "RED", "address_family": { - "ipv4": { - "unicast": {"import": {"vrf": "default" }} - }, - "ipv6": { - "unicast": {"import": {"vrf": "default" }} - } + "ipv4": {"unicast": {"import": {"vrf": "default"}}}, + "ipv6": {"unicast": {"import": {"vrf": "default"}}}, }, } ] } } result = create_router_bgp(tgen, topo, input_import_vrf) - assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) + step( + "Default VR, IPv4 and IPv6 , default-originate, \n static and loopback route are imported to R2 VRF RED table \n, default-originate route coming from VRF red should not active on R2 default VRF table" ) - step("Default VR, IPv4 and IPv6 , default-originate, \n static and loopback route are imported to R2 VRF RED table \n, default-originate route coming from VRF red should not active on R2 default VRF table") for addr_type in ADDR_TYPES: static_routes_input = { "r2": { @@ -841,42 +876,43 @@ def test_verify_default_originate_route_with_non_default_VRF_p1(request): { "network": [NETWORK1_1[addr_type]], "next_hop": NEXT_HOP_IP[addr_type], - "vrf":"RED" - }, { + "vrf": "RED", + }, + { "network": [NETWORK2_1[addr_type]], "next_hop": NEXT_HOP_IP[addr_type], - "vrf":"RED" + "vrf": "RED", }, { "network": [R1_NETWORK_LOOPBACK[addr_type]], "next_hop": R1_NETWORK_LOOPBACK_NXTHOP[addr_type], - "vrf":"RED" + "vrf": "RED", }, { "network": [R1_NETWORK_CONNECTED[addr_type]], "next_hop": R1_NETWORK_CONNECTED_NXTHOP[addr_type], - "vrf":"RED" + "vrf": "RED", }, { "network": [R3_NETWORK_CONNECTED[addr_type]], "next_hop": R3_NETWORK_CONNECTED_NXTHOP[addr_type], - "vrf":"RED" - } + "vrf": "RED", + }, ] } } result = verify_rib(tgen, addr_type, "r2", static_routes_input) assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + tc_name, result + ) result = verify_bgp_rib(tgen, addr_type, "r2", static_routes_input) assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) - - + tc_name, result + ) - STEP=""" After importing defualt VRF into non default vrf . + STEP = """ After importing defualt VRF into non default vrf . verify that the default originate from R1 --> R2(non -default) is preffered over R3 --> R2 because the Default Route prefers iBGP over eBGP over Default Route from R1 Should be present in BGP RIB and FIB @@ -887,60 +923,75 @@ def test_verify_default_originate_route_with_non_default_VRF_p1(request): static_routes_input = { "r2": { "static_routes": [ - { "network": [DEFAULT_ROUTES[addr_type]], "next_hop": DEFAULT_ROUTE_NXT_HOP_R1[addr_type], - "vrf":"RED" + "vrf": "RED", } ] } } - result = verify_rib(tgen, addr_type, "r2", static_routes_input,next_hop=DEFAULT_ROUTE_NXT_HOP_R1[addr_type]) + result = verify_rib( + tgen, + addr_type, + "r2", + static_routes_input, + next_hop=DEFAULT_ROUTE_NXT_HOP_R1[addr_type], + ) assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + tc_name, result + ) static_routes_input = { "r2": { "static_routes": [ - { "network": [DEFAULT_ROUTES[addr_type]], "next_hop": DEFAULT_ROUTE_NXT_HOP_R3[addr_type], - "vrf":"RED" + "vrf": "RED", } ] } } - result = verify_rib(tgen, addr_type, "r2", static_routes_input,next_hop=DEFAULT_ROUTE_NXT_HOP_R3[addr_type],expected =False) + result = verify_rib( + tgen, + addr_type, + "r2", + static_routes_input, + next_hop=DEFAULT_ROUTE_NXT_HOP_R3[addr_type], + expected=False, + ) assert result is not True, "Testcase {} : Failed {} \n Error: {}".format( - tc_name, STEP,result) + tc_name, STEP, result + ) static_routes_input = { "r2": { "static_routes": [ - { "network": [DEFAULT_ROUTES[addr_type]], "next_hop": DEFAULT_ROUTE_NXT_HOP_R1[addr_type], - "vrf":"RED" + "vrf": "RED", }, { "network": [DEFAULT_ROUTES[addr_type]], "next_hop": DEFAULT_ROUTE_NXT_HOP_R3[addr_type], - "vrf":"RED" - } + "vrf": "RED", + }, ] } } result = verify_bgp_rib(tgen, addr_type, "r2", static_routes_input) assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + tc_name, result + ) - step("Remove import VRF configure in step 8 and then remove import VRF configured on step 9") + step( + "Remove import VRF configure in step 8 and then remove import VRF configured on step 9" + ) local_as = get_dut_as_number(tgen, "r2") input_import_vrf = { "r2": { @@ -948,22 +999,15 @@ def test_verify_default_originate_route_with_non_default_VRF_p1(request): { "local_as": local_as, "address_family": { - "ipv4": { - "unicast": {"import": {"vrf": "RED" ,"delete": True}} - }, - "ipv6": { - "unicast": {"import": {"vrf": "RED" ,"delete": True}} - } + "ipv4": {"unicast": {"import": {"vrf": "RED", "delete": True}}}, + "ipv6": {"unicast": {"import": {"vrf": "RED", "delete": True}}}, }, } ] } } result = create_router_bgp(tgen, topo, input_import_vrf) - assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result - ) - + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) step("Verify that the routes imported from non default VRF - RED is removed") DEFAULT_ROUTES = {"ipv4": "0.0.0.0/0", "ipv6": "0::0/0"} @@ -983,43 +1027,51 @@ def test_verify_default_originate_route_with_non_default_VRF_p1(request): { "network": [R3_NETWORK_CONNECTED[addr_type]], "next_hop": R3_NETWORK_CONNECTED_NXTHOP[addr_type], - } + }, ] } } - result = verify_rib(tgen, addr_type, "r2", static_routes_input,expected=False) - assert result is not True, "Testcase {} : Failed \n routes imported from non default VRF is not expected Error: {}".format( - tc_name, result) + result = verify_rib(tgen, addr_type, "r2", static_routes_input, expected=False) + assert ( + result is not True + ), "Testcase {} : Failed \n routes imported from non default VRF is not expected Error: {}".format( + tc_name, result + ) - result = verify_bgp_rib(tgen, addr_type, "r2", static_routes_input,expected=False) - assert result is not True, "Testcase {} : Failed \n routes imported from non default VRF is not expected \nError: {}".format( - tc_name, result) + result = verify_bgp_rib( + tgen, addr_type, "r2", static_routes_input, expected=False + ) + assert ( + result is not True + ), "Testcase {} : Failed \n routes imported from non default VRF is not expected \nError: {}".format( + tc_name, result + ) - step("Remove import VRF configure in step 8 and then remove import VRF configured on step 9") + step( + "Remove import VRF configure in step 8 and then remove import VRF configured on step 9" + ) local_as = "2000" input_import_vrf = { "r2": { "bgp": [ { "local_as": local_as, - "vrf":"RED", + "vrf": "RED", "address_family": { "ipv4": { - "unicast": {"import": {"vrf": "default","delete":True}} + "unicast": {"import": {"vrf": "default", "delete": True}} }, "ipv6": { - "unicast": {"import": {"vrf": "default","delete":True }} - } + "unicast": {"import": {"vrf": "default", "delete": True}} + }, }, } ] } } result = create_router_bgp(tgen, topo, input_import_vrf) - assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result - ) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) step("Verify that the routes impoted from default VRF is removed") DEFAULT_ROUTES = {"ipv4": "0.0.0.0/0", "ipv6": "0::0/0"} @@ -1030,50 +1082,68 @@ def test_verify_default_originate_route_with_non_default_VRF_p1(request): { "network": [NETWORK1_1[addr_type]], "next_hop": NEXT_HOP_IP[addr_type], - "vrf":"RED" + "vrf": "RED", }, { "network": [R1_NETWORK_LOOPBACK[addr_type]], "next_hop": R1_NETWORK_LOOPBACK_NXTHOP[addr_type], - "vrf":"RED" + "vrf": "RED", }, { "network": [R1_NETWORK_CONNECTED[addr_type]], "next_hop": R1_NETWORK_CONNECTED_NXTHOP[addr_type], - "vrf":"RED" - } + "vrf": "RED", + }, ] } } - result = verify_rib(tgen, addr_type, "r2", static_routes_input,expected=False) - assert result is not True, "Testcase {} : Failed \n routes impoted from default VRF is not expected \n Error: {}".format( - tc_name, result) + result = verify_rib(tgen, addr_type, "r2", static_routes_input, expected=False) + assert ( + result is not True + ), "Testcase {} : Failed \n routes impoted from default VRF is not expected \n Error: {}".format( + tc_name, result + ) - result = verify_bgp_rib(tgen, addr_type, "r2", static_routes_input,expected=False) - assert result is not True, "Testcase {} : Failed \n routes impoted from default VRF is not expected \n Error: {}".format( - tc_name, result) + result = verify_bgp_rib( + tgen, addr_type, "r2", static_routes_input, expected=False + ) + assert ( + result is not True + ), "Testcase {} : Failed \n routes impoted from default VRF is not expected \n Error: {}".format( + tc_name, result + ) + + write_test_footer(tc_name) +def test_verify_default_originate_route_with_non_default_VRF_with_route_map_p1(request): + """ + Summary: "Verify default-originate route with non-default VRF with route-map import " + """ + tgen = get_topogen() + global BGP_CONVERGENCE + + if BGP_CONVERGENCE != True: + pytest.skip("skipped because of BGP Convergence failure") + # test case name + tc_name = request.node.name + write_test_header(tc_name) + if tgen.routers_have_failure(): + check_router_status(tgen) + reset_config_on_routers(tgen) + step("Configure IPV4 and IPV6 static route on R0 with Null nexthop") STEP = """ Configure IPV4 and IPV6 EBGP session between R0 and R1 Configure IPV4 and IPV6 static route on R0 with Null nexthop """ step(STEP) input_dict = { - - "r0": { - "bgp": { - "local_as": 222, - } - }, - "r1": { - "bgp": { - "local_as": 333, - } - } + "r0": {"bgp": {"local_as": 222, "vrf": "default"}}, + "r1": {"bgp": {"local_as": 333, "vrf": "default"}}, } result = modify_as_number(tgen, topo, input_dict) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) try: assert result is True except AssertionError: @@ -1082,8 +1152,9 @@ def test_verify_default_originate_route_with_non_default_VRF_p1(request): step("After changing the BGP AS Path Verify the BGP Convergence") BGP_CONVERGENCE = verify_bgp_convergence(tgen, topo) - assert BGP_CONVERGENCE is True, "setup_module :Failed \n Error: {}". \ - format(BGP_CONVERGENCE) + assert BGP_CONVERGENCE is True, "setup_module :Failed \n Error: {}".format( + BGP_CONVERGENCE + ) step("Configuring static route at R0") for addr_type in ADDR_TYPES: @@ -1099,16 +1170,29 @@ def test_verify_default_originate_route_with_non_default_VRF_p1(request): } result = create_static_routes(tgen, static_routes_input) assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) - step( - " Configure re-distribute static on R0 for R0 to R1 for IPV4 and IPV6 peer " - ) + tc_name, result + ) + step(" Configure re-distribute static on R0 for R0 to R1 for IPV4 and IPV6 peer ") redistribute_static = { "r0": { "bgp": { "address_family": { - "ipv4": {"unicast": {"redistribute": [{"redist_type": "static"} ]}}, - "ipv6": {"unicast": {"redistribute": [{"redist_type": "static"} ]}}, + "ipv4": { + "unicast": { + "redistribute": [ + {"redist_type": "static"}, + {"redist_type": "connected"}, + ] + } + }, + "ipv6": { + "unicast": { + "redistribute": [ + {"redist_type": "static"}, + {"redist_type": "connected"}, + ] + } + }, } } } @@ -1116,42 +1200,25 @@ def test_verify_default_originate_route_with_non_default_VRF_p1(request): result = create_router_bgp(tgen, topo, redistribute_static) assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) - step("Configure default-originate on R1 for R1 to R2 neighbor for IPv4 and IPv6 peer") + step( + "Configure default-originate on R1 for R1 to R2 neighbor for IPv4 and IPv6 peer" + ) local_as = get_dut_as_number(tgen, dut="r1") default_originate_config = { "r1": { "bgp": { "local_as": local_as, "address_family": { - "ipv4": { - "unicast": { - "default_originate":{ - "r2":{ - - } - - } - - } - }, "ipv6": { - "unicast": { - "default_originate":{ - "r2":{ - - } - - } - } - } - } + "ipv4": {"unicast": {"default_originate": {"r2": {}}}}, + "ipv6": {"unicast": {"default_originate": {"r2": {}}}}, + }, } } } result = create_router_bgp(tgen, topo, default_originate_config) - assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) - snapshot1 = get_prefix_count_route(tgen, topo, dut="r2", peer="r3",vrf="RED") + snapshot1 = get_prefix_count_route(tgen, topo, dut="r2", peer="r3", vrf="RED") step("Verify IPv4 and IPv6 static received on R2 default VRF as BGP routes") for addr_type in ADDR_TYPES: @@ -1161,10 +1228,11 @@ def test_verify_default_originate_route_with_non_default_VRF_p1(request): { "network": [NETWORK5_1[addr_type]], "next_hop": NEXT_HOP_IP[addr_type], - },{ + }, + { "network": [DEFAULT_ROUTES[addr_type]], "next_hop": DEFAULT_ROUTE_NXT_HOP_R1[addr_type], - } + }, ] } } @@ -1178,117 +1246,102 @@ def test_verify_default_originate_route_with_non_default_VRF_p1(request): assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result ) - step(" Configure IPv4 and IPv6 prefix-list of of route received from R1 on R2 and for 0.0.0.0/0 0::0/0 route") + step( + " Configure IPv4 and IPv6 prefix-list of of route received from R1 on R2 and for 0.0.0.0/0 0::0/0 route" + ) input_dict_3 = { "r2": { "prefix_lists": { "ipv4": { - "Pv4": [{ - "seqid": "1", - "network": NETWORK5_1["ipv4"], - "action": "permit" - }, { - "seqid": "2", - "network": "0.0.0.0/0", - "action": "permit" - }, - { - "seqid": "3", - "network": NETWORK2_1["ipv4"], - "action": "permit" - }] + "Pv4": [ + { + "seqid": "1", + "network": NETWORK5_1["ipv4"], + "action": "permit", + }, + {"seqid": "2", "network": "0.0.0.0/0", "action": "permit"}, + { + "seqid": "3", + "network": NETWORK2_1["ipv4"], + "action": "permit", + }, + ] }, "ipv6": { - "Pv6": [{ - "seqid": "1", - "network": NETWORK5_1["ipv6"], - "action": "permit" - }, + "Pv6": [ { - "seqid": "2", - "network": "0::0/0", - "action": "permit" - }, - + "seqid": "1", + "network": NETWORK5_1["ipv6"], + "action": "permit", + }, + {"seqid": "2", "network": "0::0/0", "action": "permit"}, { - "seqid": "3", - "network": NETWORK2_1["ipv6"], - "action": "permit" - }] - } + "seqid": "3", + "network": NETWORK2_1["ipv6"], + "action": "permit", + }, + ] + }, } } - } result = create_prefix_lists(tgen, input_dict_3) - assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) step("verify IPv4 and IPv6 Prefix list got configured on R3") input_dict = {"r2": {"prefix_lists": ["Pv4", "Pv6"]}} result = verify_prefix_lists(tgen, input_dict) assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) - step("Configure IPv4/IPv6 route-map on R2 with deny sequence using above prefix-list") + step( + "Configure IPv4/IPv6 route-map on R2 with deny sequence using above prefix-list" + ) input_dict_3 = { "r2": { "route_maps": { - "RMv4": [{ - "action": "deny", - 'seq_id': '1', - "match": { - "ipv4": { - "prefix_lists": "Pv4" - } - } - }, + "RMv4": [ + { + "action": "deny", + "seq_id": "1", + "match": {"ipv4": {"prefix_lists": "Pv4"}}, + }, + ], + "RMv6": [ + { + "action": "deny", + "seq_id": "1", + "match": {"ipv6": {"prefix_lists": "Pv6"}}, + }, ], - "RMv6": [{ - "action": "deny", - 'seq_id': '1', - "match": { - "ipv6": { - "prefix_lists": "Pv6" - } - } - }, - ] } } } result = create_route_maps(tgen, input_dict_3) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( - tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) - STEP =""" + STEP = """ import Route-map anf non-default VRF into defailt vrf import vrf route-map RM1 import vrf red """ step(STEP) - local_as=get_dut_as_number(tgen,"r2") + local_as = get_dut_as_number(tgen, "r2") input_import_vrf = { "r2": { "bgp": [ { "local_as": local_as, "address_family": { - "ipv4": { - "unicast": {"import": {"vrf": "RED" }} - }, - "ipv6": { - "unicast": {"import": {"vrf": "RED"}} - } + "ipv4": {"unicast": {"import": {"vrf": "RED"}}}, + "ipv6": {"unicast": {"import": {"vrf": "RED"}}}, }, } ] } } result = create_router_bgp(tgen, topo, input_import_vrf) - assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result - ) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) step(STEP) input_import_vrf = { "r2": { @@ -1296,22 +1349,18 @@ def test_verify_default_originate_route_with_non_default_VRF_p1(request): { "local_as": local_as, "address_family": { - "ipv4": { - "unicast": {"import": {"vrf": "route-map RMv4"}} - }, - "ipv6": { - "unicast": {"import": {"vrf": "route-map RMv6"}} - } + "ipv4": {"unicast": {"import": {"vrf": "route-map RMv4"}}}, + "ipv6": {"unicast": {"import": {"vrf": "route-map RMv6"}}}, }, } ] } } result = create_router_bgp(tgen, topo, input_import_vrf) - assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) + step( + "Verify IPv4 and IPv6 routes present on VRF red ( static , default-originate) should not get advertised to default VRF " ) - step("Verify IPv4 and IPv6 routes present on VRF red ( static , default-originate) should not get advertised to default VRF ") for addr_type in ADDR_TYPES: static_routes_input = { "r2": { @@ -1319,63 +1368,63 @@ def test_verify_default_originate_route_with_non_default_VRF_p1(request): { "network": [NETWORK2_1[addr_type]], "next_hop": NEXT_HOP_IP[addr_type], - },{ + }, + { "network": [DEFAULT_ROUTES[addr_type]], "next_hop": DEFAULT_ROUTE_NXT_HOP_R1[addr_type], - } + }, ] } } - result = verify_rib(tgen, addr_type, "r2", static_routes_input,expected=False) - assert result is not True, "Testcase {} : Failed \n VRF red ( static , default-originate) should not get advertised to default VRF \n Error: {}".format( + result = verify_rib(tgen, addr_type, "r2", static_routes_input, expected=False) + assert ( + result is not True + ), "Testcase {} : Failed \n VRF red ( static , default-originate) should not get advertised to default VRF \n Error: {}".format( tc_name, result ) - result = verify_bgp_rib(tgen, addr_type, "r2", static_routes_input,expected=False) - assert result is not True, "Testcase {} : Failed \n VRF red ( static , default-originate) should not get advertised to default VRF \nError: {}".format( - tc_name, result) + result = verify_bgp_rib( + tgen, addr_type, "r2", static_routes_input, expected=False + ) + assert ( + result is not True + ), "Testcase {} : Failed \n VRF red ( static , default-originate) should not get advertised to default VRF \nError: {}".format( + tc_name, result + ) step("Change route-map sequence deny to permit") input_dict_3 = { "r2": { "route_maps": { - "RMv4": [{ - "action": "permit", - 'seq_id': '1', - "match": { - "ipv4": { - "prefix_lists": "Pv4" - } - } - }, + "RMv4": [ + { + "action": "permit", + "seq_id": "1", + "match": {"ipv4": {"prefix_lists": "Pv4"}}, + }, + ], + "RMv6": [ + { + "action": "permit", + "seq_id": "1", + "match": {"ipv6": {"prefix_lists": "Pv6"}}, + }, ], - "RMv6": [{ - "action": "permit", - 'seq_id': '1', - "match": { - "ipv6": { - "prefix_lists": "Pv6" - } - } - }, - ] } } } result = create_route_maps(tgen, input_dict_3) - assert result is True, 'Testcase {} : Failed \n Error: {}'.format( - tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) - step("IPv4 and IPv6 routes present on VRF red ( static , default-originate) should get advertised to default VRF") + step( + "IPv4 and IPv6 routes present on VRF red ( static , default-originate) should get advertised to default VRF" + ) for addr_type in ADDR_TYPES: static_routes_input = { "r2": { "static_routes": [ { - "network": [NETWORK2_1[addr_type]], - "next_hop": NEXT_HOP_IP[addr_type], - },{ "network": [DEFAULT_ROUTES[addr_type]], "next_hop": DEFAULT_ROUTE_NXT_HOP_R1[addr_type], } @@ -1384,16 +1433,17 @@ def test_verify_default_originate_route_with_non_default_VRF_p1(request): } result = verify_rib(tgen, addr_type, "r2", static_routes_input) - assert result is True, "Testcase {} : Failed \n Error: {}".format( + assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result ) result = verify_bgp_rib(tgen, addr_type, "r2", static_routes_input) - assert result is True, "Testcase {} : Failed \n Error: {}".format( - tc_name, result) + assert result is True, "Testcase {} : Failed \n Error: {}".format( + tc_name, result + ) step("verify Out-prefix count incremented for IPv4/IPv6 default route on VRF red") - snapshot2 = get_prefix_count_route(tgen, topo, dut="r2", peer="r3",vrf="RED") + snapshot2 = get_prefix_count_route(tgen, topo, dut="r2", peer="r3", vrf="RED") step("verifying the prefix count incrementing or not ") isIPv4prefix_incremented = False isIPv6prefix_incremented = False @@ -1407,7 +1457,7 @@ def test_verify_default_originate_route_with_non_default_VRF_p1(request): ), "Testcase {} : Failed Error: IPV4 Prefix is not incremented on receiveing ".format( tc_name ) - write_test_footer(tc_name) + if __name__ == "__main__": args = ["-s"] + sys.argv[1:] diff --git a/tests/topotests/lib/bgp.py b/tests/topotests/lib/bgp.py index 216756f5121e..fa46da6e64b6 100644 --- a/tests/topotests/lib/bgp.py +++ b/tests/topotests/lib/bgp.py @@ -1628,10 +1628,16 @@ def modify_as_number(tgen, topo, input_dict): router_dict = {} for router in input_dict.keys(): # Remove bgp configuration - router_dict.update({router: {"bgp": {"delete": True}}}) - new_topo[router]["bgp"]["local_as"] = input_dict[router]["bgp"]["local_as"] + try: + new_topo[router]["bgp"]["local_as"] = input_dict[router]["bgp"][ + "local_as" + ] + except TypeError: + new_topo[router]["bgp"][0]["local_as"] = input_dict[router]["bgp"][ + "local_as" + ] logger.info("Removing bgp configuration") create_router_bgp(tgen, topo, router_dict)