Matthew Treinish | 3a851dc | 2015-07-30 11:34:03 -0400 | [diff] [blame] | 1 | ============================= |
| 2 | Tempest Test Plugin Interface |
| 3 | ============================= |
| 4 | |
| 5 | Tempest has an external test plugin interface which enables anyone to integrate |
| 6 | an external test suite as part of a tempest run. This will let any project |
| 7 | leverage being run with the rest of the tempest suite while not requiring the |
| 8 | tests live in the tempest tree. |
| 9 | |
| 10 | Creating a plugin |
| 11 | ================= |
| 12 | |
| 13 | Creating a plugin is fairly straightforward and doesn't require much additional |
| 14 | effort on top of creating a test suite using tempest-lib. One thing to note with |
| 15 | doing this is that the interfaces exposed by tempest are not considered stable |
| 16 | (with the exception of configuration variables which ever effort goes into |
| 17 | ensuring backwards compatibility). You should not need to import anything from |
| 18 | tempest itself except where explicitly noted. If there is an interface from |
| 19 | tempest that you need to rely on in your plugin it likely needs to be migrated |
| 20 | to tempest-lib. In that situation, file a bug, push a migration patch, etc. to |
| 21 | expedite providing the interface in a reliable manner. |
| 22 | |
| 23 | Plugin Class |
| 24 | ------------ |
| 25 | |
| 26 | To provide tempest with all the required information it needs to be able to run |
| 27 | your plugin you need to create a plugin class which tempest will load and call |
| 28 | to get information when it needs. To simplify creating this tempest provides an |
| 29 | abstract class that should be used as the parent for your plugin. To use this |
| 30 | you would do something like the following:: |
| 31 | |
| 32 | from tempest.test_discover import plugin |
| 33 | |
| 34 | class MyPlugin(plugin.TempestPlugin): |
| 35 | |
| 36 | Then you need to ensure you locally define all of the methods in the abstract |
| 37 | class, you can refer to the api doc below for a reference of what that entails. |
| 38 | |
| 39 | Also, note eventually this abstract class will likely live in tempest-lib, when |
| 40 | that migration occurs a deprecation shim will be added to tempest so as to not |
| 41 | break any existing plugins. But, when that occurs migrating to using tempest-lib |
| 42 | as the source for the abstract class will be prudent. |
| 43 | |
| 44 | Abstract Plugin Class |
| 45 | ^^^^^^^^^^^^^^^^^^^^^ |
| 46 | |
| 47 | .. autoclass:: tempest.test_discover.plugins.TempestPlugin |
| 48 | :members: |
| 49 | |
| 50 | Entry Point |
| 51 | ----------- |
| 52 | |
| 53 | Once you've created your plugin class you need to add an entry point to your |
| 54 | project to enable tempest to find the plugin. The entry point must be added |
| 55 | to the "tempest.test_plugins" namespace. |
| 56 | |
| 57 | If you are using pbr this is fairly straightforward, in the setup.cfg just add |
| 58 | something like the following:: |
| 59 | |
| 60 | [entry_points] |
| 61 | tempest.test_plugins = |
| 62 | plugin_name = module.path:PluginClass |
| 63 | |
| 64 | Plugin Structure |
| 65 | ---------------- |
| 66 | |
| 67 | While there are no hard and fast rules for the structure a plugin, there are |
| 68 | basically no constraints on what the plugin looks like as long as the 2 steps |
| 69 | above are done. However, there are some recommended patterns to follow to make |
| 70 | it easy for people to contribute and work with your plugin. For example, if you |
| 71 | create a directory structure with something like:: |
| 72 | |
| 73 | plugin_dir/ |
| 74 | config.py |
| 75 | plugin.py |
| 76 | tests/ |
| 77 | api/ |
| 78 | scenario/ |
| 79 | services/ |
| 80 | client.py |
| 81 | |
| 82 | That will mirror what people expect from tempest. The file |
| 83 | |
| 84 | * **config.py**: contains any plugin specific configuration variables |
| 85 | * **plugin.py**: contains the plugin class used for the entry point |
| 86 | * **tests**: the directory where test discovery will be run, all tests should |
| 87 | be under this dir |
| 88 | * **services**: where the plugin specific service clients are |
| 89 | |
| 90 | Additionally, when you're creating the plugin you likely want to follow all |
| 91 | of the tempest developer and reviewer documentation to ensure that the tests |
| 92 | being added in the plugin act and behave like the rest of tempest. |
| 93 | |
| 94 | Using Plugins |
| 95 | ============= |
| 96 | |
| 97 | Tempest will automatically discover any installed plugins when it is run. So by |
| 98 | just installing the python packages which contain your plugin you'll be using |
| 99 | them with tempest, nothing else is really required. |
| 100 | |
| 101 | However, you should take care when installing plugins. By their very nature |
| 102 | there are no guarantees when running tempest with plugins enabled about the |
| 103 | quality of the plugin. Additionally, while there is no limitation on running |
| 104 | with multiple plugins it's worth noting that poorly written plugins might not |
| 105 | properly isolate their tests which could cause unexpected cross interactions |
| 106 | between plugins. |
| 107 | |
| 108 | Notes for using plugins with virtualenvs |
| 109 | ---------------------------------------- |
| 110 | |
| 111 | When using a tempest inside a virtualenv (like when running under tox) you have |
| 112 | to ensure that the package that contains your plugin is either installed in the |
| 113 | venv too or that you have system site-packages enabled. The virtualenv will |
| 114 | isolate the tempest install from the rest of your system so just installing the |
| 115 | plugin package on your system and then running tempest inside a venv will not |
| 116 | work. |
| 117 | |
| 118 | Tempest also exposes a tox job, all-plugin, which will setup a tox virtualenv |
| 119 | with system site-packages enabled. This will let you leverage tox without |
| 120 | requiring to manually install plugins in the tox venv before running tests. |