bgp: tolerate route-table-show header changes of PR 2045

The table header has changed slightly for "bgp show" commands. Change
all-protocol-startup (test_bgp_ipv4() and test_bgp_ipv6()) and
bgp_multiview_topo1 (test_bgp_routingTable())  to run diffs against multiple
templates (representing the various valid outputs for different versions
of the FRR code) and mark the test "passed" if any one template matches.

Signed-off-by: G. Paul Ziemba <paulz@labn.net>
This commit is contained in:
G. Paul Ziemba 2018-04-21 10:23:54 -07:00 committed by Donald Sharp
parent e4992f04e0
commit 6a57e10314
7 changed files with 245 additions and 84 deletions

View File

@ -0,0 +1,8 @@
BGP table version is 1, local router ID is 192.168.0.1, vrf id 0
Status codes: s suppressed, d damped, h history, * valid, > best, = multipath,
i internal, r RIB-failure, S Stale, R Removed
Nexthop codes: @NNN nexthop's vrf id, < announce-nh-self
Origin codes: i - IGP, e - EGP, ? - incomplete
Network Next Hop Metric LocPrf Weight Path
*> 192.168.0.0 0.0.0.0 0 32768 i

View File

@ -0,0 +1,8 @@
BGP table version is 1, local router ID is 192.168.0.1, vrf id 0
Status codes: s suppressed, d damped, h history, * valid, > best, = multipath,
i internal, r RIB-failure, S Stale, R Removed
Nexthop codes: @NNN nexthop's vrf id, < announce-nh-self
Origin codes: i - IGP, e - EGP, ? - incomplete
Network Next Hop Metric LocPrf Weight Path
*> fc00::/64 :: 0 32768 i

View File

