]> git.ipfire.org Git - nitsi.git/commitdiff
Add self.settings and store all settings in a dictionary
authorJonatan Schlag <jonatan.schlag@ipfire.org>
Wed, 20 Jun 2018 09:57:00 +0000 (11:57 +0200)
committerJonatan Schlag <jonatan.schlag@ipfire.org>
Wed, 20 Jun 2018 09:57:00 +0000 (11:57 +0200)
Signed-off-by: Jonatan Schlag <jonatan.schlag@ipfire.org>
src/nitsi/test.py

index 6ddf96766eb8cff46004fe5b407b3f6277b08662..67968dcc8bfbd4265f2b3a558f28aa5ec0e40ba7 100755 (executable)
@@ -17,7 +17,10 @@ class TestException(Exception):
         self.message = message
 
 class Test():
-    def __init__(self, path, log_path):
+    def __init__(self, path, log_path, settings=None):
+        # init settings var
+        self.settings = {}
+
         try:
             self.path = os.path.abspath(path)
             self.log = logger.getChild(os.path.basename(self.path))
@@ -39,6 +42,8 @@ class Test():
             self.log.error("No such file: {}".format(self.recipe_file))
             raise TestException("No recipe file found")
 
+        self.cmd_settings = settings
+
     def read_settings(self):
         self.log.debug("Going to read all settings from the ini file")
         try:
@@ -48,25 +53,25 @@ class Test():
             self.log.error("Failed to parse the config")
             raise e
 
-        self.name = self.config.get("GENERAL","name", fallback="")
-        self.description = self.config.get("GENERAL", "description",  fallback="")
-        self.copy_to = self.config.get("GENERAL", "copy_to", fallback=None)
-        self.copy_from = self.config.get("GENERAL", "copy_from", fallback=None)
-        self.virtual_environ_path = self.config.get("VIRTUAL_ENVIRONMENT", "path", fallback=None)
+        self.settings["name"] = self.config.get("GENERAL","name", fallback="")
+        self.settings["description"] = self.config.get("GENERAL", "description",  fallback="")
+        self.settings["copy_to"] = self.config.get("GENERAL", "copy_to", fallback=None)
+        self.settings["copy_from"] = self.config.get("GENERAL", "copy_from", fallback=None)
+        self.settings["virtual_environ_path"] = self.config.get("VIRTUAL_ENVIRONMENT", "path", fallback=None)
 
-        if not self.virtual_environ_path:
+        if not self.settings["virtual_environ_path"]:
             self.log.error("No path for virtual environment found.")
             raise TestException("No path for virtual environment found.")
 
-        self.virtual_environ_path = os.path.normpath(self.path + "/" + self.virtual_environ_path)
+        self.settings["virtual_environ_path"] = os.path.normpath(self.path + "/" + self.settings["virtual_environ_path"])
 
         # Parse copy_from setting
-        if self.copy_from:
+        if self.settings["copy_from"]:
             self.log.debug("Going to parse the copy_from setting.")
-            self.copy_from = self.copy_from.split(",")
+            self.settings["copy_from"] = self.settings["copy_from"].split(",")
 
             tmp = []
-            for file in self.copy_from:
+            for file in self.settings["copy_from"]:
                 file = file.strip()
                 # If file is empty we do not want to add it to the list
                 if not file == "":
@@ -82,12 +87,12 @@ class Test():
                     self.log.debug("'{}' will be copied into all images".format(file))
                     tmp.append(file)
 
-            self.copy_from = tmp
+            self.settings["copy_from"] = tmp
 
 
 
     def virtual_environ_setup(self):
-        self.virtual_environ = virtual_environ.Virtual_environ(self.virtual_environ_path)
+        self.virtual_environ = virtual_environ.Virtual_environ(self.settings["virtual_environ_path"])
 
         self.virtual_networks = self.virtual_environ.get_networks()
 
@@ -102,8 +107,8 @@ class Test():
             self.virtual_machines[name].define()
             self.virtual_machines[name].create_snapshot()
             # We can only copy files when we know which and to which dir
-            if self.copy_from and self.copy_to:
-                self.virtual_machines[name].copy_in(self.copy_from, self.copy_to)
+            if self.settings["copy_from"] and self.settings["copy_to"]:
+                self.virtual_machines[name].copy_in(self.settings["copy_from"], self.settings["copy_to"])
             self.virtual_machines[name].start()
 
         # Time to which all serial output log entries are relativ