之前一直没有找到方法调试openstack的horizon代码,现在终于找到方法了,特别感谢下面这篇博客,讲解非常清晰:

http://blog.csdn.net/tantexian/article/details/38295599  但是其中有一个问题就是需要在源程序代码中添加代码以供调试用,这样调试完了还要去删除这些代码,十分不方便。所以我就想在此基础上做些改进,具体情况如下:

Komodo下载地址:http://pan.baidu.com/s/13i5Zk

PythonRemoteDebuggingClient下载地址:http://code.activestate.com/komodo/remotedebugging/

一、本地安装配置Komodo

1、Edit->Preferences:配置python解释器。

2、Debug-> Listen for debuging connections:确保勾选上,这样才能远程调试。

3、Debug->Listener Status:查看配置的远程连接端口。(Edit-> Preferences->Debugger->Connection:可以自定义远程连接端口)

二、远程服务器配置

解压PythonRemoteDebuggingClient并进入该目录!

cd pythonlib/dbgp

1.

cp client.py client.py.bak
vim client.py

在头部添加:

import stat

在brk函数处进行修改:

def brk(file=None,host = '10.10.24.96', port = 9000, idekey = '',
preloadScript = None, logLevel = logging.WARN):
filepath=os.path.abspath(file)
tmp_file='/tmp/brk_file'
if not os.path.exists(tmp_file):
with open(tmp_file,'a') as f:
  f.write(filepath)
  f.write('\n')
os.chmod(tmp_file,os.stat(tmp_file).st_mode|stat.S_IWGRP|stat.S_IWOTH)
else:
with open(tmp_file,'a') as f:
  f.write(filepath)
  f.write('\n')

说明:这里设置/tmp/brk_file为临时记录文件,记录那些添加了断点设置代码的文件路径信息。10.10.24.96为Komodo所在的机器IP地址,非调试的代码所在地址。9000为调试设置的端口。

2.

cp __init__.py __init__.py.bak
vim __init__.py

在头部添加:

from dbgp.client import brk

3.

cp -r pythonlib/dbgp /usr/lib/python2./site-packages/
cp pydbgp /usr/bin/
chmod a+x /usr/bin/pydbgp

三、设置删除断点程序

1.

vim brk-clean

添加如下内容:

#!/usr/bin/python
import subprocess
import os
import sys def delete_brk(file):
cmd="sed -i "+r"'/import dbgp/d' "+file+";"
cmd=cmd+"sed -i "+r"'/dbgp.brk(__file__)/d' "+file
proc=subprocess.Popen(cmd,shell=True,stdout=subprocess.PIPE,stderr=subprocess.PIPE)
out,err=proc.communicate()
if proc.returncode:
raise RuntimeError('Failed:\n%s' % err) def main(): result=True
#if tmp file not exist or is not a file
if not os.path.exists('/tmp/brk_file') or not os.path.isfile('/tmp/brk_file'):
print "/tmp/brk_file doesn't exist!\nCheck if it has been deleted Or you didn't set any breakpoint !"
result=False
return result #find files with brk
file_list=[]
with open('/tmp/brk_file','r') as f:
file_list=f.readlines()
try:
os.remove('/tmp/brk_file')
except:
print r"Error:Can't delete /tmp/brk_file!"
result=False for file in file_list:
file=file.rstrip('\n')
if os.path.exists(file) and os.path.isfile(file):
delete_brk(file)
print 'Deleted brk in file: '+file+r"!"
else:
print 'Error:'+file+r"doesn't exist or isn't a file"
result=False return result if __name__=='__main__':
#delete the brk in a file
if len(sys.argv)>1:
file=sys.argv[1]
if not os.path.exists(file) or not os.path.isfile(file):
print file+r" doesn't exist!"
sys.exit()
delete_brk(file)
print "Breakpoints in "+file+" have been cleaned up !"
sys.exit() result=main()
if result:
print 'Brk-Clean Completed !'

2.

mv brk-clean /usr/bin
chmod a+x /usr/bin/brk-clean

四、在需要设置断点的地方插入断点设置代码

import dbgp
dbgp.brk(__file__)

五、运行需要调试的程序或重启相关服务

  这里提供一个启动openstack服务的脚本,非本人所写 ,不过用起来也不错,参考链接:https://github.com/liuan/openstack-x

六、调试完后记得删除断点设置代码

brk-clean

七、如果有必要,须重启相关服务

