From 6cb6c403f1895553d8637c0e8d219cd632455403 Mon Sep 17 00:00:00 2001 From: Philippe Guibert Date: Wed, 25 Nov 2020 09:37:15 +0000 Subject: [PATCH 1/5] topotests: python3, replace execfile with exec python3 does not support execfile implementation. replace it with open and exec api that are available in both python 2 and 3 implementations. Signed-off-by: Philippe Guibert --- tests/topotests/lib/lutil.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/topotests/lib/lutil.py b/tests/topotests/lib/lutil.py index 1fb4f48b0f..0b46363edd 100644 --- a/tests/topotests/lib/lutil.py +++ b/tests/topotests/lib/lutil.py @@ -380,7 +380,8 @@ def luInclude(filename, CallOnFail=None): LUtil.setCallOnFail(CallOnFail) if filename.endswith(".py"): LUtil.log("luInclude: execfile " + tstFile) - execfile(tstFile) + with open(tstFile) as infile: + exec(infile.read()) else: LUtil.log("luInclude: execTestFile " + tstFile) LUtil.execTestFile(tstFile) From 0e232bb883644c8bf7c82a6f6fbaba91ed5af91a Mon Sep 17 00:00:00 2001 From: Philippe Guibert Date: Wed, 25 Nov 2020 09:32:51 +0000 Subject: [PATCH 2/5] topotests: python3, fix error ValueError: can't have unbuffered text I/O This error occurs when passing some 0 values to open() extra argument. Signed-off-by: Philippe Guibert --- tests/topotests/lib/lutil.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/topotests/lib/lutil.py b/tests/topotests/lib/lutil.py index 0b46363edd..dcf1d010b1 100644 --- a/tests/topotests/lib/lutil.py +++ b/tests/topotests/lib/lutil.py @@ -58,14 +58,14 @@ class lUtil: def log(self, str, level=6): if self.l_level > 0: if self.fout == "": - self.fout = open(self.fout_name, "w", 0) + self.fout = open(self.fout_name, "w") self.fout.write(str + "\n") if level <= self.l_level: print(str) def summary(self, str): if self.fsum == "": - self.fsum = open(self.fsum_name, "w", 0) + self.fsum = open(self.fsum_name, "w") self.fsum.write( "\ ******************************************************************************\n" From e7294b32006d87d8d47bce4c54c771cbd7a2e1ca Mon Sep 17 00:00:00 2001 From: Philippe Guibert Date: Wed, 25 Nov 2020 12:49:45 +0000 Subject: [PATCH 3/5] topotests: python3, rename iterkey() with key() for dictionary usage dictionary method iterkey() is not used in python3 and is replaced with key() method. Signed-off-by: Philippe Guibert --- .../all-protocol-startup/test_all_protocol_startup.py | 4 ++-- .../topotests/bgp_multiview_topo1/test_bgp_multiview_topo1.py | 2 +- tests/topotests/lib/bgprib.py | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/topotests/all-protocol-startup/test_all_protocol_startup.py b/tests/topotests/all-protocol-startup/test_all_protocol_startup.py index 0254ff6af6..96b88914a7 100644 --- a/tests/topotests/all-protocol-startup/test_all_protocol_startup.py +++ b/tests/topotests/all-protocol-startup/test_all_protocol_startup.py @@ -1065,7 +1065,7 @@ def test_bgp_ipv4(): if not success: resultstr = "No template matched.\n" - for f in diffresult.iterkeys(): + for f in diffresult.keys(): resultstr += "template %s: r%s failed SHOW BGP IPv4 check:\n%s\n" % ( f, i, @@ -1134,7 +1134,7 @@ def test_bgp_ipv6(): if not success: resultstr = "No template matched.\n" - for f in diffresult.iterkeys(): + for f in diffresult.keys(): resultstr += "template %s: r%s failed SHOW BGP IPv6 check:\n%s\n" % ( f, i, diff --git a/tests/topotests/bgp_multiview_topo1/test_bgp_multiview_topo1.py b/tests/topotests/bgp_multiview_topo1/test_bgp_multiview_topo1.py index 6344f7bb40..7635f74125 100644 --- a/tests/topotests/bgp_multiview_topo1/test_bgp_multiview_topo1.py +++ b/tests/topotests/bgp_multiview_topo1/test_bgp_multiview_topo1.py @@ -332,7 +332,7 @@ def test_bgp_routingTable(): if not success: resultstr = "No template matched.\n" - for f in diffresult.iterkeys(): + for f in diffresult.keys(): resultstr += ( "template %s: r%s failed Routing Table Check for view %s:\n%s\n" % (f, i, view, diffresult[f]) diff --git a/tests/topotests/lib/bgprib.py b/tests/topotests/lib/bgprib.py index a23092de83..abab9600a1 100644 --- a/tests/topotests/lib/bgprib.py +++ b/tests/topotests/lib/bgprib.py @@ -45,7 +45,7 @@ class BgpRib: def routes_include_wanted(self, pfxtbl, want, debug): # helper function to RequireVpnRoutes - for pfx in pfxtbl.iterkeys(): + for pfx in pfxtbl.keys(): if debug: self.log("trying pfx %s" % pfx) if pfx != want["p"]: @@ -107,7 +107,7 @@ class BgpRib: found = 0 if debug: self.log("want rd %s" % want["rd"]) - for rd in rds.iterkeys(): + for rd in rds.keys(): if rd != want["rd"]: continue if debug: From ecff3c7a0c2c8a9e9bef51e6683e716cc458bea0 Mon Sep 17 00:00:00 2001 From: Philippe Guibert Date: Wed, 25 Nov 2020 16:23:19 +0000 Subject: [PATCH 4/5] topotests: python3, replace iteritems with items replace iteritems() calls with items() Signed-off-by: Philippe Guibert --- tests/topotests/bgp_features/test_bgp_features.py | 2 +- tests/topotests/isis-tilfa-topo1/test_isis_tilfa_topo1.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/topotests/bgp_features/test_bgp_features.py b/tests/topotests/bgp_features/test_bgp_features.py index bd092c4340..9dce9d668b 100644 --- a/tests/topotests/bgp_features/test_bgp_features.py +++ b/tests/topotests/bgp_features/test_bgp_features.py @@ -102,7 +102,7 @@ def setup_module(module): # Starting Routers router_list = tgen.routers() - for rname, router in router_list.iteritems(): + for rname, router in router_list.items(): router.load_config( TopoRouter.RD_ZEBRA, os.path.join(CWD, "{}/zebra.conf".format(rname)) ) diff --git a/tests/topotests/isis-tilfa-topo1/test_isis_tilfa_topo1.py b/tests/topotests/isis-tilfa-topo1/test_isis_tilfa_topo1.py index 6bc097b0e7..514ea53552 100755 --- a/tests/topotests/isis-tilfa-topo1/test_isis_tilfa_topo1.py +++ b/tests/topotests/isis-tilfa-topo1/test_isis_tilfa_topo1.py @@ -179,7 +179,7 @@ def setup_module(mod): router_list = tgen.routers() # For all registered routers, load the zebra configuration file - for rname, router in router_list.iteritems(): + for rname, router in router_list.items(): router.load_config( TopoRouter.RD_ZEBRA, os.path.join(CWD, '{}/zebra.conf'.format(rname)) From 10870bbc206f79dc125f33fe6962fe2ac873ada1 Mon Sep 17 00:00:00 2001 From: Philippe Guibert Date: Tue, 24 Nov 2020 13:10:16 +0000 Subject: [PATCH 5/5] topotests: precise importation folder the topolog importation folder must be precised. otherwise following error message appears: root@dut-vm:~/topotests/bgp_flowspec# python3 test_bgp_flowspec_topo.py Traceback (most recent call last): File "test_bgp_flowspec_topo.py", line 96, in from lib.lutil import lUtil File "/root/topotests/bgp_flowspec/../lib/lutil.py", line 25, in from topolog import logger ImportError: No module named 'topolog' root@dut-vm:~/topotests/bgp_flowspec# The same error occurs with lutil and bgprib which are 2 libraries located under lib/ folder. Some precisions are added too. PR=71290 Signed-off-by: Philippe Guibert --- tests/topotests/bgp_l3vpn_to_bgp_direct/scripts/add_routes.py | 2 +- .../topotests/bgp_l3vpn_to_bgp_direct/scripts/adjacencies.py | 2 +- .../topotests/bgp_l3vpn_to_bgp_direct/scripts/check_routes.py | 2 +- .../topotests/bgp_l3vpn_to_bgp_direct/scripts/cleanup_all.py | 2 +- tests/topotests/bgp_l3vpn_to_bgp_vrf/scripts/add_routes.py | 2 +- tests/topotests/bgp_l3vpn_to_bgp_vrf/scripts/adjacencies.py | 2 +- .../bgp_l3vpn_to_bgp_vrf/scripts/check_linux_mpls.py | 2 +- .../topotests/bgp_l3vpn_to_bgp_vrf/scripts/check_linux_vrf.py | 2 +- tests/topotests/bgp_l3vpn_to_bgp_vrf/scripts/check_routes.py | 4 ++-- tests/topotests/bgp_l3vpn_to_bgp_vrf/scripts/cleanup_all.py | 2 +- .../bgp_l3vpn_to_bgp_vrf/scripts/del_bgp_instances.py | 2 +- .../bgp_l3vpn_to_bgp_vrf/scripts/notification_check.py | 2 +- tests/topotests/bgp_l3vpn_to_bgp_vrf/scripts/scale_down.py | 2 +- tests/topotests/bgp_l3vpn_to_bgp_vrf/scripts/scale_up.py | 2 +- tests/topotests/bgp_rfapi_basic_sanity/scripts/add_routes.py | 2 +- tests/topotests/bgp_rfapi_basic_sanity/scripts/check_close.py | 2 +- .../topotests/bgp_rfapi_basic_sanity/scripts/check_routes.py | 2 +- .../topotests/bgp_rfapi_basic_sanity/scripts/check_timeout.py | 2 +- tests/topotests/bgp_rfapi_basic_sanity/scripts/cleanup_all.py | 2 +- tests/topotests/lib/lutil.py | 2 +- 20 files changed, 21 insertions(+), 21 deletions(-) diff --git a/tests/topotests/bgp_l3vpn_to_bgp_direct/scripts/add_routes.py b/tests/topotests/bgp_l3vpn_to_bgp_direct/scripts/add_routes.py index 3f1157ad72..0deb181f3e 100644 --- a/tests/topotests/bgp_l3vpn_to_bgp_direct/scripts/add_routes.py +++ b/tests/topotests/bgp_l3vpn_to_bgp_direct/scripts/add_routes.py @@ -1,4 +1,4 @@ -from lutil import luCommand +from lib.lutil import luCommand luCommand( "r1", 'vtysh -c "show bgp next"', "99.0.0.. valid", "wait", "See CE static NH" diff --git a/tests/topotests/bgp_l3vpn_to_bgp_direct/scripts/adjacencies.py b/tests/topotests/bgp_l3vpn_to_bgp_direct/scripts/adjacencies.py index ea059c576e..789f93b837 100644 --- a/tests/topotests/bgp_l3vpn_to_bgp_direct/scripts/adjacencies.py +++ b/tests/topotests/bgp_l3vpn_to_bgp_direct/scripts/adjacencies.py @@ -1,4 +1,4 @@ -from lutil import luCommand +from lib.lutil import luCommand luCommand("ce1", "ping 192.168.1.1 -c 1", " 0. packet loss", "pass", "CE->PE ping") luCommand("ce2", "ping 192.168.1.1 -c 1", " 0. packet loss", "pass", "CE->PE ping") diff --git a/tests/topotests/bgp_l3vpn_to_bgp_direct/scripts/check_routes.py b/tests/topotests/bgp_l3vpn_to_bgp_direct/scripts/check_routes.py index 96b4978261..af39a951b7 100644 --- a/tests/topotests/bgp_l3vpn_to_bgp_direct/scripts/check_routes.py +++ b/tests/topotests/bgp_l3vpn_to_bgp_direct/scripts/check_routes.py @@ -1,4 +1,4 @@ -from lutil import luCommand +from lib.lutil import luCommand luCommand( "ce1", diff --git a/tests/topotests/bgp_l3vpn_to_bgp_direct/scripts/cleanup_all.py b/tests/topotests/bgp_l3vpn_to_bgp_direct/scripts/cleanup_all.py index 9f21d99913..38eac14c64 100644 --- a/tests/topotests/bgp_l3vpn_to_bgp_direct/scripts/cleanup_all.py +++ b/tests/topotests/bgp_l3vpn_to_bgp_direct/scripts/cleanup_all.py @@ -1,4 +1,4 @@ -from lutil import luCommand +from lib.lutil import luCommand luCommand( "r1", diff --git a/tests/topotests/bgp_l3vpn_to_bgp_vrf/scripts/add_routes.py b/tests/topotests/bgp_l3vpn_to_bgp_vrf/scripts/add_routes.py index 5c7427763d..375bca8a63 100644 --- a/tests/topotests/bgp_l3vpn_to_bgp_vrf/scripts/add_routes.py +++ b/tests/topotests/bgp_l3vpn_to_bgp_vrf/scripts/add_routes.py @@ -1,4 +1,4 @@ -from lutil import luCommand +from lib.lutil import luCommand luCommand( "r1", 'vtysh -c "add vrf r1-cust1 prefix 99.0.0.1/32"', ".", "none", "IP Address" diff --git a/tests/topotests/bgp_l3vpn_to_bgp_vrf/scripts/adjacencies.py b/tests/topotests/bgp_l3vpn_to_bgp_vrf/scripts/adjacencies.py index 53cf353fa0..f5145753a5 100644 --- a/tests/topotests/bgp_l3vpn_to_bgp_vrf/scripts/adjacencies.py +++ b/tests/topotests/bgp_l3vpn_to_bgp_vrf/scripts/adjacencies.py @@ -1,4 +1,4 @@ -from lutil import luCommand +from lib.lutil import luCommand luCommand("ce1", 'vtysh -c "show bgp summary"', " 00:0", "wait", "Adjacencies up", 180) luCommand("ce2", 'vtysh -c "show bgp summary"', " 00:0", "wait", "Adjacencies up", 180) diff --git a/tests/topotests/bgp_l3vpn_to_bgp_vrf/scripts/check_linux_mpls.py b/tests/topotests/bgp_l3vpn_to_bgp_vrf/scripts/check_linux_mpls.py index 20113b1058..a5f95f94bf 100644 --- a/tests/topotests/bgp_l3vpn_to_bgp_vrf/scripts/check_linux_mpls.py +++ b/tests/topotests/bgp_l3vpn_to_bgp_vrf/scripts/check_linux_mpls.py @@ -1,4 +1,4 @@ -from lutil import luCommand, luLast +from lib.lutil import luCommand, luLast from lib import topotest ret = luCommand( diff --git a/tests/topotests/bgp_l3vpn_to_bgp_vrf/scripts/check_linux_vrf.py b/tests/topotests/bgp_l3vpn_to_bgp_vrf/scripts/check_linux_vrf.py index b552ea0406..7c154ecd15 100644 --- a/tests/topotests/bgp_l3vpn_to_bgp_vrf/scripts/check_linux_vrf.py +++ b/tests/topotests/bgp_l3vpn_to_bgp_vrf/scripts/check_linux_vrf.py @@ -1,4 +1,4 @@ -from lutil import luCommand +from lib.lutil import luCommand from customize import l3mdev_accept l3mdev_rtrs = ["r1", "r3", "r4", "ce4"] diff --git a/tests/topotests/bgp_l3vpn_to_bgp_vrf/scripts/check_routes.py b/tests/topotests/bgp_l3vpn_to_bgp_vrf/scripts/check_routes.py index 98d2a3bafc..d55169a19e 100644 --- a/tests/topotests/bgp_l3vpn_to_bgp_vrf/scripts/check_routes.py +++ b/tests/topotests/bgp_l3vpn_to_bgp_vrf/scripts/check_routes.py @@ -1,5 +1,5 @@ -from lutil import luCommand -from bgprib import bgpribRequireVpnRoutes, bgpribRequireUnicastRoutes +from lib.lutil import luCommand +from lib.bgprib import bgpribRequireVpnRoutes, bgpribRequireUnicastRoutes ######################################################################## # CE routers: contain routes they originate diff --git a/tests/topotests/bgp_l3vpn_to_bgp_vrf/scripts/cleanup_all.py b/tests/topotests/bgp_l3vpn_to_bgp_vrf/scripts/cleanup_all.py index af77ab01c1..a27b178548 100644 --- a/tests/topotests/bgp_l3vpn_to_bgp_vrf/scripts/cleanup_all.py +++ b/tests/topotests/bgp_l3vpn_to_bgp_vrf/scripts/cleanup_all.py @@ -1,4 +1,4 @@ -from lutil import luCommand +from lib.lutil import luCommand luCommand( "r1", diff --git a/tests/topotests/bgp_l3vpn_to_bgp_vrf/scripts/del_bgp_instances.py b/tests/topotests/bgp_l3vpn_to_bgp_vrf/scripts/del_bgp_instances.py index 477578bdbd..fcbc3df6ef 100644 --- a/tests/topotests/bgp_l3vpn_to_bgp_vrf/scripts/del_bgp_instances.py +++ b/tests/topotests/bgp_l3vpn_to_bgp_vrf/scripts/del_bgp_instances.py @@ -1,4 +1,4 @@ -from lutil import luCommand +from lib.lutil import luCommand luCommand( "r1", diff --git a/tests/topotests/bgp_l3vpn_to_bgp_vrf/scripts/notification_check.py b/tests/topotests/bgp_l3vpn_to_bgp_vrf/scripts/notification_check.py index 2b0a85a91a..dd2e24722f 100644 --- a/tests/topotests/bgp_l3vpn_to_bgp_vrf/scripts/notification_check.py +++ b/tests/topotests/bgp_l3vpn_to_bgp_vrf/scripts/notification_check.py @@ -1,4 +1,4 @@ -from lutil import luCommand +from lib.lutil import luCommand rtrs = ["ce1", "ce2", "ce3", "r1", "r2", "r3", "r4"] for rtr in rtrs: diff --git a/tests/topotests/bgp_l3vpn_to_bgp_vrf/scripts/scale_down.py b/tests/topotests/bgp_l3vpn_to_bgp_vrf/scripts/scale_down.py index 7990533f3a..6ce81baf11 100644 --- a/tests/topotests/bgp_l3vpn_to_bgp_vrf/scripts/scale_down.py +++ b/tests/topotests/bgp_l3vpn_to_bgp_vrf/scripts/scale_down.py @@ -1,4 +1,4 @@ -from lutil import luCommand +from lib.lutil import luCommand ret = luCommand( "ce1", diff --git a/tests/topotests/bgp_l3vpn_to_bgp_vrf/scripts/scale_up.py b/tests/topotests/bgp_l3vpn_to_bgp_vrf/scripts/scale_up.py index 3c768640a1..04ca03973d 100644 --- a/tests/topotests/bgp_l3vpn_to_bgp_vrf/scripts/scale_up.py +++ b/tests/topotests/bgp_l3vpn_to_bgp_vrf/scripts/scale_up.py @@ -1,4 +1,4 @@ -from lutil import luCommand +from lib.lutil import luCommand num = 50000 b = int(num / (256 * 256)) diff --git a/tests/topotests/bgp_rfapi_basic_sanity/scripts/add_routes.py b/tests/topotests/bgp_rfapi_basic_sanity/scripts/add_routes.py index f4b4da55d2..bc47dfc85c 100644 --- a/tests/topotests/bgp_rfapi_basic_sanity/scripts/add_routes.py +++ b/tests/topotests/bgp_rfapi_basic_sanity/scripts/add_routes.py @@ -1,4 +1,4 @@ -from lutil import luCommand +from lib.lutil import luCommand holddownFactorSet = luCommand( "r1", diff --git a/tests/topotests/bgp_rfapi_basic_sanity/scripts/check_close.py b/tests/topotests/bgp_rfapi_basic_sanity/scripts/check_close.py index 9fdef84cdf..e68fac86fa 100644 --- a/tests/topotests/bgp_rfapi_basic_sanity/scripts/check_close.py +++ b/tests/topotests/bgp_rfapi_basic_sanity/scripts/check_close.py @@ -1,4 +1,4 @@ -from lutil import luCommand +from lib.lutil import luCommand holddownFactorSet = luCommand( "r1", diff --git a/tests/topotests/bgp_rfapi_basic_sanity/scripts/check_routes.py b/tests/topotests/bgp_rfapi_basic_sanity/scripts/check_routes.py index 1caa827ce2..24b3cba96e 100644 --- a/tests/topotests/bgp_rfapi_basic_sanity/scripts/check_routes.py +++ b/tests/topotests/bgp_rfapi_basic_sanity/scripts/check_routes.py @@ -1,4 +1,4 @@ -from lutil import luCommand +from lib.lutil import luCommand luCommand("r1", 'vtysh -c "show bgp ipv4 vpn"', "", "none", "VPN SAFI") luCommand("r2", 'vtysh -c "show bgp ipv4 vpn"', "", "none", "VPN SAFI") diff --git a/tests/topotests/bgp_rfapi_basic_sanity/scripts/check_timeout.py b/tests/topotests/bgp_rfapi_basic_sanity/scripts/check_timeout.py index e68e9e93ab..f5c2db25ff 100644 --- a/tests/topotests/bgp_rfapi_basic_sanity/scripts/check_timeout.py +++ b/tests/topotests/bgp_rfapi_basic_sanity/scripts/check_timeout.py @@ -1,4 +1,4 @@ -from lutil import luCommand +from lib.lutil import luCommand holddownFactorSet = luCommand( "r1", diff --git a/tests/topotests/bgp_rfapi_basic_sanity/scripts/cleanup_all.py b/tests/topotests/bgp_rfapi_basic_sanity/scripts/cleanup_all.py index eea977bfaf..7201ac8111 100644 --- a/tests/topotests/bgp_rfapi_basic_sanity/scripts/cleanup_all.py +++ b/tests/topotests/bgp_rfapi_basic_sanity/scripts/cleanup_all.py @@ -1,4 +1,4 @@ -from lutil import luCommand +from lib.lutil import luCommand luCommand( "r1", diff --git a/tests/topotests/lib/lutil.py b/tests/topotests/lib/lutil.py index dcf1d010b1..9cbea67af1 100644 --- a/tests/topotests/lib/lutil.py +++ b/tests/topotests/lib/lutil.py @@ -23,7 +23,7 @@ import time import datetime import json import math -from topolog import logger +from lib.topolog import logger from mininet.net import Mininet