diff mbox

[ovs-dev,PATCHv2,2/2] test-l7.py: Tidy up and python3-ify.

Message ID 20161222185826.25237-2-joe@ovn.org
State Accepted
Headers show

Commit Message

Joe Stringer Dec. 22, 2016, 6:58 p.m. UTC
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 <joe@ovn.org>
---
v2: First post.
---
 tests/test-l7.py | 17 +++++++++++------
 1 file changed, 11 insertions(+), 6 deletions(-)

Comments

Ben Pfaff Dec. 22, 2016, 11:57 p.m. UTC | #1
On Thu, Dec 22, 2016 at 10:58:26AM -0800, Joe Stringer wrote:
> 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 <joe@ovn.org>
> ---
> v2: First post.

Seems reasonable but I'm a poor Python reviewer.

Acked-by: Ben Pfaff <blp@ovn.org>
Joe Stringer Jan. 3, 2017, 5:35 p.m. UTC | #2
On 22 December 2016 at 15:57, Ben Pfaff <blp@ovn.org> wrote:
> On Thu, Dec 22, 2016 at 10:58:26AM -0800, Joe Stringer wrote:
>> 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 <joe@ovn.org>
>> ---
>> v2: First post.
>
> Seems reasonable but I'm a poor Python reviewer.
>
> Acked-by: Ben Pfaff <blp@ovn.org>

Thanks, applied to master.
diff mbox

Patch

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: