异常自动跳入 pdb

又是 OpenStack 社区发布新版本的时候,又是一次各种新包发布的季节,又是 CI 奔溃的节奏。

CI 好不容易把 devstack 安装上了,最后跑 tempest 测试时丢出这么一堆东西:

WARNING:test command found but not installed in testenv
  cmd: /bin/bash
  env: /opt/stack/new/tempest/.tox/testr-full
Maybe forgot to specify a dependency?
Traceback (most recent call last):
  File "setup.py", line 22, in <module>
    pbr=True)
  File "/usr/lib/python2.7/distutils/core.py", line 137, in setup
    ok = dist.parse_command_line()
  File "/opt/stack/new/tempest/.tox/testr-full/local/lib/python2.7/site-packages/setuptools/dist.py", line 250, in parse_command_line
    result = _Distribution.parse_command_line(self)
  File "/usr/lib/python2.7/distutils/dist.py", line 467, in parse_command_line
    args = self._parse_command_opts(parser, args)
  File "/opt/stack/new/tempest/.tox/testr-full/local/lib/python2.7/site-packages/setuptools/dist.py", line 533, in _parse_command_opts
    nargs = _Distribution._parse_command_opts(self, parser, args)
  File "/usr/lib/python2.7/distutils/dist.py", line 523, in _parse_command_opts
    cmd_class = self.get_command_class(command)
  File "/opt/stack/new/tempest/.tox/testr-full/local/lib/python2.7/site-packages/setuptools/dist.py", line 362, in get_command_class
    ep.require(installer=self.fetch_build_egg)
  File "/opt/stack/new/tempest/.tox/testr-full/local/lib/python2.7/site-packages/pkg_resources.py", line 2041, in require
    working_set.resolve(self.dist.requires(self.extras),env,installer)))
  File "/opt/stack/new/tempest/.tox/testr-full/local/lib/python2.7/site-packages/pkg_resources.py", line 576, in resolve
    raise VersionConflict(dist,req) # XXX put more info here
pkg_resources.VersionConflict: (pbr 0.6 (/usr/local/lib/python2.7/dist-packages), Requirement.parse('pbr>=0.11'))

看了半天才明白,意思是当前系统安装了 pbr 0.6 版本,但是需要 pbr > 0.11,到底谁要求 0.6, 谁又要求 0.11?瞎猜肯定不是办法,老规矩:重现,定位,调试。

连到 CI 的虚拟机上,敲入:

cd /opt/stack/new/tempest
ipython --pdb --c="%run setup.py testr"

在抛异常的地方直接进去 ipdb,愉快的上下文调试,setuptools 的日志比较恶心,根据异常根本没法解决问题,一定要到上一层调用(File "/opt/stack/new/tempest/.tox/testr-full/local/lib/python2.7/site-packages/pkg_resources.py", line 2041, in require),看下 self.dist ,发现是 testrepository 的版本又默默的升了。原因找到,显示指定一下版本号,走人。

发表评论

电子邮件地址不会被公开。 必填项已用*标注