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