enable loading of external plugins with different base path
Change-Id: I2ef561aac446e2f3b9788c50f4822390775a6a40
This commit is contained in:
parent
a977d577cf
commit
6e87d4fd40
@ -22,7 +22,6 @@ from vitrage import keystone_client
|
||||
from vitrage import messaging
|
||||
from vitrage import opts
|
||||
|
||||
PLUGINS_PATH = 'vitrage.synchronizer.plugins.'
|
||||
LOG = log.getLogger(__name__)
|
||||
|
||||
|
||||
@ -36,13 +35,14 @@ def prepare_service(args=None, conf=None, config_files=None):
|
||||
conf.register_opts(list(options),
|
||||
group=None if group == 'DEFAULT' else group)
|
||||
|
||||
for plugin_name in conf.synchronizer_plugins.plugin_type:
|
||||
load_plugin(conf, plugin_name)
|
||||
|
||||
keystone_client.register_keystoneauth_opts(conf)
|
||||
conf(args, project='vitrage', validate_default_values=True,
|
||||
default_config_files=config_files)
|
||||
|
||||
for plugin_name in conf.synchronizer_plugins.plugin_type:
|
||||
load_plugin(conf, plugin_name, conf.synchronizer_plugins.plugin_path)
|
||||
|
||||
keystone_client.register_keystoneauth_opts(conf)
|
||||
|
||||
keystone_client.setup_keystoneauth(conf)
|
||||
log.setup(conf, 'vitrage')
|
||||
conf.log_opt_values(LOG, logging.DEBUG)
|
||||
@ -51,6 +51,14 @@ def prepare_service(args=None, conf=None, config_files=None):
|
||||
return conf
|
||||
|
||||
|
||||
def load_plugin(conf, name):
|
||||
opt = importutils.import_module(PLUGINS_PATH + name).OPTS
|
||||
conf.register_opts(list(opt), group=None if name == 'DEFAULT' else name)
|
||||
def load_plugin(conf, name, paths):
|
||||
for path in paths:
|
||||
try:
|
||||
opt = importutils.import_module("%s.%s" % (path, name)).OPTS
|
||||
conf.register_opts(list(opt),
|
||||
group=None if name == 'DEFAULT' else name)
|
||||
return
|
||||
except ImportError:
|
||||
pass
|
||||
|
||||
LOG.error("Failed to register config options for plugin %s" % name)
|
||||
|
@ -36,4 +36,7 @@ OPTS = [
|
||||
AODH_PLUGIN,
|
||||
CINDER_VOLUME_PLUGIN],
|
||||
help='Names of supported plugins'),
|
||||
cfg.ListOpt('plugin_path',
|
||||
default=['vitrage.synchronizer.plugins'],
|
||||
help='base path for plugins')
|
||||
]
|
||||
|
@ -49,7 +49,8 @@ class TestActionExecutor(TestEntityGraphFunctionalBase):
|
||||
cls.conf.register_opts(cls.PLUGINS_OPTS,
|
||||
group='synchronizer_plugins')
|
||||
for plugin_name in cls.conf.synchronizer_plugins.plugin_type:
|
||||
load_plugin(cls.conf, plugin_name)
|
||||
load_plugin(cls.conf, plugin_name,
|
||||
cls.conf.synchronizer_plugins.plugin_path)
|
||||
|
||||
def test_execute_update_vertex(self):
|
||||
|
||||
|
@ -45,6 +45,10 @@ class TestEntityGraphUnitBase(base.BaseTest):
|
||||
NOVA_INSTANCE_PLUGIN,
|
||||
NOVA_ZONE_PLUGIN],
|
||||
help='Names of supported synchronizer plugins'),
|
||||
|
||||
cfg.ListOpt('plugin_path',
|
||||
default=['vitrage.synchronizer.plugins'],
|
||||
help='base path for plugins')
|
||||
]
|
||||
|
||||
NUM_NODES = 1
|
||||
@ -55,7 +59,8 @@ class TestEntityGraphUnitBase(base.BaseTest):
|
||||
@staticmethod
|
||||
def load_plugins(conf):
|
||||
for plugin_name in conf.synchronizer_plugins.plugin_type:
|
||||
load_plugin(conf, plugin_name)
|
||||
load_plugin(conf, plugin_name,
|
||||
conf.synchronizer_plugins.plugin_path)
|
||||
|
||||
def _create_processor_with_graph(self, conf, processor=None):
|
||||
events = self._create_mock_events()
|
||||
|
@ -43,12 +43,17 @@ class TestStateManager(base.BaseTest):
|
||||
NOVA_INSTANCE_PLUGIN,
|
||||
NOVA_ZONE_PLUGIN],
|
||||
help='Names of supported synchronizer plugins'),
|
||||
|
||||
cfg.ListOpt('plugin_path',
|
||||
default=['vitrage.synchronizer.plugins'],
|
||||
help='base path for plugins')
|
||||
]
|
||||
|
||||
@staticmethod
|
||||
def _load_plugins(conf):
|
||||
for plugin_name in conf.synchronizer_plugins.plugin_type:
|
||||
load_plugin(conf, plugin_name)
|
||||
load_plugin(conf, plugin_name,
|
||||
conf.synchronizer_plugins.plugin_path)
|
||||
|
||||
# noinspection PyAttributeOutsideInit
|
||||
def setUp(self):
|
||||
|
@ -43,6 +43,10 @@ class TransformerManagerTest(base.BaseTest):
|
||||
NOVA_INSTANCE_PLUGIN,
|
||||
NOVA_ZONE_PLUGIN],
|
||||
help='Names of supported synchronizer plugins'),
|
||||
|
||||
cfg.ListOpt('plugin_path',
|
||||
default=['vitrage.synchronizer.plugins'],
|
||||
help='base path for plugins')
|
||||
]
|
||||
|
||||
# noinspection PyPep8Naming
|
||||
@ -51,7 +55,8 @@ class TransformerManagerTest(base.BaseTest):
|
||||
cls.conf = cfg.ConfigOpts()
|
||||
cls.conf.register_opts(cls.OPTS, group='synchronizer_plugins')
|
||||
for plugin_name in cls.conf.synchronizer_plugins.plugin_type:
|
||||
load_plugin(cls.conf, plugin_name)
|
||||
load_plugin(cls.conf, plugin_name,
|
||||
cls.conf.synchronizer_plugins.plugin_path)
|
||||
cls.manager = TransformerManager(cls.conf)
|
||||
|
||||
def test_transformer_registration_nagios(self):
|
||||
|
Loading…
x
Reference in New Issue
Block a user