blob: e51b90b96c8b26cba6868083f30d407a24a87340 [file] [log] [blame]
Masayuki Igawa7e4ef4c2019-07-03 17:17:44 +09001Tempest - The OpenStack Integration Test Suite
2==============================================
3
4The documentation for Tempest is officially hosted at:
5https://docs.openstack.org/tempest/latest/
6
7This is a set of integration tests to be run against a live OpenStack
8cluster. Tempest has batteries of tests for OpenStack API validation,
9scenarios, and other specific tests useful in validating an OpenStack
10deployment.
11
12Team 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
20Design Principles
21-----------------
22Tempest 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
47Quickstart
48----------
49
50To run Tempest, you first need to create a configuration file that will tell
51Tempest where to find the various OpenStack services and other testing behavior
52switches. Where the configuration file lives and how you interact with it
53depends on how you'll be running Tempest. There are 2 methods of using Tempest.
54The first, which is a newer and recommended workflow treats Tempest as a system
55installed program. The second older method is to run Tempest assuming your
56working dir is the actually Tempest source repo, and there are a number of
57assumptions related to that. For this section we'll only cover the newer method
58as 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 Vyas6ed6fb52019-11-26 13:24:11 +0530119 use `unittest`_ compatible test runners such as `stestr`_, `pytest`_ etc.
Masayuki Igawa7e4ef4c2019-07-03 17:17:44 +0900120
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 Igawa7e4ef4c2019-07-03 17:17:44 +0900133.. _stestr: https://stestr.readthedocs.org/en/latest/MANUAL.html
134.. _pytest: https://docs.pytest.org/en/latest/
135
136Library
137-------
138Tempest exposes a library interface. This interface is a stable interface and
139should be backwards compatible (including backwards compatibility with the
140old tempest-lib package, with the exception of the import). If you plan to
141directly consume Tempest in your project you should only import code from the
142Tempest library interface, other pieces of Tempest do not have the same
143stable interface and there are no guarantees on the Python API unless otherwise
144stated.
145
146For more details refer to the `library documentation
147<https://docs.openstack.org/tempest/latest/library.html#library>`_
148
149Release Versioning
150------------------
151`Tempest Release Notes <https://docs.openstack.org/releasenotes/tempest>`_
152shows what changes have been released on each version.
153
154Tempest's released versions are broken into 2 sets of information. Depending on
155how you intend to consume Tempest you might need
156
157The version is a set of 3 numbers:
158
159X.Y.Z
160
161While this is almost `semver`_ like, the way versioning is handled is slightly
162different:
163
164X is used to represent the supported OpenStack releases for Tempest tests
165in-tree, and to signify major feature changes to Tempest. It's a monotonically
166increasing integer where each version either indicates a new supported OpenStack
167release, the drop of support for an OpenStack release (which will coincide with
168the upstream stable branch going EOL), or a major feature lands (or is removed)
169from Tempest.
170
171Y.Z is used to represent library interface changes. This is treated the same
172way as minor and patch versions from `semver`_ but only for the library
173interface. When Y is incremented we've added functionality to the library
174interface and when Z is incremented it's a bug fix release for the library.
175Also note that both Y and Z are reset to 0 at each increment of X.
176
177.. _semver: https://semver.org/
178
179Configuration
180-------------
181
182Detailed configuration of Tempest is beyond the scope of this
183document, see `Tempest Configuration Documentation
184<https://docs.openstack.org/tempest/latest/configuration.html#tempest-configuration>`_
185for more details on configuring Tempest.
186The ``etc/tempest.conf.sample`` attempts to be a self-documenting
187version of the configuration.
188
189You can generate a new sample tempest.conf file, run the following
190command from the top level of the Tempest directory::
191
192 $ tox -e genconfig
193
194The most important pieces that are needed are the user ids, OpenStack
195endpoints, and basic flavors and images needed to run tests.
196
197Unit Tests
198----------
199
200Tempest also has a set of unit tests which test the Tempest code itself. These
201tests can be run by specifying the test discovery path::
202
203 $ stestr --test-path ./tempest/tests run
204
205By setting ``--test-path`` option to ./tempest/tests it specifies that test discover
206should only be run on the unit test directory. The default value of ``test_path``
207is ``test_path=./tempest/test_discover`` which will only run test discover on the
208Tempest suite.
209
210Alternatively, there are the py27 and py36 tox jobs which will run the unit
211tests with the corresponding version of python.
212
213One common activity is to just run a single test, you can do this with tox
214simply 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
218Or all tests in the test_microversions.py file::
219
220 $ tox -e py36 -- -n tempest.tests.test_microversions
221
222You may also use regular expressions to run any matching tests::
223
224 $ tox -e py36 -- test_microversions
225
226Additionally, when running a single test, or test-file, the ``-n/--no-discover``
227argument is no longer required, however it may perform faster if included.
228
229For more information on these options and details about stestr, please see the
230`stestr documentation <https://stestr.readthedocs.io/en/latest/MANUAL.html>`_.
231
232Python 3.x
233----------
234
235Starting during the Pike cycle Tempest has a gating CI job that runs Tempest
236with Python 3. Any Tempest release after 15.0.0 should fully support running
237under Python 3 as well as Python 2.7.
238
239Legacy run method
240-----------------
241
242The legacy method of running Tempest is to just treat the Tempest source code
243as a python unittest repository and run directly from the source repo. When
244running in this way you still start with a Tempest config file and the steps
245are basically the same except that it expects you know where the Tempest code
246lives on your system and requires a bit more manual interaction to get Tempest
247running. For example, when running Tempest this way things like a lock file
248directory do not get generated automatically and the burden is on the user to
249create and configure that.
250
251To start you need to create a configuration file. The easiest way to create a
252configuration 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
259After that, open up the ``etc/tempest.conf`` file and edit the
260configuration variables to match valid data in your environment.
261This includes your Keystone endpoint, a valid user and credentials,
262and 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 Vyas6ed6fb52019-11-26 13:24:11 +0530271Tempest is not tied to any single test runner, but `stestr`_ is the most commonly
Masayuki Igawa7e4ef4c2019-07-03 17:17:44 +0900272used tool. Also, the nosetests test runner is **not** recommended to run Tempest.
273
274After setting up your configuration file, you can execute the set of Tempest
Soniya Vyas6ed6fb52019-11-26 13:24:11 +0530275tests by using ``stestr``. By default, ``stestr`` runs tests in parallel ::
Masayuki Igawa7e4ef4c2019-07-03 17:17:44 +0900276
Soniya Vyas6ed6fb52019-11-26 13:24:11 +0530277 $ stestr run
Masayuki Igawa7e4ef4c2019-07-03 17:17:44 +0900278
279To run one single test serially ::
280
Soniya Vyas6ed6fb52019-11-26 13:24:11 +0530281 $ stestr run --serial tempest.api.compute.servers.test_servers_negative.ServersNegativeTestJSON.test_reboot_non_existent_server