如何使用 pdb 调试 cinder-api 进程 (基于Openstack Queens)

cinder-api 与 nova-api,glance-api 不同,它并不是一个单独运行的进程,而是基于apache2发布的服务。因此无法简单的通过service cinder-api stop 然后手动运行 /usr/bin/python /usr/bin/cinder-api --config-file=/etc/cinder/cinder.conf --log-file=/var/log/cinder/cinder-api.log 来调试。

可以通过如下方法进行调试:

  1. 先查看跟cinder 有关的进程
    root@loadbalancer01:~# ps -ef |grep cinder
    cinder 5687 21037 0 06:43 ? 00:00:00 (wsgi:cinder-wsgi -k start
    cinder 5688 21037 0 06:43 ? 00:00:00 (wsgi:cinder-wsgi -k start
    cinder 5689 21037 0 06:43 ? 00:00:00 (wsgi:cinder-wsgi -k start
    cinder 5690 21037 0 06:43 ? 00:00:00 (wsgi:cinder-wsgi -k start
    cinder 5691 21037 0 06:43 ? 00:00:00 (wsgi:cinder-wsgi -k start
    cinder 5719 21037 0 06:43 ? 00:00:00 (wsgi:osapi_volum -k start
    cinder 5746 21037 0 06:43 ? 00:00:00 (wsgi:osapi_volum -k start
    cinder 5748 21037 0 06:43 ? 00:00:00 (wsgi:osapi_volum -k start
    cinder 5749 21037 0 06:43 ? 00:00:00 (wsgi:osapi_volum -k start
    root 6914 30165 0 06:51 pts/3 00:00:00 grep --color=auto cinder
    cinder 21913 1 0 Feb11 ? 00:06:35 /usr/bin/python /usr/bin/cinder-scheduler --config-file=/etc/cinder/cinder.conf --log-file=/var/log/cinder/cinder-scheduler.log
    cinder 21958 1 1 Feb11 ? 00:52:40 /usr/bin/python /usr/bin/cinder-volume --config-file=/etc/cinder/cinder.conf --log-file=/var/log/cinder/cinder-volume.log
    cinder 21969 21958 2 Feb11 ? 01:35:28 /usr/bin/python /usr/bin/cinder-volume --config-file=/etc/cinder/cinder.conf --log-file=/var/log/cinder/cinder-volume.log
    cinder 21970 21958 2 Feb11 ? 01:35:26 /usr/bin/python /usr/bin/cinder-volume --config-file=/etc/cinder/cinder.conf --log-file=/var/log/cinder/cinder-volume.log

其中 cinder-wsgi 和 osapi_volum 都是由 apache2 启动的。

  1. 运行apache2ctl -S,看到输出中有两个 cinder相关的配置,一个是 /etc/apache2/conf-enabled/cinder-wsgi.conf, 另一个是 (/etc/apache2/sites-enabled/cinder.conf:
    root@loadbalancer01:~# apache2ctl -S
    AH00558: apache2: Could not reliably determine the server’s fully qualified domain name, using 192.168.111.160. Set the ‘ServerName’ directive globally to suppress this message
    VirtualHost configuration:
    。。。
    192.168.111.160:8776 loadbalancer01 (/etc/apache2/sites-enabled/cinder.conf:4)
    。。。
    *:8776 192.168.111.160 (/etc/apache2/conf-enabled/cinder-wsgi.conf:4)
    。。。
    ServerRoot: “/etc/apache2”
    。。。
  2. 用 a2dissite 禁用 cinder
    //disable apache site
    a2dissite cinder
    //reload apache service
    service apache2 reload
  3. 用 a2disconf 禁用 cinder-wsgi
    //disable apache conf
    a2disconf cinder-wsgi
    //reload apache service
    service apache2 reload

此时查看ps -ef |grep cinder,与cinder有关的apache的进程已经全部停掉。

  1. 修改代码,加断点
    例如 在 /usr/lib/python2.7/dist-packages/cinder/volume/api.py

  2. 手动启动 cinder-api 进程,注意要指定 host 和 port。在我的环境里,我有一个haproxy 一直在监听 192.168.112.160(haproxy的vip):8776,如果不手动指定host和port,会出现端口已经使用的错误
    /usr/bin/python /usr/bin/cinder-wsgi --host 192.168.111.160(本机的ip) --port 8776

看到输出信息:


STARTING test server cinder.wsgi.wsgi.initialize_application
Available at http://loadbalancer01:8776/
DANGER! For testing only, do not use in production


  1. 可以开始调试了。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值