Tempest里create_test_server方法的调用问题

作者: LiHui 分类: Tempest 发布时间: 2016-12-19 20:27

昨天在测试一个简单nova接口的时候,只要是有继承base.py里的BaseComputeTest类,create_test_server函数这个case就会被默认执行,而假如测试的OpenStack环境不支持不带网卡创建虚拟机,就会报错,还是这个函数

@classmethod
def create_test_server(cls, **kwargs):
"""Wrapper utility that returns a test server."""
name = data_utils.rand_name(cls.__name__ + "-instance")
if 'name' in kwargs:
name = kwargs.pop('name')
flavor = kwargs.get('flavor', cls.flavor_ref)
image_id = kwargs.get('image_id', cls.image_ref)

resp, body = cls.servers_client.create_server(
name, image_id, flavor, **kwargs)

# handle the case of multiple servers
servers = [body]
if 'min_count' in kwargs or 'max_count' in kwargs:
# Get servers created which name match with name param.
r, b = cls.servers_client.list_servers()
servers = [s for s in b['servers'] if s['name'].startswith(name)]

if 'wait_until' in kwargs:
for server in servers:
try:
cls.servers_client.wait_for_server_status(
server['id'], kwargs['wait_until'])
except Exception as ex:
if ('preserve_server_on_error' not in kwargs
or kwargs['preserve_server_on_error'] is False):
for server in servers:
try:
cls.servers_client.delete_server(server['id'])
except Exception:
pass
raise ex

cls.servers.extend(servers)

return resp, body

当然,寻找test关键字来执行case这是nose的方式,除非不用nose,否则肯定会遇到这个奇怪的问题,带着这个问题google了下,果然也发现有人在社区提了这个bug

https://bugs.launchpad.net/tempest/+bug/1255922

这人说的问题跟我一样,然后还自己提了一个patch来review一下

https://review.openstack.org/#/c/58984/

可他居然是直接将函数名create_test_server修改成了create_vm,去掉了test,而因为后面自带还有一个create_server,所以改成这么土的一个名字,结果当然社区的人没同意,Code-Review直接-1(捂脸图)

然后bugs里给这人回复,表示这是nose的问题,并不是我tempest的问题(再次捂脸)

Zhikun Liu (zhikunliu) wrote on 2013-12-05: #3
This is a nose issue.

Changed in tempest:
status: In Progress → Invalid

最后可能怕这人想不开,给了他一个搞笑的办法,你不想执行它,直接匹配,只执行test开始的case

Zhikun Liu (zhikunliu) wrote on 2013-12-05: #4
using '--match' could fix this problem.

nosetests -sv --match '^test' tempest/api/compute/admin/test_hosts.py

看到这里,竟无言以对了,这样不知道误杀多少,社区人估计也是故意搞笑的

最好的方法就是换一个测试环境,支持无网卡创建虚拟机的,一劳永逸

$ nosetests -sv api/compute/flavors/test_flavors.py
tempest.api.compute.flavors.test_flavors.FlavorsTestJSON.create_test_server ... ok
tempest.api.compute.flavors.test_flavors.FlavorsTestJSON.test_get_flavor ... ok
tempest.api.compute.flavors.test_flavors.FlavorsTestJSON.test_list_flavors ... ok
tempest.api.compute.flavors.test_flavors.FlavorsTestJSON.test_list_flavors_detailed_filter_by_min_disk ... ok
tempest.api.compute.flavors.test_flavors.FlavorsTestJSON.test_list_flavors_detailed_filter_by_min_ram ... ok
tempest.api.compute.flavors.test_flavors.FlavorsTestJSON.test_list_flavors_detailed_limit_results ... ok
tempest.api.compute.flavors.test_flavors.FlavorsTestJSON.test_list_flavors_detailed_using_marker ... ok
tempest.api.compute.flavors.test_flavors.FlavorsTestJSON.test_list_flavors_filter_by_min_disk ... ok
tempest.api.compute.flavors.test_flavors.FlavorsTestJSON.test_list_flavors_filter_by_min_ram ... ok
tempest.api.compute.flavors.test_flavors.FlavorsTestJSON.test_list_flavors_limit_results ... ok
tempest.api.compute.flavors.test_flavors.FlavorsTestJSON.test_list_flavors_using_marker ... ok
tempest.api.compute.flavors.test_flavors.FlavorsTestJSON.test_list_flavors_with_detail ... ok

----------------------------------------------------------------------
Ran 12 tests in 15.970s

OK

纯属恶搞

浙ICP备16024533号

浙公网安备 33010802007459号