OpenStack Nova 代码调试
作者:互联网
OpenStack Nova 代码调试
1 部署 Kolla-ansible
-
1 在
/etc/kolla/globals.yaml
开启kolla_dev_mode: "yes"
-
2
kolla_dev_mode
为yes时,所有openstack
组件都会下载源码并挂载; -
3 若只调
nova
,可以修改kolla-ansible/ansible/roles/nova/default/all.yml
中nova_dev_node: "yes"
-
4 抚州环境
git clone https://opendev/openstack/nova
比较慢,可以选择自行上传脚本,并注释到部署代码中clone.yml
2 查看映射是否生效
- 部署
nova
的时候,会将nova
的源码下载在/opt/stack
,并将源码挂载到nova
容器中,如下:
{
"Type": "bind",
"Source": "/opt/stack/nova/nova",
"Destination": "/var/lib/kolla/venv/lib/python3.6/site-packages/nova",
"Mode": "rw",
"RW": true,
"Propagation": "rprivate"
},
3 成功后的现象
修改/opt/stack下nova源码,docker restart nova_compute即可生效。
4 pdb调试
-
4.1 首先需要在容器中安装remote_pdb
$ docker exec -it -u root nova_compute pip install remote_pdb
-
4.2 在程序中加断点
def index(self, req):
from remote_pdb import set_trace
set_trace() # 加入断点
# from remote_pdb import RemotePdb
# RemotePdb('127.0.0.1', 4444).set_trace()
"""Returns a list of server names and ids for a given user."""
context = req.environ['nova.context']
context.can(server_policies.SERVERS % 'index')
try:
servers = self._get_servers(req, is_detail=False)
except exception.Invalid as err:
raise exc.HTTPBadRequest(explanation=err.format_message())
return servers
-
4.3 重启docker 容器
# 此处为了查询 telnet 连接的端口号
$ docker restart nova_compute
-
4.4 telnet到日志中输出的地址,执行调试命令
telnet host:port # telnet 127.0.0.1:4444
标签:Nova,remote,nova,源码,telnet,调试,OpenStack,pdb,kolla 来源: https://www.cnblogs.com/FutureHolmes/p/15329931.html