用pdb调试OpenStack Havana
作为个人学习笔记分享,有任何问题欢迎交流!
Note:若是想要用pdb调试OpenStack,必须通过Devstack安装它。
Devstack安装Havana过程
1. 使用一般用户(非root用户),从github上获取devstack代码
git clonehttps://github.com/openstack-dev/devstack.git
2. 使用一般用户运行
cd devstack; ./stack.sh
(参考:http://devstack.org/)
3.安装过程中要求输入一些密码,这些密码将记录在localrc文件中,该文件还可以用来配置安装的openstack组件,默认的只会安装glance,keystone,nova,horizon.
4. 创建文件creds:
exportSERVICE_TOKEN=xxx(3中输入的密码)
exportOS_TENANT_NAME=admin
exportOS_USERNAME=admin
export OS_PASSWORD=xxx
exportOS_AUTH_URL=http://localhost:5000/v2.0/
exportSERVICE_ENDPOINT=http://localhost:35357/v2.0
source creds就可以使用openstack了
5. 若想更改已安装的组件,再./stack.sh即可
Pdb调试Havana过程
1. 修改代码
在需要调试的地方加入:
import pdb; pdb.set_trace()(以在nova/compute/api.py:get_all()中加入pdb为例)
2. 使用附录上的脚步restart_stack.sh重启服务(该脚本只针对默认安装的组件有效)
3. 开始调试:
显示有两个screen
screen –x stack
进入如下界面:
最下一行表示,每一个进程都有一个screen。带*号的表示当前的screen,可以同时按下ctrl+a+8和ctrl+a+2分别前进和后退,来切换不同的screen.
4. 在0$中输入nova list;切换到4$ n-api:
5. 开始使用pdb进行调试
注意问题
1. 在./restart_stack后,如果某个服务一直在waiting,说明这个服务运行到了你设置的断点,那么可以使用ctrl+z,把当前的进行切换到后台,然后screen –x stack,找到该服务对应的窗口进行调试,如果不需要在服务启动时就进行调试的话,按‘c’,让它继续执行。之后Ctrl+a +d退出screen,用jobs命令查看后台运行的进程,fg+进程ID, 就可以把./restart_stack.sh的后台进程调出来继续执行了。
2. ./restart_stack后,Horizon使用不了。
参考资料
1.使用pdb调试openstack (How to debug openstackusing pdb )
http://blog.csdn.net/hackerain/article/details/8373597
http://www.cnblogs.com/mchina/archive/2013/01/30/2880680.html
附录
###########restart_stack.sh########################
#!/usr/bin/env bash
#restart the interfaces
#sudo /etc/init.d/networking restart # close previrous screen
SCREEN=$(which screen)
if [[ -n "$SCREEN" ]]; then
SESSION=$(screen -ls | awk '/[0-9].stack/ { print $1 }')
if [[ -n "$SESSION" ]]; then
echo "close session: $SESSION"
echo ""
screen -X -S $SESSION quit
fi
fi TOP_DIR=$(cd $(dirname "$0") && pwd) # create a new named screen to run processes in
screen -d -m -S stack -t stack -s /bin/bash
sleep 1
# set a reasonable statusbar
if [ -z "$SCREEN_HARDSTATUS" ]; then
SCREEN_HARDSTATUS='%{= .} %-Lw%{= .}%> %n%f %t*%{= .}%+Lw%< %-=%{g}(%{d}%H/%l%{g})'
fi
screen -r stack -X hardstatus alwayslastline "$SCREEN_HARDSTATUS" SERVICE_TIMEOUT=${SERVICE_TIMEOUT:-60} # Specify which services to launch. These generally correspond to
# screen tabs. If you like to add other services that are not enabled
# by default you can append them in your ENABLED_SERVICES variable in
# your localrc. For example for swift you can just add this in your
# localrc to add it with the other services:
# ENABLED_SERVICES="$ENABLED_SERVICES,swift"
ENABLED_SERVICES=g-api,g-reg,key,n-api,n-crt,n-obj,n-cpu,n-net,n-cond,n-vol,n-sch,n-novnc,n-xvnc,n-cauth,horizon,mysql,rabbit # is_service_enabled() checks if the service(s) specified as arguments are
# enabled by the user in **ENABLED_SERVICES**.
#
# If there are multiple services specified as arguments the test performs a
# boolean OR or if any of the services specified on the command line
# return true.
#
# There is a special cases for some 'catch-all' services::
# **nova** returns true if any service enabled start with **n-**
# **glance** returns true if any service enabled start with **g-**
# **neutron** returns true if any service enabled start with **q-**
function is_service_enabled() {
services=$@
for service in ${services}; do
[[ ,${ENABLED_SERVICES}, =~ ,${service}, ]] && return 0
[[ ${service} == "nova" && ${ENABLED_SERVICES} =~ "n-" ]] && return 0
[[ ${service} == "glance" && ${ENABLED_SERVICES} =~ "g-" ]] && return 0
[[ ${service} == "neutron" && ${ENABLED_SERVICES} =~ "q-" ]] && return 0
done
return 1
} DEST=${DEST:-/opt/stack} # Set the destination directories for openstack projects
NOVA_DIR=$DEST/nova
HORIZON_DIR=$DEST/horizon
GLANCE_DIR=$DEST/glance
GLANCECLIENT_DIR=$DEST/python-glanceclient
KEYSTONE_DIR=$DEST/keystone
NOVACLIENT_DIR=$DEST/python-novaclient
KEYSTONECLIENT_DIR=$DEST/python-keystoneclient
OPENSTACKCLIENT_DIR=$DEST/python-openstackclient
NOVNC_DIR=$DEST/noVNC
SWIFT_DIR=$DEST/swift
SWIFT3_DIR=$DEST/swift3
NEUTRON_DIR=$DEST/neutron
NEUTRON_CLIENT_DIR=$DEST/python-neutronclient
MELANGE_DIR=$DEST/melange
MELANGECLIENT_DIR=$DEST/python-melangeclient # By default the location of swift drives and objects is located inside
# the swift source directory. SWIFT_DATA_DIR variable allow you to redefine
# this.
SWIFT_DATA_DIR=${SWIFT_DATA_DIR:-${DEST}/data/swift} # We are going to have the configuration files inside the source
# directory, change SWIFT_CONFIG_DIR if you want to adjust that.
SWIFT_CONFIG_DIR=${SWIFT_CONFIG_DIR:-/etc/swift} # devstack will create a loop-back disk formatted as XFS to store the
# swift data. By default the disk size is 1 gigabyte. The variable
# SWIFT_LOOPBACK_DISK_SIZE specified in bytes allow you to change
# that.
SWIFT_LOOPBACK_DISK_SIZE=${SWIFT_LOOPBACK_DISK_SIZE:-1000000} # The ring uses a configurable number of bits from a path聮s MD5 hash as
# a partition index that designates a device. The number of bits kept
# from the hash is known as the partition power, and 2 to the partition
# power indicates the partition count. Partitioning the full MD5 hash
# ring allows other parts of the cluster to work in batches of items at
# once which ends up either more efficient or at least less complex than
# working with each item separately or the entire cluster all at once.
# By default we define 9 for the partition count (which mean 512).
SWIFT_PARTITION_POWER_SIZE=${SWIFT_PARTITION_POWER_SIZE:-9} # This variable allows you to configure how many replicas you want to be
# configured for your Swift cluster. By default the three replicas would need a
# bit of IO and Memory on a VM you may want to lower that to 1 if you want to do
# only some quick testing.
SWIFT_REPLICAS=${SWIFT_REPLICAS:-3} if is_service_enabled swift; then
# If we are using swift, we can default the s3 port to swift instead
# of nova-objectstore
S3_SERVICE_PORT=${S3_SERVICE_PORT:-8080}
fi # Set default port for nova-objectstore
S3_SERVICE_PORT=${S3_SERVICE_PORT:-3333} # Set the tenant for service accounts in Keystone
SERVICE_TENANT_NAME=${SERVICE_TENANT_NAME:-service} HOST_IP_IFACE=${HOST_IP_IFACE:-eth0}
# Use the eth0 IP unless an explicit is set by ``HOST_IP`` environment variable
if [ -z "$HOST_IP" -o "$HOST_IP" == "dhcp" ]; then
HOST_IP=`LC_ALL=C /sbin/ifconfig ${HOST_IP_IFACE} | grep -m 1 'inet addr:'| cut -d: -f2 | awk '{print $1}'`
if [ "$HOST_IP" = "" ]; then
echo "Could not determine host ip address."
echo "Either localrc specified dhcp on ${HOST_IP_IFACE} or defaulted to eth0"
exit 1
fi
fi SERVICE_HOST=${SERVICE_HOST:-$HOST_IP} # Glance connection info. Note the port must be specified.
GLANCE_HOSTPORT=${GLANCE_HOSTPORT:-$SERVICE_HOST:9292} # Set Keystone interface configuration
KEYSTONE_API_PORT=${KEYSTONE_API_PORT:-5000}
KEYSTONE_AUTH_HOST=${KEYSTONE_AUTH_HOST:-$SERVICE_HOST}
KEYSTONE_AUTH_PORT=${KEYSTONE_AUTH_PORT:-35357}
KEYSTONE_AUTH_PROTOCOL=${KEYSTONE_AUTH_PROTOCOL:-http}
KEYSTONE_SERVICE_HOST=${KEYSTONE_SERVICE_HOST:-$SERVICE_HOST}
KEYSTONE_SERVICE_PORT=${KEYSTONE_SERVICE_PORT:-5000}
KEYSTONE_SERVICE_PROTOCOL=${KEYSTONE_SERVICE_PROTOCOL:-http} # Our screenrc file builder
function screen_rc {
SCREENRC=$TOP_DIR/stack-screenrc
if [[ ! -e $SCREENRC ]]; then
# Name the screen session
echo "sessionname stack" > $SCREENRC
# Set a reasonable statusbar
echo "hardstatus alwayslastline '$SCREEN_HARDSTATUS'" >> $SCREENRC
echo "screen -t stack bash" >> $SCREENRC
fi
# If this service doesn't already exist in the screenrc file
if ! grep $1 $SCREENRC 2>&1 > /dev/null; then
NL=`echo -ne '\015'`
echo "screen -t $1 bash" >> $SCREENRC
echo "stuff \"$2$NL\"" >> $SCREENRC
fi
} # Our screen helper to launch a service in a hidden named screen
function screen_it {
NL=`echo -ne '\015'`
if is_service_enabled $1; then
echo Starting $1 ...
# Append the service to the screen rc file
screen_rc "$1" "$2" screen -S stack -X screen -t $1
# sleep to allow bash to be ready to be send the command - we are
# creating a new window in screen and then sends characters, so if
# bash isn't running by the time we send the command, nothing happens
sleep 1.5 if [[ -n ${SCREEN_LOGDIR} ]]; then
screen -S stack -p $1 -X logfile ${SCREEN_LOGDIR}/screen-${1}.${CURRENT_LOG_TIME}.log
screen -S stack -p $1 -X log on
ln -sf ${SCREEN_LOGDIR}/screen-${1}.${CURRENT_LOG_TIME}.log ${SCREEN_LOGDIR}/screen-${1}.log
fi
screen -S stack -p $1 -X stuff "$2$NL"
fi
} GLANCE_CONF_DIR=/etc/glance # launch the glance registry service
if is_service_enabled g-reg; then
screen_it g-reg "cd $GLANCE_DIR; /usr/local/bin/glance-registry --config-file=$GLANCE_CONF_DIR/glance-registry.conf"
fi # launch the glance api and wait for it to answer before continuing
if is_service_enabled g-api; then
screen_it g-api "cd $GLANCE_DIR; /usr/local/bin/glance-api --config-file=$GLANCE_CONF_DIR/glance-api.conf"
echo "Waiting for g-api ($GLANCE_HOSTPORT) to start..."
if ! timeout $SERVICE_TIMEOUT sh -c "while ! http_proxy= wget -q -O- http://$GLANCE_HOSTPORT; do sleep 1; done"; then
echo "g-api did not start"
exit 1
fi
fi if is_service_enabled key; then KEYSTONE_CONF_DIR=${KEYSTONE_CONF_DIR:-/etc/keystone}
KEYSTONE_CONF=$KEYSTONE_CONF_DIR/keystone.conf
KEYSTONE_CATALOG=$KEYSTONE_CONF_DIR/default_catalog.templates # Set up logging
LOGGING_ROOT="devel"
if [ "$SYSLOG" != "False" ]; then
LOGGING_ROOT="$LOGGING_ROOT,production"
fi
KEYSTONE_LOG_CONFIG="--log-config $KEYSTONE_CONF_DIR/logging.conf" # launch keystone and wait for it to answer before continuing
screen_it key "cd $KEYSTONE_DIR && $KEYSTONE_DIR/bin/keystone-all --config-file $KEYSTONE_CONF $KEYSTONE_LOG_CONFIG -d --debug"
echo "Waiting for keystone to start..."
if ! timeout $SERVICE_TIMEOUT sh -c "while ! http_proxy= wget -O- $KEYSTONE_AUTH_PROTOCOL://$SERVICE_HOST:$KEYSTONE_API_PORT/v2.0/ 2>&1 | grep -q '200 OK'; do sleep 1; done"; then
echo "keystone did not start"
exit 1
fi fi # launch the nova-api and wait for it to answer before continuing
if is_service_enabled n-api; then
screen_it n-api "cd $NOVA_DIR && /usr/local/bin/nova-api"
echo "Waiting for nova-api to start..."
if ! timeout $SERVICE_TIMEOUT sh -c "while ! http_proxy= wget -q -O- http://127.0.0.1:8774; do sleep 1; done"; then
echo "nova-api did not start"
exit 1
fi
fi # Launching nova-compute should be as simple as running ``nova-compute`` but
# have to do a little more than that in our script. Since we add the group
# ``libvirtd`` to our user in this script, when nova-compute is run it is
# within the context of our original shell (so our groups won't be updated).
# Use 'sg' to execute nova-compute as a member of the libvirtd group.
# We don't check for is_service_enable as screen_it does it for us
screen_it n-cpu "cd $NOVA_DIR && sg libvirtd /usr/local/bin/nova-compute"
screen_it n-crt "cd $NOVA_DIR && /usr/local/bin/nova-cert"
screen_it n-vol "cd $NOVA_DIR && /usr/local/bin/nova-volume"
screen_it n-net "cd $NOVA_DIR && /usr/local/bin/nova-network"
screen_it n-cond "cd $NOVA_DIR && /usr/local/bin/nova-conductor"
screen_it n-sch "cd $NOVA_DIR && /usr/local/bin/nova-scheduler"
screen_it n-novnc "cd $NOVNC_DIR && /usr/local/bin/nova-novncproxy --config-file $NOVA_CONF_DIR/$NOVA_CONF --web ."
screen_it n-xvnc "cd $NOVA_DIR && /usr/local/bin/nova-xvpvncproxy --config-file $NOVA_CONF_DIR/$NOVA_CONF"
screen_it n-cauth "cd $NOVA_DIR && /usr/local/bin/nova-consoleauth"
screen_it horizon "cd $HORIZON_DIR && sudo tail -f /var/log/$APACHE_NAME/horizon_error.log"
screen_it swift "cd $SWIFT_DIR && $SWIFT_DIR/bin/swift-proxy-server ${SWIFT_CONFIG_DIR}/proxy-server.conf -v" # Starting the nova-objectstore only if swift service is not enabled.
# Swift will act as s3 objectstore.
is_service_enabled swift || \
screen_it n-obj "cd $NOVA_DIR && /usr/local/bin/nova-objectstore"
用pdb调试OpenStack Havana的更多相关文章
- CentOS6.6部署OpenStack Havana(Nova-Network版)
CentOS6.4部署OpenStack Havana(Nova-Network版) 一 基本设备介绍 测试环境 CentOS6.4 x64 OpenStack 服务 介绍 计算 (Compute) ...
- [转]Openstack Havana Dashboard测试和使用
转贴一篇陈沙克老师的文章:http://www.chenshake.com/openstack-havana-dashboard-to-test-and-use/ Openstack Havana D ...
- 使用pdb调试python
python pdb调试 python -m pdb myscript.py #注意这会重启myscript.py,这样启动的话,代码每一行都是一个节点 也可以在程序中这么设置断点: import p ...
- OpenStack Havana 部署在Ubuntu 12.04 Server 【OVS+GRE】(三)——计算节点的安装
序:OpenStack Havana 部署在Ubuntu 12.04 Server [OVS+GRE] 计算节点: 1.准备结点 安装好ubuntu 12.04 Server 64bits后,进入ro ...
- OpenStack Havana 部署在Ubuntu 12.04 Server 【OVS+GRE】(二)——网络节点的安装
序:OpenStack Havana 部署在Ubuntu 12.04 Server [OVS+GRE] 网络节点: 1.安装前更新系统 安装好ubuntu 12.04 Server 64bits后,进 ...
- OpenStack Havana 部署在Ubuntu 12.04 Server 【OVS+GRE】(一)——控制节点的安装
序:OpenStack Havana 部署在Ubuntu 12.04 Server [OVS+GRE] 控制节点: 1.准备Ubuntu 安装好Ubuntu12.04 server 64bits后 ...
- OpenStack Havana 部署在Ubuntu 12.04 Server 【OVS+GRE】——序
OpenStack Havana 部署在Ubuntu 12.04 Server [OVS+GRE](一)——控制节点的安装 OpenStack Havana 部署在Ubuntu 12.04 Serve ...
- python pdb调试以及sublime3快捷键设置
python pdb调试以及sublime3快捷键设置 pdb调试 如果对gdb比较熟悉的话,pdb就很容易上手.以一个demo快速了解常用的调试命令. def test(a): while True ...
- PDB调试模块
这里主要是一些对于调试常用的命令:1.直接通过命令端输入进行调试 以pdb调试模式运行(主要用这个) python3 -m pdb file.py 2.在代码中导入pdb模块 import pdb 功 ...
随机推荐
- eclipse 的alt shift a,r 这个快捷键怎么操作 怎么按 eclipse 快捷键 逗号 什么意思
韩梦飞沙 韩亚飞 313134555@qq.com yue31313 han_meng_fei_sha eclipse 的alt shift a,r 这个快捷键怎么操作 怎么按 eclipse ...
- 「LOJ6482」LJJ爱数数
「LOJ6482」LJJ爱数数 解题思路 : 打表发现两个数 \(a, b\) 合法的充要条件是(我不管,我就是打表过的): \[ a + b = \text{gcd}(a, b)^2 \] 设 \( ...
- 51nod1515 明辨是非 并查集 + set
一开始想的时候,好像两个并查集就可以做......然后突然懂了什么.... 相同的并查集没有问题,不同的就不能并查集了,暴力的来个set就行了..... 合并的时候启发式合并即可做到$O(n \log ...
- [CODECHEF]EASYEX
题意:有一个$k$面的骰子,上面的数字为$1\cdots k$,现在要丢$n$次骰子,设$n$次中有$a_i$次扔到数字$i$,给定$l,f$,求$\prod\limits_{i=1}^la_i^f$ ...
- ZOJ 3213 Beautiful Meadow 简单路径 插头DP
简单路径的题目,其实就是在状态后面多记了有多少个独立插头. 分类讨论独立插头: 1.只存在上插头或者左插头,可以选择作为独立插头. 2.都不存在上插头和左插头,选择作为独立插头的同时要标号为新的连通块 ...
- 判断一个js对象是不是数组
//今天突然想到一个问题,如何判断一个对象是不是数组 var arr = [0, 1, 2]; console.log(arr) //object, 显然不行 //查阅了很多资料,发现几个挺不错的方法 ...
- 解决Could not open input file: think问题
前几天做项目的时候,突然想用命令行创建TP5的控制器以及模型等 输入命令: >php think make:controller admin/Abc 报错如下: Could not open i ...
- 在Mac系统上安装Tomcat
到 apache官方主页 下载 Mac 版本的完整 .gz文件包.解压拷贝到 /Library目录下. 1.Mac中 Finder打开 Library的方法 新建 Finder窗口 按下 sh ...
- python使用游标访问数据
游标是一种数据访问对象,可用于在表中迭代一组行或者向表中插入新行.游标有三种形式:搜索.插入或更新.游标通常用于读取现有几何和写入新几何. 每种类型的游标均由对应的 ArcPy 函数(SearchCu ...
- 周赛 POJ 3934 Queue
Description Linda is a teacher in ACM kindergarten. She is in charge of n kids. Because the dinning ...