之前一直没有找到方法调试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. springboot 集成 swagger

    1. 首先配置swaggerConfigpackage com.lixcx.lismservice.config; import com.lixcx.lismservice.format.Custom ...

  2. nginx upstream 名称下划线问题

    原始配置: user  nobody;worker_processes  1; #pid        logs/nginx.pid; worker_connections  1024;} http ...

  3. java面向对象的有序数组和无序数组的比较

    package aa; class Array{ //定义一个有序数组 private long[] a; //定义数组长度 private int nElems; //构造函数初始化 public ...

  4. 关于XML文档操作类

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.X ...

  5. phpquery 学习笔记

    phpQuery是一个基于PHP的服务端开源项目,它可以让PHP开发人员轻松处理DOM文档内容,比如获取某新闻网站的头条信息.更有意思的是,它采用了jQuery的思想,你可以像使用jQuery一样处理 ...

  6. win10与linux双系统切换时间不一致的调整

    按照Linux系统之后再切换回到win10后,我发现win10的时间不再是北京时间,而是比北京时间多了整整8小时,之后百度找到了问题来源,这里给出解决方法. 如果安装了 Windows 和 Linux ...

  7. Weighted Median

    For n elements x1, x2, ..., xn with positive integer weights w1, w2, ..., wn. The weighted median is ...

  8. struts2--文件上传大小

    Struts2文件上传的大小限制问题 问题:上传大文件报错-- 解决:修改struts.xml文件中的参数如下 <constant name="struts.multipart.max ...

  9. OC创建对象并访问成员变量

    1.创建一个对象 Car *car =[Car new] 只要用new操作符定义的实体,就会在堆内存中开辟一个新空间 [Car new]在内存中 干了三件事 1)在堆中开辟一段存储空间 2)初始化成员 ...

  10. udp 局域网群聊

    UDP: 无连接协议 udp协议发送数据,用的是数据报包的形式.(64KB以内)     发送端: 1.定义发送的datagramsocket对象,发送端可以不用定义端口 2.定义封装数据包datag ...