Use init to configure plugins

Plugins currently use a couple configuration methods to set up field
data for the class. This seems superfluous. This change moves these
configuration steps into the init method so plugin classes can ingest
data as kwargs.

Here is an example of how the change will be implemented in plugins:
https://review.opendev.org/#/c/670171/

Change-Id: Ib26636f1eb4146902ee801af5bcce53d137be2ad
This commit is contained in:
Ian H. Pittwood 2019-07-10 14:36:43 -05:00 committed by Ian Pittwood
parent 601f281191
commit b3f1e59148
3 changed files with 3 additions and 33 deletions

View File

@ -91,9 +91,7 @@ def intermediary_processor(plugin_type, **kwargs):
# Extract data from plugin data source
LOG.info("Extract data from plugin data source")
data_extractor = plugin_class(kwargs['site_name'])
plugin_conf = data_extractor.get_plugin_conf(**kwargs)
data_extractor.set_config_opts(plugin_conf)
data_extractor = plugin_class(kwargs['site_name'], **kwargs)
data_extractor.extract_data()
# Apply any additional_config provided by user

View File

@ -23,40 +23,12 @@ LOG = logging.getLogger(__name__)
class BaseDataSourcePlugin(metaclass=abc.ABCMeta):
"""Provide basic hooks for data source plugins"""
def __init__(self, region):
def __init__(self, region, **kwargs):
self.source_type = None
self.source_name = None
self.region = region
self.site_data = None
@abc.abstractmethod
def set_config_opts(self, conf):
"""Placeholder to set configuration options specific to each plugin.
:param dict conf: Configuration options as dict
Example: conf = { 'excel_spec': 'spec1.yaml',
'excel_path': 'excel.xls' }
Each plugin will have their own config opts.
"""
return
@abc.abstractmethod
def get_plugin_conf(self, kwargs):
"""Validate and returns the plugin config parameters.
If validation fails, Spyglass exits.
:param char kwargs: Spyglass CLI parameters.
:returns plugin conf if successfully validated.
Each plugin implements their own validation mechanism.
"""
return {}
@abc.abstractmethod
def get_racks(self, region):
"""Return list of racks in the region

View File

@ -57,7 +57,7 @@ def _get_intermediary_data():
@mock.patch('spyglass.parser.engine.ProcessDataSource', autospec=True)
@mock.patch('spyglass_plugin_xls.excel.ExcelPlugin', autospec=True)
@mock.patch('spyglass_plugin_xls.excel.ExcelPlugin', autospec=False)
def test_intermediary_processor(mock_excel_plugin, mock_process_data_source):
"""Tests that the intermediary processor produces expected results"""
plugin_name = 'excel'