OpenStack unit tests 环境调试

大多数情况下修改OpenSTack community 的各个project source code 需要提交对应的unit test, 但是由于dependency的环境版本变化,unit test会失败,本文简单介绍如何运行/project/run_tests.sh.

以OpenStack/Neutron 为例

使用虚拟环境安装包

# /opt/stack/neutron/requirements.txt 是neutron project下依赖的安装包

tools/with_venv.sh pip install -r /opt/stack/neutron/requirements.txt 

# /opt/stack/neutron/test_requirements.txt 是neutron project下依赖的测试安装包

tools/with_venv.sh pip install -r /opt/stack/neutron/test_requirements.txt

不使用虚拟环境

pip install --upgrade -r requirements.txt
pip install --upgrade -r  test-requirements.txt


升级

tools/with_venv.sh pip install --upgrade /opt/stack/neutron/requirements.txt 
tools/with_venv.sh pip install --upgrade /opt/stack/neutron/test_requirements.txt

显示结果 :

Successfully installed amqplib jsonrpclib python-neutronclient alembic six Mako
Cleaning up...

测试project下所有的test cases

root@ubuntu:/opt/stack/heat#./run_tests.sh
....

测试 /heat/tests/test_instance.py

root@ubuntu:/opt/stack/heat# ./run_tests.sh heat.tests.test_instance

结果输出包含所有“test_instance”关键字

Ran 106 (-1407) tests in 2.115s (-53.826s)
PASSED (id=12)
Slowest Tests
Test id                                                                                                   Runtime (s)
--------------------------------------------------------------------------------------------------------  -----------
heat.tests.test_instance_group_update_policy.InstanceGroupTest.test_instance_group_update                 0.340
heat.tests.test_instance_group_update_policy.InstanceGroupTest.test_instance_group_update_policy_removed  0.318
heat.tests.test_instance.InstancesTest.test_build_nics                                                    0.274
heat.tests.test_instance_group.InstanceGroupTest.test_handle_update_size                                  0.255
heat.tests.test_instance.InstancesTest.test_instance_create_duplicate_image_name_err                      0.236
heat.tests.test_instance_group.InstanceGroupTest.test_update_error                                        0.149
heat.tests.test_instance.InstancesTest.test_instance_update_instance_type_failed                          0.117
heat.tests.test_instance_group.InstanceGroupTest.test_update_fail_badkey                                  0.115
heat.tests.test_instance_group.InstanceGroupTest.test_update_fail_badprop                                 0.111
heat.tests.test_instance_group.InstanceGroupTest.test_create_error                                        0.086

测试/heat/tests/test_instance.py中的InstancesTest类

root@ubuntu:/opt/stack/heat# ./run_tests.sh heat.tests.test_instance.InstancesTest
Ran 68 (+15) tests in 1.305s (-0.802s)
PASSED (id=13)
Slowest Tests
Test id                                                                           Runtime (s)
--------------------------------------------------------------------------------  -----------
heat.tests.test_instance.InstancesTest.test_instance_create                       0.266
heat.tests.test_instance.InstancesTest.test_build_nics                            0.256
heat.tests.test_instance.InstancesTest.test_instance_update_instance_type_failed  0.140
heat.tests.test_instance.InstancesTest.test_instance_create_unexpected_status     0.138
heat.tests.test_instance.InstancesTest.test_instance_status_verify_resize         0.110
heat.tests.test_instance.InstancesTest.test_instance_status_password              0.086
heat.tests.test_instance.InstancesTest.test_instance_status_rescue                0.085
heat.tests.test_instance.InstancesTest.test_instance_status_resize                0.081
heat.tests.test_instance.InstancesTest.test_instance_resume_volumes_step          0.075
heat.tests.test_instance.InstancesTest.test_instance_suspend_volumes_step         0.074

测试/heat/tests/test_instance.py中的InstancesTest类的test_build_nics方法

