move audit-related code to backend
Add two functions in filebackend, to retrieve all audits, and to retrieve an audit script's config given the name. Replace occurences of utils.load_yaml in engine.py with calls to above functions Change-Id: Ia204d0db8a078c28ce27a2ae2ed57eb8b7fdf23b
This commit is contained in:
parent
d4fcac48f1
commit
e7c8fee0a8
|
@ -19,13 +19,25 @@ 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._audit_cfg = conf['audit_cfg']
|
||||||
|
self._repair_cfg = conf['repair_cfg']
|
||||||
self.setup()
|
self.setup()
|
||||||
|
|
||||||
def setup(self):
|
def setup(self):
|
||||||
utils.create_files([self._conf['audit_cfg'], self._conf['repair_cfg']])
|
utils.create_files([self._audit_cfg, self._repair_cfg])
|
||||||
|
|
||||||
def open(self):
|
def open(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def close(self):
|
def close(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
def get_audits(self):
|
||||||
|
audits = utils.load_yaml(self._audit_cfg)
|
||||||
|
return audits
|
||||||
|
|
||||||
|
def audit_cfg_from_name(self, name):
|
||||||
|
audits = self.get_audits()
|
||||||
|
conf = audits[name]['cfg']
|
||||||
|
audit_cfg = dict(utils.load_yaml(conf))
|
||||||
|
return audit_cfg
|
||||||
|
|
|
@ -100,7 +100,7 @@ class Engine(object):
|
||||||
scheduler = self.executor.submit(self.schedule)
|
scheduler = self.executor.submit(self.schedule)
|
||||||
self.futures.append(scheduler)
|
self.futures.append(scheduler)
|
||||||
|
|
||||||
#watchdog
|
# watchdog
|
||||||
watchdog_thread = self.start_watchdog(self.cfg_dir)
|
watchdog_thread = self.start_watchdog(self.cfg_dir)
|
||||||
watchdog_thread.join()
|
watchdog_thread.join()
|
||||||
|
|
||||||
|
@ -155,16 +155,15 @@ class Engine(object):
|
||||||
|
|
||||||
def run_serializer(self, next_iteration, current_time):
|
def run_serializer(self, next_iteration, current_time):
|
||||||
LOG.info("Running serializer for %s at %s", self.name, current_time)
|
LOG.info("Running serializer for %s at %s", self.name, current_time)
|
||||||
audits = utils.load_yaml(self.audit_cfg)
|
audits = self._backend_driver.get_audits()
|
||||||
schedules = {}
|
schedules = {}
|
||||||
if not audits:
|
if not audits:
|
||||||
return
|
return
|
||||||
try:
|
try:
|
||||||
for audit_name in audits:
|
for audit_name in audits:
|
||||||
conf = audits[audit_name]['cfg']
|
audit_cfg = self._backend_driver.audit_cfg_from_name(
|
||||||
audit_config = dict(utils.load_yaml(conf))
|
audit_name)
|
||||||
schedules[audit_name] = audit_config['schedule']
|
schedules[audit_name] = audit_cfg['schedule']
|
||||||
|
|
||||||
new_additions = []
|
new_additions = []
|
||||||
|
|
||||||
for key in six.iterkeys(schedules):
|
for key in six.iterkeys(schedules):
|
||||||
|
@ -202,11 +201,11 @@ 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 = 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']
|
||||||
audit_cfg = utils.load_yaml(audits[audit_name]['cfg'])
|
audit_cfg = self._backend_driver.audit_cfg_from_name(
|
||||||
|
audit_name)
|
||||||
future = self.executor.submit(self.run_audit,
|
future = self.executor.submit(self.run_audit,
|
||||||
audit_name=audit_name,
|
audit_name=audit_name,
|
||||||
**audit_cfg)
|
**audit_cfg)
|
||||||
|
|
Loading…
Reference in New Issue