From patchwork Tue Jun 15 15:58:02 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rosemarie O'Riorden X-Patchwork-Id: 1492332 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=140.211.166.137; helo=smtp4.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=Dx5AJ+HJ; dkim-atps=neutral Received: from smtp4.osuosl.org (smtp4.osuosl.org [140.211.166.137]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4G4Cf31bsyz9sWM for ; Wed, 16 Jun 2021 01:58:18 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by smtp4.osuosl.org (Postfix) with ESMTP id 7C2C3405EB; Tue, 15 Jun 2021 15:58:15 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp4.osuosl.org ([127.0.0.1]) by localhost (smtp4.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id KXPmdX-BFH00; Tue, 15 Jun 2021 15:58:13 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by smtp4.osuosl.org (Postfix) with ESMTPS id CD377404AB; Tue, 15 Jun 2021 15:58:12 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 99EB9C000E; Tue, 15 Jun 2021 15:58:12 +0000 (UTC) X-Original-To: ovs-dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp2.osuosl.org (smtp2.osuosl.org [140.211.166.133]) by lists.linuxfoundation.org (Postfix) with ESMTP id AB960C000B for ; Tue, 15 Jun 2021 15:58:10 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp2.osuosl.org (Postfix) with ESMTP id 9AD0C401FD for ; Tue, 15 Jun 2021 15:58:10 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Authentication-Results: smtp2.osuosl.org (amavisd-new); dkim=pass (1024-bit key) header.d=redhat.com Received: from smtp2.osuosl.org ([127.0.0.1]) by localhost (smtp2.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id CqNlqHQMWWfn for ; Tue, 15 Jun 2021 15:58:09 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.8.0 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by smtp2.osuosl.org (Postfix) with ESMTPS id 171F1400C9 for ; Tue, 15 Jun 2021 15:58:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1623772687; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=WyI7rR816WXwd4IkwAI82rxR1ymNdgVANbj/tt+hxjA=; b=Dx5AJ+HJ7jdFA2obBzIzcFXBgqfRvktmBH+iuK40CaBnT+Fj6wesAbcE/vTpCVhidLJBsL N+5cHMELYVd4+lWKC4QXuunzxnOV2DjDiKW4CyGJZio8jfrGewIQ3syn9q81vA64LmgyxX lgBLibRbq/7Z3NyR4l9Kp2PkYHNWoKY= Received: from mail-qt1-f197.google.com (mail-qt1-f197.google.com [209.85.160.197]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-447-DtESzno5Nr-Fv8uZFVLL0g-1; Tue, 15 Jun 2021 11:58:06 -0400 X-MC-Unique: DtESzno5Nr-Fv8uZFVLL0g-1 Received: by mail-qt1-f197.google.com with SMTP id t6-20020ac80dc60000b029024e988e8277so438423qti.23 for ; Tue, 15 Jun 2021 08:58:06 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=WyI7rR816WXwd4IkwAI82rxR1ymNdgVANbj/tt+hxjA=; b=LHPENpJMl0XwemJx7Nsq+0Izavn7smHiRYMoR73m0szXeYusXVrSdiLOokfVHEwDvm kt8yEeuUixL5EBCHaWSsIZJF2TM0cGsaFJZg9ymmtLUBVwWyMBVv4RMmTU7ORMtKxHrp MzA6Nhi0gEn3jHbsF2yzHaZLJ/3hXYBhOJbXVyFJWj5tS6S1DqYPpivC1T85WZeXlEl2 mC55LQyoypeNA3bP0LnoiprSZHJbbbfZP8kYO+ck7AfA2MwPV+8FJmCSS5B8Nl0OizvW qfX24JxQy6gjrZ5LRP3GpYpU2XQ9c7FczzCW9fQcVNKaDTAvDJN1tmBVIQzgUsISuwy4 c51w== X-Gm-Message-State: AOAM533aPaPa4fm0SoJvZ4ub7uKHlHjcAfPJwHKg4rzezOZIlRy4qxgL xwtZjjff0uQKrmowFrp7L95DK7UHpF1EojveBqfsAH0C6KPaMI3aNLdHYbgN2mJfqGAdF2refFh yUPRdnlPz5cGiQz5WBQMdL4LNC9msIT7c3QEdI9P8LHarKFCR1U2RAf1CkhaTnpPkANytzQ== X-Received: by 2002:a05:620a:219b:: with SMTP id g27mr292988qka.399.1623772685850; Tue, 15 Jun 2021 08:58:05 -0700 (PDT) X-Google-Smtp-Source: ABdhPJznl/hro3VQ2iBNGczjvcxBVi8tdDamv9rRhULI2F0VERgPeplYIDBqKr6ojzr76JWjEtjfLA== X-Received: by 2002:a05:620a:219b:: with SMTP id g27mr292948qka.399.1623772685406; Tue, 15 Jun 2021 08:58:05 -0700 (PDT) Received: from fedora.hsd1.ma.comcast.net ([2601:18f:903:27d0::c3be]) by smtp.gmail.com with ESMTPSA id s20sm8137922qtc.94.2021.06.15.08.58.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Jun 2021 08:58:04 -0700 (PDT) From: Rosemarie O'Riorden To: ovs-dev@openvswitch.org Date: Tue, 15 Jun 2021 11:58:02 -0400 Message-Id: <20210615155802.209024-1-roriorde@redhat.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=roriorde@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Cc: Rosemarie O'Riorden , Ilya Maximets Subject: [ovs-dev] [PATCH v4] Remove Python 2 leftovers. X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" Fixes: 1ca0323e7c29 ("Require Python 3 and remove support for Python 2.") Reported at: https://bugzilla.redhat.com/show_bug.cgi?id=1949875 Signed-off-by: Rosemarie O'Riorden --- Version 2: - Fixed import errors in v1. - Removed lines that indicate compatibility with python 2. Version 3: - Fixed import errors and some files that were not covered in v2. Version 4: - Added missing new line that caused flake8-check to fail. ofproto/ipfix-gen-entities | 2 -- ovsdb/ovsdb-idlc.in | 1 - .../ovs/compat/sortedcontainers/sortedlist.py | 2 -- python/ovstest/rpcserver.py | 14 ++-------- python/ovstest/tcp.py | 4 +-- python/ovstest/tests.py | 2 -- python/ovstest/util.py | 4 +-- python/ovstest/vswitch.py | 2 +- python/setup.py | 4 --- tests/test-jsonrpc.py | 2 -- utilities/checkpatch.py | 1 - utilities/gdb/ovs_gdb.py | 1 - utilities/ovs-l3ping.in | 14 +++++----- utilities/ovs-parse-backtrace.in | 12 ++++---- utilities/ovs-pcap.in | 4 +-- utilities/ovs-vlan-test.in | 28 +++++++++---------- 16 files changed, 35 insertions(+), 62 deletions(-) diff --git a/ofproto/ipfix-gen-entities b/ofproto/ipfix-gen-entities index d5abe9c2e..dcecdab21 100755 --- a/ofproto/ipfix-gen-entities +++ b/ofproto/ipfix-gen-entities @@ -7,8 +7,6 @@ # notice and this notice are preserved. This file is offered as-is, # without warranty of any kind. -from __future__ import print_function - import getopt import re import sys diff --git a/ovsdb/ovsdb-idlc.in b/ovsdb/ovsdb-idlc.in index 5914e0878..61cded16d 100755 --- a/ovsdb/ovsdb-idlc.in +++ b/ovsdb/ovsdb-idlc.in @@ -1,6 +1,5 @@ #! @PYTHON3@ -from __future__ import print_function import getopt import os import re diff --git a/python/ovs/compat/sortedcontainers/sortedlist.py b/python/ovs/compat/sortedcontainers/sortedlist.py index 8aec6bbac..ba5556692 100644 --- a/python/ovs/compat/sortedcontainers/sortedlist.py +++ b/python/ovs/compat/sortedcontainers/sortedlist.py @@ -3,8 +3,6 @@ """ # pylint: disable=redefined-builtin, ungrouped-imports -from __future__ import print_function - from bisect import bisect_left, bisect_right, insort from collections import Sequence, MutableSequence from functools import wraps diff --git a/python/ovstest/rpcserver.py b/python/ovstest/rpcserver.py index c4aab7020..05b6b1be2 100644 --- a/python/ovstest/rpcserver.py +++ b/python/ovstest/rpcserver.py @@ -18,22 +18,14 @@ rpcserver is an XML RPC server that allows RPC client to initiate tests import sys -import exceptions - import xmlrpc.client -import tcp - from twisted.internet import reactor from twisted.internet.error import CannotListenError from twisted.web import server from twisted.web import xmlrpc -import udp - -import util - -import vswitch +from . import tcp, udp, util, vswitch class TestArena(xmlrpc.XMLRPC): @@ -210,7 +202,7 @@ class TestArena(xmlrpc.XMLRPC): (_, port) = self.__get_handle_resources(handle) port.loseConnection() self.__delete_handle(handle) - except exceptions.KeyError: + except KeyError: return -1 return 0 @@ -222,7 +214,7 @@ class TestArena(xmlrpc.XMLRPC): (_, connector) = self.__get_handle_resources(handle) connector.disconnect() self.__delete_handle(handle) - except exceptions.KeyError: + except KeyError: return -1 return 0 diff --git a/python/ovstest/tcp.py b/python/ovstest/tcp.py index c495717f2..098c6cba3 100644 --- a/python/ovstest/tcp.py +++ b/python/ovstest/tcp.py @@ -21,7 +21,7 @@ import time from twisted.internet import interfaces from twisted.internet.protocol import ClientFactory, Factory, Protocol -from zope.interface import implements +from zope.interface.declarations import implementer class TcpListenerConnection(Protocol): @@ -55,8 +55,8 @@ class TcpListenerFactory(Factory): return str(self.stats) +@implementer(interfaces.IPushProducer) class Producer(object): - implements(interfaces.IPushProducer) """ This producer class generates infinite byte stream for a specified time duration diff --git a/python/ovstest/tests.py b/python/ovstest/tests.py index 6de3cc3af..f959f945e 100644 --- a/python/ovstest/tests.py +++ b/python/ovstest/tests.py @@ -10,8 +10,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -from __future__ import print_function - import math import time diff --git a/python/ovstest/util.py b/python/ovstest/util.py index 72457158f..270d6a037 100644 --- a/python/ovstest/util.py +++ b/python/ovstest/util.py @@ -26,8 +26,6 @@ import socket import struct import subprocess -import exceptions - import xmlrpc.client @@ -88,7 +86,7 @@ def start_process(args): stderr=subprocess.PIPE) out, err = p.communicate() return (p.returncode, out, err) - except exceptions.OSError: + except OSError: return (-1, None, None) diff --git a/python/ovstest/vswitch.py b/python/ovstest/vswitch.py index 9d5b5cffd..45c9587ee 100644 --- a/python/ovstest/vswitch.py +++ b/python/ovstest/vswitch.py @@ -15,7 +15,7 @@ """ vswitch module allows its callers to interact with OVS DB. """ -import util +from . import util def ovs_vsctl_add_bridge(bridge): diff --git a/python/setup.py b/python/setup.py index d385d8372..cfe01763f 100644 --- a/python/setup.py +++ b/python/setup.py @@ -10,8 +10,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -from __future__ import print_function - import sys from distutils.command.build_ext import build_ext @@ -82,8 +80,6 @@ setup_args = dict( 'Topic :: Software Development :: Libraries :: Python Modules', 'Topic :: System :: Networking', 'License :: OSI Approved :: Apache Software License', - 'Programming Language :: Python :: 2', - 'Programming Language :: Python :: 2.7', 'Programming Language :: Python :: 3', 'Programming Language :: Python :: 3.4', 'Programming Language :: Python :: 3.5', diff --git a/tests/test-jsonrpc.py b/tests/test-jsonrpc.py index 3eabcd78d..1df5afa22 100644 --- a/tests/test-jsonrpc.py +++ b/tests/test-jsonrpc.py @@ -12,8 +12,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -from __future__ import print_function - import argparse import errno import os diff --git a/utilities/checkpatch.py b/utilities/checkpatch.py index bc6bfae15..ac14da29b 100755 --- a/utilities/checkpatch.py +++ b/utilities/checkpatch.py @@ -13,7 +13,6 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -from __future__ import print_function import email import getopt diff --git a/utilities/gdb/ovs_gdb.py b/utilities/gdb/ovs_gdb.py index 1111f3100..0b2ecb81b 100644 --- a/utilities/gdb/ovs_gdb.py +++ b/utilities/gdb/ovs_gdb.py @@ -55,7 +55,6 @@ # ... # ... # -from __future__ import print_function import gdb import sys import uuid diff --git a/utilities/ovs-l3ping.in b/utilities/ovs-l3ping.in index 92d32acb3..1ece06457 100644 --- a/utilities/ovs-l3ping.in +++ b/utilities/ovs-l3ping.in @@ -19,7 +19,7 @@ achieved by tunneling the control connection inside the tunnel itself. """ import socket -import xmlrpclib +import xmlrpc.client import ovstest.args as args import ovstest.tests as tests @@ -64,13 +64,13 @@ if __name__ == '__main__': ps = get_packet_sizes(me, he, args.client[0]) tests.do_direct_tests(me, he, bandwidth, interval, ps) except KeyboardInterrupt: - print "Terminating" - except xmlrpclib.Fault: - print "Couldn't contact peer" + print("Terminating") + except xmlrpc.client.Fault: + print("Couldn't contact peer") except socket.error: - print "Couldn't contact peer" - except xmlrpclib.ProtocolError: - print "XMLRPC control channel was abruptly terminated" + print("Couldn't contact peer") + except xmlrpc.client.ProtocolError: + print("XMLRPC control channel was abruptly terminated") finally: if local_server is not None: local_server.terminate() diff --git a/utilities/ovs-parse-backtrace.in b/utilities/ovs-parse-backtrace.in index d5506769a..f44f05cd1 100755 --- a/utilities/ovs-parse-backtrace.in +++ b/utilities/ovs-parse-backtrace.in @@ -70,7 +70,7 @@ result. Expected usage is for ovs-appctl backtrace to be piped in.""") if os.path.exists(debug): binary = debug - print "Binary: %s\n" % binary + print("Binary: %s\n" % binary) stdin = sys.stdin.read() @@ -88,15 +88,15 @@ result. Expected usage is for ovs-appctl backtrace to be piped in.""") for lines, count in traces: longest = max(len(l) for l in lines) - print "Backtrace Count: %d" % count + print("Backtrace Count: %d" % count) for line in lines: match = re.search(r'\[(0x.*)]', line) if match: - print "%s %s" % (line.ljust(longest), - addr2line(binary, match.group(1))) + print("%s %s" % (line.ljust(longest), + addr2line(binary, match.group(1)))) else: - print line - print + print(line) + print() if __name__ == "__main__": diff --git a/utilities/ovs-pcap.in b/utilities/ovs-pcap.in index dddbee4df..6b5f63399 100755 --- a/utilities/ovs-pcap.in +++ b/utilities/ovs-pcap.in @@ -14,8 +14,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -from __future__ import print_function - import binascii import getopt import struct @@ -79,7 +77,7 @@ if __name__ == "__main__": try: options, args = getopt.gnu_getopt(sys.argv[1:], 'hV', ['help', 'version']) - except getopt.GetoptException as geo: + except getopt.GetoptError as geo: sys.stderr.write("%s: %s\n" % (argv0, geo.msg)) sys.exit(1) diff --git a/utilities/ovs-vlan-test.in b/utilities/ovs-vlan-test.in index 154573a9b..de3ae1686 100755 --- a/utilities/ovs-vlan-test.in +++ b/utilities/ovs-vlan-test.in @@ -14,9 +14,9 @@ # See the License for the specific language governing permissions and # limitations under the License. -import BaseHTTPServer import getopt -import httplib +import http.client +import http.server import os import threading import time @@ -84,7 +84,7 @@ class UDPReceiver: try: sock.bind((self.vlan_ip, self.vlan_port)) - except socket.error, e: + except socket.error as e: print_safe('Failed to bind to %s:%d with error: %s' % (self.vlan_ip, self.vlan_port, e)) os._exit(1) #sys.exit only exits the current thread. @@ -95,7 +95,7 @@ class UDPReceiver: data, _ = sock.recvfrom(4096) except socket.timeout: continue - except socket.error, e: + except socket.error as e: print_safe('Failed to receive from %s:%d with error: %s' % (self.vlan_ip, self.vlan_port, e)) os._exit(1) @@ -180,7 +180,7 @@ class VlanServer: for _ in range(send_time * 2): try: send_packet(test_id, size, ip, port) - except socket.error, e: + except socket.error as e: self.set_result(test_id, 'Failure: ' + str(e)) return time.sleep(.5) @@ -194,15 +194,15 @@ class VlanServer: def run(self): self.udp_recv.start() try: - BaseHTTPServer.HTTPServer((self.server_ip, self.server_port), + http.server.HTTPServer((self.server_ip, self.server_port), VlanServerHandler).serve_forever() - except socket.error, e: + except socket.error as e: print_safe('Failed to start control server: %s' % e) self.udp_recv.stop() return 1 -class VlanServerHandler(BaseHTTPServer.BaseHTTPRequestHandler): +class VlanServerHandler(http.server.BaseHTTPRequestHandler): def do_GET(self): #Guarantee three arguments. @@ -244,7 +244,7 @@ class VlanClient: self.udp_recv = UDPReceiver(vlan_ip, vlan_port) def request(self, resource): - conn = httplib.HTTPConnection(self.server_ip_port) + conn = http.client.HTTPConnection(self.server_ip_port) conn.request('GET', resource) return conn @@ -256,7 +256,7 @@ class VlanClient: try: conn = self.request('/start/recv') data = conn.getresponse().read() - except (socket.error, httplib.HTTPException), e: + except (socket.error, http.client.HTTPException) as e: error_msg(e) return False @@ -277,7 +277,7 @@ class VlanClient: send_packet(test_id, size, ip, port) resp = self.request('/result/%d' % test_id).getresponse() data = resp.read() - except (socket.error, httplib.HTTPException), e: + except (socket.error, http.client.HTTPException) as e: error_msg(e) return False @@ -302,7 +302,7 @@ class VlanClient: try: conn = self.request(resource) test_id = conn.getresponse().read() - except (socket.error, httplib.HTTPException), e: + except (socket.error, http.client.HTTPException) as e: error_msg(e) return False @@ -335,7 +335,7 @@ class VlanClient: try: resp = self.request('/ping').getresponse() data = resp.read() - except (socket.error, httplib.HTTPException), e: + except (socket.error, http.client.HTTPException) as e: error_msg(e) return False @@ -383,7 +383,7 @@ def main(): try: options, args = getopt.gnu_getopt(sys.argv[1:], 'hVs', ['help', 'version', 'server']) - except getopt.GetoptError, geo: + except getopt.GetoptError as geo: print_safe('%s: %s\n' % (sys.argv[0], geo.msg)) return 1