summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorJoe Stringer <joe@ovn.org>2016-12-22 10:58:26 -0800
committerJoe Stringer <joe@ovn.org>2017-01-03 09:32:59 -0800
commita27b51e97f8e55873ff74945624133030581bd9f (patch)
treebaf89b6e4de056375972244dd0739e7e5231abc6 /tests
parent40c7b2fc0d181155ea87a962a522d48f4166370b (diff)
downloadopenvswitch-a27b51e97f8e55873ff74945624133030581bd9f.tar.gz
test-l7.py: Tidy up and python3-ify.
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> Acked-by: Ben Pfaff <blp@ovn.org>
Diffstat (limited to 'tests')
-rwxr-xr-xtests/test-l7.py17
1 files changed, 11 insertions, 6 deletions
diff --git a/tests/test-l7.py b/tests/test-l7.py
index e5f473b56..d7854a1df 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: