Masayuki Igawa | 7e4ef4c | 2019-07-03 17:17:44 +0900 | [diff] [blame] | 1 | Tempest - The OpenStack Integration Test Suite |
| 2 | ============================================== |
| 3 | |
| 4 | The documentation for Tempest is officially hosted at: |
| 5 | https://docs.openstack.org/tempest/latest/ |
| 6 | |
| 7 | This is a set of integration tests to be run against a live OpenStack |
| 8 | cluster. Tempest has batteries of tests for OpenStack API validation, |
| 9 | scenarios, and other specific tests useful in validating an OpenStack |
| 10 | deployment. |
| 11 | |
| 12 | Team and repository tags |
| 13 | ------------------------ |
| 14 | |
| 15 | .. image:: https://governance.openstack.org/tc/badges/tempest.svg |
| 16 | :target: https://governance.openstack.org/tc/reference/tags/index.html |
| 17 | |
| 18 | .. Change things from this point on |
| 19 | |
| 20 | Design Principles |
| 21 | ----------------- |
| 22 | Tempest Design Principles that we strive to live by. |
| 23 | |
| 24 | - Tempest should be able to run against any OpenStack cloud, be it a |
| 25 | one node DevStack install, a 20 node LXC cloud, or a 1000 node KVM |
| 26 | cloud. |
| 27 | - Tempest should be explicit in testing features. It is easy to auto |
| 28 | discover features of a cloud incorrectly, and give people an |
| 29 | incorrect assessment of their cloud. Explicit is always better. |
| 30 | - Tempest uses OpenStack public interfaces. Tests in Tempest should |
| 31 | only touch public OpenStack APIs. |
| 32 | - Tempest should not touch private or implementation specific |
| 33 | interfaces. This means not directly going to the database, not |
| 34 | directly hitting the hypervisors, not testing extensions not |
| 35 | included in the OpenStack base. If there are some features of |
| 36 | OpenStack that are not verifiable through standard interfaces, this |
| 37 | should be considered a possible enhancement. |
| 38 | - Tempest strives for complete coverage of the OpenStack API and |
| 39 | common scenarios that demonstrate a working cloud. |
| 40 | - Tempest drives load in an OpenStack cloud. By including a broad |
| 41 | array of API and scenario tests Tempest can be reused in whole or in |
| 42 | parts as load generation for an OpenStack cloud. |
| 43 | - Tempest should attempt to clean up after itself, whenever possible |
| 44 | we should tear down resources when done. |
| 45 | - Tempest should be self-testing. |
| 46 | |
| 47 | Quickstart |
| 48 | ---------- |
| 49 | |
| 50 | To run Tempest, you first need to create a configuration file that will tell |
| 51 | Tempest where to find the various OpenStack services and other testing behavior |
| 52 | switches. Where the configuration file lives and how you interact with it |
| 53 | depends on how you'll be running Tempest. There are 2 methods of using Tempest. |
| 54 | The first, which is a newer and recommended workflow treats Tempest as a system |
| 55 | installed program. The second older method is to run Tempest assuming your |
| 56 | working dir is the actually Tempest source repo, and there are a number of |
| 57 | assumptions related to that. For this section we'll only cover the newer method |
| 58 | as it is simpler, and quicker to work with. |
| 59 | |
| 60 | #. You first need to install Tempest. This is done with pip after you check out |
| 61 | the Tempest repo:: |
| 62 | |
| 63 | $ git clone https://opendev.org/openstack/tempest |
| 64 | $ pip install tempest/ |
| 65 | |
| 66 | This can be done within a venv, but the assumption for this guide is that |
| 67 | the Tempest CLI entry point will be in your shell's PATH. |
| 68 | |
| 69 | #. Installing Tempest may create a ``/etc/tempest dir``, however if one isn't |
| 70 | created you can create one or use ``~/.tempest/etc`` or ``~/.config/tempest`` in |
| 71 | place of ``/etc/tempest``. If none of these dirs are created Tempest will create |
| 72 | ``~/.tempest/etc`` when it's needed. The contents of this dir will always |
| 73 | automatically be copied to all ``etc/`` dirs in local workspaces as an initial |
| 74 | setup step. So if there is any common configuration you'd like to be shared |
| 75 | between local Tempest workspaces it's recommended that you pre-populate it |
| 76 | before running ``tempest init``. |
| 77 | |
| 78 | #. Setup a local Tempest workspace. This is done by using the tempest init |
| 79 | command:: |
| 80 | |
| 81 | $ tempest init cloud-01 |
| 82 | |
| 83 | which also works the same as:: |
| 84 | |
| 85 | $ mkdir cloud-01 && cd cloud-01 && tempest init |
| 86 | |
| 87 | This will create a new directory for running a single Tempest configuration. |
| 88 | If you'd like to run Tempest against multiple OpenStack deployments the idea |
| 89 | is that you'll create a new working directory for each to maintain separate |
| 90 | configuration files and local artifact storage for each. |
| 91 | |
| 92 | #. Then ``cd`` into the newly created working dir and also modify the local |
| 93 | config files located in the ``etc/`` subdir created by the ``tempest init`` |
| 94 | command. Tempest is expecting a ``tempest.conf`` file in etc/ so if only a |
| 95 | sample exists you must rename or copy it to tempest.conf before making |
| 96 | any changes to it otherwise Tempest will not know how to load it. For |
| 97 | details on configuring Tempest refer to the |
| 98 | `Tempest Configuration <https://docs.openstack.org/tempest/latest/configuration.html#tempest-configuration>`_ |
| 99 | |
| 100 | #. Once the configuration is done you're now ready to run Tempest. This can |
| 101 | be done using the `Tempest Run <https://docs.openstack.org/tempest/latest/run.html#tempest-run>`_ |
| 102 | command. This can be done by either |
| 103 | running:: |
| 104 | |
| 105 | $ tempest run |
| 106 | |
| 107 | from the Tempest workspace directory. Or you can use the ``--workspace`` |
| 108 | argument to run in the workspace you created regardless of your current |
| 109 | working directory. For example:: |
| 110 | |
| 111 | $ tempest run --workspace cloud-01 |
| 112 | |
| 113 | There is also the option to use `stestr`_ directly. For example, from |
| 114 | the workspace dir run:: |
| 115 | |
| 116 | $ stestr run --black-regex '\[.*\bslow\b.*\]' '^tempest\.(api|scenario)' |
| 117 | |
| 118 | will run the same set of tests as the default gate jobs. Or you can |
Soniya Vyas | 6ed6fb5 | 2019-11-26 13:24:11 +0530 | [diff] [blame] | 119 | use `unittest`_ compatible test runners such as `stestr`_, `pytest`_ etc. |
Masayuki Igawa | 7e4ef4c | 2019-07-03 17:17:44 +0900 | [diff] [blame] | 120 | |
| 121 | Tox also contains several existing job configurations. For example:: |
| 122 | |
| 123 | $ tox -e full |
| 124 | |
| 125 | which will run the same set of tests as the OpenStack gate. (it's exactly how |
| 126 | the gate invokes Tempest) Or:: |
| 127 | |
| 128 | $ tox -e smoke |
| 129 | |
| 130 | to run the tests tagged as smoke. |
| 131 | |
| 132 | .. _unittest: https://docs.python.org/3/library/unittest.html |
Masayuki Igawa | 7e4ef4c | 2019-07-03 17:17:44 +0900 | [diff] [blame] | 133 | .. _stestr: https://stestr.readthedocs.org/en/latest/MANUAL.html |
| 134 | .. _pytest: https://docs.pytest.org/en/latest/ |
| 135 | |
| 136 | Library |
| 137 | ------- |
| 138 | Tempest exposes a library interface. This interface is a stable interface and |
| 139 | should be backwards compatible (including backwards compatibility with the |
| 140 | old tempest-lib package, with the exception of the import). If you plan to |
| 141 | directly consume Tempest in your project you should only import code from the |
| 142 | Tempest library interface, other pieces of Tempest do not have the same |
| 143 | stable interface and there are no guarantees on the Python API unless otherwise |
| 144 | stated. |
| 145 | |
| 146 | For more details refer to the `library documentation |
| 147 | <https://docs.openstack.org/tempest/latest/library.html#library>`_ |
| 148 | |
| 149 | Release Versioning |
| 150 | ------------------ |
| 151 | `Tempest Release Notes <https://docs.openstack.org/releasenotes/tempest>`_ |
| 152 | shows what changes have been released on each version. |
| 153 | |
| 154 | Tempest's released versions are broken into 2 sets of information. Depending on |
| 155 | how you intend to consume Tempest you might need |
| 156 | |
| 157 | The version is a set of 3 numbers: |
| 158 | |
| 159 | X.Y.Z |
| 160 | |
| 161 | While this is almost `semver`_ like, the way versioning is handled is slightly |
| 162 | different: |
| 163 | |
| 164 | X is used to represent the supported OpenStack releases for Tempest tests |
| 165 | in-tree, and to signify major feature changes to Tempest. It's a monotonically |
| 166 | increasing integer where each version either indicates a new supported OpenStack |
| 167 | release, the drop of support for an OpenStack release (which will coincide with |
| 168 | the upstream stable branch going EOL), or a major feature lands (or is removed) |
| 169 | from Tempest. |
| 170 | |
| 171 | Y.Z is used to represent library interface changes. This is treated the same |
| 172 | way as minor and patch versions from `semver`_ but only for the library |
| 173 | interface. When Y is incremented we've added functionality to the library |
| 174 | interface and when Z is incremented it's a bug fix release for the library. |
| 175 | Also note that both Y and Z are reset to 0 at each increment of X. |
| 176 | |
| 177 | .. _semver: https://semver.org/ |
| 178 | |
| 179 | Configuration |
| 180 | ------------- |
| 181 | |
| 182 | Detailed configuration of Tempest is beyond the scope of this |
| 183 | document, see `Tempest Configuration Documentation |
| 184 | <https://docs.openstack.org/tempest/latest/configuration.html#tempest-configuration>`_ |
| 185 | for more details on configuring Tempest. |
| 186 | The ``etc/tempest.conf.sample`` attempts to be a self-documenting |
| 187 | version of the configuration. |
| 188 | |
| 189 | You can generate a new sample tempest.conf file, run the following |
| 190 | command from the top level of the Tempest directory:: |
| 191 | |
| 192 | $ tox -e genconfig |
| 193 | |
| 194 | The most important pieces that are needed are the user ids, OpenStack |
| 195 | endpoints, and basic flavors and images needed to run tests. |
| 196 | |
| 197 | Unit Tests |
| 198 | ---------- |
| 199 | |
| 200 | Tempest also has a set of unit tests which test the Tempest code itself. These |
| 201 | tests can be run by specifying the test discovery path:: |
| 202 | |
| 203 | $ stestr --test-path ./tempest/tests run |
| 204 | |
| 205 | By setting ``--test-path`` option to ./tempest/tests it specifies that test discover |
| 206 | should only be run on the unit test directory. The default value of ``test_path`` |
| 207 | is ``test_path=./tempest/test_discover`` which will only run test discover on the |
| 208 | Tempest suite. |
| 209 | |
| 210 | Alternatively, there are the py27 and py36 tox jobs which will run the unit |
| 211 | tests with the corresponding version of python. |
| 212 | |
| 213 | One common activity is to just run a single test, you can do this with tox |
| 214 | simply by specifying to just run py27 or py36 tests against a single test:: |
| 215 | |
| 216 | $ tox -e py36 -- -n tempest.tests.test_microversions.TestMicroversionsTestsClass.test_config_version_none_23 |
| 217 | |
| 218 | Or all tests in the test_microversions.py file:: |
| 219 | |
| 220 | $ tox -e py36 -- -n tempest.tests.test_microversions |
| 221 | |
| 222 | You may also use regular expressions to run any matching tests:: |
| 223 | |
| 224 | $ tox -e py36 -- test_microversions |
| 225 | |
| 226 | Additionally, when running a single test, or test-file, the ``-n/--no-discover`` |
| 227 | argument is no longer required, however it may perform faster if included. |
| 228 | |
| 229 | For more information on these options and details about stestr, please see the |
| 230 | `stestr documentation <https://stestr.readthedocs.io/en/latest/MANUAL.html>`_. |
| 231 | |
| 232 | Python 3.x |
| 233 | ---------- |
| 234 | |
| 235 | Starting during the Pike cycle Tempest has a gating CI job that runs Tempest |
| 236 | with Python 3. Any Tempest release after 15.0.0 should fully support running |
| 237 | under Python 3 as well as Python 2.7. |
| 238 | |
| 239 | Legacy run method |
| 240 | ----------------- |
| 241 | |
| 242 | The legacy method of running Tempest is to just treat the Tempest source code |
| 243 | as a python unittest repository and run directly from the source repo. When |
| 244 | running in this way you still start with a Tempest config file and the steps |
| 245 | are basically the same except that it expects you know where the Tempest code |
| 246 | lives on your system and requires a bit more manual interaction to get Tempest |
| 247 | running. For example, when running Tempest this way things like a lock file |
| 248 | directory do not get generated automatically and the burden is on the user to |
| 249 | create and configure that. |
| 250 | |
| 251 | To start you need to create a configuration file. The easiest way to create a |
| 252 | configuration file is to generate a sample in the ``etc/`` directory :: |
| 253 | |
| 254 | $ cd $TEMPEST_ROOT_DIR |
| 255 | $ oslo-config-generator --config-file \ |
| 256 | tempest/cmd/config-generator.tempest.conf \ |
| 257 | --output-file etc/tempest.conf |
| 258 | |
| 259 | After that, open up the ``etc/tempest.conf`` file and edit the |
| 260 | configuration variables to match valid data in your environment. |
| 261 | This includes your Keystone endpoint, a valid user and credentials, |
| 262 | and reference data to be used in testing. |
| 263 | |
| 264 | .. note:: |
| 265 | |
| 266 | If you have a running DevStack environment, Tempest will be |
| 267 | automatically configured and placed in ``/opt/stack/tempest``. It |
| 268 | will have a configuration file already set up to work with your |
| 269 | DevStack installation. |
| 270 | |
Soniya Vyas | 6ed6fb5 | 2019-11-26 13:24:11 +0530 | [diff] [blame] | 271 | Tempest is not tied to any single test runner, but `stestr`_ is the most commonly |
Masayuki Igawa | 7e4ef4c | 2019-07-03 17:17:44 +0900 | [diff] [blame] | 272 | used tool. Also, the nosetests test runner is **not** recommended to run Tempest. |
| 273 | |
| 274 | After setting up your configuration file, you can execute the set of Tempest |
Soniya Vyas | 6ed6fb5 | 2019-11-26 13:24:11 +0530 | [diff] [blame] | 275 | tests by using ``stestr``. By default, ``stestr`` runs tests in parallel :: |
Masayuki Igawa | 7e4ef4c | 2019-07-03 17:17:44 +0900 | [diff] [blame] | 276 | |
Soniya Vyas | 6ed6fb5 | 2019-11-26 13:24:11 +0530 | [diff] [blame] | 277 | $ stestr run |
Masayuki Igawa | 7e4ef4c | 2019-07-03 17:17:44 +0900 | [diff] [blame] | 278 | |
| 279 | To run one single test serially :: |
| 280 | |
Soniya Vyas | 6ed6fb5 | 2019-11-26 13:24:11 +0530 | [diff] [blame] | 281 | $ stestr run --serial tempest.api.compute.servers.test_servers_negative.ServersNegativeTestJSON.test_reboot_non_existent_server |