Browse Source

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
changes/21/97021/5
pran1990 5 years ago
parent
commit
e7c8fee0a8
2 changed files with 20 additions and 9 deletions
  1. 13
    1
      entropy/backends/file_backend.py
  2. 7
    8
      entropy/engine.py

+ 13
- 1
entropy/backends/file_backend.py View File

@@ -19,13 +19,25 @@ class FileBackend(base.Backend):
19 19
     """A directory based backend."""
20 20
     def __init__(self, conf):
21 21
         super(FileBackend, self).__init__(conf)
22
+        self._audit_cfg = conf['audit_cfg']
23
+        self._repair_cfg = conf['repair_cfg']
22 24
         self.setup()
23 25
 
24 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 29
     def open(self):
28 30
         pass
29 31
 
30 32
     def close(self):
31 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

+ 7
- 8
entropy/engine.py View File

@@ -100,7 +100,7 @@ class Engine(object):
100 100
         scheduler = self.executor.submit(self.schedule)
101 101
         self.futures.append(scheduler)
102 102
 
103
-        #watchdog
103
+        # watchdog
104 104
         watchdog_thread = self.start_watchdog(self.cfg_dir)
105 105
         watchdog_thread.join()
106 106
 
@@ -155,16 +155,15 @@ class Engine(object):
155 155
 
156 156
     def run_serializer(self, next_iteration, current_time):
157 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 159
         schedules = {}
160 160
         if not audits:
161 161
             return
162 162
         try:
163 163
             for audit_name in audits:
164
-                conf = audits[audit_name]['cfg']
165
-                audit_config = dict(utils.load_yaml(conf))
166
-                schedules[audit_name] = audit_config['schedule']
167
-
164
+                audit_cfg = self._backend_driver.audit_cfg_from_name(
165
+                    audit_name)
166
+                schedules[audit_name] = audit_cfg['schedule']
168 167
             new_additions = []
169 168
 
170 169
             for key in six.iterkeys(schedules):
@@ -202,11 +201,11 @@ class Engine(object):
202 201
         try:
203 202
             pause.until(execution_time)
204 203
             LOG.info("Time: %s, Starting %s", execution_time, audit_list)
205
-            audits = self._backend_driver.get_audits()
206 204
             audit_futures = []
207 205
             for audit in audit_list:
208 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 209
                 future = self.executor.submit(self.run_audit,
211 210
                                               audit_name=audit_name,
212 211
                                               **audit_cfg)

Loading…
Cancel
Save