blob: 23bc61ba6fb982ff220cce43bb4a6e44dace5a10 [file] [log] [blame]
Attila Fazekas23fdf1d2013-06-09 16:35:23 +02001Tempest Coding Guide
2====================
3
Joe Gordon1374f882013-07-12 17:00:34 +01004- Step 1: Read the OpenStack Style Commandments
chenxinge98720a2017-07-19 03:42:23 +00005 https://docs.openstack.org/hacking/latest/
Joe Gordon1374f882013-07-12 17:00:34 +01006- Step 2: Read on
7
8Tempest Specific Commandments
Sergey Vilgelmeac094a2018-11-21 18:27:51 -06009-----------------------------
Joe Gordon1374f882013-07-12 17:00:34 +010010
ghanshyam50f19472014-11-26 17:04:37 +090011- [T102] Cannot import OpenStack python clients in tempest/api &
Masayuki Igawab78b9232017-11-17 16:12:37 +090012 tempest/scenario tests
Matthew Treinish5e4c0f22013-09-10 18:38:28 +000013- [T104] Scenario tests require a services decorator
Andrea Frittolia5ddd552014-08-19 18:30:00 +010014- [T105] Tests cannot use setUpClass/tearDownClass
Ken'ichi Ohmichi7581bcd2015-02-16 04:09:58 +000015- [T107] Check that a service tag isn't in the module path
Ken'ichi Ohmichi80369a92015-04-06 23:41:14 +000016- [T108] Check no hyphen at the end of rand_name() argument
John Warren3059a092015-08-31 15:34:49 -040017- [T109] Cannot use testtools.skip decorator; instead use
Masayuki Igawab78b9232017-11-17 16:12:37 +090018 decorators.skip_because from tempest.lib
Ken'ichi Ohmichic0d96be2015-11-11 12:33:48 +000019- [T110] Check that service client names of GET should be consistent
Ken'ichi Ohmichi4f525f72016-03-25 15:20:01 -070020- [T111] Check that service client names of DELETE should be consistent
Ken'ichi Ohmichi0dc97472016-03-25 15:10:08 -070021- [T112] Check that tempest.lib should not import local tempest code
Ken'ichi Ohmichid079c892016-04-19 11:23:36 -070022- [T113] Check that tests use data_utils.rand_uuid() instead of uuid.uuid4()
Matthew Treinish59d9eaa2016-05-31 23:42:55 -040023- [T114] Check that tempest.lib does not use tempest config
Ken'ichi Ohmichif741d0b2017-05-01 16:56:14 -070024- [T115] Check that admin tests should exist under admin path
Ghanshyam2a180b82014-06-16 13:54:22 +090025- [N322] Method's default argument shouldn't be mutable
junbolibc2ae862017-07-29 15:46:48 +080026- [T116] Unsupported 'message' Exception attribute in PY3
Felipe Monteiro4d011af2018-07-18 00:11:48 -040027- [T117] Check negative tests have ``@decorators.attr(type=['negative'])``
28 applied.
Takashi Kajinami2a5ef1b2021-11-29 15:48:25 +090029- [T118] LOG.warn is deprecated. Enforce use of LOG.warning.
Attila Fazekas23fdf1d2013-06-09 16:35:23 +020030
Attila Fazekasc07edb52019-03-17 15:38:03 +010031It is recommended to use ``tox -eautopep8`` before submitting a patch.
32
Matthew Treinish8b372892012-12-07 17:13:16 -050033Test Data/Configuration
34-----------------------
35- Assume nothing about existing test data
36- Tests should be self contained (provide their own data)
37- Clean up test data at the completion of each test
38- Use configuration files for values that will vary by environment
39
Felipe Monteirof22e6ec2018-11-03 17:51:18 -040040Supported OpenStack Components
41------------------------------
42
43Tempest's :ref:`library` and :ref:`plugin interface <tempest_plugin>` can be
44leveraged to support integration testing for virtually any OpenStack component.
45
46However, Tempest only offers **in-tree** integration testing coverage for the
47following components:
48
49* Cinder
50* Glance
51* Keystone
52* Neutron
53* Nova
54* Swift
55
56Historically, Tempest offered in-tree testing for other components as well, but
57since the introduction of the `External Plugin Interface`_, Tempest's in-tree
58testing scope has been limited to the projects above. Integration tests for
59projects not included above should go into one of the
60`relevant plugin projects`_.
61
62.. _External Plugin Interface: https://specs.openstack.org/openstack/qa-specs/specs/tempest/implemented/tempest-external-plugin-interface.html
Ghanshyam Mannda3bb612020-05-04 20:52:01 -050063.. _relevant plugin projects: https://docs.openstack.org/tempest/latest/plugins/plugin-registry.html#detected-plugins
Matthew Treinish8b372892012-12-07 17:13:16 -050064
Attila Fazekas10fd63d2013-07-04 18:38:21 +020065Exception Handling
66------------------
67According to the ``The Zen of Python`` the
Attila Fazekas58d23302013-07-24 10:25:02 +020068``Errors should never pass silently.``
Attila Fazekas10fd63d2013-07-04 18:38:21 +020069Tempest usually runs in special environment (jenkins gate jobs), in every
70error or failure situation we should provide as much error related
71information as possible, because we usually do not have the chance to
72investigate the situation after the issue happened.
73
74In every test case the abnormal situations must be very verbosely explained,
75by the exception and the log.
76
77In most cases the very first issue is the most important information.
78
Mithil Arunbe067ec2014-11-05 15:58:50 +053079Try to avoid using ``try`` blocks in the test cases, as both the ``except``
80and ``finally`` blocks could replace the original exception,
Attila Fazekas10fd63d2013-07-04 18:38:21 +020081when the additional operations leads to another exception.
82
Mithil Arunbe067ec2014-11-05 15:58:50 +053083Just letting an exception to propagate, is not a bad idea in a test case,
Bruce R. Montague44a6a192013-12-17 09:06:04 -080084at all.
Attila Fazekas10fd63d2013-07-04 18:38:21 +020085
86Try to avoid using any exception handling construct which can hide the errors
87origin.
88
89If you really need to use a ``try`` block, please ensure the original
90exception at least logged. When the exception is logged you usually need
91to ``raise`` the same or a different exception anyway.
92
Chris Yeohc2ff7272013-07-22 22:25:25 +093093Use of ``self.addCleanup`` is often a good way to avoid having to catch
94exceptions and still ensure resources are correctly cleaned up if the
95test fails part way through.
96
Mithil Arunbe067ec2014-11-05 15:58:50 +053097Use the ``self.assert*`` methods provided by the unit test framework.
98This signals the failures early on.
Attila Fazekas10fd63d2013-07-04 18:38:21 +020099
Mithil Arunbe067ec2014-11-05 15:58:50 +0530100Avoid using the ``self.fail`` alone, its stack trace will signal
Bruce R. Montague44a6a192013-12-17 09:06:04 -0800101the ``self.fail`` line as the origin of the error.
Attila Fazekas10fd63d2013-07-04 18:38:21 +0200102
103Avoid constructing complex boolean expressions for assertion.
Attila Fazekas7899d312013-08-16 09:18:17 +0200104The ``self.assertTrue`` or ``self.assertFalse`` without a ``msg`` argument,
105will just tell you the single boolean value, and you will not know anything
106about the values used in the formula, the ``msg`` argument might be good enough
107for providing more information.
108
109Most other assert method can include more information by default.
Attila Fazekas10fd63d2013-07-04 18:38:21 +0200110For example ``self.assertIn`` can include the whole set.
111
Matthew Treinishf45ba2e2015-08-24 15:05:01 -0400112It is recommended to use testtools `matcher`_ for the more tricky assertions.
113You can implement your own specific `matcher`_ as well.
Attila Fazekas7899d312013-08-16 09:18:17 +0200114
davyyyac670dc2017-11-16 21:27:03 +0800115.. _matcher: https://testtools.readthedocs.org/en/latest/for-test-authors.html#matchers
Attila Fazekas7899d312013-08-16 09:18:17 +0200116
Attila Fazekas10fd63d2013-07-04 18:38:21 +0200117If the test case fails you can see the related logs and the information
118carried by the exception (exception class, backtrack and exception info).
Mithil Arunbe067ec2014-11-05 15:58:50 +0530119This and the service logs are your only guide to finding the root cause of flaky
120issues.
Attila Fazekas10fd63d2013-07-04 18:38:21 +0200121
Attila Fazekas7899d312013-08-16 09:18:17 +0200122Test cases are independent
123--------------------------
124Every ``test_method`` must be callable individually and MUST NOT depends on,
125any other ``test_method`` or ``test_method`` ordering.
126
127Test cases MAY depend on commonly initialized resources/facilities, like
128credentials management, testresources and so on. These facilities, MUST be able
Mithil Arunbe067ec2014-11-05 15:58:50 +0530129to work even if just one ``test_method`` is selected for execution.
Attila Fazekas7899d312013-08-16 09:18:17 +0200130
Matthew Treinish5e4c0f22013-09-10 18:38:28 +0000131Service Tagging
132---------------
133Service tagging is used to specify which services are exercised by a particular
mmkmmk57ce3bb9b2017-09-20 13:41:41 +0900134test method. You specify the services with the ``tempest.common.utils.services``
Jordan Pittier74a56ab2017-04-26 16:46:20 +0200135decorator. For example:
Matthew Treinish5e4c0f22013-09-10 18:38:28 +0000136
Felipe Monteiro46920b82018-07-09 23:58:20 -0400137``@utils.services('compute', 'image')``
Matthew Treinish5e4c0f22013-09-10 18:38:28 +0000138
139Valid service tag names are the same as the list of directories in tempest.api
140that have tests.
141
Jordan Pittier74a56ab2017-04-26 16:46:20 +0200142For scenario tests having a service tag is required. For the API tests service
143tags are only needed if the test method makes an API call (either directly or
Matthew Treinish5e4c0f22013-09-10 18:38:28 +0000144indirectly through another service) that differs from the parent directory
Jordan Pittier74a56ab2017-04-26 16:46:20 +0200145name. For example, any test that make an API call to a service other than Nova
146in ``tempest.api.compute`` would require a service tag for those services,
147however they do not need to be tagged as ``compute``.
Matthew Treinish5e4c0f22013-09-10 18:38:28 +0000148
Felipe Monteiro46920b82018-07-09 23:58:20 -0400149Test Attributes
150---------------
151Tempest leverages `test attributes`_ which are a simple but effective way of
152distinguishing between different "types" of API tests. A test can be "tagged"
153with such attributes using the ``decorators.attr`` decorator, for example::
154
155 @decorators.attr(type=['negative'])
156 def test_aggregate_create_aggregate_name_length_less_than_1(self):
157 [...]
158
159These test attributes can be used for test selection via regular expressions.
160For example, ``(?!.*\[.*\bslow\b.*\])(^tempest\.scenario)`` runs all the tests
161in the ``scenario`` test module, *except* for those tagged with the ``slow``
162attribute (via a negative lookahead in the regular expression). These
163attributes are used in Tempest's ``tox.ini`` as well as Tempest's Zuul job
164definitions for specifying particular batches of Tempest test suites to run.
165
166.. _test attributes: https://testtools.readthedocs.io/en/latest/for-test-authors.html?highlight=attr#test-attributes
167
168Negative Attribute
169^^^^^^^^^^^^^^^^^^
170The ``type='negative'`` attribute is used to signify that a test is a negative
171test, which is a test that handles invalid input gracefully. This attribute
172should be applied to all negative test scenarios.
173
174This attribute must be applied to each test that belongs to a negative test
175class, i.e. a test class name ending with "Negative.*" substring.
176
Felipe Monteiro46920b82018-07-09 23:58:20 -0400177Slow Attribute
178^^^^^^^^^^^^^^
179The ``type='slow'`` attribute is used to signify that a test takes a long time
180to run, relatively speaking. This attribute is usually applied to
181:ref:`scenario tests <scenario_field_guide>`, which involve a complicated
182series of API operations, the total runtime of which can be relatively long.
183This long runtime has performance implications on `Zuul`_ jobs, which is why
184the ``slow`` attribute is leveraged to run slow tests on a selective basis,
185to keep total `Zuul`_ job runtime down to a reasonable time frame.
186
Martin Kopecd76178e2024-01-16 20:43:56 +0100187.. _Zuul: https://zuul-ci.org/docs/zuul/latest/
Felipe Monteiro46920b82018-07-09 23:58:20 -0400188
189Smoke Attribute
190^^^^^^^^^^^^^^^
191The ``type='smoke'`` attribute is used to signify that a test is a so-called
192smoke test, which is a type of test that tests the most vital OpenStack
193functionality, like listing servers or flavors or creating volumes. The
194attribute should be sparingly applied to only the tests that sanity-check the
195most essential functionality of an OpenStack cloud.
196
Martin Kopecec893e32023-02-14 11:39:27 +0100197Multinode Attribute
198^^^^^^^^^^^^^^^^^^^
199The ``type='multinode'`` attribute is used to signify that a test is desired
200to be executed in a multinode environment. By marking the tests with this
201attribute we can avoid running tests which aren't that beneficial for the
202multinode setup and thus reduce the consumption of resources.
203
Andrea Frittolia5ddd552014-08-19 18:30:00 +0100204Test fixtures and resources
205---------------------------
206Test level resources should be cleaned-up after the test execution. Clean-up
Masayuki Igawabbbaad62017-11-21 16:04:03 +0900207is best scheduled using ``addCleanup`` which ensures that the resource cleanup
Andrea Frittolia5ddd552014-08-19 18:30:00 +0100208code is always invoked, and in reverse order with respect to the creation
209order.
210
Masayuki Igawabbbaad62017-11-21 16:04:03 +0900211Test class level resources should be defined in the ``resource_setup`` method
212of the test class, except for any credential obtained from the credentials
213provider, which should be set-up in the ``setup_credentials`` method.
214Cleanup is best scheduled using ``addClassResourceCleanup`` which ensures that
Andrea Frittoli3be57482017-08-25 22:41:26 +0100215the cleanup code is always invoked, and in reverse order with respect to the
216creation order.
217
218In both cases - test level and class level cleanups - a wait loop should be
219scheduled before the actual delete of resources with an asynchronous delete.
Andrea Frittolia5ddd552014-08-19 18:30:00 +0100220
Masayuki Igawabbbaad62017-11-21 16:04:03 +0900221The test base class ``BaseTestCase`` defines Tempest framework for class level
222fixtures. ``setUpClass`` and ``tearDownClass`` are defined here and cannot be
Andrea Frittolia5ddd552014-08-19 18:30:00 +0100223overwritten by subclasses (enforced via hacking rule T105).
224
225Set-up is split in a series of steps (setup stages), which can be overwritten
226by test classes. Set-up stages are:
Masayuki Igawae63cf0f2016-05-25 10:25:21 +0900227
Masayuki Igawabbbaad62017-11-21 16:04:03 +0900228- ``skip_checks``
229- ``setup_credentials``
230- ``setup_clients``
231- ``resource_setup``
Andrea Frittolia5ddd552014-08-19 18:30:00 +0100232
233Tear-down is also split in a series of steps (teardown stages), which are
234stacked for execution only if the corresponding setup stage had been
235reached during the setup phase. Tear-down stages are:
Masayuki Igawae63cf0f2016-05-25 10:25:21 +0900236
Masayuki Igawabbbaad62017-11-21 16:04:03 +0900237- ``clear_credentials`` (defined in the base test class)
238- ``resource_cleanup``
Andrea Frittolia5ddd552014-08-19 18:30:00 +0100239
240Skipping Tests
241--------------
242Skipping tests should be based on configuration only. If that is not possible,
243it is likely that either a configuration flag is missing, or the test should
244fail rather than be skipped.
245Using discovery for skipping tests is generally discouraged.
246
247When running a test that requires a certain "feature" in the target
248cloud, if that feature is missing we should fail, because either the test
249configuration is invalid, or the cloud is broken and the expected "feature" is
250not there even if the cloud was configured with it.
251
Matthew Treinish8b79bb32013-10-10 17:11:05 -0400252Negative Tests
253--------------
Chris Hoge2b478412016-06-23 16:03:28 -0700254Error handling is an important aspect of API design and usage. Negative
255tests are a way to ensure that an application can gracefully handle
256invalid or unexpected input. However, as a black box integration test
257suite, Tempest is not suitable for handling all negative test cases, as
258the wide variety and complexity of negative tests can lead to long test
259runs and knowledge of internal implementation details. The bulk of
Ken'ichi Ohmichi8db40752016-09-28 14:43:05 -0700260negative testing should be handled with project function tests.
261All negative tests should be based on `API-WG guideline`_ . Such negative
262tests can block any changes from accurate failure code to invalid one.
263
davyyyac670dc2017-11-16 21:27:03 +0800264.. _API-WG guideline: https://specs.openstack.org/openstack/api-wg/guidelines/http.html#failure-code-clarifications
Ken'ichi Ohmichi8db40752016-09-28 14:43:05 -0700265
266If facing some gray area which is not clarified on the above guideline, propose
267a new guideline to the API-WG. With a proposal to the API-WG we will be able to
268build a consensus across all OpenStack projects and improve the quality and
269consistency of all the APIs.
270
271In addition, we have some guidelines for additional negative tests.
272
273- About BadRequest(HTTP400) case: We can add a single negative tests of
274 BadRequest for each resource and method(POST, PUT).
275 Please don't implement more negative tests on the same combination of
276 resource and method even if API request parameters are different from
277 the existing test.
278- About NotFound(HTTP404) case: We can add a single negative tests of
279 NotFound for each resource and method(GET, PUT, DELETE, HEAD).
280 Please don't implement more negative tests on the same combination
281 of resource and method.
282
283The above guidelines don't cover all cases and we will grow these guidelines
284organically over time. Patches outside of the above guidelines are left up to
285the reviewers' discretion and if we face some conflicts between reviewers, we
286will expand the guideline based on our discussion and experience.
Matthew Treinish8b79bb32013-10-10 17:11:05 -0400287
Giulio Fidente83181a92013-10-01 06:02:24 +0200288Test skips because of Known Bugs
289--------------------------------
Giulio Fidente83181a92013-10-01 06:02:24 +0200290If a test is broken because of a bug it is appropriate to skip the test until
Jordan Pittier74a56ab2017-04-26 16:46:20 +0200291bug has been fixed. You should use the ``skip_because`` decorator so that
Giulio Fidente83181a92013-10-01 06:02:24 +0200292Tempest's skip tracking tool can watch the bug status.
293
294Example::
295
296 @skip_because(bug="980688")
297 def test_this_and_that(self):
298 ...
299
Chris Yeohc2ff7272013-07-22 22:25:25 +0930300Guidelines
301----------
302- Do not submit changesets with only testcases which are skipped as
303 they will not be merged.
304- Consistently check the status code of responses in testcases. The
305 earlier a problem is detected the easier it is to debug, especially
306 where there is complicated setup required.
Matthew Treinish96c28d12013-09-16 17:05:09 +0000307
DennyZhang900f02b2013-09-23 08:34:04 -0500308Parallel Test Execution
309-----------------------
Matthew Treinish96c28d12013-09-16 17:05:09 +0000310Tempest by default runs its tests in parallel this creates the possibility for
311interesting interactions between tests which can cause unexpected failures.
Andrea Frittoli (andreaf)17209bb2015-05-22 10:16:57 -0700312Dynamic credentials provides protection from most of the potential race
313conditions between tests outside the same class. But there are still a few of
314things to watch out for to try to avoid issues when running your tests in
315parallel.
Matthew Treinish96c28d12013-09-16 17:05:09 +0000316
Sean Dagueed6e5862016-04-04 10:49:13 -0400317- Resources outside of a project scope still have the potential to conflict. This
Matthew Treinish96c28d12013-09-16 17:05:09 +0000318 is a larger concern for the admin tests since most resources and actions that
Sean Dagueed6e5862016-04-04 10:49:13 -0400319 require admin privileges are outside of projects.
Matthew Treinish96c28d12013-09-16 17:05:09 +0000320
321- Races between methods in the same class are not a problem because
Jordan Pittier74a56ab2017-04-26 16:46:20 +0200322 parallelization in Tempest is at the test class level, but if there is a json
Matthew Treinish96c28d12013-09-16 17:05:09 +0000323 and xml version of the same test class there could still be a race between
324 methods.
325
jeremy.zhangc0f95562017-05-26 13:41:57 +0800326- The rand_name() function from tempest.lib.common.utils.data_utils should be
327 used anywhere a resource is created with a name. Static naming should be
328 avoided to prevent resource conflicts.
Matthew Treinish96c28d12013-09-16 17:05:09 +0000329
330- If the execution of a set of tests is required to be serialized then locking
Jordan Pittier74a56ab2017-04-26 16:46:20 +0200331 can be used to perform this. See usage of ``LockFixture`` for examples of
Balazs Gibizerdfb30432021-12-14 17:25:16 +0100332 using locking. However, LockFixture only helps if you want to separate the
333 execution of two small sets of test cases. On the other hand, if you need to
334 run a set of tests separately from potentially all other tests then
335 ``LockFixture`` does not scale as you would need to take the lock in all the
336 other tests too. In this case, you can use the ``@serial`` decorator on top
337 of the test class holding the tests that need to run separately from the
338 potentially parallel test set. See more in :ref:`tempest_test_writing`.
339
Marc Koderer31fe4832013-11-06 17:02:03 +0100340
Matthew Treinish6eb05852013-11-26 15:28:12 +0000341Sample Configuration File
342-------------------------
343The sample config file is autogenerated using a script. If any changes are made
David Kranzfb0f51f2014-11-11 14:07:20 -0500344to the config variables in tempest/config.py then the sample config file must be
345regenerated. This can be done running::
346
Hai Shi6f52fc52017-04-03 21:17:37 +0800347 tox -e genconfig
Matthew Treinishecf212c2013-12-06 18:23:54 +0000348
349Unit Tests
350----------
Jordan Pittier74a56ab2017-04-26 16:46:20 +0200351Unit tests are a separate class of tests in Tempest. They verify Tempest
Matthew Treinishecf212c2013-12-06 18:23:54 +0000352itself, and thus have a different set of guidelines around them:
353
3541. They can not require anything running externally. All you should need to
355 run the unit tests is the git tree, python and the dependencies installed.
356 This includes running services, a config file, etc.
357
3582. The unit tests cannot use setUpClass, instead fixtures and testresources
359 should be used for shared state between tests.
Matthew Treinish55078882014-08-12 19:01:34 -0400360
361
362.. _TestDocumentation:
363
364Test Documentation
365------------------
366For tests being added we need to require inline documentation in the form of
Xicheng Chang6fb98ec2015-08-13 14:02:52 -0700367docstrings to explain what is being tested. In API tests for a new API a class
Matthew Treinish55078882014-08-12 19:01:34 -0400368level docstring should be added to an API reference doc. If one doesn't exist
369a TODO comment should be put indicating that the reference needs to be added.
370For individual API test cases a method level docstring should be used to
371explain the functionality being tested if the test name isn't descriptive
372enough. For example::
373
374 def test_get_role_by_id(self):
375 """Get a role by its id."""
376
377the docstring there is superfluous and shouldn't be added. but for a method
378like::
379
380 def test_volume_backup_create_get_detailed_list_restore_delete(self):
381 pass
382
383a docstring would be useful because while the test title is fairly descriptive
384the operations being performed are complex enough that a bit more explanation
385will help people figure out the intent of the test.
386
387For scenario tests a class level docstring describing the steps in the scenario
388is required. If there is more than one test case in the class individual
389docstrings for the workflow in each test methods can be used instead. A good
390example of this would be::
391
zhufl42bcb552018-09-17 16:06:30 +0800392 class TestServerBasicOps(manager.ScenarioTest):
Matthew Treinish55078882014-08-12 19:01:34 -0400393
zhufl42bcb552018-09-17 16:06:30 +0800394 """The test suite for server basic operations
395
396 This smoke test case follows this basic set of operations:
397 * Create a keypair for use in launching an instance
398 * Create a security group to control network access in instance
399 * Add simple permissive rules to the security group
400 * Launch an instance
401 * Perform ssh to instance
402 * Verify metadata service
403 * Verify metadata on config_drive
404 * Terminate the instance
Dougal Matthews4bebca02014-10-28 08:36:04 +0000405 """
Matthew Treinisha970d652015-03-11 15:39:24 -0400406
Chris Hoge0e000ed2015-07-28 14:19:53 -0500407Test Identification with Idempotent ID
408--------------------------------------
409
410Every function that provides a test must have an ``idempotent_id`` decorator
411that is a unique ``uuid-4`` instance. This ID is used to complement the fully
Naomichi Wakuidbe9aab2015-08-26 03:36:02 +0000412qualified test name and track test functionality through refactoring. The
Chris Hoge0e000ed2015-07-28 14:19:53 -0500413format of the metadata looks like::
414
Ken'ichi Ohmichi8a082112017-03-06 16:03:17 -0800415 @decorators.idempotent_id('585e934c-448e-43c4-acbf-d06a9b899997')
Chris Hoge0e000ed2015-07-28 14:19:53 -0500416 def test_list_servers_with_detail(self):
417 # The created server should be in the detailed list of all servers
418 ...
419
Andrea Frittoli (andreaf)1370baf2016-04-29 14:26:22 -0500420Tempest.lib includes a ``check-uuid`` tool that will test for the existence
Matthew Treinishc1802bc2015-12-03 18:48:11 -0500421and uniqueness of idempotent_id metadata for every test. If you have
Jordan Pittier74a56ab2017-04-26 16:46:20 +0200422Tempest installed you run the tool against Tempest by calling from the
423Tempest repo::
Chris Hoge0e000ed2015-07-28 14:19:53 -0500424
Matthew Treinishc1802bc2015-12-03 18:48:11 -0500425 check-uuid
Chris Hoge0e000ed2015-07-28 14:19:53 -0500426
427It can be invoked against any test suite by passing a package name::
428
Matthew Treinishc1802bc2015-12-03 18:48:11 -0500429 check-uuid --package <package_name>
Chris Hoge0e000ed2015-07-28 14:19:53 -0500430
431Tests without an ``idempotent_id`` can be automatically fixed by running
432the command with the ``--fix`` flag, which will modify the source package
433by inserting randomly generated uuids for every test that does not have
434one::
435
Matthew Treinishc1802bc2015-12-03 18:48:11 -0500436 check-uuid --fix
Chris Hoge0e000ed2015-07-28 14:19:53 -0500437
Jordan Pittier74a56ab2017-04-26 16:46:20 +0200438The ``check-uuid`` tool is used as part of the Tempest gate job
Chris Hoge0e000ed2015-07-28 14:19:53 -0500439to ensure that all tests have an ``idempotent_id`` decorator.
440
Matthew Treinisha970d652015-03-11 15:39:24 -0400441Branchless Tempest Considerations
442---------------------------------
443
444Starting with the OpenStack Icehouse release Tempest no longer has any stable
445branches. This is to better ensure API consistency between releases because
446the API behavior should not change between releases. This means that the stable
447branches are also gated by the Tempest master branch, which also means that
448proposed commits to Tempest must work against both the master and all the
449currently supported stable branches of the projects. As such there are a few
450special considerations that have to be accounted for when pushing new changes
Jordan Pittier74a56ab2017-04-26 16:46:20 +0200451to Tempest.
Matthew Treinisha970d652015-03-11 15:39:24 -0400452
4531. New Tests for new features
454^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
455
456When adding tests for new features that were not in previous releases of the
Felipe Monteiro356f0592018-03-26 21:51:52 -0400457projects the new test has to be properly skipped with a feature flag. This can
458be just as simple as using the ``@utils.requires_ext()`` or
459``testtools.skipUnless`` decorators to check if the required extension (or
460discoverable optional API) or feature is enabled or can be as difficult as
Andrea Frittolicd368412017-08-14 21:37:56 +0100461adding a new config option to the appropriate section. If there isn't a method
462of selecting the new **feature** from the config file then there won't be a
Felipe Monteiro356f0592018-03-26 21:51:52 -0400463mechanism to disable the test with older stable releases and the new test
464won't be able to merge.
465
466Introduction of a new feature flag requires specifying a default value for
467the corresponding config option that is appropriate in the latest OpenStack
468release. Because Tempest is branchless, the feature flag's default value will
469need to be overridden to a value that is appropriate in earlier releases
470in which the feature isn't available. In DevStack, this can be accomplished
471by modifying Tempest's `lib installation script`_ for previous branches
472(because DevStack is branched).
473
caoyuan349ba752019-04-23 19:40:06 +0800474.. _lib installation script: https://opendev.org/openstack/devstack/src/branch/master/lib/tempest
Matthew Treinisha970d652015-03-11 15:39:24 -0400475
4762. Bug fix on core project needing Tempest changes
477^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
478
479When trying to land a bug fix which changes a tested API you'll have to use the
480following procedure::
481
Jordan Pittier74a56ab2017-04-26 16:46:20 +0200482 1. Propose change to the project, get a +2 on the change even with failing
483 2. Propose skip on Tempest which will only be approved after the
Matthew Treinisha970d652015-03-11 15:39:24 -0400484 corresponding change in the project has a +2 on change
Jordan Pittier74a56ab2017-04-26 16:46:20 +0200485 3. Land project change in master and all open stable branches (if required)
486 4. Land changed test in Tempest
Matthew Treinisha970d652015-03-11 15:39:24 -0400487
488Otherwise the bug fix won't be able to land in the project.
489
gaofei6ec582f2018-01-24 14:08:36 +0800490Handily, `Zuul's cross-repository dependencies
Martin Kopecd76178e2024-01-16 20:43:56 +0100491<https://zuul-ci.org/docs/zuul/latest/gating.html#cross-project-dependencies>`_.
Jordan Pittier74a56ab2017-04-26 16:46:20 +0200492can be leveraged to do without step 2 and to have steps 3 and 4 happen
493"atomically". To do that, make the patch written in step 1 to depend (refer to
494Zuul's documentation above) on the patch written in step 4. The commit message
495for the Tempest change should have a link to the Gerrit review that justifies
496that change.
497
Matthew Treinisha970d652015-03-11 15:39:24 -04004983. New Tests for existing features
499^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
500
501If a test is being added for a feature that exists in all the current releases
502of the projects then the only concern is that the API behavior is the same
503across all the versions of the project being tested. If the behavior is not
504consistent the test will not be able to merge.
505
506API Stability
507-------------
508
509For new tests being added to Tempest the assumption is that the API being
510tested is considered stable and adheres to the OpenStack API stability
511guidelines. If an API is still considered experimental or in development then
512it should not be tested by Tempest until it is considered stable.