diff options
author | venkata edara <redara@redhat.com> | 2017-11-22 13:35:46 +0530 |
---|---|---|
committer | Prashanth Pai <ppai@redhat.com> | 2017-11-22 09:07:11 +0000 |
commit | 488744a005fb399af8d094ad7a62c1917410398c (patch) | |
tree | 714441b43e09061fc339cae6a68de5c26f0fdf52 /test/__init__.py | |
parent | 8af00bf3fa5aa7cd29a53e5e43ea230c196d10b0 (diff) |
Change-Id: I84ebb44c5c3cf2f80c50f2d4ae4bd92b619a4297
Signed-off-by: venkata edara <redara@redhat.com>
Reviewed-on: https://review.gluster.org/18412
Reviewed-by: Prashanth Pai <ppai@redhat.com>
Tested-by: Prashanth Pai <ppai@redhat.com>
Diffstat (limited to 'test/__init__.py')
-rw-r--r-- | test/__init__.py | 35 |
1 files changed, 23 insertions, 12 deletions
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 |