From 11761ab0f4bb85112c94a182f835852aaab67d99 Mon Sep 17 00:00:00 2001 From: Mark Stapp Date: Wed, 23 Sep 2020 17:08:36 -0400 Subject: [PATCH] tests: python3 compat fixes for topotests: tabs and misc Use only spaces in python files; no tabs; also a couple of small api fixes. Signed-off-by: Mark Stapp --- .../test_all_protocol_startup.py | 160 +++++++++--------- .../test_bgp_basic_functionality.py | 0 tests/topotests/bgp-evpn-mh/test_evpn_mh.py | 4 +- .../test_bgp_path_attributes.py | 0 .../test_prefix_lists.py | 0 .../bgp-route-map/test_route_map_topo1.py | 0 .../bgp-route-map/test_route_map_topo2.py | 0 .../bgp_as_allow_in/test_bgp_as_allow_in.py | 0 tests/topotests/bgp_evpn_rt5/test_bgp_evpn.py | 2 +- .../test_bgp_gr_functionality_topo1.py | 0 .../test_bgp_gr_functionality_topo2.py | 0 .../test_bgp_large_community_topo_1.py | 0 .../test_bgp_large_community_topo_2.py | 0 .../test_bgp_multi_vrf_topo1.py | 0 .../test_bgp_multi_vrf_topo2.py | 0 .../test_bgp_multiview_topo1.py | 0 ...test_bgp_recursive_route_ebgp_multi_hop.py | 0 .../test_bgp_aggregation.py | 0 .../test_bgp_vrf_dynamic_route_leak_topo1.py | 0 .../test_bgp_vrf_dynamic_route_leak_topo2.py | 0 .../topotests/eigrp-topo1/test_eigrp_topo1.py | 2 +- .../test_evpn_type5_chaos_topo1.py | 0 .../test_evpn_type5_topo1.py | 4 +- .../isis-topo1-vrf/test_isis_topo1_vrf.py | 4 +- tests/topotests/ldp-topo1/test_ldp_topo1.py | 0 tests/topotests/lib/common_config.py | 4 +- tests/topotests/lib/ltemplate.py | 8 +- tests/topotests/lib/lutil.py | 38 ++--- tests/topotests/lib/ospf.py | 8 +- tests/topotests/lib/topogen.py | 21 +-- tests/topotests/lib/topojson.py | 2 +- tests/topotests/lib/topolog.py | 2 +- tests/topotests/lib/topotest.py | 8 +- tests/topotests/ospf-topo2/test_ospf_topo2.py | 22 +-- tests/topotests/pbr-topo1/test_pbr_topo1.py | 20 +-- tests/topotests/rip-topo1/test_rip_topo1.py | 8 +- .../topotests/ripng-topo1/test_ripng_topo1.py | 0 37 files changed, 158 insertions(+), 159 deletions(-) mode change 100755 => 100644 tests/topotests/all-protocol-startup/test_all_protocol_startup.py mode change 100755 => 100644 tests/topotests/bgp-basic-functionality-topo1/test_bgp_basic_functionality.py mode change 100755 => 100644 tests/topotests/bgp-path-attributes-topo1/test_bgp_path_attributes.py mode change 100755 => 100644 tests/topotests/bgp-prefix-list-topo1/test_prefix_lists.py mode change 100755 => 100644 tests/topotests/bgp-route-map/test_route_map_topo1.py mode change 100755 => 100644 tests/topotests/bgp-route-map/test_route_map_topo2.py mode change 100755 => 100644 tests/topotests/bgp_as_allow_in/test_bgp_as_allow_in.py mode change 100755 => 100644 tests/topotests/bgp_evpn_rt5/test_bgp_evpn.py mode change 100755 => 100644 tests/topotests/bgp_gr_functionality_topo1/test_bgp_gr_functionality_topo1.py mode change 100755 => 100644 tests/topotests/bgp_gr_functionality_topo2/test_bgp_gr_functionality_topo2.py mode change 100755 => 100644 tests/topotests/bgp_large_community/test_bgp_large_community_topo_1.py mode change 100755 => 100644 tests/topotests/bgp_large_community/test_bgp_large_community_topo_2.py mode change 100755 => 100644 tests/topotests/bgp_multi_vrf_topo1/test_bgp_multi_vrf_topo1.py mode change 100755 => 100644 tests/topotests/bgp_multi_vrf_topo2/test_bgp_multi_vrf_topo2.py mode change 100755 => 100644 tests/topotests/bgp_multiview_topo1/test_bgp_multiview_topo1.py mode change 100755 => 100644 tests/topotests/bgp_recursive_route_ebgp_multi_hop/test_bgp_recursive_route_ebgp_multi_hop.py mode change 100755 => 100644 tests/topotests/bgp_route_aggregation/test_bgp_aggregation.py mode change 100755 => 100644 tests/topotests/bgp_vrf_dynamic_route_leak/test_bgp_vrf_dynamic_route_leak_topo1.py mode change 100755 => 100644 tests/topotests/bgp_vrf_dynamic_route_leak/test_bgp_vrf_dynamic_route_leak_topo2.py mode change 100755 => 100644 tests/topotests/evpn_type5_test_topo1/test_evpn_type5_chaos_topo1.py mode change 100755 => 100644 tests/topotests/evpn_type5_test_topo1/test_evpn_type5_topo1.py mode change 100755 => 100644 tests/topotests/ldp-topo1/test_ldp_topo1.py mode change 100755 => 100644 tests/topotests/lib/lutil.py mode change 100755 => 100644 tests/topotests/rip-topo1/test_rip_topo1.py mode change 100755 => 100644 tests/topotests/ripng-topo1/test_ripng_topo1.py diff --git a/tests/topotests/all-protocol-startup/test_all_protocol_startup.py b/tests/topotests/all-protocol-startup/test_all_protocol_startup.py old mode 100755 new mode 100644 index 2a00398e28..136689e01e --- a/tests/topotests/all-protocol-startup/test_all_protocol_startup.py +++ b/tests/topotests/all-protocol-startup/test_all_protocol_startup.py @@ -113,8 +113,8 @@ def setup_module(module): net['r%s' % i].loadConf('ospfd', '%s/r%s/ospfd.conf' % (thisDir, i)) if net['r1'].checkRouterVersion('<', '4.0'): net['r%s' % i].loadConf('ospf6d', '%s/r%s/ospf6d.conf-pre-v4' % (thisDir, i)) - else: - net['r%s' % i].loadConf('ospf6d', '%s/r%s/ospf6d.conf' % (thisDir, i)) + else: + net['r%s' % i].loadConf('ospf6d', '%s/r%s/ospf6d.conf' % (thisDir, i)) net['r%s' % i].loadConf('isisd', '%s/r%s/isisd.conf' % (thisDir, i)) net['r%s' % i].loadConf('bgpd', '%s/r%s/bgpd.conf' % (thisDir, i)) if net['r%s' % i].daemon_available('ldpd'): @@ -611,7 +611,7 @@ def test_ospfv2_interfaces(): actual = net['r%s' % i].cmd('vtysh -c "show ip ospf interface" 2> /dev/null').rstrip() # Mask out Bandwidth portion. They may change.. actual = re.sub(r"BW [0-9]+ Mbit", "BW XX Mbit", actual) - actual = re.sub(r"ifindex [0-9]", "ifindex X", actual) + actual = re.sub(r"ifindex [0-9]", "ifindex X", actual) # Drop time in next due actual = re.sub(r"Hello due in [0-9\.]+s", "Hello due in XX.XXXs", actual) @@ -882,45 +882,45 @@ def test_bgp_ipv4(): print("******************************************\n") diffresult = {} for i in range(1, 2): - success = 0 - for refTableFile in (glob.glob( - '%s/r%s/show_bgp_ipv4*.ref' % (thisDir, i))): - if os.path.isfile(refTableFile): - # Read expected result from file - expected = open(refTableFile).read().rstrip() - # Fix newlines (make them all the same) - expected = ('\n'.join(expected.splitlines()) + '\n').splitlines(1) - - # Actual output from router - actual = net['r%s' % i].cmd('vtysh -c "show bgp ipv4" 2> /dev/null').rstrip() - # Remove summary line (changed recently) - actual = re.sub(r'Total number.*', '', actual) - actual = re.sub(r'Displayed.*', '', actual) - actual = actual.rstrip() - # Fix newlines (make them all the same) - actual = ('\n'.join(actual.splitlines()) + '\n').splitlines(1) - - # Generate Diff - diff = topotest.get_textdiff(actual, expected, - title1="actual SHOW BGP IPv4", - title2="expected SHOW BGP IPv4") - - # Empty string if it matches, otherwise diff contains unified diff - if diff: - diffresult[refTableFile] = diff - else: - success = 1 - print("template %s matched: r%s ok" % (refTableFile, i)) - break - - if not success: - resultstr = 'No template matched.\n' - for f in diffresult.iterkeys(): - resultstr += ( - 'template %s: r%s failed SHOW BGP IPv4 check:\n%s\n' - % (f, i, diffresult[f])) - raise AssertionError( - "SHOW BGP IPv4 failed for router r%s:\n%s" % (i, resultstr)) + success = 0 + for refTableFile in (glob.glob( + '%s/r%s/show_bgp_ipv4*.ref' % (thisDir, i))): + if os.path.isfile(refTableFile): + # Read expected result from file + expected = open(refTableFile).read().rstrip() + # Fix newlines (make them all the same) + expected = ('\n'.join(expected.splitlines()) + '\n').splitlines(1) + + # Actual output from router + actual = net['r%s' % i].cmd('vtysh -c "show bgp ipv4" 2> /dev/null').rstrip() + # Remove summary line (changed recently) + actual = re.sub(r'Total number.*', '', actual) + actual = re.sub(r'Displayed.*', '', actual) + actual = actual.rstrip() + # Fix newlines (make them all the same) + actual = ('\n'.join(actual.splitlines()) + '\n').splitlines(1) + + # Generate Diff + diff = topotest.get_textdiff(actual, expected, + title1="actual SHOW BGP IPv4", + title2="expected SHOW BGP IPv4") + + # Empty string if it matches, otherwise diff contains unified diff + if diff: + diffresult[refTableFile] = diff + else: + success = 1 + print("template %s matched: r%s ok" % (refTableFile, i)) + break + + if not success: + resultstr = 'No template matched.\n' + for f in diffresult.iterkeys(): + resultstr += ( + 'template %s: r%s failed SHOW BGP IPv4 check:\n%s\n' + % (f, i, diffresult[f])) + raise AssertionError( + "SHOW BGP IPv4 failed for router r%s:\n%s" % (i, resultstr)) # Make sure that all daemons are running for i in range(1, 2): @@ -945,44 +945,44 @@ def test_bgp_ipv6(): print("******************************************\n") diffresult = {} for i in range(1, 2): - success = 0 - for refTableFile in (glob.glob( - '%s/r%s/show_bgp_ipv6*.ref' % (thisDir, i))): - if os.path.isfile(refTableFile): - # Read expected result from file - expected = open(refTableFile).read().rstrip() - # Fix newlines (make them all the same) - expected = ('\n'.join(expected.splitlines()) + '\n').splitlines(1) - - # Actual output from router - actual = net['r%s' % i].cmd('vtysh -c "show bgp ipv6" 2> /dev/null').rstrip() - # Remove summary line (changed recently) - actual = re.sub(r'Total number.*', '', actual) - actual = re.sub(r'Displayed.*', '', actual) - actual = actual.rstrip() - # Fix newlines (make them all the same) - actual = ('\n'.join(actual.splitlines()) + '\n').splitlines(1) - - # Generate Diff - diff = topotest.get_textdiff(actual, expected, - title1="actual SHOW BGP IPv6", - title2="expected SHOW BGP IPv6") - - # Empty string if it matches, otherwise diff contains unified diff - if diff: - diffresult[refTableFile] = diff - else: - success = 1 - print("template %s matched: r%s ok" % (refTableFile, i)) - - if not success: - resultstr = 'No template matched.\n' - for f in diffresult.iterkeys(): - resultstr += ( - 'template %s: r%s failed SHOW BGP IPv6 check:\n%s\n' - % (f, i, diffresult[f])) - raise AssertionError( - "SHOW BGP IPv6 failed for router r%s:\n%s" % (i, resultstr)) + success = 0 + for refTableFile in (glob.glob( + '%s/r%s/show_bgp_ipv6*.ref' % (thisDir, i))): + if os.path.isfile(refTableFile): + # Read expected result from file + expected = open(refTableFile).read().rstrip() + # Fix newlines (make them all the same) + expected = ('\n'.join(expected.splitlines()) + '\n').splitlines(1) + + # Actual output from router + actual = net['r%s' % i].cmd('vtysh -c "show bgp ipv6" 2> /dev/null').rstrip() + # Remove summary line (changed recently) + actual = re.sub(r'Total number.*', '', actual) + actual = re.sub(r'Displayed.*', '', actual) + actual = actual.rstrip() + # Fix newlines (make them all the same) + actual = ('\n'.join(actual.splitlines()) + '\n').splitlines(1) + + # Generate Diff + diff = topotest.get_textdiff(actual, expected, + title1="actual SHOW BGP IPv6", + title2="expected SHOW BGP IPv6") + + # Empty string if it matches, otherwise diff contains unified diff + if diff: + diffresult[refTableFile] = diff + else: + success = 1 + print("template %s matched: r%s ok" % (refTableFile, i)) + + if not success: + resultstr = 'No template matched.\n' + for f in diffresult.iterkeys(): + resultstr += ( + 'template %s: r%s failed SHOW BGP IPv6 check:\n%s\n' + % (f, i, diffresult[f])) + raise AssertionError( + "SHOW BGP IPv6 failed for router r%s:\n%s" % (i, resultstr)) # Make sure that all daemons are running for i in range(1, 2): diff --git a/tests/topotests/bgp-basic-functionality-topo1/test_bgp_basic_functionality.py b/tests/topotests/bgp-basic-functionality-topo1/test_bgp_basic_functionality.py old mode 100755 new mode 100644 diff --git a/tests/topotests/bgp-evpn-mh/test_evpn_mh.py b/tests/topotests/bgp-evpn-mh/test_evpn_mh.py index ee50a422a7..9af22c06bd 100644 --- a/tests/topotests/bgp-evpn-mh/test_evpn_mh.py +++ b/tests/topotests/bgp-evpn-mh/test_evpn_mh.py @@ -477,9 +477,9 @@ def check_es(dut): vtep_ips.append(vtep["vtep_ip"]) if "local" in types: - result = check_local_es(esi, vtep_ips, dut.name, []) + result = check_local_es(esi, vtep_ips, dut.name, []) else: - result = check_remote_es(esi, vtep_ips, dut.name, []) + result = check_remote_es(esi, vtep_ips, dut.name, []) if result: return result diff --git a/tests/topotests/bgp-path-attributes-topo1/test_bgp_path_attributes.py b/tests/topotests/bgp-path-attributes-topo1/test_bgp_path_attributes.py old mode 100755 new mode 100644 diff --git a/tests/topotests/bgp-prefix-list-topo1/test_prefix_lists.py b/tests/topotests/bgp-prefix-list-topo1/test_prefix_lists.py old mode 100755 new mode 100644 diff --git a/tests/topotests/bgp-route-map/test_route_map_topo1.py b/tests/topotests/bgp-route-map/test_route_map_topo1.py old mode 100755 new mode 100644 diff --git a/tests/topotests/bgp-route-map/test_route_map_topo2.py b/tests/topotests/bgp-route-map/test_route_map_topo2.py old mode 100755 new mode 100644 diff --git a/tests/topotests/bgp_as_allow_in/test_bgp_as_allow_in.py b/tests/topotests/bgp_as_allow_in/test_bgp_as_allow_in.py old mode 100755 new mode 100644 diff --git a/tests/topotests/bgp_evpn_rt5/test_bgp_evpn.py b/tests/topotests/bgp_evpn_rt5/test_bgp_evpn.py old mode 100755 new mode 100644 index 3ad989c601..0d99f23ad9 --- a/tests/topotests/bgp_evpn_rt5/test_bgp_evpn.py +++ b/tests/topotests/bgp_evpn_rt5/test_bgp_evpn.py @@ -143,7 +143,7 @@ def setup_module(mod): logger.info('result: '+output); router = tgen.gears['r1'] - for rname, router in router_list.iteritems(): + for rname, router in router_list.items(): if rname == 'r1': router.load_config( TopoRouter.RD_ZEBRA, diff --git a/tests/topotests/bgp_gr_functionality_topo1/test_bgp_gr_functionality_topo1.py b/tests/topotests/bgp_gr_functionality_topo1/test_bgp_gr_functionality_topo1.py old mode 100755 new mode 100644 diff --git a/tests/topotests/bgp_gr_functionality_topo2/test_bgp_gr_functionality_topo2.py b/tests/topotests/bgp_gr_functionality_topo2/test_bgp_gr_functionality_topo2.py old mode 100755 new mode 100644 diff --git a/tests/topotests/bgp_large_community/test_bgp_large_community_topo_1.py b/tests/topotests/bgp_large_community/test_bgp_large_community_topo_1.py old mode 100755 new mode 100644 diff --git a/tests/topotests/bgp_large_community/test_bgp_large_community_topo_2.py b/tests/topotests/bgp_large_community/test_bgp_large_community_topo_2.py old mode 100755 new mode 100644 diff --git a/tests/topotests/bgp_multi_vrf_topo1/test_bgp_multi_vrf_topo1.py b/tests/topotests/bgp_multi_vrf_topo1/test_bgp_multi_vrf_topo1.py old mode 100755 new mode 100644 diff --git a/tests/topotests/bgp_multi_vrf_topo2/test_bgp_multi_vrf_topo2.py b/tests/topotests/bgp_multi_vrf_topo2/test_bgp_multi_vrf_topo2.py old mode 100755 new mode 100644 diff --git a/tests/topotests/bgp_multiview_topo1/test_bgp_multiview_topo1.py b/tests/topotests/bgp_multiview_topo1/test_bgp_multiview_topo1.py old mode 100755 new mode 100644 diff --git a/tests/topotests/bgp_recursive_route_ebgp_multi_hop/test_bgp_recursive_route_ebgp_multi_hop.py b/tests/topotests/bgp_recursive_route_ebgp_multi_hop/test_bgp_recursive_route_ebgp_multi_hop.py old mode 100755 new mode 100644 diff --git a/tests/topotests/bgp_route_aggregation/test_bgp_aggregation.py b/tests/topotests/bgp_route_aggregation/test_bgp_aggregation.py old mode 100755 new mode 100644 diff --git a/tests/topotests/bgp_vrf_dynamic_route_leak/test_bgp_vrf_dynamic_route_leak_topo1.py b/tests/topotests/bgp_vrf_dynamic_route_leak/test_bgp_vrf_dynamic_route_leak_topo1.py old mode 100755 new mode 100644 diff --git a/tests/topotests/bgp_vrf_dynamic_route_leak/test_bgp_vrf_dynamic_route_leak_topo2.py b/tests/topotests/bgp_vrf_dynamic_route_leak/test_bgp_vrf_dynamic_route_leak_topo2.py old mode 100755 new mode 100644 diff --git a/tests/topotests/eigrp-topo1/test_eigrp_topo1.py b/tests/topotests/eigrp-topo1/test_eigrp_topo1.py index 70666a3d61..3ce1472ac0 100644 --- a/tests/topotests/eigrp-topo1/test_eigrp_topo1.py +++ b/tests/topotests/eigrp-topo1/test_eigrp_topo1.py @@ -252,7 +252,7 @@ def ip_eigrp_topo(node): if code not in ["P", "A", "U", "Q", "R", "r", "s"]: continue - if not result.has_key(code): + if code not in result: result[code] = {} # Split network from the rest diff --git a/tests/topotests/evpn_type5_test_topo1/test_evpn_type5_chaos_topo1.py b/tests/topotests/evpn_type5_test_topo1/test_evpn_type5_chaos_topo1.py old mode 100755 new mode 100644 diff --git a/tests/topotests/evpn_type5_test_topo1/test_evpn_type5_topo1.py b/tests/topotests/evpn_type5_test_topo1/test_evpn_type5_topo1.py old mode 100755 new mode 100644 index 9e385823fc..c1eb7d68bb --- a/tests/topotests/evpn_type5_test_topo1/test_evpn_type5_topo1.py +++ b/tests/topotests/evpn_type5_test_topo1/test_evpn_type5_topo1.py @@ -26,9 +26,9 @@ Following tests are covered to test EVPN-Type5 functionality: 1. RD verification (manual/auto). 2. RT verification(manual) 3. In an active/standby EVPN implementation, if active DCG goes down, - secondary takes over. + secondary takes over. 4. EVPN routes are advertised/withdrawn, based on VNFs - advertising/withdrawing IP prefixes. + advertising/withdrawing IP prefixes. 5. Route-map operations for EVPN address family. 6. BGP attributes for EVPN address-family. """ diff --git a/tests/topotests/isis-topo1-vrf/test_isis_topo1_vrf.py b/tests/topotests/isis-topo1-vrf/test_isis_topo1_vrf.py index 65515f22cc..7943b94189 100644 --- a/tests/topotests/isis-topo1-vrf/test_isis_topo1_vrf.py +++ b/tests/topotests/isis-topo1-vrf/test_isis_topo1_vrf.py @@ -210,7 +210,7 @@ def test_isis_linux_route_installation(): dist = platform.dist() if (dist[1] == "16.04"): - pytest.skip("Kernel not supported for vrf") + pytest.skip("Kernel not supported for vrf") "Check whether all expected routes are present and installed in the OS" tgen = get_topogen() @@ -267,7 +267,7 @@ def test_isis_linux_route6_installation(): dist = platform.dist() if (dist[1] == "16.04"): - pytest.skip("Kernel not supported for vrf") + pytest.skip("Kernel not supported for vrf") "Check whether all expected routes are present and installed in the OS" tgen = get_topogen() diff --git a/tests/topotests/ldp-topo1/test_ldp_topo1.py b/tests/topotests/ldp-topo1/test_ldp_topo1.py old mode 100755 new mode 100644 diff --git a/tests/topotests/lib/common_config.py b/tests/topotests/lib/common_config.py index 6dd8d646f3..c6944c3568 100644 --- a/tests/topotests/lib/common_config.py +++ b/tests/topotests/lib/common_config.py @@ -31,16 +31,14 @@ from re import search as re_search from tempfile import mkdtemp import os +import io import sys -import ConfigParser import traceback import socket import ipaddress import platform - if sys.version_info[0] > 2: - import io import configparser else: import StringIO diff --git a/tests/topotests/lib/ltemplate.py b/tests/topotests/lib/ltemplate.py index 192c121008..3c93e1ac5c 100644 --- a/tests/topotests/lib/ltemplate.py +++ b/tests/topotests/lib/ltemplate.py @@ -157,8 +157,8 @@ def ltemplateTest(script, SkipIfFailed=True, CallOnFail=None, CheckFuncStr=None, if SkipIfFailed and tgen.routers_have_failure(): pytest.skip(tgen.errors) if numEntry > 0: - if not KeepGoing: - pytest.skip("Have %d errors" % numEntry) + if not KeepGoing: + pytest.skip("Have %d errors" % numEntry) if CheckFuncStr != None: check = eval(CheckFuncStr) @@ -172,8 +172,8 @@ def ltemplateTest(script, SkipIfFailed=True, CallOnFail=None, CheckFuncStr=None, if numFail > 0: luShowFail() fatal_error = "%d tests failed" % numFail - if not KeepGoing: - assert "scripts/cleanup_all.py failed" == "See summary output above", fatal_error + if not KeepGoing: + assert "scripts/cleanup_all.py failed" == "See summary output above", fatal_error # Memory leak test template def test_memory_leak(): diff --git a/tests/topotests/lib/lutil.py b/tests/topotests/lib/lutil.py old mode 100755 new mode 100644 index 4ea97a3692..05ed9c007d --- a/tests/topotests/lib/lutil.py +++ b/tests/topotests/lib/lutil.py @@ -204,17 +204,17 @@ Total %-4d %-4d %d\n\ self.log('WARNING: JSON load failed -- confirm command output is in JSON format.') self.log('COMMAND OUTPUT:%s:' % report) - # Experiment: can we achieve the same match behavior via DOTALL - # without converting newlines to spaces? - out_nl = out - search_nl = re.search(regexp, out_nl, re.DOTALL); - self.l_last_nl = search_nl - # Set up for comparison - if search_nl != None: - group_nl = search_nl.group() - group_nl_converted = " ".join(group_nl.splitlines()) + # Experiment: can we achieve the same match behavior via DOTALL + # without converting newlines to spaces? + out_nl = out + search_nl = re.search(regexp, out_nl, re.DOTALL); + self.l_last_nl = search_nl + # Set up for comparison + if search_nl != None: + group_nl = search_nl.group() + group_nl_converted = " ".join(group_nl.splitlines()) else: - group_nl_converted = None + group_nl_converted = None out = " ".join(out.splitlines()) search = re.search(regexp, out) @@ -234,9 +234,9 @@ Total %-4d %-4d %d\n\ success = False level = 5 self.log('found:%s:' % ret, level) - # Experiment: compare matched strings obtained each way - if self.l_dotall_experiment and (group_nl_converted != ret): - self.log('DOTALL experiment: strings differ dotall=[%s] orig=[%s]' % (group_nl_converted, ret), 9) + # Experiment: compare matched strings obtained each way + if self.l_dotall_experiment and (group_nl_converted != ret): + self.log('DOTALL experiment: strings differ dotall=[%s] orig=[%s]' % (group_nl_converted, ret), 9) if op == 'pass' or op == 'fail': self.result(target, success, result) if js != None: @@ -297,13 +297,13 @@ def luCommand(target, command, regexp='.', op='none', result='', time=10, return def luLast(usenl=False): if usenl: - if LUtil.l_last_nl != None: - LUtil.log('luLast:%s:' % LUtil.l_last_nl.group(), 7) - return LUtil.l_last_nl + if LUtil.l_last_nl != None: + LUtil.log('luLast:%s:' % LUtil.l_last_nl.group(), 7) + return LUtil.l_last_nl else: - if LUtil.l_last != None: - LUtil.log('luLast:%s:' % LUtil.l_last.group(), 7) - return LUtil.l_last + if LUtil.l_last != None: + LUtil.log('luLast:%s:' % LUtil.l_last.group(), 7) + return LUtil.l_last def luInclude(filename, CallOnFail=None): tstFile = LUtil.base_script_dir + '/' + filename diff --git a/tests/topotests/lib/ospf.py b/tests/topotests/lib/ospf.py index a2351bf747..3596525c5e 100644 --- a/tests/topotests/lib/ospf.py +++ b/tests/topotests/lib/ospf.py @@ -516,7 +516,7 @@ def verify_ospf_neighbor(tgen, topo, dut=None, input_dict=None, lan=False): logger.debug("Entering lib API: verify_ospf_neighbor()") result = False if input_dict: - for router, rnode in tgen.routers().iteritems(): + for router, rnode in tgen.routers().items(): if 'ospf' not in topo['routers'][router]: continue @@ -584,7 +584,7 @@ def verify_ospf_neighbor(tgen, topo, dut=None, input_dict=None, lan=False): return errormsg continue else: - for router, rnode in tgen.routers().iteritems(): + for router, rnode in tgen.routers().items(): if 'ospf' not in topo['routers'][router]: continue @@ -694,7 +694,7 @@ def verify_ospf_rib(tgen, dut, input_dict, next_hop=None, additional_nexthops_in_required_nhs = [] found_hops = [] for routerInput in input_dict.keys(): - for router, rnode in router_list.iteritems(): + for router, rnode in router_list.items(): if router != dut: continue @@ -927,7 +927,7 @@ def verify_ospf_interface(tgen, topo, dut=None,lan=False, input_dict=None): logger.debug("Entering lib API: verify_ospf_interface()") result = False - for router, rnode in tgen.routers().iteritems(): + for router, rnode in tgen.routers().items(): if 'ospf' not in topo['routers'][router]: continue diff --git a/tests/topotests/lib/topogen.py b/tests/topotests/lib/topogen.py index 171a894b35..ffdcb683e7 100644 --- a/tests/topotests/lib/topogen.py +++ b/tests/topotests/lib/topogen.py @@ -40,6 +40,7 @@ Basic usage instructions: import os import sys +import io import logging import json @@ -97,7 +98,7 @@ tgen_defaults = { "verbosity": "info", "frrdir": "/usr/lib/frr", "routertype": "frr", - "memleak_path": None, + "memleak_path": "", } @@ -182,7 +183,7 @@ class Topogen(object): params["frrdir"] = self.config.get(self.CONFIG_SECTION, "frrdir") params["memleak_path"] = self.config.get(self.CONFIG_SECTION, "memleak_path") - if not params.has_key("routertype"): + if "routertype" not in params: params["routertype"] = self.config.get(self.CONFIG_SECTION, "routertype") self.gears[name] = TopoRouter(self, cls, name, **params) @@ -360,7 +361,7 @@ class Topogen(object): memleak_file = os.environ.get("TOPOTESTS_CHECK_MEMLEAK") or self.config.get( self.CONFIG_SECTION, "memleak_path" ) - if memleak_file is None: + if memleak_file == "" or memleak_file == None: return False return True @@ -586,7 +587,7 @@ class TopoRouter(TopoGear): self.cls = cls self.options = {} self.routertype = params.get("routertype", "frr") - if not params.has_key("privateDirs"): + if "privateDirs" not in params: params["privateDirs"] = self.PRIVATE_DIRS self.options["memleak_path"] = params.get("memleak_path", None) @@ -822,7 +823,7 @@ class TopoRouter(TopoGear): memleak_file = ( os.environ.get("TOPOTESTS_CHECK_MEMLEAK") or self.options["memleak_path"] ) - if memleak_file is None: + if memleak_file == "" or memleak_file == None: return self.stop() @@ -1011,7 +1012,7 @@ def diagnose_env_linux(): logger.info("Running environment diagnostics") # Load configuration - config = configparser.ConfigParser(tgen_defaults) + config = configparser.ConfigParser(defaults=tgen_defaults) pytestini_path = os.path.join(CWD, "../pytest.ini") config.read(pytestini_path) @@ -1106,10 +1107,10 @@ def diagnose_env_linux(): # TODO remove me when we start supporting exabgp >= 4 try: - output = subprocess.check_output(["exabgp", "-v"]) - line = output.split("\n")[0] - version = line.split(" ")[2] - if topotest.version_cmp(version, "4") >= 0: + p = os.popen("exabgp -v") + line = p.readlines() + version = line[0].split() + if topotest.version_cmp(version[2], "4") >= 0: logger.warning( "BGP topologies are still using exabgp version 3, expect failures" ) diff --git a/tests/topotests/lib/topojson.py b/tests/topotests/lib/topojson.py index b3af09aa99..6535918e36 100644 --- a/tests/topotests/lib/topojson.py +++ b/tests/topotests/lib/topojson.py @@ -216,7 +216,7 @@ def build_topo_from_json(tgen, topo): # Physical Interfaces if "links" in topo['switches'][curSwitch]: for destRouterLink, data in sorted( - topo['switches'][curSwitch]['links'].iteritems()): + topo['switches'][curSwitch]['links'].items()): # Loopback interfaces if "dst_node" in data: diff --git a/tests/topotests/lib/topolog.py b/tests/topotests/lib/topolog.py index 0dfa870930..9fde01cca0 100644 --- a/tests/topotests/lib/topolog.py +++ b/tests/topotests/lib/topolog.py @@ -93,7 +93,7 @@ class Logger(object): """ if log_level is None: log_level = self.log_level - if self.loggers.has_key(name): + if name in self.loggers: return self.loggers[name] nlogger = logging.Logger(name, level=log_level) diff --git a/tests/topotests/lib/topotest.py b/tests/topotests/lib/topotest.py index f8843b0f19..ba6d38ad42 100644 --- a/tests/topotests/lib/topotest.py +++ b/tests/topotests/lib/topotest.py @@ -992,11 +992,11 @@ class Router(Node): # Backward compatibility: # Load configuration defaults like topogen. self.config_defaults = configparser.ConfigParser( - { + defaults = { "verbosity": "info", "frrdir": "/usr/lib/frr", "routertype": "frr", - "memleak_path": None, + "memleak_path": "", } ) self.config_defaults.read( @@ -1523,7 +1523,7 @@ class Router(Node): for daemon in self.daemons: if (self.daemons[daemon] == 1) and not (daemon in daemonsRunning): sys.stderr.write("%s: Daemon %s not running\n" % (self.name, daemon)) - if daemon is "staticd": + if daemon == "staticd": sys.stderr.write( "You may have a copy of staticd installed but are attempting to test against\n" ) @@ -1589,7 +1589,7 @@ class Router(Node): logger.info("{}: running version: {}".format(self.name, self.version)) rversion = self.version - if rversion is None: + if rversion == None: return False result = version_cmp(rversion, version) diff --git a/tests/topotests/ospf-topo2/test_ospf_topo2.py b/tests/topotests/ospf-topo2/test_ospf_topo2.py index 0b6f568462..79e8e6bf58 100644 --- a/tests/topotests/ospf-topo2/test_ospf_topo2.py +++ b/tests/topotests/ospf-topo2/test_ospf_topo2.py @@ -86,19 +86,19 @@ def setup_module(mod): os.path.join(CWD, '{}/ospfd.conf'.format(rname)) ) - # What is this? OSPF Unnumbered depends on the rp_filter - # being set appropriately( HA! ) - # Effectively we are putting different /32's on the interface - # the multicast packet delivery is somewhat controlled by - # the rp_filter. Setting it to '0' allows the OS to pass - # up the mcast packet not destined for the local routers - # network. - topotest.set_sysctl(tgen.net['r1'], - 'net.ipv4.conf.r1-eth1.rp_filter', 0) + # What is this? OSPF Unnumbered depends on the rp_filter + # being set appropriately( HA! ) + # Effectively we are putting different /32's on the interface + # the multicast packet delivery is somewhat controlled by + # the rp_filter. Setting it to '0' allows the OS to pass + # up the mcast packet not destined for the local routers + # network. + topotest.set_sysctl(tgen.net['r1'], + 'net.ipv4.conf.r1-eth1.rp_filter', 0) topotest.set_sysctl(tgen.net['r1'], 'net.ipv4.conf.all.rp_filter', 0) - topotest.set_sysctl(tgen.net['r2'], - 'net.ipv4.conf.r2-eth1.rp_filter', 0) + topotest.set_sysctl(tgen.net['r2'], + 'net.ipv4.conf.r2-eth1.rp_filter', 0) topotest.set_sysctl(tgen.net['r2'], 'net.ipv4.conf.all.rp_filter', 0) diff --git a/tests/topotests/pbr-topo1/test_pbr_topo1.py b/tests/topotests/pbr-topo1/test_pbr_topo1.py index 9ae4cce360..91979a8f04 100644 --- a/tests/topotests/pbr-topo1/test_pbr_topo1.py +++ b/tests/topotests/pbr-topo1/test_pbr_topo1.py @@ -88,8 +88,8 @@ def setup_module(module): krel = platform.release() if topotest.version_cmp(krel, "4.10") < 0: - tgen.errors = "Newer kernel than 4.9 needed for pbr tests" - pytest.skip(tgen.errors) + tgen.errors = "Newer kernel than 4.9 needed for pbr tests" + pytest.skip(tgen.errors) router_list = tgen.routers() for rname, router in router_list.items(): @@ -150,8 +150,8 @@ def test_pbr_data(): test_func = partial(topotest.router_json_cmp, router, "show pbr interface json", expected) _, result = topotest.run_and_expect(test_func, None, count=30, wait=1) assertmsg = '"show pbr interface" mismatches on {}'.format(router.name) - if result is not None: - gather_pbr_data_on_error(router) + if result is not None: + gather_pbr_data_on_error(router) assert result is None, assertmsg map_file = "{}/{}/pbr-map.json".format(CWD, router.name) @@ -164,8 +164,8 @@ def test_pbr_data(): test_func = partial(topotest.router_json_cmp, router, "show pbr map json", expected) _, result = topotest.run_and_expect(test_func, None, count=30, wait=1) assertmsg = '"show pbr map" mismatches on {}'.format(router.name) - if result is not None: - gather_pbr_data_on_error(router) + if result is not None: + gather_pbr_data_on_error(router) assert result is None, assertmsg nexthop_file = "{}/{}/pbr-nexthop-groups.json".format(CWD, router.name) @@ -178,8 +178,8 @@ def test_pbr_data(): test_func = partial(topotest.router_json_cmp, router, "show pbr nexthop-groups json", expected) _, result = topotest.run_and_expect(test_func, None, count=30, wait=1) assertmsg = '"show pbr nexthop-groups" mismatches on {}'.format(router.name) - if result is not None: - gather_pbr_data_on_error(router) + if result is not None: + gather_pbr_data_on_error(router) assert result is None, assertmsg def test_pbr_flap(): @@ -215,8 +215,8 @@ def test_pbr_flap(): test_func = partial(topotest.router_json_cmp, router, "show pbr interface json", expected) _, result = topotest.run_and_expect(test_func, None, count=30, wait=1) assertmsg = '"show pbr interface" mismatches on {}'.format(router.name) - if result is not None: - gather_pbr_data_on_error(router) + if result is not None: + gather_pbr_data_on_error(router) assert result is None, assertmsg diff --git a/tests/topotests/rip-topo1/test_rip_topo1.py b/tests/topotests/rip-topo1/test_rip_topo1.py old mode 100755 new mode 100644 index 7ff18ba524..de11b78824 --- a/tests/topotests/rip-topo1/test_rip_topo1.py +++ b/tests/topotests/rip-topo1/test_rip_topo1.py @@ -91,11 +91,11 @@ class NetworkTopo(Topo): switch[4] = self.addSwitch("sw4", cls=topotest.LegacySwitch) self.addLink(switch[4], router[3], intfName2="r3-eth0") - switch[5] = self.addSwitch("sw5", cls=topotest.LegacySwitch) - self.addLink(switch[5], router[1], intfName2="r1-eth2") + switch[5] = self.addSwitch("sw5", cls=topotest.LegacySwitch) + self.addLink(switch[5], router[1], intfName2="r1-eth2") - switch[6] = self.addSwitch("sw6", cls=topotest.LegacySwitch) - self.addLink(switch[6], router[1], intfName2="r1-eth3") + switch[6] = self.addSwitch("sw6", cls=topotest.LegacySwitch) + self.addLink(switch[6], router[1], intfName2="r1-eth3") ##################################################### diff --git a/tests/topotests/ripng-topo1/test_ripng_topo1.py b/tests/topotests/ripng-topo1/test_ripng_topo1.py old mode 100755 new mode 100644 -- 2.39.5