summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpran1990 <praneshpg@gmail.com>2014-05-31 00:47:05 -0700
committerPranesh Pandurangan <praneshpg@gmail.com>2014-06-05 02:24:19 -0700
commite7c8fee0a80466cae14264a94c044a5a5349b8a4 (patch)
tree646b9fc08bc2009b6654f22da7b169afa42bd303
parentd4fcac48f173b60608d4c6ac05b966aaac739489 (diff)
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
Notes
Notes (review): Verified+2: Jenkins Code-Review+2: Pranesh Pandurangan <praneshpg@gmail.com> Workflow+1: Pranesh Pandurangan <praneshpg@gmail.com> Submitted-by: Jenkins Submitted-at: Thu, 05 Jun 2014 09:38:18 +0000 Reviewed-on: https://review.openstack.org/97021 Project: stackforge/entropy Branch: refs/heads/master
-rw-r--r--entropy/backends/file_backend.py14
-rw-r--r--entropy/engine.py15
2 files changed, 20 insertions, 9 deletions
diff --git a/entropy/backends/file_backend.py b/entropy/backends/file_backend.py
index 70ab9ed..9235842 100644
--- a/entropy/backends/file_backend.py
+++ b/entropy/backends/file_backend.py
@@ -19,13 +19,25 @@ class FileBackend(base.Backend):
19 """A directory based backend.""" 19 """A directory based backend."""
20 def __init__(self, conf): 20 def __init__(self, conf):
21 super(FileBackend, self).__init__(conf) 21 super(FileBackend, self).__init__(conf)
22 self._audit_cfg = conf['audit_cfg']
23 self._repair_cfg = conf['repair_cfg']
22 self.setup() 24 self.setup()
23 25
24 def setup(self): 26 def setup(self):
25 utils.create_files([self._conf['audit_cfg'], self._conf['repair_cfg']]) 27 utils.create_files([self._audit_cfg, self._repair_cfg])
26 28
27 def open(self): 29 def open(self):
28 pass 30 pass
29 31
30 def close(self): 32 def close(self):
31 pass 33 pass
34
35 def get_audits(self):
36 audits = utils.load_yaml(self._audit_cfg)
37 return audits
38
39 def audit_cfg_from_name(self, name):
40 audits = self.get_audits()
41 conf = audits[name]['cfg']
42 audit_cfg = dict(utils.load_yaml(conf))
43 return audit_cfg
diff --git a/entropy/engine.py b/entropy/engine.py
index 3deef3f..2fd32f3 100644
--- a/entropy/engine.py
+++ b/entropy/engine.py
@@ -100,7 +100,7 @@ class Engine(object):
100 scheduler = self.executor.submit(self.schedule) 100 scheduler = self.executor.submit(self.schedule)
101 self.futures.append(scheduler) 101 self.futures.append(scheduler)
102 102
103 #watchdog 103 # watchdog
104 watchdog_thread = self.start_watchdog(self.cfg_dir) 104 watchdog_thread = self.start_watchdog(self.cfg_dir)
105 watchdog_thread.join() 105 watchdog_thread.join()
106 106
@@ -155,16 +155,15 @@ class Engine(object):
155 155
156 def run_serializer(self, next_iteration, current_time): 156 def run_serializer(self, next_iteration, current_time):
157 LOG.info("Running serializer for %s at %s", self.name, current_time) 157 LOG.info("Running serializer for %s at %s", self.name, current_time)
158 audits = utils.load_yaml(self.audit_cfg) 158 audits = self._backend_driver.get_audits()
159 schedules = {} 159 schedules = {}
160 if not audits: 160 if not audits:
161 return 161 return
162 try: 162 try:
163 for audit_name in audits: 163 for audit_name in audits:
164 conf = audits[audit_name]['cfg'] 164 audit_cfg = self._backend_driver.audit_cfg_from_name(
165 audit_config = dict(utils.load_yaml(conf)) 165 audit_name)
166 schedules[audit_name] = audit_config['schedule'] 166 schedules[audit_name] = audit_cfg['schedule']
167
168 new_additions = [] 167 new_additions = []
169 168
170 for key in six.iterkeys(schedules): 169 for key in six.iterkeys(schedules):
@@ -202,11 +201,11 @@ class Engine(object):
202 try: 201 try:
203 pause.until(execution_time) 202 pause.until(execution_time)
204 LOG.info("Time: %s, Starting %s", execution_time, audit_list) 203 LOG.info("Time: %s, Starting %s", execution_time, audit_list)
205 audits = self._backend_driver.get_audits()
206 audit_futures = [] 204 audit_futures = []
207 for audit in audit_list: 205 for audit in audit_list:
208 audit_name = audit['name'] 206 audit_name = audit['name']
209 audit_cfg = utils.load_yaml(audits[audit_name]['cfg']) 207 audit_cfg = self._backend_driver.audit_cfg_from_name(
208 audit_name)
210 future = self.executor.submit(self.run_audit, 209 future = self.executor.submit(self.run_audit,
211 audit_name=audit_name, 210 audit_name=audit_name,
212 **audit_cfg) 211 **audit_cfg)