远程调试openstack的更多相关文章

  1. 利用pycharm远程调试openstack代码

    1.安装pycharm专业版 本文安装pycharm 2016.2.3专业版.网上教程较多,这里不做详细介绍,只要到pycharm官网上下载应用程序进行安装即可. 2.pycharm配置 (1)首先按 ...

  2. [转]使用eclipse+pydev远程调试OpenStack

    作者:张华  发表于:2014-01-17版权声明:可以任意转载,转载时请务必以超链接形式标明文章原始出处和作者信息及本版权声明 ( http://blog.csdn.net/quqi99 ) 1, ...

  3. Python远程调试Openstack

    前言 由于开始着手openstack运维方面的东西,我这颗大白菜必须要学一学这个高端的东西啦. 准备 pycharm依赖于专业版(这里需要注意,我前面浪费了好多时间...)下载并安装pycharm,网 ...

  4. Openstack Pycharm 的远程调试

    问题背景 最近再研究openstack cinder api的时候遇到了个问题:使用命令行调用API的时候,使用domain的token时,会产生一个错误,但是通过cinder的api都无法确定产生错 ...

  5. 微信公众号开发之VS远程调试

    目录 (一)微信公众号开发之VS远程调试 (二)微信公众号开发之基础梳理 (三)微信公众号开发之自动消息回复和自定义菜单 前言 微信公众平台消息接口的工作原理大概可以这样理解:从用户端到公众号端一个流 ...

  6. tomcat开发远程调试端口以及利用eclipse进行远程调试

    一.tomcat开发远程调试端口 方法1 WIN系统 在catalina.bat里:  SET CATALINA_OPTS=-server -Xdebug -Xnoagent -Djava.compi ...

  7. Visual Studio 2012远程调试中遇到的问题

    有的时候开发环境没问题的代码在生产环境中会某些开发环境无法重现的问题,或者需要对生产环境代码进行远程调试该怎么办? Vs已经提供给开发者远程调试的工具 下面简单讲讲该怎么用,前期准备:1.本地登录账户 ...

  8. 使用Eclipse进行远程调试

    转自:http://blog.csdn.net/sunyujia/article/details/2614614 今天决定做件有意义的事,写篇图文并茂的blog,为什么要图文并茂?因为很多事可能用语言 ...

  9. 微信公众号开发系列教程一(调试环境部署续:vs远程调试)

    http://www.cnblogs.com/zskbll/p/4080328.html 目录 C#微信公众号开发系列教程一(调试环境部署) C#微信公众号开发系列教程一(调试环境部署续:vs远程调试 ...

随机推荐

  1. presto——java.sql.SQLException: Error executing query与javax.net.ssl.SSLException: Unrecognized SSL message, plaintext connection?异常问题

    使用presto的时候以mysql为presto的数据源 安装的presto是0.95版本:使用的presto-jdbc是0.202的,这里使用jdbc去访问时候,connection可以链接成功,但 ...

  2. java 乐观锁 vs 悲观锁

    在数据库的锁机制中介绍过,数据库管理系统(DBMS)中的并发控制的任务是确保在多个事务同时存取数据库中同一数据时不破坏事务的隔离性和统一性以及数据库的统一性. 悲观锁其实就是 完全同步 比如 sync ...

  3. [Algorithm] A* Search Algorithm Basic

    A* is a best-first search, meaning that it solves problems by searching amoung all possible paths to ...

  4. vim 编码方式的设置

    和所有的流行文本编辑器一样,Vim 可以很好的编辑各种字符编码的文件,这当然包括UCS-2.UTF-8 等流行的 Unicode 编码方式.然而不幸的是,和很多来自 Linux 世界的软件一样,这需要 ...

  5. c# 修改exe.config文件并且及时更新

    1.config文件地址:AppDomain.CurrentDomain.SetupInformation.ConfigurationFile 注意:如果是在调试程序中运行,此地址指代的是vhost. ...

  6. 智能客服 对话实现--python aiml包

    利用了python的aiml包进行应答 什么是AIML? AIML是Richard Wallace开发的. 他开发了一个叫A.L.I.C.E(Artificial Linguistics Intern ...

  7. C语言的调查

    1.你对自己的未来有什么规划?做了哪些准备?从事跟本专业相关的工作.认真学习好书本的知识,并能很好的运用它. 2.你认为什么是学习?学习有什么用?现在学习动力如何?为什么?学习可以让自己懂得更多,完善 ...

  8. C++对象内存布局测试总结

    C++对象内存布局测试总结 http://hi.baidu.com/����/blog/item/826d38ff13c32e3a5d6008e8.html 上文是半年前对虚函数.虚拟继承的理解.可能 ...

  9. Node.js系列——(1)安装配置与基本使用

    1.安装 进入下载地址 小编下载的是msi文件,下一步下一步傻瓜式安装. 打印个hello看看: 2.REPL 全称Read Eval Print Loop,即交互式解释器,可以执行读取.执行.打印. ...

  10. CentOS下php安装mcrypt扩展

    CentOS下php安装mcrypt扩展 Posted on 2012-09-12 15:27 C'est la vie 阅读(48294) 评论(3) 编辑 收藏 (以下步骤均为本人实际操作,可能与 ...