设为首页 收藏本站
查看: 1310|回复: 0

[经验分享] 远程调试openstack

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2015-4-12 08:11:08 | 显示全部楼层 |阅读模式
  之前一直没有找到方法调试openstack的horizon代码,现在终于找到方法了,特别感谢下面这篇博客,讲解非常清晰:
  http://blog.iyunv.com/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.6/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
  
  七、如果有必要,须重启相关服务
  

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-56152-1-1.html 上篇帖子: [转] Customizing OpenStack RBAC policies 下篇帖子: Openstack Horizon and Django Compare the Working of authentication (Login)
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表