eclipse + pydev遠程調試OpenStack

1、安裝eclipse、PyDev插件
html

官方eclipse下載地址:https://www.eclipse.org/downloads/ java

這裏不詳細描述了,先裝java運行環境(若是沒裝,安裝eclipse的過程會自動提示要先裝jre),再裝eclipse就對了。python


安裝PyDev插件:打開eclipse --> Help --> Install New Software;詳情參考這(http://www.pydev.org/manual_101_install.htmlgit

wKioL1buWELgJBzEAAFe7b24DYM749.png


2、配置Pydev debug
github

wKioL1buW0eiDklEAACzsGCMUg8427.png

wKiom1buW3jjvFffAAEqRJYrOD8592.png


wKiom1buXW6DJpDPAACiXMuiE4g651.png


wKioL1buXqGyudGiAADPl1oqaaE128.png

wKiom1buXg6T5ns_AABou3P4s0w638.png


wKioL1buXvCAuZeUAAEk_nPG8_g006.png


配置debug server信息ubuntu

wKiom1buYL7CFf3qAAGn-OYR-VQ680.png


3、遠程調試OpenStack Nova api(nova stop instance的api調用)
vim

一、確保遠程運行nova api服務器有pydevd.py,能夠從本地安裝eclipse的pydev插件目錄下找到(不一樣環境下目錄可能有所不一樣)api

而後拷貝到運行nova api服務器的python路徑下bash

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


二、其次要保證本地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

wKioL1buZ3vD4PYRAADKu5hDBuk793.png


wKiom1buZ6jARGwrAAEMugTE53c702.png


三、遠程運行nova api服務器設置斷點

本地eclipse機器開啓debug監聽

wKiom1buatuD4BvEAACrAVOiwwo636.png


wKiom1buaxLhUuj-AAEi3AG6HR4691.png


登入遠程的devstack環境,進入screen,加上--remote_debug-host 172.16.1.10 --remote_debug-port 12306,從新啓動服務

172.16.1.10:本地安裝eclipse的機器ip

stack@yxb-devstack:/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"


stack@yxb-devstack:~/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)


設置斷點

stack@yxb-devstack:~/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)
        
stack@yxb-devstack:~/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 |
+--------------------------------------+------+--------+------------+-------------+--------------------------------+
stack@yxb-devstack:~/nova$
stack@yxb-devstack:~/nova$ nova stop c04f9a2f-36b3-4104-8c75-5461491aca97   # nova客戶端發起請求


本地eclipse機器捕獲到,接下來就能夠進行調試了

wKioL1bubU-y82CqAANMOpWVTz8148.png


參考連接

http://www.pydev.org/manual_101_install.html (PyDev安裝)

http://zhaozhiming.github.io/blog/2014/04/13/python-remote-debug-setting-by-pycharm-and-eclipse-in-ubuntu/

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

相關文章
相關標籤/搜索