From patchwork Thu Dec 22 18:58:26 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joe Stringer X-Patchwork-Id: 708326 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from mail.linuxfoundation.org (mail.linuxfoundation.org [140.211.169.12]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3tl15G3bfmz9svs for ; Fri, 23 Dec 2016 05:58:42 +1100 (AEDT) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id E6069C0A; Thu, 22 Dec 2016 18:58:38 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@mail.linuxfoundation.org Received: from smtp1.linuxfoundation.org (smtp1.linux-foundation.org [172.17.192.35]) by mail.linuxfoundation.org (Postfix) with ESMTPS id CAB4DBF4 for ; Thu, 22 Dec 2016 18:58:37 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from relay5-d.mail.gandi.net (relay5-d.mail.gandi.net [217.70.183.197]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id 375791C5 for ; Thu, 22 Dec 2016 18:58:37 +0000 (UTC) Received: from mfilter13-d.gandi.net (mfilter13-d.gandi.net [217.70.178.141]) by relay5-d.mail.gandi.net (Postfix) with ESMTP id 19C1441C089 for ; Thu, 22 Dec 2016 19:58:36 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at mfilter13-d.gandi.net Received: from relay5-d.mail.gandi.net ([IPv6:::ffff:217.70.183.197]) by mfilter13-d.gandi.net (mfilter13-d.gandi.net [::ffff:10.0.15.180]) (amavisd-new, port 10024) with ESMTP id WlOmOcspH5La for ; Thu, 22 Dec 2016 19:58:34 +0100 (CET) X-Originating-IP: 208.91.1.34 Received: from carno.eng.vmware.com (unknown [208.91.1.34]) (Authenticated sender: joe@ovn.org) by relay5-d.mail.gandi.net (Postfix) with ESMTPSA id 47BEE41C04C for ; Thu, 22 Dec 2016 19:58:34 +0100 (CET) From: Joe Stringer To: dev@openvswitch.org Date: Thu, 22 Dec 2016 10:58:26 -0800 Message-Id: <20161222185826.25237-2-joe@ovn.org> X-Mailer: git-send-email 2.10.2 In-Reply-To: <20161222185826.25237-1-joe@ovn.org> References: <20161222185826.25237-1-joe@ovn.org> X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on smtp1.linux-foundation.org Subject: [ovs-dev] [PATCHv2 2/2] test-l7.py: Tidy up and python3-ify. X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: ovs-dev-bounces@openvswitch.org Errors-To: ovs-dev-bounces@openvswitch.org Haul test-l7.py into the 202nd decade by supporting python3. TFTPY still doesn't support python3, so work around this by handling import syntax errors so that even if tftpy is installed in a python3 environment, test-l7.py will not throw an exception while attempting to load it. Signed-off-by: Joe Stringer Acked-by: Ben Pfaff --- v2: First post. --- tests/test-l7.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/tests/test-l7.py b/tests/test-l7.py index e5f473b56740..d7854a1df31b 100755 --- a/tests/test-l7.py +++ b/tests/test-l7.py @@ -1,3 +1,4 @@ +#!/usr/bin/env python # Copyright (c) 2015, 2016 Nicira, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -15,9 +16,13 @@ import argparse import socket -from BaseHTTPServer import HTTPServer -from SimpleHTTPServer import SimpleHTTPRequestHandler -from SocketServer import TCPServer +try: # Python 2.7 + from BaseHTTPServer import HTTPServer + from SimpleHTTPServer import SimpleHTTPRequestHandler + from SocketServer import TCPServer +except: + from http.server import HTTPServer, SimpleHTTPRequestHandler + from socketserver import TCPServer class TCPServerV6(HTTPServer): @@ -62,7 +67,7 @@ def get_tftpd(): def serve_forever(self): self.listen(self.ip, self.port) server = [OVSTFTPServer, None, TftpShared.DEF_TFTP_PORT] - except ImportError: + except (ImportError, SyntaxError): server = None pass return server @@ -78,9 +83,9 @@ def main(): protocols = [srv for srv in SERVERS if SERVERS[srv] is not None] parser = argparse.ArgumentParser( - description='Run basic application servers.') + description='Run basic application servers.') parser.add_argument('proto', default='http', nargs='?', - help='protocol to serve (%s)' % protocols) + help='protocol to serve (%s)' % protocols) args = parser.parse_args() if args.proto not in protocols: