From 2cbea242092dabf4c54544d5c8c32ba4b5fb8a1f Mon Sep 17 00:00:00 2001 From: Tracy Jones Date: Wed, 13 Nov 2013 13:16:26 -0800 Subject: [PATCH] Enable remote debugging for nova This patch added 2 command line parameters which are used to connect to an external debugger such as pycharm or eclipse. This feature is used when you want to connect to a nova service via a debugger running on a different host. To use it you start the nova service with the following command line parameters --remote_debug-host --remote_debug-port it's listening on>. DocImpact Closes-bug: #1251021 Change-Id: I6ede9bf0813eafbeb91d858c297d4c160aafceba --- doc/source/devref/development.environment.rst | 14 ++++++++ etc/nova/nova.conf.sample | 21 ++++++++++++ nova/cmd/__init__.py | 6 +++- nova/service.py | 33 +++++++++++++++++++ 4 files changed, 73 insertions(+), 1 deletion(-) diff --git a/doc/source/devref/development.environment.rst b/doc/source/devref/development.environment.rst index c366c849ec..f8809c2068 100644 --- a/doc/source/devref/development.environment.rst +++ b/doc/source/devref/development.environment.rst @@ -142,6 +142,20 @@ basis by running:: $ tools/with_venv.sh +Using a remote debugger +---------------------- + +Some modern IDE such as pycharm (commercial) or Eclipse (open source) support remote debugging. In order to run nova with remote debugging, start the nova process +with the following parameters +--remote_debug-host +--remote_debug-port + +Before you start your nova process, start the remote debugger using the instructions for that debugger. +For pycharm - http://blog.jetbrains.com/pycharm/2010/12/python-remote-debug-with-pycharm/ +For Eclipse - http://pydev.org/manual_adv_remote_debugger.html + +More detailed instructions are located here - http://novaremotedebug.blogspot.com + Contributing Your Work ---------------------- diff --git a/etc/nova/nova.conf.sample b/etc/nova/nova.conf.sample index 37a30c7570..d679105084 100644 --- a/etc/nova/nova.conf.sample +++ b/etc/nova/nova.conf.sample @@ -2439,6 +2439,27 @@ #topics=notifications +[remote_debug] + +# +# Options defined in nova.service +# + +# Debug host (ip or name) to connect. Note that using the +# remote debug option changes how Nova uses the eventlet +# library to support async IO. This could result in failures +# that do not occur under normal operation. Use at your own +# risk. (string value) +#host= + +# Debug port to connect. Note that using the remote debug +# option changes how Nova uses the eventlet library to support +# async IO. This could result in failures that do not occur +# under normal operation. Use at your own risk. (integer +# value) +#port= + + [conductor] # diff --git a/nova/cmd/__init__.py b/nova/cmd/__init__.py index 87edf9b4b9..580a3893c1 100644 --- a/nova/cmd/__init__.py +++ b/nova/cmd/__init__.py @@ -31,4 +31,8 @@ os.environ['EVENTLET_NO_GREENDNS'] = 'yes' import eventlet -eventlet.monkey_patch(os=False) +if '--remote_debug-host' in sys.argv and '--remote_debug-port' in sys.argv: + # turn off thread patching to enable the remote debugger + eventlet.monkey_patch(os=False, thread=False) +else: + eventlet.monkey_patch(os=False) diff --git a/nova/service.py b/nova/service.py index 9e82ba1dba..94b29ed608 100644 --- a/nova/service.py +++ b/nova/service.py @@ -105,9 +105,27 @@ service_opts = [ help='maximum time since last check-in for up service'), ] +cli_opts = [ + cfg.StrOpt('host', + help='Debug host (ip or name) to connect. Note ' + 'that using the remote debug option changes how ' + 'Nova uses the eventlet library to support async IO. ' + 'This could result in failures that do not occur ' + 'under normal operation. Use at your own risk.'), + + cfg.IntOpt('port', + help='Debug port to connect. Note ' + 'that using the remote debug option changes how ' + 'Nova uses the eventlet library to support async IO. ' + 'This could result in failures that do not occur ' + 'under normal operation. Use at your own risk.') + + ] + CONF = cfg.CONF CONF.register_opts(service_opts) CONF.import_opt('host', 'nova.netconf') +CONF.register_cli_opts(cli_opts, 'remote_debug') class Service(service.Service): @@ -249,6 +267,21 @@ class Service(service.Service): periodic_enable = CONF.periodic_enable if periodic_fuzzy_delay is None: periodic_fuzzy_delay = CONF.periodic_fuzzy_delay + if CONF.remote_debug.host and CONF.remote_debug.port: + from pydev import pydevd + LOG = logging.getLogger('nova') + LOG.debug(_('Listening on %(host)s:%(port)s for debug connection'), + {'host': CONF.remote_debug.host, + 'port': CONF.remote_debug.port}) + pydevd.settrace(host=CONF.remote_debug.host, + port=CONF.remote_debug.port, + stdoutToServer=False, + stderrToServer=False) + LOG.warn(_('WARNING: Using the remote debug option changes how ' + 'Nova uses the eventlet library to support async IO. This ' + 'could result in failures that do not occur under normal ' + 'operation. Use at your own risk.')) + service_obj = cls(host, binary, topic, manager, report_interval=report_interval, periodic_enable=periodic_enable,