Browse Source

Merge "move audit-related code to backend"

Jenkins 4 years ago
parent
commit
aa01b73c14
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

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

Loading…
Cancel
Save