Merge pull request #6533 from opensourcerouting/topofixes

topotests: stabilize ospf-sr-topo1
This commit is contained in:
Donald Sharp 2020-06-09 10:29:18 -04:00 committed by GitHub
commit 0da93db878
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 91 additions and 116 deletions

View File

@ -113,32 +113,32 @@
"extendedLink":[ "extendedLink":[
{ {
"prefix":"10.0.0.1\/32", "prefix":"10.0.0.1\/32",
"sid":"XX", "sid":"*",
"inputLabel":"XX", "inputLabel":"*",
"outputLabel":3, "outputLabel":3,
"interface":"r1-eth0", "interface":"r1-eth0",
"nexthop":"10.0.0.2" "nexthop":"10.0.0.2"
}, },
{ {
"prefix":"10.0.0.1\/32", "prefix":"10.0.0.1\/32",
"sid":"XX", "sid":"*",
"inputLabel":"XX", "inputLabel":"*",
"outputLabel":3, "outputLabel":3,
"interface":"r1-eth0", "interface":"r1-eth0",
"nexthop":"10.0.0.2" "nexthop":"10.0.0.2"
}, },
{ {
"prefix":"10.0.1.1\/32", "prefix":"10.0.1.1\/32",
"sid":"XX", "sid":"*",
"inputLabel":"XX", "inputLabel":"*",
"outputLabel":3, "outputLabel":3,
"interface":"r1-eth1", "interface":"r1-eth1",
"nexthop":"10.0.1.2" "nexthop":"10.0.1.2"
}, },
{ {
"prefix":"10.0.1.1\/32", "prefix":"10.0.1.1\/32",
"sid":"XX", "sid":"*",
"inputLabel":"XX", "inputLabel":"*",
"outputLabel":3, "outputLabel":3,
"interface":"r1-eth1", "interface":"r1-eth1",
"nexthop":"10.0.1.2" "nexthop":"10.0.1.2"

View File

@ -71,8 +71,8 @@
} }
] ]
}, },
"XX":{ "label-1":{
"inLabel":"XX", "inLabel":"*",
"installed":true, "installed":true,
"nexthops":[ "nexthops":[
{ {
@ -84,8 +84,8 @@
} }
] ]
}, },
"XX":{ "label-2":{
"inLabel":"XX", "inLabel":"*",
"installed":true, "installed":true,
"nexthops":[ "nexthops":[
{ {
@ -97,8 +97,8 @@
} }
] ]
}, },
"XX":{ "label-3":{
"inLabel":"XX", "inLabel":"*",
"installed":true, "installed":true,
"nexthops":[ "nexthops":[
{ {
@ -110,8 +110,8 @@
} }
] ]
}, },
"XX":{ "label-4":{
"inLabel":"XX", "inLabel":"*",
"installed":true, "installed":true,
"nexthops":[ "nexthops":[
{ {

View File

@ -27,64 +27,64 @@
"extendedLink":[ "extendedLink":[
{ {
"prefix":"10.0.4.2\/32", "prefix":"10.0.4.2\/32",
"sid":"XX", "sid":"*",
"inputLabel":"XX", "inputLabel":"*",
"outputLabel":3, "outputLabel":3,
"interface":"r2-eth3", "interface":"r2-eth3",
"nexthop":"10.0.4.1" "nexthop":"10.0.4.1"
}, },
{ {
"prefix":"10.0.4.2\/32", "prefix":"10.0.4.2\/32",
"sid":"XX", "sid":"*",
"inputLabel":"XX", "inputLabel":"*",
"outputLabel":3, "outputLabel":3,
"interface":"r2-eth3", "interface":"r2-eth3",
"nexthop":"10.0.4.1" "nexthop":"10.0.4.1"
}, },
{ {
"prefix":"10.0.0.2\/32", "prefix":"10.0.0.2\/32",
"sid":"XX", "sid":"*",
"inputLabel":"XX", "inputLabel":"*",
"outputLabel":3, "outputLabel":3,
"interface":"r2-eth0", "interface":"r2-eth0",
"nexthop":"10.0.0.1" "nexthop":"10.0.0.1"
}, },
{ {
"prefix":"10.0.0.2\/32", "prefix":"10.0.0.2\/32",
"sid":"XX", "sid":"*",
"inputLabel":"XX", "inputLabel":"*",
"outputLabel":3, "outputLabel":3,
"interface":"r2-eth0", "interface":"r2-eth0",
"nexthop":"10.0.0.1" "nexthop":"10.0.0.1"
}, },
{ {
"prefix":"10.0.1.2\/32", "prefix":"10.0.1.2\/32",
"sid":"XX", "sid":"*",
"inputLabel":"XX", "inputLabel":"*",
"outputLabel":3, "outputLabel":3,
"interface":"r2-eth1", "interface":"r2-eth1",
"nexthop":"10.0.1.1" "nexthop":"10.0.1.1"
}, },
{ {
"prefix":"10.0.1.2\/32", "prefix":"10.0.1.2\/32",
"sid":"XX", "sid":"*",
"inputLabel":"XX", "inputLabel":"*",
"outputLabel":3, "outputLabel":3,
"interface":"r2-eth1", "interface":"r2-eth1",
"nexthop":"10.0.1.1" "nexthop":"10.0.1.1"
}, },
{ {
"prefix":"10.0.3.2\/32", "prefix":"10.0.3.2\/32",
"sid":"XX", "sid":"*",
"inputLabel":"XX", "inputLabel":"*",
"outputLabel":3, "outputLabel":3,
"interface":"r2-eth2", "interface":"r2-eth2",
"nexthop":"10.0.3.1" "nexthop":"10.0.3.1"
}, },
{ {
"prefix":"10.0.3.2\/32", "prefix":"10.0.3.2\/32",
"sid":"XX", "sid":"*",
"inputLabel":"XX", "inputLabel":"*",
"outputLabel":3, "outputLabel":3,
"interface":"r2-eth2", "interface":"r2-eth2",
"nexthop":"10.0.3.1" "nexthop":"10.0.3.1"

View File

@ -45,8 +45,8 @@
} }
] ]
}, },
"XX":{ "label-1":{
"inLabel":"XX", "inLabel":"*",
"installed":true, "installed":true,
"nexthops":[ "nexthops":[
{ {
@ -58,8 +58,8 @@
} }
] ]
}, },
"XX":{ "label-2":{
"inLabel":"XX", "inLabel":"*",
"installed":true, "installed":true,
"nexthops":[ "nexthops":[
{ {
@ -71,8 +71,8 @@
} }
] ]
}, },
"XX":{ "label-3":{
"inLabel":"XX", "inLabel":"*",
"installed":true, "installed":true,
"nexthops":[ "nexthops":[
{ {
@ -84,8 +84,8 @@
} }
] ]
}, },
"XX":{ "label-4":{
"inLabel":"XX", "inLabel":"*",
"installed":true, "installed":true,
"nexthops":[ "nexthops":[
{ {
@ -97,8 +97,8 @@
} }
] ]
}, },
"XX":{ "label-5":{
"inLabel":"XX", "inLabel":"*",
"installed":true, "installed":true,
"nexthops":[ "nexthops":[
{ {
@ -110,8 +110,8 @@
} }
] ]
}, },
"XX":{ "label-6":{
"inLabel":"XX", "inLabel":"*",
"installed":true, "installed":true,
"nexthops":[ "nexthops":[
{ {
@ -123,8 +123,8 @@
} }
] ]
}, },
"XX":{ "label-7":{
"inLabel":"XX", "inLabel":"*",
"installed":true, "installed":true,
"nexthops":[ "nexthops":[
{ {
@ -136,8 +136,8 @@
} }
] ]
}, },
"XX":{ "label-8":{
"inLabel":"XX", "inLabel":"*",
"installed":true, "installed":true,
"nexthops":[ "nexthops":[
{ {

View File

@ -77,16 +77,16 @@
"extendedLink":[ "extendedLink":[
{ {
"prefix":"10.0.3.1\/32", "prefix":"10.0.3.1\/32",
"sid":"XX", "sid":"*",
"inputLabel":"XX", "inputLabel":"*",
"outputLabel":3, "outputLabel":3,
"interface":"r3-eth0", "interface":"r3-eth0",
"nexthop":"10.0.3.2" "nexthop":"10.0.3.2"
}, },
{ {
"prefix":"10.0.3.1\/32", "prefix":"10.0.3.1\/32",
"sid":"XX", "sid":"*",
"inputLabel":"XX", "inputLabel":"*",
"outputLabel":3, "outputLabel":3,
"interface":"r3-eth0", "interface":"r3-eth0",
"nexthop":"10.0.3.2" "nexthop":"10.0.3.2"

View File

@ -38,8 +38,8 @@
} }
] ]
}, },
"XX":{ "label-1":{
"inLabel":"XX", "inLabel":"*",
"installed":true, "installed":true,
"nexthops":[ "nexthops":[
{ {
@ -51,8 +51,8 @@
} }
] ]
}, },
"XX":{ "label-2":{
"inLabel":"XX", "inLabel":"*",
"installed":true, "installed":true,
"nexthops":[ "nexthops":[
{ {

View File

@ -49,16 +49,16 @@
"extendedLink":[ "extendedLink":[
{ {
"prefix":"10.0.4.1\/32", "prefix":"10.0.4.1\/32",
"sid":"XX", "sid":"*",
"inputLabel":"XX", "inputLabel":"*",
"outputLabel":3, "outputLabel":3,
"interface":"r4-eth0", "interface":"r4-eth0",
"nexthop":"10.0.4.2" "nexthop":"10.0.4.2"
}, },
{ {
"prefix":"10.0.4.1\/32", "prefix":"10.0.4.1\/32",
"sid":"XX", "sid":"*",
"inputLabel":"XX", "inputLabel":"*",
"outputLabel":3, "outputLabel":3,
"interface":"r4-eth0", "interface":"r4-eth0",
"nexthop":"10.0.4.2" "nexthop":"10.0.4.2"

View File

@ -50,8 +50,8 @@
} }
] ]
}, },
"XX":{ "label-1":{
"inLabel":"XX", "inLabel":"*",
"installed":true, "installed":true,
"nexthops":[ "nexthops":[
{ {
@ -63,8 +63,8 @@
} }
] ]
}, },
"XX":{ "label-2":{
"inLabel":"XX", "inLabel":"*",
"installed":true, "installed":true,
"nexthops":[ "nexthops":[
{ {

View File

@ -29,6 +29,7 @@ test_ospf_sr_topo1.py: Test the FRR OSPF routing daemon with Segment Routing.
import os import os
import re import re
import sys import sys
import json
from functools import partial from functools import partial
# Save the Current Working Directory to find configuration files. # Save the Current Working Directory to find configuration files.
@ -103,19 +104,6 @@ def setup_module(mod):
# Initialize all routers. # Initialize all routers.
tgen.start_router() tgen.start_router()
# Verify that version, MPLS and Segment Routing are OK
for router in router_list.values():
# Check for Version
if router.has_version("<", "4"):
tgen.set_error("Unsupported FRR version")
break
# Check that Segment Routing is available
output = tgen.gears[router.name].vtysh_cmd(
"show ip ospf database segment-routing json"
)
if output.find("Unknown") != -1:
tgen.set_error("Segment Routing is not available")
def teardown_module(mod): def teardown_module(mod):
"Teardown the pytest environment" "Teardown the pytest environment"
@ -126,37 +114,6 @@ def teardown_module(mod):
logger.info("\n\n---- OSPF Segment Routing tests End ----\n") logger.info("\n\n---- OSPF Segment Routing tests End ----\n")
# Shared test function to validate expected output.
def compare_ospf_srdb(rname, expected):
"""
Calls 'show ip ospf database segment-routing json' for router `rname`
and compare the obtained result with the expected output.
"""
tgen = get_topogen()
current = tgen.gears[rname].vtysh_cmd("show ip ospf database segment-routing json")
# Filter Adjacency SID allocation
current = re.sub(r'"sid":5000[0-9],', '"sid":"XX",', current)
current = re.sub(r'"inputLabel":5000[0-9],', '"inputLabel":"XX",', current)
return topotest.difflines(
current, expected, title1="Current output", title2="Expected output"
)
def compare_mpls_table(rname, expected):
"""
Calls 'show mpls table json' for router `rname` and compare the obtained
result with the expected output.
"""
tgen = get_topogen()
current = tgen.gears[rname].vtysh_cmd("show mpls table json")
# Filter Adjacency SID allocation
current = re.sub(r'"5000[0-9]":', '"XX":', current)
current = re.sub(r'"inLabel":5000[0-9],', '"inLabel":"XX",', current)
return topotest.difflines(
current, expected, title1="Current output", title2="Expected output"
)
def test_ospf_sr(): def test_ospf_sr():
"Test OSPF daemon Segment Routing" "Test OSPF daemon Segment Routing"
tgen = get_topogen() tgen = get_topogen()
@ -172,12 +129,15 @@ def test_ospf_sr():
# Load expected results from the command # Load expected results from the command
reffile = os.path.join(CWD, "{}/ospf_srdb.json".format(router)) reffile = os.path.join(CWD, "{}/ospf_srdb.json".format(router))
expected = open(reffile).read() expected = json.loads(open(reffile).read())
# Run test function until we get an result. Wait at most 60 seconds. # Run test function until we get an result. Wait at most 60 seconds.
test_func = partial(compare_ospf_srdb, router, expected) rt = tgen.gears[router]
result, diff = topotest.run_and_expect(test_func, "", count=25, wait=3) test_func = partial(
assert result, ("OSPF did not start Segment Routing on {}:\n{}").format( topotest.router_json_cmp, rt, 'show ip ospf database segment-routing json', expected
)
rv, diff = topotest.run_and_expect(test_func, None, count=25, wait=3)
assert rv, "OSPF did not start Segment Routing on {}:\n{}".format(
router, diff router, diff
) )
@ -190,6 +150,20 @@ def test_ospf_kernel_route():
logger.info("--- test OSPF Segment Routing MPLS tables ---") logger.info("--- test OSPF Segment Routing MPLS tables ---")
def show_mpls_table_json_cmp(rt, expected):
"Removes random label and use `label-X` instead."
text = rt.vtysh_cmd('show mpls table json')
# Substitue random labels with fixed label value.
for label in range(1, 10):
text = re.sub(r'"5000[0-9]"', '"label-{}"'.format(label), text,
count=1)
print '\n{}\n'.format(text)
output = json.loads(text)
return topotest.json_cmp(output, expected)
for rnum in range(1, 5): for rnum in range(1, 5):
router = "r{}".format(rnum) router = "r{}".format(rnum)
@ -197,12 +171,13 @@ def test_ospf_kernel_route():
# Load expected results from the command # Load expected results from the command
reffile = os.path.join(CWD, "{}/zebra_mpls.json".format(router)) reffile = os.path.join(CWD, "{}/zebra_mpls.json".format(router))
expected = open(reffile).read() expected = json.loads(open(reffile).read())
# Run test function until we get an result. Wait at most 60 seconds. # Run test function until we get an result. Wait at most 60 seconds.
test_func = partial(compare_mpls_table, router, expected) rt = tgen.gears[router]
result, diff = topotest.run_and_expect(test_func, "", count=25, wait=3) test_func = partial(show_mpls_table_json_cmp, rt, expected)
assert result, ("OSPF did not properly instal MPLS table on {}:\n{}").format( rv, diff = topotest.run_and_expect(test_func, None, count=25, wait=3)
assert rv, "OSPF did not properly instal MPLS table on {}:\n{}".format(
router, diff router, diff
) )