test: minor refactor to check for nexthop (gw) in routes

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
Joachim Wiberg
2023-12-14 16:40:41 +01:00
committed by Mattias Walström
parent cb5419c84c
commit a61b3b8aef
+13 -10
View File
@@ -1,4 +1,4 @@
def _get_routes(target,protocol):
def _get_routes(target, protocol):
xpath=f"/ietf-routing:routing"
rib = target.get_data(xpath)["routing"]["ribs"]["rib"]
for r in rib:
@@ -7,16 +7,19 @@ def _get_routes(target,protocol):
return r.get("routes", {}).get("route",{})
return {}
def _exist_route(target,destination_prefix, protocol):
routes=_get_routes(target,protocol)
def _exist_route(target, prefix, nexthop, protocol):
routes = _get_routes(target, protocol)
for r in routes:
if(r["destination-prefix"] == destination_prefix):
return True
if r["destination-prefix"] != prefix:
continue
nh = r["next-hop"]
if nexthop and nh["next-hop-address"] != nexthop:
continue
return True
return False
def ipv4_route_exist(target, destination_prefix):
return _exist_route(target,destination_prefix, "ipv4")
def ipv4_route_exist(target, prefix, nexthop=None):
return _exist_route(target, prefix, nexthop, "ipv4")
def ipv6_route_exist(target, destination_prefix):
return _exist_route(target,destination_prefix, "ipv6")
def ipv6_route_exist(target, prefix, nexthop=None):
return _exist_route(target, prefix, nexthop, "ipv6")