summaryrefslogtreecommitdiff
path: root/tests/topotests/lib/bgprib.py
diff options
context:
space:
mode:
authorDonald Sharp <sharpd@nvidia.com>2023-01-11 10:14:11 -0500
committerDonald Sharp <sharpd@nvidia.com>2023-01-13 08:13:52 -0500
commit2bb8b49ce13aee725fbce975eac1493890f8caff (patch)
treebd594621e7bd3e909684f6bd7f20f5d6ae1b4131 /tests/topotests/lib/bgprib.py
parent1ab8721a5ca32842b2904333ac6d62e90a81a129 (diff)
Revert "Merge pull request #11127 from louis-6wind/bgp-leak"
This reverts commit 16aa1809e7c8caad37e8edd4e5aaac4f344bc7d3, reversing changes made to f616e716089b16d9a678846282a6ac5c55e31a56.
Diffstat (limited to 'tests/topotests/lib/bgprib.py')
-rw-r--r--tests/topotests/lib/bgprib.py193
1 files changed, 78 insertions, 115 deletions
diff --git a/tests/topotests/lib/bgprib.py b/tests/topotests/lib/bgprib.py
index 01439373c5..35a57d0a99 100644
--- a/tests/topotests/lib/bgprib.py
+++ b/tests/topotests/lib/bgprib.py
@@ -37,7 +37,6 @@
from lib.lutil import luCommand, luResult, LUtil
import json
import re
-import time
# gpz: get rib in json form and compare against desired routes
class BgpRib:
@@ -49,15 +48,7 @@ class BgpRib:
for pfx in pfxtbl.keys():
if debug:
self.log("trying pfx %s" % pfx)
- if "exist" in want and want["exist"] == False:
- if pfx == want["p"]:
- if debug:
- self.log("unexpected route: pfx=" + want["p"])
- return 0
- if debug:
- self.log("unwant pfx=" + want["p"] + ", not " + pfx)
- continue
- elif pfx != want["p"]:
+ if pfx != want["p"]:
if debug:
self.log("want pfx=" + want["p"] + ", not " + pfx)
continue
@@ -84,67 +75,53 @@ class BgpRib:
if debug:
self.log("missing route: pfx=" + want["p"] + ", nh=" + want["n"])
return 0
- if "exist" in want and want["exist"] == False:
- return 1
- return 0
- def RequireVpnRoutes(self, target, title, wantroutes, retry=0, wait=1, debug=0):
+ def RequireVpnRoutes(self, target, title, wantroutes, debug=0):
import json
logstr = "RequireVpnRoutes " + str(wantroutes)
- retry += 1
- while retry:
- retry -= 1
- # non json form for humans
- luCommand(
- target,
- 'vtysh -c "show bgp ipv4 vpn"',
- ".",
- "None",
- "Get VPN RIB (non-json)",
- )
- ret = luCommand(
- target,
- 'vtysh -c "show bgp ipv4 vpn json"',
- ".*",
- "None",
- "Get VPN RIB (json)",
- )
- if re.search(r"^\s*$", ret):
- # degenerate case: empty json means no routes
- if len(wantroutes) > 0:
- luResult(target, False, title, logstr)
- return
- luResult(target, True, title, logstr)
- rib = json.loads(ret)
- rds = rib["routes"]["routeDistinguishers"]
- for want in wantroutes:
- found = 0
- if debug:
- self.log("want rd %s" % want["rd"])
- for rd in rds.keys():
- if rd != want["rd"]:
- continue
- if debug:
- self.log("found rd %s" % rd)
- table = rds[rd]
- if self.routes_include_wanted(table, want, debug):
- found = 1
- break
- if not found:
- if retry:
- break
- luResult(target, False, title, logstr)
- return
- if not found and retry:
- time.sleep(wait)
- continue
+ # non json form for humans
+ luCommand(
+ target,
+ 'vtysh -c "show bgp ipv4 vpn"',
+ ".",
+ "None",
+ "Get VPN RIB (non-json)",
+ )
+ ret = luCommand(
+ target,
+ 'vtysh -c "show bgp ipv4 vpn json"',
+ ".*",
+ "None",
+ "Get VPN RIB (json)",
+ )
+ if re.search(r"^\s*$", ret):
+ # degenerate case: empty json means no routes
+ if len(wantroutes) > 0:
+ luResult(target, False, title, logstr)
+ return
luResult(target, True, title, logstr)
- break
+ rib = json.loads(ret)
+ rds = rib["routes"]["routeDistinguishers"]
+ for want in wantroutes:
+ found = 0
+ if debug:
+ self.log("want rd %s" % want["rd"])
+ for rd in rds.keys():
+ if rd != want["rd"]:
+ continue
+ if debug:
+ self.log("found rd %s" % rd)
+ table = rds[rd]
+ if self.routes_include_wanted(table, want, debug):
+ found = 1
+ break
+ if not found:
+ luResult(target, False, title, logstr)
+ return
+ luResult(target, True, title, logstr)
- def RequireUnicastRoutes(
- self, target, afi, vrf, title, wantroutes, retry=0, wait=1, debug=0
- ):
+ def RequireUnicastRoutes(self, target, afi, vrf, title, wantroutes, debug=0):
logstr = "RequireUnicastRoutes %s" % str(wantroutes)
vrfstr = ""
if vrf != "":
@@ -153,62 +130,48 @@ class BgpRib:
if (afi != "ipv4") and (afi != "ipv6"):
self.log("ERROR invalid afi")
- retry += 1
- while retry:
- retry -= 1
- cmdstr = "show bgp %s %s unicast" % (vrfstr, afi)
- # non json form for humans
- cmd = 'vtysh -c "%s"' % cmdstr
- luCommand(
- target, cmd, ".", "None", "Get %s %s RIB (non-json)" % (vrfstr, afi)
- )
- cmd = 'vtysh -c "%s json"' % cmdstr
- ret = luCommand(
- target, cmd, ".*", "None", "Get %s %s RIB (json)" % (vrfstr, afi)
- )
- if re.search(r"^\s*$", ret):
- # degenerate case: empty json means no routes
- if len(wantroutes) > 0:
- luResult(target, False, title, logstr)
- return
- luResult(target, True, title, logstr)
- rib = json.loads(ret)
- try:
- table = rib["routes"]
- # KeyError: 'routes' probably means missing/bad VRF
- except KeyError as err:
- if vrf != "":
- errstr = "-script ERROR: check if wrong vrf (%s)" % (vrf)
- else:
- errstr = "-script ERROR: check if vrf missing"
- if retry:
- time.sleep(wait)
- continue
- luResult(target, False, title + errstr, logstr)
+ cmdstr = "show bgp %s %s unicast" % (vrfstr, afi)
+ # non json form for humans
+ cmd = 'vtysh -c "%s"' % cmdstr
+ luCommand(target, cmd, ".", "None", "Get %s %s RIB (non-json)" % (vrfstr, afi))
+ cmd = 'vtysh -c "%s json"' % cmdstr
+ ret = luCommand(
+ target, cmd, ".*", "None", "Get %s %s RIB (json)" % (vrfstr, afi)
+ )
+ if re.search(r"^\s*$", ret):
+ # degenerate case: empty json means no routes
+ if len(wantroutes) > 0:
+ luResult(target, False, title, logstr)
return
- # if debug:
- # self.log("table=%s" % table)
- for want in wantroutes:
- if debug:
- self.log("want=%s" % want)
- if not self.routes_include_wanted(table, want, debug):
- if retry:
- time.sleep(wait)
- continue
- luResult(target, False, title, logstr)
- return
luResult(target, True, title, logstr)
- break
+ rib = json.loads(ret)
+ try:
+ table = rib["routes"]
+ # KeyError: 'routes' probably means missing/bad VRF
+ except KeyError as err:
+ if vrf != "":
+ errstr = "-script ERROR: check if wrong vrf (%s)" % (vrf)
+ else:
+ errstr = "-script ERROR: check if vrf missing"
+ luResult(target, False, title + errstr, logstr)
+ return
+ # if debug:
+ # self.log("table=%s" % table)
+ for want in wantroutes:
+ if debug:
+ self.log("want=%s" % want)
+ if not self.routes_include_wanted(table, want, debug):
+ luResult(target, False, title, logstr)
+ return
+ luResult(target, True, title, logstr)
BgpRib = BgpRib()
-def bgpribRequireVpnRoutes(target, title, wantroutes, retry=0, wait=1, debug=0):
- BgpRib.RequireVpnRoutes(target, title, wantroutes, retry, wait, debug)
+def bgpribRequireVpnRoutes(target, title, wantroutes, debug=0):
+ BgpRib.RequireVpnRoutes(target, title, wantroutes, debug)
-def bgpribRequireUnicastRoutes(
- target, afi, vrf, title, wantroutes, retry=0, wait=1, debug=0
-):
- BgpRib.RequireUnicastRoutes(target, afi, vrf, title, wantroutes, retry, wait, debug)
+def bgpribRequireUnicastRoutes(target, afi, vrf, title, wantroutes, debug=0):
+ BgpRib.RequireUnicastRoutes(target, afi, vrf, title, wantroutes, debug)