From 587e28a4f05aa46715120cc8ab2b37f46993cde7 Mon Sep 17 00:00:00 2001 From: "G. Paul Ziemba" Date: Tue, 6 Mar 2018 13:11:13 -0800 Subject: [PATCH] lib/bgprib.py: handle empty json results gracefully Signed-off-by: G. Paul Ziemba --- tests/topotests/lib/bgprib.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tests/topotests/lib/bgprib.py b/tests/topotests/lib/bgprib.py index 9bd038e675..b6fcd91794 100644 --- a/tests/topotests/lib/bgprib.py +++ b/tests/topotests/lib/bgprib.py @@ -20,6 +20,7 @@ from lutil import luCommand,luResult import json +import re # gpz: get rib in json form and compare against desired routes class BgpRib: @@ -55,6 +56,12 @@ class BgpRib: def RequireVpnRoutes(self, target, title, wantroutes, debug=0): import json ret = luCommand(target,'vtysh -c "show bgp ipv4 vpn json"','.*','None','Get VPN RIB') + if re.search(r'^\s*$', ret): + # degenerate case: empty json means no routes + if len(wantroutes) > 0: + luResult(target, False, title) + return + luResult(target, True, title) rib = json.loads(ret) rds = rib['routes']['routeDistinguishers'] for want in wantroutes: @@ -87,6 +94,12 @@ class BgpRib: str = 'show bgp %s %s unicast json' % (vrfstr, afi) cmd = 'vtysh -c "%s"' % str ret = luCommand(target,cmd,'.*','None','Get %s %s RIB' % (vrfstr, afi)) + if re.search(r'^\s*$', ret): + # degenerate case: empty json means no routes + if len(wantroutes) > 0: + luResult(target, False, title) + return + luResult(target, True, title) rib = json.loads(ret) table = rib['routes'] for want in wantroutes: -- 2.39.5