From b3f1e59148d4ca929dc1884caa9cb3b120cbe509 Mon Sep 17 00:00:00 2001 From: "Ian H. Pittwood" Date: Wed, 10 Jul 2019 14:36:43 -0500 Subject: [PATCH] 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 --- spyglass/cli.py | 4 +--- spyglass/data_extractor/base.py | 30 +----------------------------- tests/unit/test_cli.py | 2 +- 3 files changed, 3 insertions(+), 33 deletions(-) diff --git a/spyglass/cli.py b/spyglass/cli.py index c5d53d3..ec40b73 100644 --- a/spyglass/cli.py +++ b/spyglass/cli.py @@ -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 diff --git a/spyglass/data_extractor/base.py b/spyglass/data_extractor/base.py index d1c25f7..5b5baef 100755 --- a/spyglass/data_extractor/base.py +++ b/spyglass/data_extractor/base.py @@ -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 diff --git a/tests/unit/test_cli.py b/tests/unit/test_cli.py index 2346bdb..be75d49 100644 --- a/tests/unit/test_cli.py +++ b/tests/unit/test_cli.py @@ -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'