blob: ad2674161c84af6676acc71a0c6a567922a79108 [file] [log] [blame]
Matthew Treinish3a851dc2015-07-30 11:34:03 -04001=============================
2Tempest Test Plugin Interface
3=============================
4
5Tempest has an external test plugin interface which enables anyone to integrate
6an external test suite as part of a tempest run. This will let any project
7leverage being run with the rest of the tempest suite while not requiring the
8tests live in the tempest tree.
9
10Creating a plugin
11=================
12
13Creating a plugin is fairly straightforward and doesn't require much additional
Andrea Frittoli (andreaf)1370baf2016-04-29 14:26:22 -050014effort on top of creating a test suite using tempest.lib. One thing to note with
Matthew Treinish3a851dc2015-07-30 11:34:03 -040015doing this is that the interfaces exposed by tempest are not considered stable
16(with the exception of configuration variables which ever effort goes into
17ensuring backwards compatibility). You should not need to import anything from
18tempest itself except where explicitly noted. If there is an interface from
19tempest that you need to rely on in your plugin it likely needs to be migrated
Andrea Frittoli (andreaf)1370baf2016-04-29 14:26:22 -050020to tempest.lib. In that situation, file a bug, push a migration patch, etc. to
Matthew Treinish3a851dc2015-07-30 11:34:03 -040021expedite providing the interface in a reliable manner.
22
Marc Koderer66210aa2015-10-26 10:52:32 +010023Plugin Cookiecutter
24-------------------
25
26In order to create the basic structure with base classes and test directories
27you can use the tempest-plugin-cookiecutter project::
28
Yuiko Takadaccb2bbf2015-11-17 10:09:44 +090029 > pip install -U cookiecutter && cookiecutter https://git.openstack.org/openstack/tempest-plugin-cookiecutter
Marc Koderer66210aa2015-10-26 10:52:32 +010030
31 Cloning into 'tempest-plugin-cookiecutter'...
32 remote: Counting objects: 17, done.
33 remote: Compressing objects: 100% (13/13), done.
34 remote: Total 17 (delta 1), reused 14 (delta 1)
35 Unpacking objects: 100% (17/17), done.
36 Checking connectivity... done.
37 project (default is "sample")? foo
38 testclass (default is "SampleTempestPlugin")? FooTempestPlugin
39
40This would create a folder called ``foo_tempest_plugin/`` with all necessary
41basic classes. You only need to move/create your test in
42``foo_tempest_plugin/tests``.
43
44Entry Point
45-----------
46
47Once you've created your plugin class you need to add an entry point to your
48project to enable tempest to find the plugin. The entry point must be added
49to the "tempest.test_plugins" namespace.
50
51If you are using pbr this is fairly straightforward, in the setup.cfg just add
52something like the following::
53
54 [entry_points]
55 tempest.test_plugins =
56 plugin_name = module.path:PluginClass
57
Matthew Treinish00686f22016-03-09 15:39:19 -050058Standalone Plugin vs In-repo Plugin
59-----------------------------------
60
61Since all that's required for a plugin to be detected by tempest is a valid
62setuptools entry point in the proper namespace there is no difference from the
63tempest perspective on either creating a separate python package to
64house the plugin or adding the code to an existing python project. However,
65there are tradeoffs to consider when deciding which approach to take when
66creating a new plugin.
67
68If you create a separate python project for your plugin this makes a lot of
69things much easier. Firstly it makes packaging and versioning much simpler, you
70can easily decouple the requirements for the plugin from the requirements for
71the other project. It lets you version the plugin independently and maintain a
72single version of the test code across project release boundaries (see the
73`Branchless Tempest Spec`_ for more details on this). It also greatly
74simplifies the install time story for external users. Instead of having to
75install the right version of a project in the same python namespace as tempest
76they simply need to pip install the plugin in that namespace. It also means
77that users don't have to worry about inadvertently installing a tempest plugin
78when they install another package.
79
80.. _Branchless Tempest Spec: http://specs.openstack.org/openstack/qa-specs/specs/tempest/implemented/branchless-tempest.html
81
82The sole advantage to integrating a plugin into an existing python project is
83that it enables you to land code changes at the same time you land test changes
84in the plugin. This reduces some of the burden on contributors by not having
85to land 2 changes to add a new API feature and then test it and doing it as a
86single combined commit.
87
88
Matthew Treinish3a851dc2015-07-30 11:34:03 -040089Plugin Class
Marc Koderer66210aa2015-10-26 10:52:32 +010090============
Matthew Treinish3a851dc2015-07-30 11:34:03 -040091
92To provide tempest with all the required information it needs to be able to run
93your plugin you need to create a plugin class which tempest will load and call
94to get information when it needs. To simplify creating this tempest provides an
95abstract class that should be used as the parent for your plugin. To use this
96you would do something like the following::
97
YAMAMOTO Takashicb2ac6e2015-10-19 15:54:42 +090098 from tempest.test_discover import plugins
Matthew Treinish3a851dc2015-07-30 11:34:03 -040099
YAMAMOTO Takashicb2ac6e2015-10-19 15:54:42 +0900100 class MyPlugin(plugins.TempestPlugin):
Matthew Treinish3a851dc2015-07-30 11:34:03 -0400101
102Then you need to ensure you locally define all of the methods in the abstract
103class, you can refer to the api doc below for a reference of what that entails.
104
Matthew Treinish3a851dc2015-07-30 11:34:03 -0400105Abstract Plugin Class
Marc Koderer66210aa2015-10-26 10:52:32 +0100106---------------------
Matthew Treinish3a851dc2015-07-30 11:34:03 -0400107
108.. autoclass:: tempest.test_discover.plugins.TempestPlugin
109 :members:
110
Matthew Treinish3a851dc2015-07-30 11:34:03 -0400111Plugin Structure
Marc Koderer66210aa2015-10-26 10:52:32 +0100112================
Matthew Treinish3a851dc2015-07-30 11:34:03 -0400113While there are no hard and fast rules for the structure a plugin, there are
114basically no constraints on what the plugin looks like as long as the 2 steps
115above are done. However, there are some recommended patterns to follow to make
116it easy for people to contribute and work with your plugin. For example, if you
117create a directory structure with something like::
118
119 plugin_dir/
120 config.py
121 plugin.py
122 tests/
123 api/
124 scenario/
125 services/
126 client.py
127
128That will mirror what people expect from tempest. The file
129
130* **config.py**: contains any plugin specific configuration variables
131* **plugin.py**: contains the plugin class used for the entry point
132* **tests**: the directory where test discovery will be run, all tests should
133 be under this dir
134* **services**: where the plugin specific service clients are
135
136Additionally, when you're creating the plugin you likely want to follow all
137of the tempest developer and reviewer documentation to ensure that the tests
138being added in the plugin act and behave like the rest of tempest.
139
Matthew Treinish9392a832015-08-24 10:00:49 -0400140Dealing with configuration options
Marc Koderer66210aa2015-10-26 10:52:32 +0100141----------------------------------
Matthew Treinish9392a832015-08-24 10:00:49 -0400142
143Historically Tempest didn't provide external guarantees on its configuration
144options. However, with the introduction of the plugin interface this is no
145longer the case. An external plugin can rely on using any configuration option
146coming from Tempest, there will be at least a full deprecation cycle for any
147option before it's removed. However, just the options provided by Tempest
148may not be sufficient for the plugin. If you need to add any plugin specific
149configuration options you should use the ``register_opts`` and
150``get_opt_lists`` methods to pass them to Tempest when the plugin is loaded.
151When adding configuration options the ``register_opts`` method gets passed the
152CONF object from tempest. This enables the plugin to add options to both
153existing sections and also create new configuration sections for new options.
154
Matthew Treinish3a851dc2015-07-30 11:34:03 -0400155Using Plugins
156=============
157
158Tempest will automatically discover any installed plugins when it is run. So by
159just installing the python packages which contain your plugin you'll be using
160them with tempest, nothing else is really required.
161
162However, you should take care when installing plugins. By their very nature
163there are no guarantees when running tempest with plugins enabled about the
164quality of the plugin. Additionally, while there is no limitation on running
165with multiple plugins it's worth noting that poorly written plugins might not
166properly isolate their tests which could cause unexpected cross interactions
167between plugins.
168
169Notes for using plugins with virtualenvs
170----------------------------------------
171
172When using a tempest inside a virtualenv (like when running under tox) you have
173to ensure that the package that contains your plugin is either installed in the
174venv too or that you have system site-packages enabled. The virtualenv will
175isolate the tempest install from the rest of your system so just installing the
176plugin package on your system and then running tempest inside a venv will not
177work.
178
179Tempest also exposes a tox job, all-plugin, which will setup a tox virtualenv
180with system site-packages enabled. This will let you leverage tox without
181requiring to manually install plugins in the tox venv before running tests.