Disable eventlet monkey-patching of DNS

This change avoids eventlet's monkey-patching of DNS
resolution. eventlet's doesn't support IPv6, for example.

The way to avoid eventlet's DNS is to set an environment
variable. The trick is the environment variable needs to be set
before eventlet is imported.

A similar change was made in nova, so this is just copying
that code and technique to keystone.

This allows re-enabling the IPv6 tests, too.

Change-Id: I30524a1cebd43580d692fd88ef32be45e62758c5
This commit is contained in:
Brant Knudson 2013-05-09 17:32:24 -05:00
parent 693a486f39
commit 6219f94b3a
3 changed files with 33 additions and 7 deletions

View File

@ -2,12 +2,25 @@
# vim: tabstop=4 shiftwidth=4 softtabstop=4
import greenlet
import eventlet
import logging
import os
import signal
import sys
# NOTE(mikal): All of this is because if dnspython is present in your
# environment then eventlet monkeypatches socket.getaddrinfo() with an
# implementation which doesn't work for IPv6. What we're checking here is
# that the magic environment variable was set when the import happened.
if ('eventlet' in sys.modules and
os.environ.get('EVENTLET_NO_GREENDNS', '').lower() != 'yes'):
raise ImportError('eventlet imported before keystone-all '
'(env var set to %s)'
% os.environ.get('EVENTLET_NO_GREENDNS'))
os.environ['EVENTLET_NO_GREENDNS'] = 'yes'
import eventlet
# If ../keystone/__init__.py exists, add ../ to Python search path, so that
# it will override what happens to be installed in /usr/(local/)lib/python...
possible_topdir = os.path.normpath(os.path.join(os.path.abspath(__file__),

View File

@ -0,0 +1,15 @@
import os
import sys
# NOTE(mikal): All of this is because if dnspython is present in your
# environment then eventlet monkeypatches socket.getaddrinfo() with an
# implementation which doesn't work for IPv6. What we're checking here is
# that the magic environment variable was set when the import happened.
if ('eventlet' in sys.modules and os.environ.get(
'EVENTLET_NO_GREENDNS', '').lower() != 'yes'):
raise ImportError('eventlet imported before keystone '
'(env var set to %s)'
% os.environ.get('EVENTLET_NO_GREENDNS'))
os.environ['EVENTLET_NO_GREENDNS'] = 'yes'

View File

@ -14,12 +14,14 @@
# License for the specific language governing permissions and limitations
# under the License.
import os
import sys
import datetime
import errno
import os
import socket
import subprocess
import sys
import time
import eventlet
@ -351,10 +353,6 @@ class TestCase(NoModule, unittest.TestCase):
@staticmethod
def skip_if_no_ipv6():
# TODO(blk-u): lp 1176204. At this time, eventlet address resolution
# doesn't support IPv6. Once it does, remove the next line.
raise nose.exc.SkipTest("Eventlet doesn't support IPv6, lp 1176204")
try:
s = socket.socket(socket.AF_INET6)
except socket.error as e: