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 <where the debugger is running>
--remote_debug-port <port> it's listening on>.

DocImpact
Closes-bug: #1251021
Change-Id: I6ede9bf0813eafbeb91d858c297d4c160aafceba
This commit is contained in:
Tracy Jones 2013-11-13 13:16:26 -08:00
parent 5f14f9df59
commit 2cbea24209
4 changed files with 73 additions and 1 deletions

View File

@ -142,6 +142,20 @@ basis by running::
$ tools/with_venv.sh <your command> $ tools/with_venv.sh <your command>
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 <host IP where the debugger is running>
--remote_debug-port <port it is listening on>
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 Contributing Your Work
---------------------- ----------------------

View File

@ -2439,6 +2439,27 @@
#topics=notifications #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=<None>
# 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=<None>
[conductor] [conductor]
# #

View File

@ -31,4 +31,8 @@ os.environ['EVENTLET_NO_GREENDNS'] = 'yes'
import eventlet 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)

View File

@ -105,9 +105,27 @@ service_opts = [
help='maximum time since last check-in for up service'), 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 = cfg.CONF
CONF.register_opts(service_opts) CONF.register_opts(service_opts)
CONF.import_opt('host', 'nova.netconf') CONF.import_opt('host', 'nova.netconf')
CONF.register_cli_opts(cli_opts, 'remote_debug')
class Service(service.Service): class Service(service.Service):
@ -249,6 +267,21 @@ class Service(service.Service):
periodic_enable = CONF.periodic_enable periodic_enable = CONF.periodic_enable
if periodic_fuzzy_delay is None: if periodic_fuzzy_delay is None:
periodic_fuzzy_delay = CONF.periodic_fuzzy_delay 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, service_obj = cls(host, binary, topic, manager,
report_interval=report_interval, report_interval=report_interval,
periodic_enable=periodic_enable, periodic_enable=periodic_enable,