From d4fcac48f173b60608d4c6ac05b966aaac739489 Mon Sep 17 00:00:00 2001 From: pran1990 Date: Fri, 30 May 2014 20:51:37 -0700 Subject: [PATCH] Move cfg file creation to driver Added code to load the file backend as a driver in engine __init__, and a function in FileBackend to create cfg files. Also added extra field in engine.cfg to specify what kind of backend to use. Change-Id: I6d3f24d4f676c72c94afff2c4c7f54a35cf1d4b1 --- entropy/__main__.py | 2 -- entropy/backends/file_backend.py | 16 ++++++++++++---- entropy/engine.py | 15 ++++++++++++++- entropy/examples/cfg/test.cfg | 2 +- 4 files changed, 27 insertions(+), 8 deletions(-) diff --git a/entropy/__main__.py b/entropy/__main__.py index b310874..293ac8c 100644 --- a/entropy/__main__.py +++ b/entropy/__main__.py @@ -102,8 +102,6 @@ def start_engine(args): } } utils.write_yaml(cfg, engine_cfg) - # create cfg files - utils.create_files([cfg_data['audit_cfg'], cfg_data['repair_cfg']]) LOG.info('Added %s to engine cfg', args.name) entropy_engine = Engine(args.name, **cfg_data) entropy_engine.run() diff --git a/entropy/backends/file_backend.py b/entropy/backends/file_backend.py index af542da..70ab9ed 100644 --- a/entropy/backends/file_backend.py +++ b/entropy/backends/file_backend.py @@ -11,13 +11,21 @@ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. -import os - from entropy.backends import base +from entropy import utils class FileBackend(base.Backend): """A directory based backend.""" def __init__(self, conf): - super(FileBackend, self).__init(conf) - self.path = os.path.abspath(conf['path']) + super(FileBackend, self).__init__(conf) + self.setup() + + def setup(self): + utils.create_files([self._conf['audit_cfg'], self._conf['repair_cfg']]) + + def open(self): + pass + + def close(self): + pass diff --git a/entropy/engine.py b/entropy/engine.py index 8482de2..3deef3f 100644 --- a/entropy/engine.py +++ b/entropy/engine.py @@ -27,6 +27,7 @@ from kombu import Exchange from kombu import Queue import pause import six +from stevedore import driver from entropy import exceptions from entropy import utils @@ -40,6 +41,7 @@ class Engine(object): Engine.set_logger(**cfg_data) # constants # TODO(praneshp): Hardcode for now, could/should be cmdline input + self._engine_cfg_data = cfg_data self.max_workers = 8 self.audit_type = 'audit' self.repair_type = 'repair' @@ -52,6 +54,8 @@ class Engine(object): self.serializer_schedule = cfg_data['serializer_schedule'] self.engine_timeout = cfg_data['engine_timeout'] # TODO(praneshp): Assuming cfg files are in 1 dir. Change later + self._backend = cfg_data['backend'] + self._backend_driver = self.get_backend() self.cfg_dir = os.path.dirname(self.audit_cfg) self.log_file = cfg_data['log_file'] self.executor = cf.ThreadPoolExecutor(max_workers=self.max_workers) @@ -73,6 +77,15 @@ class Engine(object): LOG.addHandler(log_to_file) LOG.propagate = False + def get_backend(self): + backend = driver.DriverManager( + namespace='entropy.backend', + name=self._backend, + invoke_on_load=True, + invoke_args=(self._engine_cfg_data,), + ) + return backend.driver + def run(self): LOG.info('Starting Scheduler for %s', self.name) self.start_scheduler() @@ -189,7 +202,7 @@ class Engine(object): try: pause.until(execution_time) LOG.info("Time: %s, Starting %s", execution_time, audit_list) - audits = utils.load_yaml(self.audit_cfg) + audits = self._backend_driver.get_audits() audit_futures = [] for audit in audit_list: audit_name = audit['name'] diff --git a/entropy/examples/cfg/test.cfg b/entropy/examples/cfg/test.cfg index fbe6d5c..9f64cd9 100644 --- a/entropy/examples/cfg/test.cfg +++ b/entropy/examples/cfg/test.cfg @@ -5,4 +5,4 @@ test: log_format: "%(filename)s %(lineno)s %(message)s" serializer_schedule: "*/2 * * * *" engine_timeout: "25" - backend: EntropyFileBackend + backend: file