From 488744a005fb399af8d094ad7a62c1917410398c Mon Sep 17 00:00:00 2001 From: venkata edara Date: Wed, 22 Nov 2017 13:35:46 +0530 Subject: Rebase to Swift 2.15.1 (pike) Change-Id: I84ebb44c5c3cf2f80c50f2d4ae4bd92b619a4297 Signed-off-by: venkata edara Reviewed-on: https://review.gluster.org/18412 Reviewed-by: Prashanth Pai Tested-by: Prashanth Pai --- test/__init__.py | 35 +++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-) (limited to 'test/__init__.py') diff --git a/test/__init__.py b/test/__init__.py index 3bd25b1..1a56597 100644 --- a/test/__init__.py +++ b/test/__init__.py @@ -15,7 +15,7 @@ # See http://code.google.com/p/python-nose/issues/detail?id=373 # The code below enables nosetests to work with i18n _() blocks - +from __future__ import print_function import sys import os try: @@ -33,6 +33,8 @@ except ImportError: return result return result[:_MAX_LENGTH] + ' [truncated]...' +from eventlet.green import socket + # make unittests pass on all locale import swift setattr(swift, 'gettext_', lambda x: x) @@ -61,17 +63,26 @@ def get_config(section_name=None, defaults=None): '/etc/swift/test.conf') try: config = readconf(config_file, section_name) - except SystemExit: + except IOError: if not os.path.exists(config_file): - print >>sys.stderr, \ - 'Unable to read test config %s - file not found' \ - % config_file + print('Unable to read test config %s - file not found' + % config_file, file=sys.stderr) elif not os.access(config_file, os.R_OK): - print >>sys.stderr, \ - 'Unable to read test config %s - permission denied' \ - % config_file - else: - print >>sys.stderr, \ - 'Unable to read test config %s - section %s not found' \ - % (config_file, section_name) + print('Unable to read test config %s - permission denied' + % config_file, file=sys.stderr) + except ValueError as e: + print(e) return config + + +def listen_zero(): + """ + The eventlet.listen() always sets SO_REUSEPORT, so when called with + ("localhost",0), instead of returning unique ports it can return the + same port twice. That causes our tests to fail, so open-code it here + without SO_REUSEPORT. + """ + sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + sock.bind(("127.0.0.1", 0)) + sock.listen(50) + return sock -- cgit