跳转到: 导航, 搜索

Barbican/Barbican-IDE-Debugging

本页描述了如何使用您最喜欢的 IDE(Eclipse 或 PyCharm)调试器设置和调试 Barbican 代码。此说明可用于本地或远程调试场景。

前提条件

  1. Barbican 已按照说明安装。
  2. 已安装 IDE(PyCharm/Eclipse)并配置了 Barbican 项目。
  3. 对于 'Eclipse',已安装 PyDev 插件。
  4. Barbican 可以本地或远程安装。对于本地安装,IDE 和 Barbican 必须位于同一主机上。

Python 设置

必须将 'pydev' 库安装到将运行 OpenStack Barbican 服务的 python 环境中。

PyCharm

在您安装 pycharm 的目录中找到文件 pycharm-debug.egg。它应该位于顶级目录中。现在执行以下操作

   cd <python installation that will run barbican>/lib/python2.7/site-packages
   unzip <installation of pycharm>/pycharm-debug.egg

Eclipse

在 '<ECLIPSE_HOME>/plugins/' 文件夹中找到包含 pydev 库的 'pysrc' 目录。

   e.g. <ECLIPSE_HOME>/plugins/org.python.pydev_2.8.2.2013090511/pysrc

更新 'PYTHONPATH' 环境变量,该环境变量将运行 'OpenStack Barbican' 服务,并将其路径添加到 'pydev' 库中。

   e.g. if Barbican service is started from Linux shell then
   export PYTHONPATH=<ECLIPSE_HOME>/plugins/org.python.pydev_<version>/pysrc
   
   Note: for remote debugging, copy 'pysrc' folder to the remote machine and set the 'PYTHONPATH' as above.

在 IDE 中启动调试服务器

PyCharm

请按照 此帖子 中的说明设置并启动特定主机和端口上的调试服务器。

假设配置了 'localhost' 和 '5678' 作为调试器,您将在控制台上看到以下消息。

   Starting debug server at port 5678
   Waiting for connection...

Eclipse

转到 'Window > Preferences > PyDev > Debug' 并根据需要更改调试服务器端口(默认 5678)。单击“PyDev > Start Debug server”以启动 eclipse 调试服务器。

以调试模式启动 Barbican 服务

要以调试模式启动 Barbican

1. 如果 Barbican 和 IDE 正在同一主机上运行,并且调试器进程正在侦听默认端口(例如 5678)。

   cd <barbican_home>/bin
   ./barbican.sh debug

2. 如果 Barbican 和 IDE 不在同一主机上。在托管 Barbican 服务的远程主机上运行以下命令。

   cd <barbican_home on the remote host>/bin
   ./barbican.sh debug --pydev-debug-host localhost  --pydev-debug-port 5678

注意:默认情况下,'pydevd.settrace'(调试断点)在 'barbican/common/config.py' 的 'setup_remote_pydev_debug()' 方法中设置。如果 barbican 进程似乎被阻止,请不要感到惊讶,按 IDE 上的“F8”或“Resume”按钮继续。

故障排除

ImportError: No module named pydevd

2014-04-16 14:13:16.539 19741 ERROR barbican.common.config [-] Unable to join debugger, please make sure that the debugger processes is listening on debug-host 'localhost' debug-port '5678'.
2014-04-16 14:13:16.539 19741 TRACE barbican.common.config Traceback (most recent call last)
2014-04-16 14:13:16.539 19741 TRACE barbican.common.config File "/home/atiwari/cloudDev/barbicanDev/barbican-master/barbican/common/config.py", line 109, in setup_remote_pydev_debug
2014-04-16 14:13:16.539 19741 TRACE barbican.common.config import pydevd
2014-04-16 14:13:16.539 19741 TRACE barbican.common.config ImportError: No module named pydevd
2014-04-16 14:13:16.539 19741 TRACE barbican.common.config
2014-04-16 14:13:16.540 19741 CRITICAL barbican [-] ImportError: No module named pydevd
2014-04-16 14:13:16.540 19741 TRACE barbican Traceback (most recent call last):v 2014-04-16 14:13:16.540 19741 TRACE barbican File "/home/atiwari/.pyenv/versions/barbican27/lib/python2.7/site-packages/paste/deploy/loadwsgi.py", line 247, in loadapp
2014-04-16 14:13:16.540 19741 TRACE barbican return loadobj(APP, uri, name=name, **kw)
2014-04-16 14:13:16.540 19741 TRACE barbican File "/home/atiwari/.pyenv/versions/barbican27/lib/python2.7/site-packages/paste/deploy/loadwsgi.py", line 272, in loadobjv 2014-04-16 14:13:16.540 19741 TRACE barbican return context.create()v

解决方案 确保 pydev 库已正确配置。请按照上述 Python 设置 中的说明进行操作。

error: [Errno 111] Connection refused

Loading paste environment: config:/etc/barbican/barbican-api-paste.ini
2014-04-16 14:27:46.205 20635 ERROR barbican.common.config [-] Unable to join debugger, please make sure that the debugger processes is listening on debug-host 'localhost' debug-port '567'.
2014-04-16 14:27:46.205 20635 TRACE barbican.common.config Traceback (most recent call last)
2014-04-16 14:27:46.205 20635 TRACE barbican.common.config File "/home/atiwari/cloudDev/barbicanDev/barbican-master/barbican/common/config.py", line 114, in setup_remote_pydev_debug
2014-04-16 14:27:46.205 20635 TRACE barbican.common.config stderrToServer=True)
2014-04-16 14:27:46.205 20635 TRACE barbican.common.config File "/home/atiwari/eclipse4py/plugins/org.python.pydev_2.8.2.2013090511/pysrc/pydevd.py", line 1247, in settrace
2014-04-16 14:27:46.205 20635 TRACE barbican.common.config _locked_settrace(host, stdoutToServer, stderrToServer, port, suspend, trace_only_current_thread)
2014-04-16 14:27:46.205 20635 TRACE barbican.common.config File "/home/atiwari/eclipse4py/plugins/org.python.pydev_2.8.2.2013090511/pysrc/pydevd.py", line 1272, in _locked_settrace
2014-04-16 14:27:46.205 20635 TRACE barbican.common.config debugger.connect(host, port)
2014-04-16 14:27:46.205 20635 TRACE barbican.common.config File "/home/atiwari/eclipse4py/plugins/org.python.pydev_2.8.2.2013090511/pysrc/pydevd_comm.py", line 300, in connect
2014-04-16 14:27:46.205 20635 TRACE barbican.common.config s = StartClient(host, port)
2014-04-16 14:27:46.205 20635 TRACE barbican.common.config File "/home/atiwari/eclipse4py/plugins/org.python.pydev_2.8.2.2013090511/pysrc/pydevd_comm.py", line 365, in StartClient
2014-04-16 14:27:46.205 20635 TRACE barbican.common.config s.connect((host, port))
2014-04-16 14:27:46.205 20635 TRACE barbican.common.config File "/home/atiwari/.pyenv/versions/2.7.5/lib/python2.7/socket.py", line 224, in meth
2014-04-16 14:27:46.205 20635 TRACE barbican.common.config return getattr(self._sock,name)(*args)
2014-04-16 14:27:46.205 20635 TRACE barbican.common.config error: [Errno 111] Connection refused

解决方案

调试服务器进程未在 debug-host 'localhost' debug-port '567' 上侦听。请确保您已在正确的端口上启动它。

参考资料