Matthew Treinish | 7a51877 | 2015-07-01 12:46:41 -0400 | [diff] [blame^] | 1 | # Copyright (c) 2015 Hewlett-Packard Development Company, L.P. |
| 2 | # |
| 3 | # Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 4 | # not use this file except in compliance with the License. You may obtain |
| 5 | # a copy of the License at |
| 6 | # |
| 7 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | # |
| 9 | # Unless required by applicable law or agreed to in writing, software |
| 10 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 11 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 12 | # License for the specific language governing permissions and limitations |
| 13 | # under the License. |
| 14 | |
| 15 | import abc |
| 16 | |
| 17 | import six |
| 18 | import stevedore |
| 19 | from tempest_lib.common.utils import misc |
| 20 | |
| 21 | |
| 22 | @six.add_metaclass(abc.ABCMeta) |
| 23 | class TempestPlugin(object): |
| 24 | """A TempestPlugin class provides the basic hooks for an external |
| 25 | plugin to provide tempest the necessary information to run the plugin. |
| 26 | """ |
| 27 | |
| 28 | @abc.abstractmethod |
| 29 | def load_tests(self): |
| 30 | """Method to return the information necessary to load the tests in the |
| 31 | plugin. |
| 32 | |
| 33 | :return: a tuple with the first value being the test_dir and the second |
| 34 | being the top_level |
| 35 | :rtype: tuple |
| 36 | """ |
| 37 | return |
| 38 | |
| 39 | |
| 40 | @misc.singleton |
| 41 | class TempestTestPluginManager(object): |
| 42 | """Tempest test plugin manager class |
| 43 | |
| 44 | This class is used to manage the lifecycle of external tempest test |
| 45 | plugins. It provides functions for getting set |
| 46 | """ |
| 47 | def __init__(self): |
| 48 | self.ext_plugins = stevedore.ExtensionManager( |
| 49 | 'tempest.test.plugins', invoke_on_load=True, |
| 50 | propagate_map_exceptions=True) |
| 51 | |
| 52 | def get_plugin_load_tests_tuple(self): |
| 53 | load_tests_dict = {} |
| 54 | for plug in self.ext_plugins: |
| 55 | load_tests_dict[plug.name] = plug.obj.load_tests() |
| 56 | return load_tests_dict |