Support for debug mode start in barbican

Closes-Bug: #1295903

Change-Id: I23b508a88f666009f77a3c021e2600a279068e4b
This commit is contained in:
Arvind Tiwari 2014-03-21 18:47:48 -06:00
parent ef40e55b01
commit 177d4499af
3 changed files with 65 additions and 2 deletions

View File

@ -43,7 +43,7 @@ def create_main_app(global_config, **local_conf):
# Configure oslo logging and configuration services.
config.parse_args()
log.setup('barbican')
config.setup_remote_pydev_debug()
# Crypto Plugin Manager
crypto_mgr = ext.CryptoExtensionManager()

View File

@ -38,6 +38,8 @@ CONF.import_opt('log_date_format', 'barbican.openstack.common.log')
CONF.import_opt('use_syslog', 'barbican.openstack.common.log')
CONF.import_opt('syslog_log_facility', 'barbican.openstack.common.log')
LOG = logging.getLogger(__name__)
def parse_args(args=None, usage=None, default_config_files=None):
CONF(args=args,
@ -47,6 +49,9 @@ def parse_args(args=None, usage=None, default_config_files=None):
usage=usage,
default_config_files=default_config_files)
CONF.pydev_debug_host = os.environ.get('PYDEV_DEBUG_HOST')
CONF.pydev_debug_port = os.environ.get('PYDEV_DEBUG_PORT')
def setup_logging():
"""
@ -91,3 +96,25 @@ def setup_logging():
handler.setFormatter(formatter)
root_logger.addHandler(handler)
def setup_remote_pydev_debug():
"""Required setup for remote debugging"""
if CONF.pydev_debug_host and CONF.pydev_debug_port:
try:
try:
from pydev import pydevd
except ImportError:
import pydevd
pydevd.settrace(CONF.pydev_debug_host,
port=int(CONF.pydev_debug_port),
stdoutToServer=True,
stderrToServer=True)
except Exception:
LOG.exception('Unable to join debugger, please '
'make sure that the debugger processes is '
'listening on debug-host \'%s\' debug-port \'%s\'.',
CONF.pydev_debug_host, CONF.pydev_debug_port)
raise

View File

@ -17,6 +17,38 @@ LOCAL_CONFIG=$LOCAL_CONFIG_DIR/barbican-api.conf
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
echo 'DIR: '$DIR
debug_barbican()
{
# Start barbican server in debug mode.
# Note: for Eclipse IDE users
# Make sure PYTHONPATH is set with pydev
# export PYTHONPATH=/<eclipse_home>/plugins/org.python.pydev_2.8.2.2013090511/pysrc"
# Note: for Pycharm IDE users
# Follow the instruction in link below
# https://github.com/cloudkeep/barbican/wiki/Developer-Guide-for-Contributors#debugging-using-pycharm
# Following are two commands to start barbican in debug mode
# (1) ./barbican.sh debug
# (2) ./barbican.sh debug --pydev-debug-host localhost --pydev-debug-port 5678
if [ -z $3 ] ;
then
debug_host=localhost
else
debug_host=$3
fi
if [ -z $5 ] ; then
debug_port=5678
else
debug_port=$5
fi
echo "Starting barbican in debug mode ..." --pydev-debug-host $debug_host --pydev-debug-port $debug_port
PYDEV_DEBUG_PARAM="--env PYDEV_DEBUG_HOST=$debug_host --env PYDEV_DEBUG_PORT=$debug_port"
uwsgi --master --emperor $CONFIG_DIR/vassals -H $VENV_DIR $PYDEV_DEBUG_PARAM
}
start_barbican()
{
# Start barbican server up.
@ -78,6 +110,9 @@ case "$1" in
install)
install_barbican
;;
debug)
debug_barbican $*
;;
start)
start_barbican
;;
@ -91,6 +126,7 @@ case "$1" in
;;
*)
echo "Usage: barbican.sh {install|start|stop|restart}"
echo "Usage: barbican.sh {install|start|stop|debug <debug_params>|restart}"
echo "where debug_params are: --pydev-debug-host <host> --pydev-debug-port <port>, <host> defaults to 'localhost' and <port> defaults to '5678'"
exit 1
esac