From 365aae94ccb3a37ab7b01181722c4faf95c34b4c Mon Sep 17 00:00:00 2001 From: Davanum Srinivas Date: Sun, 27 Jul 2014 21:37:30 -0400 Subject: [PATCH] docs - Prevent eventlet exception during docs generation build_sphinx has a lot of spurious tracebacks, We don't really need this check for document generation Change-Id: Id9442c5902918592c4c242cc66975062cf9f2461 --- nova/cmd/__init__.py | 7 ++++++- nova/tests/__init__.py | 8 +++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/nova/cmd/__init__.py b/nova/cmd/__init__.py index cbe5ae351e67..5f1129d9c11b 100644 --- a/nova/cmd/__init__.py +++ b/nova/cmd/__init__.py @@ -16,13 +16,18 @@ # TODO(mikal): move eventlet imports to nova.__init__ once we move to PBR import os import sys +import traceback # 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. +# NOTE(dims): Prevent this code from kicking in under docs generation +# as it leads to spurious errors/warning. +stack = traceback.extract_stack() if ('eventlet' in sys.modules and - os.environ.get('EVENTLET_NO_GREENDNS', '').lower() != 'yes'): + os.environ.get('EVENTLET_NO_GREENDNS', '').lower() != 'yes' and + (len(stack) < 2 or 'sphinx' not in stack[-2][0])): raise ImportError('eventlet imported before nova/cmd/__init__ ' '(env var set to %s)' % os.environ.get('EVENTLET_NO_GREENDNS')) diff --git a/nova/tests/__init__.py b/nova/tests/__init__.py index 566fabba1d0a..a40a66648480 100644 --- a/nova/tests/__init__.py +++ b/nova/tests/__init__.py @@ -25,13 +25,19 @@ # TODO(mikal): move eventlet imports to nova.__init__ once we move to PBR import os import sys +import traceback + # 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. +# NOTE(dims): Prevent this code from kicking in under docs generation +# as it leads to spurious errors/warning. +stack = traceback.extract_stack() if ('eventlet' in sys.modules and - os.environ.get('EVENTLET_NO_GREENDNS', '').lower() != 'yes'): + os.environ.get('EVENTLET_NO_GREENDNS', '').lower() != 'yes' and + (len(stack) < 2 or 'sphinx' not in stack[-2][0])): raise ImportError('eventlet imported before nova/cmd/__init__ ' '(env var set to %s)' % os.environ.get('EVENTLET_NO_GREENDNS'))