mirror of
https://git.proxmox.com/git/mirror_frr
synced 2025-08-06 14:29:47 +00:00
tests: improve unicode handling
Support more of the string/unicode interactions in various topotests. Signed-off-by: Mark Stapp <mjs@voltanet.io>
This commit is contained in:
parent
11761ab0f4
commit
61196140a6
@ -28,6 +28,7 @@ from lib import topotest
|
|||||||
from lib.topolog import logger
|
from lib.topolog import logger
|
||||||
|
|
||||||
from lib.topogen import TopoRouter, get_topogen
|
from lib.topogen import TopoRouter, get_topogen
|
||||||
|
from lib.topotest import frr_unicode
|
||||||
|
|
||||||
# Import common_config to use commomnly used APIs
|
# Import common_config to use commomnly used APIs
|
||||||
from lib.common_config import (
|
from lib.common_config import (
|
||||||
@ -393,7 +394,7 @@ def __create_bgp_unicast_neighbor(
|
|||||||
# Generating IPs for verification
|
# Generating IPs for verification
|
||||||
network_list = generate_ips(network, no_of_network)
|
network_list = generate_ips(network, no_of_network)
|
||||||
for ip in network_list:
|
for ip in network_list:
|
||||||
ip = str(ipaddress.ip_network(unicode(ip)))
|
ip = str(ipaddress.ip_network(frr_unicode(ip)))
|
||||||
|
|
||||||
cmd = "network {}".format(ip)
|
cmd = "network {}".format(ip)
|
||||||
if del_action:
|
if del_action:
|
||||||
@ -1037,7 +1038,7 @@ def verify_router_id(tgen, topo, input_dict):
|
|||||||
logger.info("Checking router %s router-id", router)
|
logger.info("Checking router %s router-id", router)
|
||||||
show_bgp_json = run_frr_cmd(rnode, "show bgp summary json", isjson=True)
|
show_bgp_json = run_frr_cmd(rnode, "show bgp summary json", isjson=True)
|
||||||
router_id_out = show_bgp_json["ipv4Unicast"]["routerId"]
|
router_id_out = show_bgp_json["ipv4Unicast"]["routerId"]
|
||||||
router_id_out = ipaddress.IPv4Address(unicode(router_id_out))
|
router_id_out = ipaddress.IPv4Address(frr_unicode(router_id_out))
|
||||||
|
|
||||||
# Once router-id is deleted, highest interface ip should become
|
# Once router-id is deleted, highest interface ip should become
|
||||||
# router-id
|
# router-id
|
||||||
@ -1045,7 +1046,7 @@ def verify_router_id(tgen, topo, input_dict):
|
|||||||
router_id = find_interface_with_greater_ip(topo, router)
|
router_id = find_interface_with_greater_ip(topo, router)
|
||||||
else:
|
else:
|
||||||
router_id = input_dict[router]["bgp"]["router_id"]
|
router_id = input_dict[router]["bgp"]["router_id"]
|
||||||
router_id = ipaddress.IPv4Address(unicode(router_id))
|
router_id = ipaddress.IPv4Address(frr_unicode(router_id))
|
||||||
|
|
||||||
if router_id == router_id_out:
|
if router_id == router_id_out:
|
||||||
logger.info("Found expected router-id %s for router %s", router_id, router)
|
logger.info("Found expected router-id %s for router %s", router_id, router)
|
||||||
@ -2286,7 +2287,7 @@ def verify_best_path_as_per_bgp_attribute(
|
|||||||
|
|
||||||
routes = generate_ips(_network, no_of_ip)
|
routes = generate_ips(_network, no_of_ip)
|
||||||
for route in routes:
|
for route in routes:
|
||||||
route = str(ipaddress.ip_network(unicode(route)))
|
route = str(ipaddress.ip_network(frr_unicode(route)))
|
||||||
|
|
||||||
if route in sh_ip_bgp_json["routes"]:
|
if route in sh_ip_bgp_json["routes"]:
|
||||||
route_attributes = sh_ip_bgp_json["routes"][route]
|
route_attributes = sh_ip_bgp_json["routes"][route]
|
||||||
@ -2604,7 +2605,7 @@ def verify_bgp_rib(tgen, addr_type, dut, input_dict, next_hop=None, aspath=None)
|
|||||||
ip_list = generate_ips(network, no_of_ip)
|
ip_list = generate_ips(network, no_of_ip)
|
||||||
|
|
||||||
for st_rt in ip_list:
|
for st_rt in ip_list:
|
||||||
st_rt = str(ipaddress.ip_network(unicode(st_rt)))
|
st_rt = str(ipaddress.ip_network(frr_unicode(st_rt)))
|
||||||
|
|
||||||
_addr_type = validate_ip_address(st_rt)
|
_addr_type = validate_ip_address(st_rt)
|
||||||
if _addr_type != addr_type:
|
if _addr_type != addr_type:
|
||||||
@ -2742,7 +2743,7 @@ def verify_bgp_rib(tgen, addr_type, dut, input_dict, next_hop=None, aspath=None)
|
|||||||
ip_list = generate_ips(network, no_of_network)
|
ip_list = generate_ips(network, no_of_network)
|
||||||
|
|
||||||
for st_rt in ip_list:
|
for st_rt in ip_list:
|
||||||
st_rt = str(ipaddress.ip_network(unicode(st_rt)))
|
st_rt = str(ipaddress.ip_network(frr_unicode(st_rt)))
|
||||||
|
|
||||||
_addr_type = validate_ip_address(st_rt)
|
_addr_type = validate_ip_address(st_rt)
|
||||||
if _addr_type != addr_type:
|
if _addr_type != addr_type:
|
||||||
|
@ -46,7 +46,7 @@ else:
|
|||||||
|
|
||||||
from lib.topolog import logger, logger_config
|
from lib.topolog import logger, logger_config
|
||||||
from lib.topogen import TopoRouter, get_topogen
|
from lib.topogen import TopoRouter, get_topogen
|
||||||
from lib.topotest import interface_set_status, version_cmp
|
from lib.topotest import interface_set_status, version_cmp, frr_unicode
|
||||||
|
|
||||||
FRRCFG_FILE = "frr_json.conf"
|
FRRCFG_FILE = "frr_json.conf"
|
||||||
FRRCFG_BKUP_FILE = "frr_json_initial.conf"
|
FRRCFG_BKUP_FILE = "frr_json_initial.conf"
|
||||||
@ -1150,10 +1150,10 @@ def generate_ips(network, no_of_ips):
|
|||||||
|
|
||||||
addr_type = validate_ip_address(start_ip)
|
addr_type = validate_ip_address(start_ip)
|
||||||
if addr_type == "ipv4":
|
if addr_type == "ipv4":
|
||||||
start_ip = ipaddress.IPv4Address(unicode(start_ip))
|
start_ip = ipaddress.IPv4Address(frr_unicode(start_ip))
|
||||||
step = 2 ** (32 - mask)
|
step = 2 ** (32 - mask)
|
||||||
if addr_type == "ipv6":
|
if addr_type == "ipv6":
|
||||||
start_ip = ipaddress.IPv6Address(unicode(start_ip))
|
start_ip = ipaddress.IPv6Address(frr_unicode(start_ip))
|
||||||
step = 2 ** (128 - mask)
|
step = 2 ** (128 - mask)
|
||||||
|
|
||||||
next_ip = start_ip
|
next_ip = start_ip
|
||||||
@ -2665,7 +2665,7 @@ def verify_rib(
|
|||||||
nh_found = False
|
nh_found = False
|
||||||
|
|
||||||
for st_rt in ip_list:
|
for st_rt in ip_list:
|
||||||
st_rt = str(ipaddress.ip_network(unicode(st_rt)))
|
st_rt = str(ipaddress.ip_network(frr_unicode(st_rt)))
|
||||||
|
|
||||||
_addr_type = validate_ip_address(st_rt)
|
_addr_type = validate_ip_address(st_rt)
|
||||||
if _addr_type != addr_type:
|
if _addr_type != addr_type:
|
||||||
@ -2861,7 +2861,7 @@ def verify_rib(
|
|||||||
nh_found = False
|
nh_found = False
|
||||||
|
|
||||||
for st_rt in ip_list:
|
for st_rt in ip_list:
|
||||||
st_rt = str(ipaddress.ip_network(unicode(st_rt)))
|
st_rt = str(ipaddress.ip_network(frr_unicode(st_rt)))
|
||||||
|
|
||||||
_addr_type = validate_ip_address(st_rt)
|
_addr_type = validate_ip_address(st_rt)
|
||||||
if _addr_type != addr_type:
|
if _addr_type != addr_type:
|
||||||
@ -3010,7 +3010,7 @@ def verify_fib_routes(tgen, addr_type, dut, input_dict, next_hop=None):
|
|||||||
nh_found = False
|
nh_found = False
|
||||||
|
|
||||||
for st_rt in ip_list:
|
for st_rt in ip_list:
|
||||||
st_rt = str(ipaddress.ip_network(unicode(st_rt)))
|
st_rt = str(ipaddress.ip_network(frr_unicode(st_rt)))
|
||||||
#st_rt = str(ipaddr.IPNetwork(unicode(st_rt)))
|
#st_rt = str(ipaddr.IPNetwork(unicode(st_rt)))
|
||||||
|
|
||||||
_addr_type = validate_ip_address(st_rt)
|
_addr_type = validate_ip_address(st_rt)
|
||||||
@ -3117,7 +3117,7 @@ def verify_fib_routes(tgen, addr_type, dut, input_dict, next_hop=None):
|
|||||||
|
|
||||||
for st_rt in ip_list:
|
for st_rt in ip_list:
|
||||||
#st_rt = str(ipaddr.IPNetwork(unicode(st_rt)))
|
#st_rt = str(ipaddr.IPNetwork(unicode(st_rt)))
|
||||||
st_rt = str(ipaddress.ip_network(unicode(st_rt)))
|
st_rt = str(ipaddress.ip_network(frr_unicode(st_rt)))
|
||||||
|
|
||||||
_addr_type = validate_ip_address(st_rt)
|
_addr_type = validate_ip_address(st_rt)
|
||||||
if _addr_type != addr_type:
|
if _addr_type != addr_type:
|
||||||
@ -3266,7 +3266,7 @@ def verify_fib_routes(tgen, addr_type, dut, input_dict, next_hop=None):
|
|||||||
nh_found = False
|
nh_found = False
|
||||||
|
|
||||||
for st_rt in ip_list:
|
for st_rt in ip_list:
|
||||||
st_rt = str(ipaddress.ip_network(unicode(st_rt)))
|
st_rt = str(ipaddress.ip_network(frr_unicode(st_rt)))
|
||||||
|
|
||||||
_addr_type = validate_ip_address(st_rt)
|
_addr_type = validate_ip_address(st_rt)
|
||||||
if _addr_type != addr_type:
|
if _addr_type != addr_type:
|
||||||
@ -3371,7 +3371,7 @@ def verify_fib_routes(tgen, addr_type, dut, input_dict, next_hop=None):
|
|||||||
nh_found = False
|
nh_found = False
|
||||||
|
|
||||||
for st_rt in ip_list:
|
for st_rt in ip_list:
|
||||||
st_rt = str(ipaddress.ip_network(unicode(st_rt)))
|
st_rt = str(ipaddress.ip_network(frr_unicode(st_rt)))
|
||||||
|
|
||||||
_addr_type = validate_ip_address(st_rt)
|
_addr_type = validate_ip_address(st_rt)
|
||||||
if _addr_type != addr_type:
|
if _addr_type != addr_type:
|
||||||
|
@ -23,7 +23,7 @@ import traceback
|
|||||||
from time import sleep
|
from time import sleep
|
||||||
from lib.topolog import logger
|
from lib.topolog import logger
|
||||||
import ipaddr
|
import ipaddr
|
||||||
|
from lib.topotest import frr_unicode
|
||||||
|
|
||||||
# Import common_config to use commomnly used APIs
|
# Import common_config to use commomnly used APIs
|
||||||
from lib.common_config import (create_common_configuration,
|
from lib.common_config import (create_common_configuration,
|
||||||
@ -739,7 +739,7 @@ def verify_ospf_rib(tgen, dut, input_dict, next_hop=None,
|
|||||||
nh_found = False
|
nh_found = False
|
||||||
|
|
||||||
for st_rt in ip_list:
|
for st_rt in ip_list:
|
||||||
st_rt = str(ipaddr.IPNetwork(unicode(st_rt)))
|
st_rt = str(ipaddr.IPNetwork(frr_unicode(st_rt)))
|
||||||
|
|
||||||
_addr_type = validate_ip_address(st_rt)
|
_addr_type = validate_ip_address(st_rt)
|
||||||
if _addr_type != 'ipv4':
|
if _addr_type != 'ipv4':
|
||||||
|
@ -1735,3 +1735,10 @@ class LegacySwitch(OVSSwitch):
|
|||||||
def __init__(self, name, **params):
|
def __init__(self, name, **params):
|
||||||
OVSSwitch.__init__(self, name, failMode="standalone", **params)
|
OVSSwitch.__init__(self, name, failMode="standalone", **params)
|
||||||
self.switchIP = None
|
self.switchIP = None
|
||||||
|
|
||||||
|
def frr_unicode(s):
|
||||||
|
'''Convert string to unicode, depending on python version'''
|
||||||
|
if sys.version_info[0] > 2:
|
||||||
|
return s
|
||||||
|
else:
|
||||||
|
return unicode(s)
|
||||||
|
Loading…
Reference in New Issue
Block a user