eclipse + pydev远程调试OpenStack
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了eclipse + pydev远程调试OpenStack相关的知识,希望对你有一定的参考价值。
一、安装eclipse、PyDev插件
官方eclipse下载地址:https://www.eclipse.org/downloads/
这里不详细描述了,先装java运行环境,再装eclipse就对了。
安装PyDev插件:打开eclipse --> Help --> Install New Software;详情参考这(http://www.pydev.org/manual_101_install.html)
二、配置Pydev debug
配置debug server信息
三、远程调试OpenStack Nova api(nova stop instance的api调用)
1、确保远程运行nova api服务器有pydevd.py,可以从本地安装eclipse的pydev插件目录下找到(不同环境下目录可能有所不同)
然后拷贝到运行nova api服务器的python路径下
ices-MacBook-Air:~ iceyao$ ls -l /Users/iceyao/.p2/pool/plugins/org.python.pydev_4.5.4.201601292234/pysrc/pydevd.py -rw-r--r-- 1 iceyao staff 60901 Jan 29 20:32 /Users/iceyao/.p2/pool/plugins/org.python.pydev_4.5.4.201601292234/pysrc/pydevd.py
2、其次要保证本地eclipse端也有一份相同代码,如果在不同目录,可以使用修改pydevd_file_utils.py文件来实现
# 不同环境下文件位置可能有所不同 ices-MacBook-Air:~ iceyao$ ls -l /Users/iceyao/.p2/pool/plugins/org.python.pydev_4.5.4.201601292234/pysrc/pydevd_file_utils.py -rw-r--r-- 1 iceyao staff 14343 Mar 20 14:50 /Users/iceyao/.p2/pool/plugins/org.python.pydev_4.5.4.201601292234/pysrc/pydevd_file_utils.py ices-MacBook-Air:~ iceyao$ vim /Users/iceyao/.p2/pool/plugins/org.python.pydev_4.5.4.201601292234/pysrc/pydevd_file_utils.py # 找到PATHS_FROM_ECLIPSE_TO_PYTHON PATHS_FROM_ECLIPSE_TO_PYTHON = [ (r‘/opt/stack/a/nova‘, # 本地路径 r‘/opt/stack/nova‘) # 远端python process路径 ]
导入本地/opt/stack/a/nova项目
File --> Import --> General --> Existing Projects into Workspace
3、远程运行nova api服务器设置断点
本地eclipse机器开启debug监听
登入远程的devstack环境,进入screen,加上--remote_debug-host 172.16.1.10 --remote_debug-port 12306,重新启动服务
172.16.1.10:本地安装eclipse的机器ip
[email protected]:/opt/devstack$ /usr/local/bin/nova-api --remote_debug-host 172.16.1.10 --remote_debug-port 12306 & echo $! >/opt/stack/status/stack/n-api.pid; fg || echo "n-api failed to start" | tee "/opt/stack/status/stack/n-api.failure"
[email protected]:~/nova$ cat nova/cmd/__init__.py # 上述参数的意义 import eventlet from nova import debugger if debugger.enabled(): # turn off thread patching to enable the remote debugger eventlet.monkey_patch(os=False, thread=False) # 加上上述debug参数后,自动eventlet关闭多线程,不然会出现无法捕获到断电调试的代码 else: eventlet.monkey_patch(os=False)
设置断点
[email protected]:~/nova$ vim nova/compute/api.py @check_instance_lock @check_instance_host @check_instance_cell @check_instance_state(vm_state=[vm_states.ACTIVE, vm_states.ERROR]) def stop(self, context, instance, do_cast=True, clean_shutdown=True): """Stop an instance.""" import pydevd;pydevd.settrace(host=‘172.16.1.10‘, port=12306, stdoutToServer=True, stderrToServer=True,suspend=True) # 断点处 self.force_stop(context, instance, do_cast, clean_shutdown) [email protected]:~/nova$ nova list +--------------------------------------+------+--------+------------+-------------+--------------------------------+ | ID | Name | Status | Task State | Power State | Networks | +--------------------------------------+------+--------+------------+-------------+--------------------------------+ | c04f9a2f-36b3-4104-8c75-5461491aca97 | test | ACTIVE | - | Running | public=2001:db8::3, 172.24.4.3 | +--------------------------------------+------+--------+------------+-------------+--------------------------------+ [email protected]:~/nova$ [email protected]:~/nova$ nova stop c04f9a2f-36b3-4104-8c75-5461491aca97 # nova客户端发起请求
本地eclipse机器捕获到,接下来就可以进行调试了
参考链接
http://www.pydev.org/manual_101_install.html (PyDev安装)
http://blog.csdn.net/tantexian/article/details/47003385
http://blog.csdn.net/quqi99/article/details/18404807
http://yikun.github.io/2016/02/23/%E4%BC%98%E9%9B%85%E5%9C%B0%E8%B0%83%E8%AF%95OpenStack/(PyCharm远程调试OpenStack)
本文出自 “the-way-to-cloud” 博客,请务必保留此出处http://iceyao.blog.51cto.com/9426658/1753169
以上是关于eclipse + pydev远程调试OpenStack的主要内容,如果未能解决你的问题,请参考以下文章
调试 python 在 Eclipse ( pydev ) 中终止