@ -31,6 +31,7 @@ import os
import re import re
import sys import sys
import pytest import pytest
import glob
from time import sleep from time import sleep
from mininet.topo import Topo from mininet.topo import Topo
@ -699,37 +700,47 @@ def test_bgp_ipv4():
print("\n\n** Verifying BGP IPv4") print("\n\n** Verifying BGP IPv4")
print("******************************************\n") print("******************************************\n")
failures = 0 diffresult = {}
for i in range(1, 2): for i in range(1, 2):
refTableFile = '%s/r%s/show_bgp_ipv4.ref' % (thisDir, i) success = 0
if os.path.isfile(refTableFile): for refTableFile in (glob.glob(
# Read expected result from file '%s/r%s/show_bgp_ipv4*.ref' % (thisDir, i))):
expected = open(refTableFile).read().rstrip() if os.path.isfile(refTableFile):
# Fix newlines (make them all the same) # Read expected result from file
expected = ('\n'.join(expected.splitlines()) + '\n').splitlines(1) expected = open(refTableFile).read().rstrip()
# Fix newlines (make them all the same)
expected = ('\n'.join(expected.splitlines()) + '\n').splitlines(1)
# Actual output from router # Actual output from router
actual = net['r%s' % i].cmd('vtysh -c "show bgp ipv4" 2> /dev/null').rstrip() actual = net['r%s' % i].cmd('vtysh -c "show bgp ipv4" 2> /dev/null').rstrip()
# Remove summary line (changed recently) # Remove summary line (changed recently)
actual = re.sub(r'Total number.*', '', actual) actual = re.sub(r'Total number.*', '', actual)
actual = re.sub(r'Displayed.*', '', actual) actual = re.sub(r'Displayed.*', '', actual)
actual = actual.rstrip() actual = actual.rstrip()
# Fix newlines (make them all the same) # Fix newlines (make them all the same)
actual = ('\n'.join(actual.splitlines()) + '\n').splitlines(1) actual = ('\n'.join(actual.splitlines()) + '\n').splitlines(1)
# Generate Diff # Generate Diff
diff = topotest.get_textdiff(actual, expected, diff = topotest.get_textdiff(actual, expected,
title1="actual SHOW BGP IPv4", title1="actual SHOW BGP IPv4",
title2="expected SHOW BGP IPv4") title2="expected SHOW BGP IPv4")
# Empty string if it matches, otherwise diff contains unified diff # Empty string if it matches, otherwise diff contains unified diff
if diff: if diff:
sys.stderr.write('r%s failed SHOW BGP IPv4 check:\n%s\n' % (i, diff)) diffresult[refTableFile] = diff
failures += 1 else:
else: success = 1
print("r%s ok" % i) print("template %s matched: r%s ok" % (refTableFile, i))
break
assert failures == 0, "SHOW BGP IPv4 failed for router r%s:\n%s" % (i, diff) if not success:
resultstr = 'No template matched.\n'
for f in diffresult.iterkeys():
resultstr += (
'template %s: r%s failed SHOW BGP IPv4 check:\n%s\n'
% (f, i, diffresult[f]))
raise AssertionError(
"SHOW BGP IPv4 failed for router r%s:\n%s" % (i, resultstr))
# Make sure that all daemons are running # Make sure that all daemons are running
for i in range(1, 2): for i in range(1, 2):
@ -752,37 +763,46 @@ def test_bgp_ipv6():
print("\n\n** Verifying BGP IPv6") print("\n\n** Verifying BGP IPv6")
print("******************************************\n") print("******************************************\n")
failures = 0 diffresult = {}
for i in range(1, 2): for i in range(1, 2):
refTableFile = '%s/r%s/show_bgp_ipv6.ref' % (thisDir, i) success = 0
if os.path.isfile(refTableFile): for refTableFile in (glob.glob(
# Read expected result from file '%s/r%s/show_bgp_ipv6*.ref' % (thisDir, i))):
expected = open(refTableFile).read().rstrip() if os.path.isfile(refTableFile):
# Fix newlines (make them all the same) # Read expected result from file
expected = ('\n'.join(expected.splitlines()) + '\n').splitlines(1) expected = open(refTableFile).read().rstrip()
# Fix newlines (make them all the same)
expected = ('\n'.join(expected.splitlines()) + '\n').splitlines(1)
# Actual output from router # Actual output from router
actual = net['r%s' % i].cmd('vtysh -c "show bgp ipv6" 2> /dev/null').rstrip() actual = net['r%s' % i].cmd('vtysh -c "show bgp ipv6" 2> /dev/null').rstrip()
# Remove summary line (changed recently) # Remove summary line (changed recently)
actual = re.sub(r'Total number.*', '', actual) actual = re.sub(r'Total number.*', '', actual)
actual = re.sub(r'Displayed.*', '', actual) actual = re.sub(r'Displayed.*', '', actual)
actual = actual.rstrip() actual = actual.rstrip()
# Fix newlines (make them all the same) # Fix newlines (make them all the same)
actual = ('\n'.join(actual.splitlines()) + '\n').splitlines(1) actual = ('\n'.join(actual.splitlines()) + '\n').splitlines(1)
# Generate Diff # Generate Diff
diff = topotest.get_textdiff(actual, expected, diff = topotest.get_textdiff(actual, expected,
title1="actual SHOW BGP IPv6", title1="actual SHOW BGP IPv6",
title2="expected SHOW BGP IPv6") title2="expected SHOW BGP IPv6")
# Empty string if it matches, otherwise diff contains unified diff # Empty string if it matches, otherwise diff contains unified diff
if diff: if diff:
sys.stderr.write('r%s failed SHOW BGP IPv6 check:\n%s\n' % (i, diff)) diffresult[refTableFile] = diff
failures += 1 else:
else: success = 1
print("r%s ok" % i) print("template %s matched: r%s ok" % (refTableFile, i))
assert failures == 0, "SHOW BGP IPv6 failed for router r%s:\n%s" % (i, diff) if not success:
resultstr = 'No template matched.\n'
for f in diffresult.iterkeys():
resultstr += (
'template %s: r%s failed SHOW BGP IPv6 check:\n%s\n'
% (f, i, diffresult[f]))
raise AssertionError(
"SHOW BGP IPv6 failed for router r%s:\n%s" % (i, resultstr))
# Make sure that all daemons are running # Make sure that all daemons are running
for i in range(1, 2): for i in range(1, 2):

View File

@ -0,0 +1,41 @@
BGP table version is XXX, local router ID is 172.30.1.1, vrf id 0
Status codes: s suppressed, d damped, h history, * valid, > best, = multipath,
i internal, r RIB-failure, S Stale, R Removed
Nexthop codes: @NNN nexthop's vrf id, < announce-nh-self
Origin codes: i - IGP, e - EGP, ? - incomplete
Network Next Hop Metric LocPrf Weight Path
* 10.0.1.0/24 172.16.1.5 0 65005 i
* 172.16.1.2 0 65002 i
*> 172.16.1.1 0 65001 i
*> 10.101.0.0/24 172.16.1.1 100 0 65001 i
*> 10.101.1.0/24 172.16.1.1 100 0 65001 i
*> 10.101.2.0/24 172.16.1.1 100 0 65001 i
*> 10.101.3.0/24 172.16.1.1 100 0 65001 i
*> 10.101.4.0/24 172.16.1.1 100 0 65001 i
*> 10.101.5.0/24 172.16.1.1 100 0 65001 i
*> 10.101.6.0/24 172.16.1.1 100 0 65001 i
*> 10.101.7.0/24 172.16.1.1 100 0 65001 i
*> 10.101.8.0/24 172.16.1.1 100 0 65001 i
*> 10.101.9.0/24 172.16.1.1 100 0 65001 i
*> 10.102.0.0/24 172.16.1.2 100 0 65002 i
*> 10.102.1.0/24 172.16.1.2 100 0 65002 i
*> 10.102.2.0/24 172.16.1.2 100 0 65002 i
*> 10.102.3.0/24 172.16.1.2 100 0 65002 i
*> 10.102.4.0/24 172.16.1.2 100 0 65002 i
*> 10.102.5.0/24 172.16.1.2 100 0 65002 i
*> 10.102.6.0/24 172.16.1.2 100 0 65002 i
*> 10.102.7.0/24 172.16.1.2 100 0 65002 i
*> 10.102.8.0/24 172.16.1.2 100 0 65002 i
*> 10.102.9.0/24 172.16.1.2 100 0 65002 i
*> 10.105.0.0/24 172.16.1.5 100 0 65005 i
*> 10.105.1.0/24 172.16.1.5 100 0 65005 i
*> 10.105.2.0/24 172.16.1.5 100 0 65005 i
*> 10.105.3.0/24 172.16.1.5 100 0 65005 i
*> 10.105.4.0/24 172.16.1.5 100 0 65005 i
*> 10.105.5.0/24 172.16.1.5 100 0 65005 i
*> 10.105.6.0/24 172.16.1.5 100 0 65005 i
*> 10.105.7.0/24 172.16.1.5 100 0 65005 i
*> 10.105.8.0/24 172.16.1.5 100 0 65005 i
*> 10.105.9.0/24 172.16.1.5 100 0 65005 i
*> 172.20.0.0/28 0.0.0.0 0 32768 i

View File

@ -0,0 +1,30 @@
BGP table version is XXX, local router ID is 172.30.1.1, vrf id 0
Status codes: s suppressed, d damped, h history, * valid, > best, = multipath,
i internal, r RIB-failure, S Stale, R Removed
Nexthop codes: @NNN nexthop's vrf id, < announce-nh-self
Origin codes: i - IGP, e - EGP, ? - incomplete
Network Next Hop Metric LocPrf Weight Path
* 10.0.1.0/24 172.16.1.4 0 65004 i
*> 172.16.1.3 0 65003 i
*> 10.103.0.0/24 172.16.1.3 100 0 65003 i
*> 10.103.1.0/24 172.16.1.3 100 0 65003 i
*> 10.103.2.0/24 172.16.1.3 100 0 65003 i
*> 10.103.3.0/24 172.16.1.3 100 0 65003 i
*> 10.103.4.0/24 172.16.1.3 100 0 65003 i
*> 10.103.5.0/24 172.16.1.3 100 0 65003 i
*> 10.103.6.0/24 172.16.1.3 100 0 65003 i
*> 10.103.7.0/24 172.16.1.3 100 0 65003 i
*> 10.103.8.0/24 172.16.1.3 100 0 65003 i
*> 10.103.9.0/24 172.16.1.3 100 0 65003 i
*> 10.104.0.0/24 172.16.1.4 100 0 65004 i
*> 10.104.1.0/24 172.16.1.4 100 0 65004 i
*> 10.104.2.0/24 172.16.1.4 100 0 65004 i
*> 10.104.3.0/24 172.16.1.4 100 0 65004 i
*> 10.104.4.0/24 172.16.1.4 100 0 65004 i
*> 10.104.5.0/24 172.16.1.4 100 0 65004 i
*> 10.104.6.0/24 172.16.1.4 100 0 65004 i
*> 10.104.7.0/24 172.16.1.4 100 0 65004 i
*> 10.104.8.0/24 172.16.1.4 100 0 65004 i
*> 10.104.9.0/24 172.16.1.4 100 0 65004 i
*> 172.20.0.0/28 0.0.0.0 9999 32768 100 100 100 100 100 i

View File

@ -0,0 +1,41 @@
BGP table version is XXX, local router ID is 172.30.1.1, vrf id 0
Status codes: s suppressed, d damped, h history, * valid, > best, = multipath,
i internal, r RIB-failure, S Stale, R Removed
Nexthop codes: @NNN nexthop's vrf id, < announce-nh-self
Origin codes: i - IGP, e - EGP, ? - incomplete
Network Next Hop Metric LocPrf Weight Path
* 10.0.1.0/24 172.16.1.8 0 65008 i
* 172.16.1.7 0 65007 i
*> 172.16.1.6 0 65006 i
*> 10.106.0.0/24 172.16.1.6 100 0 65006 i
*> 10.106.1.0/24 172.16.1.6 100 0 65006 i
*> 10.106.2.0/24 172.16.1.6 100 0 65006 i
*> 10.106.3.0/24 172.16.1.6 100 0 65006 i
*> 10.106.4.0/24 172.16.1.6 100 0 65006 i
*> 10.106.5.0/24 172.16.1.6 100 0 65006 i
*> 10.106.6.0/24 172.16.1.6 100 0 65006 i
*> 10.106.7.0/24 172.16.1.6 100 0 65006 i
*> 10.106.8.0/24 172.16.1.6 100 0 65006 i
*> 10.106.9.0/24 172.16.1.6 100 0 65006 i
*> 10.107.0.0/24 172.16.1.7 100 0 65007 i
*> 10.107.1.0/24 172.16.1.7 100 0 65007 i
*> 10.107.2.0/24 172.16.1.7 100 0 65007 i
*> 10.107.3.0/24 172.16.1.7 100 0 65007 i
*> 10.107.4.0/24 172.16.1.7 100 0 65007 i
*> 10.107.5.0/24 172.16.1.7 100 0 65007 i
*> 10.107.6.0/24 172.16.1.7 100 0 65007 i
*> 10.107.7.0/24 172.16.1.7 100 0 65007 i
*> 10.107.8.0/24 172.16.1.7 100 0 65007 i
*> 10.107.9.0/24 172.16.1.7 100 0 65007 i
*> 10.108.0.0/24 172.16.1.8 100 0 65008 i
*> 10.108.1.0/24 172.16.1.8 100 0 65008 i
*> 10.108.2.0/24 172.16.1.8 100 0 65008 i
*> 10.108.3.0/24 172.16.1.8 100 0 65008 i
*> 10.108.4.0/24 172.16.1.8 100 0 65008 i
*> 10.108.5.0/24 172.16.1.8 100 0 65008 i
*> 10.108.6.0/24 172.16.1.8 100 0 65008 i
*> 10.108.7.0/24 172.16.1.8 100 0 65008 i
*> 10.108.8.0/24 172.16.1.8 100 0 65008 i
*> 10.108.9.0/24 172.16.1.8 100 0 65008 i
*> 172.20.0.0/28 0.0.0.0 0 32768 i

View File

@ -66,6 +66,7 @@ import os
import re import re
import sys import sys
import pytest import pytest
import glob
from time import sleep from time import sleep
from mininet.topo import Topo from mininet.topo import Topo
@ -270,45 +271,57 @@ def test_bgp_routingTable():
print("\n\n** Verifying BGP Routing Tables") print("\n\n** Verifying BGP Routing Tables")
print("******************************************\n") print("******************************************\n")
failures = 0 diffresult = {}
for i in range(1, 2): for i in range(1, 2):
for view in range(1, 4): for view in range(1, 4):
refTableFile = '%s/r%s/show_ip_bgp_view_%s.ref' % (thisDir, i, view) success = 0
if os.path.isfile(refTableFile): # This glob pattern should work as long as number of views < 10
# Read expected result from file for refTableFile in (glob.glob(
expected = open(refTableFile).read().rstrip() '%s/r%s/show_ip_bgp_view_%s*.ref' % (thisDir, i, view))):
# Fix newlines (make them all the same)
expected = ('\n'.join(expected.splitlines()) + '\n').splitlines(1)
# Actual output from router if os.path.isfile(refTableFile):
actual = net['r%s' % i].cmd('vtysh -c "show ip bgp view %s" 2> /dev/null' % view).rstrip() # Read expected result from file
expected = open(refTableFile).read().rstrip()
# Fix inconsitent spaces between 0.99.24 and newer versions of Quagga... # Fix newlines (make them all the same)
actual = re.sub('0 0', '0 0', actual) expected = ('\n'.join(expected.splitlines()) + '\n').splitlines(1)
actual = re.sub(r'([0-9]) 32768', r'\1 32768', actual)
# Remove summary line (changed recently)
actual = re.sub(r'Total number.*', '', actual)
actual = re.sub(r'Displayed.*', '', actual)
actual = actual.rstrip()
# Fix table version (ignore it)
actual = re.sub(r'(BGP table version is )[0-9]+', r'\1XXX', actual)
# Fix newlines (make them all the same) # Actual output from router
actual = ('\n'.join(actual.splitlines()) + '\n').splitlines(1) actual = net['r%s' % i].cmd('vtysh -c "show ip bgp view %s" 2> /dev/null' % view).rstrip()
# Fix inconsitent spaces between 0.99.24 and newer versions of Quagga...
actual = re.sub('0 0', '0 0', actual)
actual = re.sub(r'([0-9]) 32768', r'\1 32768', actual)
# Remove summary line (changed recently)
actual = re.sub(r'Total number.*', '', actual)
actual = re.sub(r'Displayed.*', '', actual)
actual = actual.rstrip()
# Fix table version (ignore it)
actual = re.sub(r'(BGP table version is )[0-9]+', r'\1XXX', actual)
# Generate Diff # Fix newlines (make them all the same)
diff = topotest.get_textdiff(actual, expected, actual = ('\n'.join(actual.splitlines()) + '\n').splitlines(1)
title1="actual BGP routing table",
title2="expected BGP routing table")
if diff: # Generate Diff
sys.stderr.write('r%s failed Routing Table Check for view %s:\n%s\n' diff = topotest.get_textdiff(actual, expected,
% (i, view, diff)) title1="actual BGP routing table",
failures += 1 title2="expected BGP routing table")
else:
print("r%s ok" % i) if diff:
diffresult[refTableFile] = diff
else:
success = 1
print("template %s matched: r%s ok" % (refTableFile, i))
break;
if not success:
resultstr = 'No template matched.\n'
for f in diffresult.iterkeys():
resultstr += (
'template %s: r%s failed Routing Table Check for view %s:\n%s\n'
% (f, i, view, diffresult[f]))
raise AssertionError(
"Routing Table verification failed for router r%s, view %s:\n%s" % (i, view, resultstr))
assert failures == 0, "Routing Table verification failed for router r%s, view %s:\n%s" % (i, view, diff)
# Make sure that all daemons are running # Make sure that all daemons are running
for i in range(1, 2): for i in range(1, 2):