blob: 2701f026330875c01cf11c8d0b027c3e6a57ef69 [file] [log] [blame]
Matthew Treinish7a518772015-07-01 12:46:41 -04001# 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
15import abc
Marc Koderer25319f62015-07-15 11:28:38 +020016import logging
Matthew Treinish7a518772015-07-01 12:46:41 -040017
18import six
19import stevedore
20from tempest_lib.common.utils import misc
21
22
Marc Koderer25319f62015-07-15 11:28:38 +020023LOG = logging.getLogger(__name__)
24
25
Matthew Treinish7a518772015-07-01 12:46:41 -040026@six.add_metaclass(abc.ABCMeta)
27class TempestPlugin(object):
28 """A TempestPlugin class provides the basic hooks for an external
29 plugin to provide tempest the necessary information to run the plugin.
30 """
31
32 @abc.abstractmethod
33 def load_tests(self):
34 """Method to return the information necessary to load the tests in the
35 plugin.
36
37 :return: a tuple with the first value being the test_dir and the second
38 being the top_level
39 :rtype: tuple
40 """
41 return
42
43
44@misc.singleton
45class TempestTestPluginManager(object):
46 """Tempest test plugin manager class
47
48 This class is used to manage the lifecycle of external tempest test
49 plugins. It provides functions for getting set
50 """
51 def __init__(self):
52 self.ext_plugins = stevedore.ExtensionManager(
Marc Koderer191419c2015-07-14 14:30:45 +020053 'tempest.test_plugins', invoke_on_load=True,
Marc Koderer25319f62015-07-15 11:28:38 +020054 propagate_map_exceptions=True,
55 on_load_failure_callback=self.failure_hook)
56
57 @staticmethod
58 def failure_hook(_, ep, err):
59 LOG.error('Could not load %r: %s', ep.name, err)
60 raise err
Matthew Treinish7a518772015-07-01 12:46:41 -040061
62 def get_plugin_load_tests_tuple(self):
63 load_tests_dict = {}
64 for plug in self.ext_plugins:
65 load_tests_dict[plug.name] = plug.obj.load_tests()
66 return load_tests_dict