之前一直没有找到方法调试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. 初试Gevent – 高性能的Python并发框架

    Gevent是一个基于greenlet的Python的并发框架,以微线程greenlet为核心,使用了epoll事件监听机制以及诸多其他优化而变得高效. 于greenlet.eventlet相比,性能 ...

  2. Bate版本控制报告

    报告beta阶段2周中,项目的版本控制情况,不包括未在coding.net的部分. 包括不限于:check in (不是push)次数; 总词数为29次 check in log(时间.人员.mess ...

  3. Unicode和UTF-8

    作者:于洋链接:https://www.zhihu.com/question/23374078/answer/69732605来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非商业转载请注明出 ...

  4. lintcode-201-线段树的构造

    201-线段树的构造 线段树是一棵二叉树,他的每个节点包含了两个额外的属性start和end用于表示该节点所代表的区间.start和end都是整数,并按照如下的方式赋值: 根节点的 start 和 e ...

  5. DNS测试工具的使用(了解)

    dig命令, host命令, nslookup命令,rndc命令 dig命令(直接测试DNS性能,不会查询/etc/hosts文件) dig [-t RR_TYPE] name [@SERVER] [ ...

  6. app测试更多机型系统解决方法

    手头上测试机有限,不可能每个机型每个系统都 有一部手机,此时寻求一个什么都有的测试平台就显得尤为重要了. 作为小白的我刚刚使用了一波腾讯优测,简单粗暴有效给力,而且新注册认证用户还有60min免费使用 ...

  7. HDU 2162 Add ‘em

    http://acm.hdu.edu.cn/showproblem.php?pid=2162 Problem Description Write a program to determine the ...

  8. 小程序获取access_token

    <?php //小程序appid $appid = 'wx79d7c348d19f010c'; //小程序 APPSecret 密钥 $appsecret = 'd624aca86d0350ee ...

  9. 【Linux学习笔记】Linux C中内联汇编的语法格式及使用方法(Inline Assembly in Linux C)

    http://blog.csdn.net/slvher/article/details/8864996 https://gcc.gnu.org/onlinedocs/gcc/Extended-Asm. ...

  10. 第194天:js---函数对象详解(arguments、length)

    一.函数即对象 function add1(a,b){ return a+b; } //Function对象的实例 -- 高级技巧 --- 写框架必须用的... //前面表示参数,后面表示函数语句 v ...