diff --git a/glance/common/config.py b/glance/common/config.py index 461ebf5266..3a49d1208d 100644 --- a/glance/common/config.py +++ b/glance/common/config.py @@ -58,6 +58,12 @@ common_opts = [ help=_("Deploy the v1 OpenStack Images API. ")), cfg.BoolOpt('enable_v2_api', default=True, help=_("Deploy the v2 OpenStack Images API. ")), + cfg.StrOpt('pydev_worker_debug_host', default=None, + help=_('The hostname/IP of the pydev process listening for ' + 'debug connections')), + cfg.IntOpt('pydev_worker_debug_port', default=5678, + help=_('The port on which a pydev process is listening for ' + 'connections.')), ] CONF = cfg.CONF diff --git a/glance/common/utils.py b/glance/common/utils.py index 9070883dd0..1500522d72 100644 --- a/glance/common/utils.py +++ b/glance/common/utils.py @@ -36,6 +36,7 @@ import sys from webob import exc from glance.common import exception +from glance.openstack.common import cfg import glance.openstack.common.log as logging @@ -410,3 +411,23 @@ def mutating(func): content_type="text/plain") return func(self, req, *args, **kwargs) return wrapped + + +def setup_remote_pydev_debug(host, port): + + error_msg = ('Error setting up the debug environment. Verify that the' + ' option pydev_worker_debug_port is pointing to a valid ' + 'hostname or IP on which a pydev server is listening on' + ' the port indicated by pydev_worker_debug_port.') + + try: + from pydev import pydevd + + pydevd.settrace(host, + port=port, + stdoutToServer=True, + stderrToServer=True) + return True + except: + LOG.exception(error_msg) + raise diff --git a/glance/common/wsgi.py b/glance/common/wsgi.py index 7d5e0449a9..a62af7a0a7 100644 --- a/glance/common/wsgi.py +++ b/glance/common/wsgi.py @@ -40,6 +40,7 @@ import webob.dec import webob.exc from glance.common import exception +from glance.common import utils from glance.openstack.common import cfg import glance.openstack.common.log as os_logging @@ -266,6 +267,10 @@ class Server(object): def run_server(self): """Run a WSGI server.""" + if cfg.CONF.pydev_worker_debug_host: + utils.setup_remote_pydev_debug(cfg.CONF.pydev_worker_debug_host, + cfg.CONF.pydev_worker_debug_port) + eventlet.wsgi.HttpProtocol.default_request_version = "HTTP/1.0" try: eventlet.hubs.use_hub('poll')