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
This commit is contained in:
parent
0f5954359c
commit
d4fcac48f1
|
@ -102,8 +102,6 @@ def start_engine(args):
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
utils.write_yaml(cfg, engine_cfg)
|
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)
|
LOG.info('Added %s to engine cfg', args.name)
|
||||||
entropy_engine = Engine(args.name, **cfg_data)
|
entropy_engine = Engine(args.name, **cfg_data)
|
||||||
entropy_engine.run()
|
entropy_engine.run()
|
||||||
|
|
|
@ -11,13 +11,21 @@
|
||||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
import os
|
|
||||||
|
|
||||||
from entropy.backends import base
|
from entropy.backends import base
|
||||||
|
from entropy import utils
|
||||||
|
|
||||||
|
|
||||||
class FileBackend(base.Backend):
|
class FileBackend(base.Backend):
|
||||||
"""A directory based backend."""
|
"""A directory based backend."""
|
||||||
def __init__(self, conf):
|
def __init__(self, conf):
|
||||||
super(FileBackend, self).__init(conf)
|
super(FileBackend, self).__init__(conf)
|
||||||
self.path = os.path.abspath(conf['path'])
|
self.setup()
|
||||||
|
|
||||||
|
def setup(self):
|
||||||
|
utils.create_files([self._conf['audit_cfg'], self._conf['repair_cfg']])
|
||||||
|
|
||||||
|
def open(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def close(self):
|
||||||
|
pass
|
||||||
|
|
|
@ -27,6 +27,7 @@ from kombu import Exchange
|
||||||
from kombu import Queue
|
from kombu import Queue
|
||||||
import pause
|
import pause
|
||||||
import six
|
import six
|
||||||
|
from stevedore import driver
|
||||||
|
|
||||||
from entropy import exceptions
|
from entropy import exceptions
|
||||||
from entropy import utils
|
from entropy import utils
|
||||||
|
@ -40,6 +41,7 @@ class Engine(object):
|
||||||
Engine.set_logger(**cfg_data)
|
Engine.set_logger(**cfg_data)
|
||||||
# constants
|
# constants
|
||||||
# TODO(praneshp): Hardcode for now, could/should be cmdline input
|
# TODO(praneshp): Hardcode for now, could/should be cmdline input
|
||||||
|
self._engine_cfg_data = cfg_data
|
||||||
self.max_workers = 8
|
self.max_workers = 8
|
||||||
self.audit_type = 'audit'
|
self.audit_type = 'audit'
|
||||||
self.repair_type = 'repair'
|
self.repair_type = 'repair'
|
||||||
|
@ -52,6 +54,8 @@ class Engine(object):
|
||||||
self.serializer_schedule = cfg_data['serializer_schedule']
|
self.serializer_schedule = cfg_data['serializer_schedule']
|
||||||
self.engine_timeout = cfg_data['engine_timeout']
|
self.engine_timeout = cfg_data['engine_timeout']
|
||||||
# TODO(praneshp): Assuming cfg files are in 1 dir. Change later
|
# 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.cfg_dir = os.path.dirname(self.audit_cfg)
|
||||||
self.log_file = cfg_data['log_file']
|
self.log_file = cfg_data['log_file']
|
||||||
self.executor = cf.ThreadPoolExecutor(max_workers=self.max_workers)
|
self.executor = cf.ThreadPoolExecutor(max_workers=self.max_workers)
|
||||||
|
@ -73,6 +77,15 @@ class Engine(object):
|
||||||
LOG.addHandler(log_to_file)
|
LOG.addHandler(log_to_file)
|
||||||
LOG.propagate = False
|
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):
|
def run(self):
|
||||||
LOG.info('Starting Scheduler for %s', self.name)
|
LOG.info('Starting Scheduler for %s', self.name)
|
||||||
self.start_scheduler()
|
self.start_scheduler()
|
||||||
|
@ -189,7 +202,7 @@ class Engine(object):
|
||||||
try:
|
try:
|
||||||
pause.until(execution_time)
|
pause.until(execution_time)
|
||||||
LOG.info("Time: %s, Starting %s", execution_time, audit_list)
|
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 = []
|
audit_futures = []
|
||||||
for audit in audit_list:
|
for audit in audit_list:
|
||||||
audit_name = audit['name']
|
audit_name = audit['name']
|
||||||
|
|
|
@ -5,4 +5,4 @@ test:
|
||||||
log_format: "%(filename)s %(lineno)s %(message)s"
|
log_format: "%(filename)s %(lineno)s %(message)s"
|
||||||
serializer_schedule: "*/2 * * * *"
|
serializer_schedule: "*/2 * * * *"
|
||||||
engine_timeout: "25"
|
engine_timeout: "25"
|
||||||
backend: EntropyFileBackend
|
backend: file
|
||||||
|
|
Loading…
Reference in New Issue