Browse Source

Merge "Move cfg file creation to driver"

Jenkins 4 years ago
parent
commit
af40dcba1b
4 changed files with 27 additions and 8 deletions
  1. 0
    2
      entropy/__main__.py
  2. 12
    4
      entropy/backends/file_backend.py
  3. 14
    1
      entropy/engine.py
  4. 1
    1
      entropy/examples/cfg/test.cfg

+ 0
- 2
entropy/__main__.py View File

@@ -102,8 +102,6 @@ def start_engine(args):
102 102
         }
103 103
     }
104 104
     utils.write_yaml(cfg, engine_cfg)
105
-    # create cfg files
106
-    utils.create_files([cfg_data['audit_cfg'], cfg_data['repair_cfg']])
107 105
     LOG.info('Added %s to engine cfg', args.name)
108 106
     entropy_engine = Engine(args.name, **cfg_data)
109 107
     entropy_engine.run()

+ 12
- 4
entropy/backends/file_backend.py View File

@@ -11,13 +11,21 @@
11 11
 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12 12
 # License for the specific language governing permissions and limitations
13 13
 # under the License.
14
-import os
15
-
16 14
 from entropy.backends import base
15
+from entropy import utils
17 16
 
18 17
 
19 18
 class FileBackend(base.Backend):
20 19
     """A directory based backend."""
21 20
     def __init__(self, conf):
22
-        super(FileBackend, self).__init(conf)
23
-        self.path = os.path.abspath(conf['path'])
21
+        super(FileBackend, self).__init__(conf)
22
+        self.setup()
23
+
24
+    def setup(self):
25
+        utils.create_files([self._conf['audit_cfg'], self._conf['repair_cfg']])
26
+
27
+    def open(self):
28
+        pass
29
+
30
+    def close(self):
31
+        pass

+ 14
- 1
entropy/engine.py View File

@@ -27,6 +27,7 @@ from kombu import Exchange
27 27
 from kombu import Queue
28 28
 import pause
29 29
 import six
30
+from stevedore import driver
30 31
 
31 32
 from entropy import exceptions
32 33
 from entropy import utils
@@ -40,6 +41,7 @@ class Engine(object):
40 41
         Engine.set_logger(**cfg_data)
41 42
         # constants
42 43
         # TODO(praneshp): Hardcode for now, could/should be cmdline input
44
+        self._engine_cfg_data = cfg_data
43 45
         self.max_workers = 8
44 46
         self.audit_type = 'audit'
45 47
         self.repair_type = 'repair'
@@ -52,6 +54,8 @@ class Engine(object):
52 54
         self.serializer_schedule = cfg_data['serializer_schedule']
53 55
         self.engine_timeout = cfg_data['engine_timeout']
54 56
         # TODO(praneshp): Assuming cfg files are in 1 dir. Change later
57
+        self._backend = cfg_data['backend']
58
+        self._backend_driver = self.get_backend()
55 59
         self.cfg_dir = os.path.dirname(self.audit_cfg)
56 60
         self.log_file = cfg_data['log_file']
57 61
         self.executor = cf.ThreadPoolExecutor(max_workers=self.max_workers)
@@ -75,6 +79,15 @@ class Engine(object):
75 79
         LOG.addHandler(log_to_file)
76 80
         LOG.propagate = False
77 81
 
82
+    def get_backend(self):
83
+        backend = driver.DriverManager(
84
+            namespace='entropy.backend',
85
+            name=self._backend,
86
+            invoke_on_load=True,
87
+            invoke_args=(self._engine_cfg_data,),
88
+        )
89
+        return backend.driver
90
+
78 91
     def run(self):
79 92
         LOG.info('Starting Scheduler for %s', self.name)
80 93
         self.start_scheduler()
@@ -186,7 +199,7 @@ class Engine(object):
186 199
         try:
187 200
             pause.until(execution_time)
188 201
             LOG.info("Time: %s, Starting %s", execution_time, audit_list)
189
-            audits = utils.load_yaml(self.audit_cfg)
202
+            audits = self._backend_driver.get_audits()
190 203
             audit_futures = []
191 204
             for audit in audit_list:
192 205
                 audit_name = audit['name']

+ 1
- 1
entropy/examples/cfg/test.cfg View File

@@ -5,4 +5,4 @@ test:
5 5
     log_format: "%(filename)s %(lineno)s %(message)s"
6 6
     serializer_schedule: "*/2 * * * *"
7 7
     engine_timeout: "25"
8
-    backend: EntropyFileBackend
8
+    backend: file

Loading…
Cancel
Save