]> git.puffer.fish Git - mirror/frr.git/commitdiff
tests: improve unicode handling
authorMark Stapp <mjs@voltanet.io>
Fri, 25 Sep 2020 14:29:54 +0000 (10:29 -0400)
committerMark Stapp <mjs@voltanet.io>
Sat, 26 Sep 2020 19:40:00 +0000 (15:40 -0400)
Support more of the string/unicode interactions in various
topotests.

Signed-off-by: Mark Stapp <mjs@voltanet.io>
tests/topotests/lib/bgp.py
tests/topotests/lib/common_config.py
tests/topotests/lib/ospf.py
tests/topotests/lib/topotest.py

index a3d846edbb1c659ab09a7bbefd5df4054a893784..72b99eeba847d8ed3db7e3e1eff03df95077e996 100644 (file)
@@ -28,6 +28,7 @@ from lib import topotest
 from lib.topolog import logger
 
 from lib.topogen import TopoRouter, get_topogen
+from lib.topotest import frr_unicode
 
 # Import common_config to use commomnly used APIs
 from lib.common_config import (
@@ -393,7 +394,7 @@ def __create_bgp_unicast_neighbor(
             # Generating IPs for verification
             network_list = generate_ips(network, no_of_network)
             for ip in network_list:
-                ip = str(ipaddress.ip_network(unicode(ip)))
+                ip = str(ipaddress.ip_network(frr_unicode(ip)))
 
                 cmd = "network {}".format(ip)
                 if del_action:
@@ -1037,7 +1038,7 @@ def verify_router_id(tgen, topo, input_dict):
         logger.info("Checking router %s router-id", router)
         show_bgp_json = run_frr_cmd(rnode, "show bgp summary json", isjson=True)
         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
         # router-id
@@ -1045,7 +1046,7 @@ def verify_router_id(tgen, topo, input_dict):
             router_id = find_interface_with_greater_ip(topo, router)
         else:
             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:
             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)
             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"]:
                     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)
 
                     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)
                         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)
 
                     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)
                         if _addr_type != addr_type:
index c6944c3568afbc4efba54a45889e4160ee963d15..4d46b72199bc5b625c49072dd04bae1cf3b02e4f 100644 (file)
@@ -46,7 +46,7 @@ else:
 
 from lib.topolog import logger, logger_config
 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_BKUP_FILE = "frr_json_initial.conf"
@@ -1150,10 +1150,10 @@ def generate_ips(network, no_of_ips):
 
         addr_type = validate_ip_address(start_ip)
         if addr_type == "ipv4":
-            start_ip = ipaddress.IPv4Address(unicode(start_ip))
+            start_ip = ipaddress.IPv4Address(frr_unicode(start_ip))
             step = 2 ** (32 - mask)
         if addr_type == "ipv6":
-            start_ip = ipaddress.IPv6Address(unicode(start_ip))
+            start_ip = ipaddress.IPv6Address(frr_unicode(start_ip))
             step = 2 ** (128 - mask)
 
         next_ip = start_ip
@@ -2665,7 +2665,7 @@ def verify_rib(
                     nh_found = False
 
                     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)
                         if _addr_type != addr_type:
@@ -2861,7 +2861,7 @@ def verify_rib(
                 nh_found = False
 
                 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)
                     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
 
                     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)))
 
                         _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:
                     #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)
                     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
 
                     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)
                         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
 
                 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)
                     if _addr_type != addr_type:
index 3596525c5e104c7b580b576fd9b4ddacc8070850..9d6b8fa691be4e9abd2b7be2fc46a8ec2dc61cfd 100644 (file)
@@ -23,7 +23,7 @@ import traceback
 from time import sleep
 from lib.topolog import logger
 import ipaddr
-
+from lib.topotest import frr_unicode
 
 # Import common_config to use commomnly used APIs
 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
 
                     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)
                         if _addr_type != 'ipv4':
index ba6d38ad425c02bd74229c8ceb892e09318f0b6d..5aa9c5dcb78d7495301413156140a9d502dde3d7 100644 (file)
@@ -1735,3 +1735,10 @@ class LegacySwitch(OVSSwitch):
     def __init__(self, name, **params):
         OVSSwitch.__init__(self, name, failMode="standalone", **params)
         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)