Merge pull request #7837 from ckishimo/tests_ospf

tests: fix redistribute key in ospf tests
This commit is contained in:
Donald Sharp 2021-01-13 13:31:32 -05:00 committed by GitHub
commit f2aee6967c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 72 additions and 246 deletions

View File

@ -3065,7 +3065,11 @@ def verify_rib(
errormsg = ( errormsg = (
"[DUT: {}]: tag value {}" "[DUT: {}]: tag value {}"
" is not matched for" " is not matched for"
" route {} in RIB \n".format(dut, _tag, st_rt,) " route {} in RIB \n".format(
dut,
_tag,
st_rt,
)
) )
return errormsg return errormsg
@ -3082,7 +3086,11 @@ def verify_rib(
errormsg = ( errormsg = (
"[DUT: {}]: metric value " "[DUT: {}]: metric value "
"{} is not matched for " "{} is not matched for "
"route {} in RIB \n".format(dut, metric, st_rt,) "route {} in RIB \n".format(
dut,
metric,
st_rt,
)
) )
return errormsg return errormsg

View File

@ -62,7 +62,7 @@ def create_router_ospf(tgen, topo, input_dict=None, build=False, load_config=Tru
"r1": { "r1": {
"ospf": { "ospf": {
"router_id": "22.22.22.22", "router_id": "22.22.22.22",
"area": [{ "id":0.0.0.0, "type": "nssa"}] "area": [{ "id": "0.0.0.0", "type": "nssa"}]
} }
} }
@ -327,7 +327,7 @@ def config_ospf_interface(tgen, topo, input_dict=None, build=False, load_config=
"links": { "links": {
"r2": { "r2": {
"ospf": { "ospf": {
"authentication": 'message-digest', "authentication": "message-digest",
"authentication-key": "ospf", "authentication-key": "ospf",
"message-digest-key": "10" "message-digest-key": "10"
} }
@ -376,6 +376,7 @@ def config_ospf_interface(tgen, topo, input_dict=None, build=False, load_config=
if data_ospf_area: if data_ospf_area:
cmd = "ip ospf area {}".format(data_ospf_area) cmd = "ip ospf area {}".format(data_ospf_area)
config_data.append(cmd) config_data.append(cmd)
# interface ospf auth # interface ospf auth
if data_ospf_auth: if data_ospf_auth:
if data_ospf_auth == "null": if data_ospf_auth == "null":
@ -461,6 +462,32 @@ def clear_ospf(tgen, router):
logger.debug("Exiting lib API: clear_ospf()") logger.debug("Exiting lib API: clear_ospf()")
def redistribute_ospf(tgen, topo, dut, route_type, **kwargs):
"""
Redstribution of routes inside ospf.
Parameters
----------
* `tgen`: Topogen object
* `topo` : json file data
* `dut`: device under test
* `route_type`: "static" or "connected" or ....
* `kwargs`: pass extra information (see below)
Usage
-----
redistribute_ospf(tgen, topo, "r0", "static", delete=True)
redistribute_ospf(tgen, topo, "r0", "static", route_map="rmap_ipv4")
"""
ospf_red = {dut: {"ospf": {"redistribute": [{"redist_type": route_type}]}}}
for k, v in kwargs.items():
ospf_red[dut]["ospf"]["redistribute"][0][k] = v
result = create_router_ospf(tgen, topo, ospf_red)
assert result is True, "Testcase : Failed \n Error: {}".format(result)
################################ ################################
# Verification procs # Verification procs
################################ ################################
@ -844,18 +871,22 @@ def verify_ospf_rib(
if "routeType" not in ospf_rib_json[st_rt]: if "routeType" not in ospf_rib_json[st_rt]:
errormsg = ( errormsg = (
"[DUT: {}]: routeType missing" "[DUT: {}]: routeType missing"
"for route {} in OSPF RIB \n".format(dut, st_rt) " for route {} in OSPF RIB \n".format(
dut, st_rt
)
) )
return errormsg return errormsg
elif _rtype != ospf_rib_json[st_rt]["routeType"]: elif _rtype != ospf_rib_json[st_rt]["routeType"]:
errormsg = ( errormsg = (
"[DUT: {}]: routeType mismatch" "[DUT: {}]: routeType mismatch"
"for route {} in OSPF RIB \n".format(dut, st_rt) " for route {} in OSPF RIB \n".format(
dut, st_rt
)
) )
return errormsg return errormsg
else: else:
logger.info( logger.info(
"DUT: {}]: Found routeType {}" "[DUT: {}]: Found routeType {}"
" for route {}".format(dut, _rtype, st_rt) " for route {}".format(dut, _rtype, st_rt)
) )
if tag: if tag:

View File

@ -65,6 +65,7 @@ from lib.ospf import (
verify_ospf_rib, verify_ospf_rib,
create_router_ospf, create_router_ospf,
verify_ospf_interface, verify_ospf_interface,
redistribute_ospf,
) )
topo = None topo = None
@ -184,38 +185,6 @@ def teardown_module(mod):
logger.info("=" * 40) logger.info("=" * 40)
def red_static(dut, config=True):
"""Local def for Redstribute static routes inside ospf."""
global topo
tgen = get_topogen()
if config:
ospf_red = {dut: {"ospf": {"redistribute": [{"redist_type": "static"}]}}}
else:
ospf_red = {
dut: {"ospf": {"redistribute": [{"redist_type": "static", "delete": True}]}}
}
result = create_router_ospf(tgen, topo, ospf_red)
assert result is True, "Testcase : Failed \n Error: {}".format(result)
def red_connected(dut, config=True):
"""Local def for Redstribute connected routes inside ospf."""
global topo
tgen = get_topogen()
if config:
ospf_red = {dut: {"ospf": {"redistribute": [{"redist_type": "connected"}]}}}
else:
ospf_red = {
dut: {
"ospf": {
"redistribute": [{"redist_type": "connected", "del_action": True}]
}
}
}
result = create_router_ospf(tgen, topo, ospf_red)
assert result is True, "Testcase: Failed \n Error: {}".format(result)
# ################################## # ##################################
# Test cases start here. # Test cases start here.
# ################################## # ##################################
@ -264,7 +233,7 @@ def test_ospf_ecmp_tc16_p0(request):
assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
dut = "r0" dut = "r0"
red_static(dut) redistribute_ospf(tgen, topo, dut, "static")
step("Verify that route in R2 in stalled with 8 next hops.") step("Verify that route in R2 in stalled with 8 next hops.")
nh = [] nh = []
@ -345,7 +314,7 @@ def test_ospf_ecmp_tc16_p0(request):
step(" Un configure static route on R0") step(" Un configure static route on R0")
dut = "r0" dut = "r0"
red_static(dut, config=False) redistribute_ospf(tgen, topo, dut, "static", delete=True)
# Wait for R0 to flush external LSAs. # Wait for R0 to flush external LSAs.
sleep(10) sleep(10)
@ -376,7 +345,7 @@ def test_ospf_ecmp_tc16_p0(request):
step("Re configure the static route in R0.") step("Re configure the static route in R0.")
dut = "r0" dut = "r0"
red_static(dut) redistribute_ospf(tgen, topo, dut, "static")
dut = "r1" dut = "r1"
result = verify_ospf_rib(tgen, dut, input_dict, next_hop=nh) result = verify_ospf_rib(tgen, dut, input_dict, next_hop=nh)
@ -431,7 +400,7 @@ def test_ospf_ecmp_tc17_p0(request):
assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
dut = "r0" dut = "r0"
red_static(dut) redistribute_ospf(tgen, topo, dut, "static")
step("Verify that route in R2 in stalled with 2 next hops.") step("Verify that route in R2 in stalled with 2 next hops.")
@ -450,7 +419,7 @@ def test_ospf_ecmp_tc17_p0(request):
step(" Un configure static route on R0") step(" Un configure static route on R0")
dut = "r0" dut = "r0"
red_static(dut, config=False) redistribute_ospf(tgen, topo, dut, "static", delete=True)
# sleep till the route gets withdrawn # sleep till the route gets withdrawn
sleep(10) sleep(10)
@ -480,7 +449,7 @@ def test_ospf_ecmp_tc17_p0(request):
step("Reconfigure the static route in R0.Change ECMP value to 2.") step("Reconfigure the static route in R0.Change ECMP value to 2.")
dut = "r0" dut = "r0"
red_static(dut) redistribute_ospf(tgen, topo, dut, "static")
step("Configure cost on R0 as 100") step("Configure cost on R0 as 100")
r0_ospf_cost = {"r0": {"links": {"r1": {"ospf": {"cost": 100}}}}} r0_ospf_cost = {"r0": {"links": {"r1": {"ospf": {"cost": 100}}}}}

View File

@ -66,6 +66,7 @@ from lib.ospf import (
verify_ospf_rib, verify_ospf_rib,
create_router_ospf, create_router_ospf,
verify_ospf_interface, verify_ospf_interface,
redistribute_ospf,
) )
from ipaddress import IPv4Address from ipaddress import IPv4Address
@ -187,42 +188,6 @@ def teardown_module():
pass pass
def red_static(dut, config=True):
"""Local def for Redstribute static routes inside ospf."""
global topo
tgen = get_topogen()
if config:
ospf_red = {dut: {"ospf": {"redistribute": [{"redist_type": "static"}]}}}
else:
ospf_red = {
dut: {
"ospf": {
"redistribute": [{"redist_type": "static", "del_action": True}]
}
}
}
result = create_router_ospf(tgen, topo, ospf_red)
assert result is True, "Testcase : Failed \n Error: {}".format(result)
def red_connected(dut, config=True):
"""Local def for Redstribute connected routes inside ospf."""
global topo
tgen = get_topogen()
if config:
ospf_red = {dut: {"ospf": {"redistribute": [{"redist_type": "connected"}]}}}
else:
ospf_red = {
dut: {
"ospf": {
"redistribute": [{"redist_type": "connected", "del_action": True}]
}
}
}
result = create_router_ospf(tgen, topo, ospf_red)
assert result is True, "Testcase: Failed \n Error: {}".format(result)
# ################################## # ##################################
# Test cases start here. # Test cases start here.
# ################################## # ##################################
@ -275,7 +240,7 @@ def test_ospf_lan_ecmp_tc18_p0(request):
) )
dut = rtr dut = rtr
red_static(dut) redistribute_ospf(tgen, topo, dut, "static")
step( step(
"Verify that route in R0 in stalled with 8 hops. " "Verify that route in R0 in stalled with 8 hops. "

View File

@ -183,42 +183,6 @@ def teardown_module():
pass pass
def red_static(dut, config=True):
"""Local def for Redstribute static routes inside ospf."""
global topo
tgen = get_topogen()
if config:
ospf_red = {dut: {"ospf": {"redistribute": [{"redist_type": "static"}]}}}
else:
ospf_red = {
dut: {
"ospf": {
"redistribute": [{"redist_type": "static", "del_action": True}]
}
}
}
result = create_router_ospf(tgen, topo, ospf_red)
assert result is True, "Testcase : Failed \n Error: {}".format(result)
def red_connected(dut, config=True):
"""Local def for Redstribute connected routes inside ospf."""
global topo
tgen = get_topogen()
if config:
ospf_red = {dut: {"ospf": {"redistribute": [{"redist_type": "connected"}]}}}
else:
ospf_red = {
dut: {
"ospf": {
"redistribute": [{"redist_type": "connected", "del_action": True}]
}
}
}
result = create_router_ospf(tgen, topo, ospf_red)
assert result is True, "Testcase: Failed \n Error: {}".format(result)
# ################################## # ##################################
# Test cases start here. # Test cases start here.
# ################################## # ##################################

View File

@ -30,6 +30,7 @@ from lib.ospf import (
verify_ospf_rib, verify_ospf_rib,
create_router_ospf, create_router_ospf,
verify_ospf_interface, verify_ospf_interface,
redistribute_ospf,
) )
from lib.topojson import build_topo_from_json, build_config_from_json from lib.topojson import build_topo_from_json, build_config_from_json
from lib.topolog import logger from lib.topolog import logger
@ -181,38 +182,6 @@ def teardown_module(mod):
logger.info("=" * 40) logger.info("=" * 40)
def red_static(dut, config=True):
"""Local def for Redstribute static routes inside ospf."""
global topo
tgen = get_topogen()
if config:
ospf_red = {dut: {"ospf": {"redistribute": [{"redist_type": "static"}]}}}
else:
ospf_red = {
dut: {"ospf": {"redistribute": [{"redist_type": "static", "delete": True}]}}
}
result = create_router_ospf(tgen, topo, ospf_red)
assert result is True, "Testcase : Failed \n Error: {}".format(result)
def red_connected(dut, config=True):
"""Local def for Redstribute connected routes inside ospf."""
global topo
tgen = get_topogen()
if config:
ospf_red = {dut: {"ospf": {"redistribute": [{"redist_type": "connected"}]}}}
else:
ospf_red = {
dut: {
"ospf": {
"redistribute": [{"redist_type": "connected", "del_action": True}]
}
}
}
result = create_router_ospf(tgen, topo, ospf_red)
assert result is True, "Testcase: Failed \n Error: {}".format(result)
# ################################## # ##################################
# Test cases start here. # Test cases start here.
# ################################## # ##################################
@ -268,7 +237,7 @@ def test_ospf_learning_tc15_p0(request):
step("Redistribute static route in R2 ospf.") step("Redistribute static route in R2 ospf.")
dut = "r2" dut = "r2"
red_static(dut) redistribute_ospf(tgen, topo, dut, "static")
step("Verify that Type 5 LSA is originated by R2.") step("Verify that Type 5 LSA is originated by R2.")
dut = "r0" dut = "r0"

View File

@ -62,6 +62,7 @@ from lib.ospf import (
verify_ospf_rib, verify_ospf_rib,
create_router_ospf, create_router_ospf,
verify_ospf_database, verify_ospf_database,
redistribute_ospf,
) )
# Global variables # Global variables
@ -226,9 +227,7 @@ def test_ospf_routemaps_functionality_tc19_p0(request):
result = create_static_routes(tgen, input_dict) result = create_static_routes(tgen, input_dict)
assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
ospf_red_r1 = {"r0": {"ospf": {"redistribute": [{"redist_type": "static"}]}}} redistribute_ospf(tgen, topo, "r0", "static")
result = create_router_ospf(tgen, topo, ospf_red_r1)
assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
dut = "r1" dut = "r1"
lsid = NETWORK["ipv4"][0].split("/")[0] lsid = NETWORK["ipv4"][0].split("/")[0]
@ -240,13 +239,7 @@ def test_ospf_routemaps_functionality_tc19_p0(request):
result = verify_rib(tgen, "ipv4", dut, input_dict, protocol=protocol) result = verify_rib(tgen, "ipv4", dut, input_dict, protocol=protocol)
assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
ospf_red_r1 = { redistribute_ospf(tgen, topo, "r0", "static", delete=True)
"r0": {
"ospf": {"redistribute": [{"redist_type": "static", "del_action": True}]}
}
}
result = create_router_ospf(tgen, topo, ospf_red_r1)
assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
step( step(
"Create prefix-list in R0 to permit 10.0.20.1/32 prefix &" " deny 10.0.20.2/32" "Create prefix-list in R0 to permit 10.0.20.1/32 prefix &" " deny 10.0.20.2/32"
@ -293,15 +286,7 @@ def test_ospf_routemaps_functionality_tc19_p0(request):
" ospf using route map rmap1" " ospf using route map rmap1"
) )
ospf_red_r1 = { redistribute_ospf(tgen, topo, "r0", "static", route_map="rmap_ipv4")
"r0": {
"ospf": {
"redistribute": [{"redist_type": "static", "route_map": "rmap_ipv4"}]
}
}
}
result = create_router_ospf(tgen, topo, ospf_red_r1)
assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
step("Change prefix rules to permit 10.0.20.2 and deny 10.0.20.1") step("Change prefix rules to permit 10.0.20.2 and deny 10.0.20.1")
# Create ip prefix list # Create ip prefix list
@ -495,15 +480,7 @@ def test_ospf_routemaps_functionality_tc20_p0(request):
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("Redistribute to ospf using route map ( non existent route map)") step("Redistribute to ospf using route map ( non existent route map)")
ospf_red_r1 = { redistribute_ospf(tgen, topo, "r0", "static", route_map="rmap_ipv4")
"r0": {
"ospf": {
"redistribute": [{"redist_type": "static", "route_map": "rmap_ipv4"}]
}
}
}
result = create_router_ospf(tgen, topo, ospf_red_r1)
assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
step( step(
"Verify that routes are not allowed in OSPF even tough no " "Verify that routes are not allowed in OSPF even tough no "
@ -633,15 +610,7 @@ def test_ospf_routemaps_functionality_tc21_p0(request):
result = create_static_routes(tgen, input_dict) result = create_static_routes(tgen, input_dict)
assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
ospf_red_r0 = { redistribute_ospf(tgen, topo, "r0", "static", route_map="rmap_ipv4")
"r0": {
"ospf": {
"redistribute": [{"redist_type": "static", "route_map": "rmap_ipv4"}]
}
}
}
result = create_router_ospf(tgen, topo, ospf_red_r0)
assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
# Create route map # Create route map
routemaps = { routemaps = {
@ -877,15 +846,7 @@ def test_ospf_routemaps_functionality_tc24_p0(request):
result = create_static_routes(tgen, input_dict) result = create_static_routes(tgen, input_dict)
assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
ospf_red_r0 = { redistribute_ospf(tgen, topo, "r0", "static", route_map="rmap_ipv4")
"r0": {
"ospf": {
"redistribute": [{"redist_type": "static", "route_map": "rmap_ipv4"}]
}
}
}
result = create_router_ospf(tgen, topo, ospf_red_r0)
assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
# Create ip prefix list # Create ip prefix list
pfx_list = { pfx_list = {

View File

@ -61,6 +61,7 @@ from lib.ospf import (
clear_ospf, clear_ospf,
verify_ospf_rib, verify_ospf_rib,
create_router_ospf, create_router_ospf,
redistribute_ospf,
) )
# Global variables # Global variables
@ -183,42 +184,6 @@ def teardown_module(mod):
logger.info("=" * 40) logger.info("=" * 40)
def red_static(dut, config=True):
"""Local def for Redstribute static routes inside ospf."""
global topo
tgen = get_topogen()
if config:
ospf_red = {dut: {"ospf": {"redistribute": [{"redist_type": "static"}]}}}
else:
ospf_red = {
dut: {
"ospf": {
"redistribute": [{"redist_type": "static", "del_action": True}]
}
}
}
result = create_router_ospf(tgen, topo, ospf_red)
assert result is True, "Testcase : Failed \n Error: {}".format(result)
def red_connected(dut, config=True):
"""Local def for Redstribute connected routes inside ospf."""
global topo
tgen = get_topogen()
if config:
ospf_red = {dut: {"ospf": {"redistribute": [{"redist_type": "connected"}]}}}
else:
ospf_red = {
dut: {
"ospf": {
"redistribute": [{"redist_type": "connected", "del_action": True}]
}
}
}
result = create_router_ospf(tgen, topo, ospf_red)
assert result is True, "Testcase: Failed \n Error: {}".format(result)
# ################################## # ##################################
# Test cases start here. # Test cases start here.
# ################################## # ##################################
@ -486,8 +451,8 @@ def test_ospf_redistribution_tc8_p1(request):
"advertised/exchaged via ospf" "advertised/exchaged via ospf"
) )
for rtr in topo["routers"]: for rtr in topo["routers"]:
red_static(rtr) redistribute_ospf(tgen, topo, rtr, "static")
red_connected(rtr) redistribute_ospf(tgen, topo, rtr, "connected")
for node in topo["routers"]: for node in topo["routers"]:
input_dict = { input_dict = {
"r0": { "r0": {
@ -544,13 +509,7 @@ def test_ospf_redistribution_tc8_p1(request):
) )
for rtr in topo["routers"]: for rtr in topo["routers"]:
ospf_red = { redistribute_ospf(tgen, topo, rtr, "static", delete=True)
rtr: {"ospf": {"redistribute": [{"redist_type": "static", "delete": True}]}}
}
result = create_router_ospf(tgen, topo, ospf_red)
assert result is True, "Testcase {} : Failed \n Error: {}".format(
tc_name, result
)
input_dict = { input_dict = {
"r0": { "r0": {