安装
$ git clone https://github.com/openstack/tempest/ # 下载源码
$ pip install tempest # 安装tempest项目
如果pip install 报错,比如某个Python包版本冲突或者之类的,可以先执行下
$ pip install -r tempest/requirements.txt # 安装Python依赖包
然后再执行
$ pip install tempest
初始化
安装完毕要初始化配置,需要执行如下命令
$ tempest init my-tempest-env-01 # 初始化测试环境目录
此步骤相当于执行如下命令
$ mkdir my-tempest-env-01 && cd my-tempest-env-01 && tempest init
修改配置
初始化测试环境目录过程中,会在测试环境目录my-tempest-env-01下自动生成如下子目录
$ etc logs tempest_lock
其中etc目录下生成了tempest.conf.sample示例配置文件,我们修改好这个文件并重命名为tempest.conf,即可执行tempest测试,
下面是我修改完毕的配置文件和初始化完毕的示例配置文件的diff结果:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 |
root@control-1:~# diff origin-sample-conf/etc/tempest.conf.sample my-tempest-env-01/etc/tempest.conf -u --- origin-sample-conf/etc/tempest.conf.sample 2015-12-23 20:07:37.703580165 +0800 +++ my-tempest-env-01/etc/tempest.conf 2015-12-23 19:45:27.390680269 +0800 @@ -178,19 +178,19 @@ # authenticating requests made by tenant isolation to create users and # projects (string value) # Deprecated group/name - [identity]/admin_username -#admin_username = <None> +admin_username = admin # Tenant name to use for an administrative user. This is needed for # authenticating requests made by tenant isolation to create users and # projects (string value) # Deprecated group/name - [identity]/admin_tenant_name -#admin_tenant_name = <None> +admin_tenant_name = admin # Password to use for an administrative user. This is needed for # authenticating requests made by tenant isolation to create users and # projects (string value) # Deprecated group/name - [identity]/admin_password -#admin_password = <None> +admin_password = admin # Admin domain name for authentication (Keystone V3).The same domain # applies to user and project (string value) @@ -290,18 +290,18 @@ # Valid primary image reference to be used in tests. This is a # required option (string value) -#image_ref = <None> +image_ref = 643ea9b2-f2f8-408e-ab37-309494e82832 # Valid secondary image reference to be used in tests. This is a # required option, but if only one image is available duplicate the # value of image_ref above (string value) -#image_ref_alt = <None> +image_ref_alt = 42074fa5-231c-48f2-9db1-e283a5ea5b10 # Valid primary flavor to use in tests. (string value) -#flavor_ref = 1 +flavor_ref = 1 # Valid secondary flavor to be used in tests. (string value) -#flavor_ref_alt = 2 +flavor_ref_alt = 2 # Time in seconds between build status checks. (integer value) #build_interval = 1 @@ -320,7 +320,7 @@ # which will be used for creating servers if tempest does not create a # network or a network is not specified elsewhere. It may be used for # ssh validation only if floating IPs are disabled. (string value) -#fixed_network_name = <None> +fixed_network_name = public # Catalog type of the Compute service. (string value) #catalog_type = compute @@ -590,14 +590,14 @@ #ca_certificates_file = <None> # Full URI of the OpenStack Identity API (Keystone), v2 (string value) -#uri = <None> +uri = http://127.0.0.1:5000/v2.0/ # Full URI of the OpenStack Identity API (Keystone), v3 (string value) #uri_v3 = <None> # Identity API version to be used for authentication for API tests. # (string value) -#auth_version = v2 +auth_version = v2 # The identity region name to use. Also used as the other services' # region name unless they are set explicitly. If no such region is @@ -624,12 +624,12 @@ # Username to use for Nova API requests. (string value) # This option is deprecated for removal. # Its value may be silently ignored in the future. -#username = <None> +username = demo # Tenant name to use for Nova API requests. (string value) # This option is deprecated for removal. # Its value may be silently ignored in the future. -#tenant_name = <None> +tenant_name = demo # Role required to administrate keystone. (string value) #admin_role = admin @@ -637,7 +637,7 @@ # API key to use when authenticating. (string value) # This option is deprecated for removal. # Its value may be silently ignored in the future. -#password = <None> +password = demo # Domain name for authentication (Keystone V3).The same domain applies # to user and project (string value) @@ -683,10 +683,10 @@ #trust = true # Is the v2 identity API enabled (boolean value) -#api_v2 = true +api_v2 = true # Is the v3 identity API enabled (boolean value) -#api_v3 = true +api_v3 = false # A list of enabled identity extensions with a special entry all which # indicates every extension is enabled. Empty list indicates all @@ -851,7 +851,7 @@ # Id of the public network that provides external connectivity (string # value) -#public_network_id = +#public_network_id = <None> # Default floating network name. Used to allocate floating IPs when # neutron is enabled. (string value) @@ -891,7 +891,7 @@ # # Allow the execution of IPv6 tests (boolean value) -#ipv6 = true +ipv6 = false # A list of enabled network extensions with a special entry all which # indicates every extension is enabled. Empty list indicates all @@ -1086,32 +1086,32 @@ # # Whether or not cinder is expected to be available (boolean value) -#cinder = true +cinder = false # Whether or not neutron is expected to be available (boolean value) -#neutron = false +neutron = true # Whether or not glance is expected to be available (boolean value) -#glance = true +glance = true # Whether or not swift is expected to be available (boolean value) -#swift = true +swift = false # Whether or not nova is expected to be available (boolean value) -#nova = true +nova = true # Whether or not Heat is expected to be available (boolean value) #heat = false # Whether or not Ceilometer is expected to be available (boolean # value) -#ceilometer = true +ceilometer = true # Whether or not Aodh is expected to be available (boolean value) #aodh = false # Whether or not Horizon is expected to be available (boolean value) -#horizon = true +horizon = true # Whether or not Sahara is expected to be available (boolean value) #sahara = false |
执行测试
”’执行测试需要在修改好配置文件的测试环境配置目录下进行。”’
执行全部测试用例
有好几种方式可以执行tempest测试:
$ testr run
并发测试:
$ testr run –parallel # 注意是双横杠
更多参数可以查看testr的帮助文档:
$ testr help run
也可以用:
$ nosetests -v tempest
执行完毕后会给出结果,例如:
Ran 767 (+766) tests in 2207.974s (+2207.726s)
FAILED (id=11, failures=118 (+118), skips=196)
执行部分用例
可以按照目录+文件+类+方法的方式执行某个特定用例,比如:
$ testr run tempest.api.compute.servers.test_servers_negative.ServersNegativeTestJSON.test_reboot_non_existent_server
也可以仅执行某个文件中的所有用例,比如:
$ testr run tempest.api.compute.servers.test_servers_negative
或者一个类的所有用例:
$ testr run tempest.api.compute.servers.test_servers_negative.ServersNegativeTestJSON
还可以用python -m testtools.run来执行部分用例,比如:
$ python -m testtools.run tempest.api.compute.servers.test_servers_negative.ServersNegativeTestJSON.test_reboot_non_existent_server
也可以用这种方式执行某个文件或者某个类的全部用例,用法与testr run相同。
nosetests命令执行部分用例的方法也是类似的,只不过要加上-s参数,比如:
$ nosetests -sv testtools.run tempest.api.compute.servers.test_servers_negative.ServersNegativeTestJSON.test_reboot_non_existent_server
调试用例
如果某个用例执行出错,可能需要加入断点单步调试,可以用pdb调试库来完成调试工作,但我更建议用ipdb库来调试,这个库更智能易用,它的缺点是不是Python系统库,需要手工安装才能使用。
””’如果要加入断点单步调试,需要使用python -m testtools.run方法来执行被调试的用例,否则可能导致断点无法进入,也就没办法进行单步调试了,切记切记!!!!!。””’
调试的第一步是在被调试的用例里面加上断点(下面以tempest.api.compute.servers.test_servers_negative.ServersNegativeTestJSON.test_reboot_non_existent_server用例为例进行说明,这里使用的是ipdb,pdb也是类似):
1 2 3 4 5 6 7 8 |
@test.attr(type=['negative']) @test.idempotent_id('d4c023a0-9c55-4747-9dd5-413b820143c7') def test_reboot_non_existent_server(self): import ipdb;ipdb.set_trace() # Reboot a non existent server nonexistent_server = data_utils.rand_uuid() self.assertRaises(lib_exc.NotFound, self.client.reboot_server, nonexistent_server, type='SOFT') |
之后用python -m testtools.run跑起来这个用例即可进入断点调试模式。
ipdb库安装
执行如下命令即可:
$ pip install ipdb