Ran 2 (-32) tests in 0.191s (-1.106s)
PASSED (id=14)
Slowest Tests
Test id                                                 Runtime (s)
------------------------------------------------------  -----------
heat.tests.test_instance.InstancesTest.test_build_nics  0.188

错误解决

1.AttributeError: 'module' object has no attribute 'DeprecatedOpt'

======================================================================
FAIL: unittest.loader.ModuleImportFailure.neutron.tests.unit.test_security_groups_rpc
unittest.loader.ModuleImportFailure.neutron.tests.unit.test_security_groups_rpc
----------------------------------------------------------------------
_StringException: ImportError: Failed to import test module: neutron.tests.unit.test_security_groups_rpc
Traceback (most recent call last):
  File "/usr/lib/python2.7/unittest/loader.py", line 252, in _find_tests
    module = self._get_module_from_name(name)
  File "/usr/lib/python2.7/unittest/loader.py", line 230, in _get_module_from_name
    __import__(name)
  File "/opt/stack/neutron/neutron/tests/unit/test_security_groups_rpc.py", line 29, in <module>
    from neutron import context
  File "/opt/stack/neutron/neutron/context.py", line 24, in <module>
    from neutron.db import api as db_api
  File "/opt/stack/neutron/neutron/db/api.py", line 22, in <module>
    from neutron.db import model_base
  File "/opt/stack/neutron/neutron/db/model_base.py", line 19, in <module>
    from neutron.openstack.common.db.sqlalchemy import models
  File "/opt/stack/neutron/neutron/openstack/common/db/sqlalchemy/models.py", line 29, in <module>
    from neutron.openstack.common.db.sqlalchemy.session import get_session
  File "/opt/stack/neutron/neutron/openstack/common/db/sqlalchemy/session.py", line 283, in <module>
    deprecated_opts=[cfg.DeprecatedOpt('sql_connection',
AttributeError: 'module' object has no attribute 'DeprecatedOpt'

解决方法: (来自https://bugs.launchpad.net/tripleo/+bug/1194807)

cd /usr/local/

lib/python2.7/dist-packages/
rm -rf oslo
pip install http://tarballs.openstack.org/oslo.config/oslo.config-1.2.0a2.tar.gz#egg=oslo.config-1.2.0a2

2. No module named webtest

解决方法 :

root@ubuntu:/opt/stack/neutron# pip install webtest
Downloading/unpacking webtest
  Downloading WebTest-2.0.7.zip (81kB): 81kB downloaded
  Running setup.py egg_info for package webtest
    
    no previously-included directories found matching 'docs/_build'
    warning: no previously-included files matching '*.pyc' found anywhere in distribution
    warning: no previously-included files matching '__pycache__' found anywhere in distribution
Requirement already satisfied (use --upgrade to upgrade): six in /usr/local/lib/python2.7/dist-packages (from webtest)
Requirement already satisfied (use --upgrade to upgrade): WebOb>=1.2 in /usr/local/lib/python2.7/dist-packages (from webtest)
Downloading/unpacking waitress>=0.8.5 (from webtest)
  Downloading waitress-0.8.7.tar.gz (115kB): 115kB downloaded
  Running setup.py egg_info for package waitress
    
Downloading/unpacking beautifulsoup4 (from webtest)
  Downloading beautifulsoup4-4.3.1.tar.gz (142kB): 142kB downloaded
  Running setup.py egg_info for package beautifulsoup4
    
Requirement already satisfied (use --upgrade to upgrade): setuptools in /usr/local/lib/python2.7/dist-packages (from waitress>=0.8.5->webtest)
Installing collected packages: webtest, waitress, beautifulsoup4
  Running setup.py install for webtest
    
    no previously-included directories found matching 'docs/_build'
    warning: no previously-included files matching '*.pyc' found anywhere in distribution
    warning: no previously-included files matching '__pycache__' found anywhere in distribution
  Running setup.py install for waitress
    
    Installing waitress-serve script to /usr/local/bin
  Running setup.py install for beautifulsoup4
    
Successfully installed webtest waitress beautifulsoup4
Cleaning up...

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值