]> git.ipfire.org Git - nitsi.git/blobdiff - src/nitsi/test.py
Make all parameters in the ini file lower-case
[nitsi.git] / src / nitsi / test.py
index 1f7728f2f3b4747c40e5960b72b64a8e4abe2583..1b880d251b7c19587ceb5891a51f5750f7d48886 100755 (executable)
@@ -1,18 +1,13 @@
 #!/usr/bin/python3
 
-
+import configparser
 import libvirt
-
+import logging
 import os
-
-import configparser
-
 import time
 
-from nitsi.virtual_environ import virtual_environ
-from nitsi.recipe import recipe
-
-import logging
+from . import recipe
+from . import virtual_environ
 
 logger = logging.getLogger("nitsi.test")
 
@@ -28,6 +23,7 @@ class test():
             self.log = logger.getChild(os.path.basename(self.path))
         except BaseException as e:
             logger.error("Could not get absolute path")
+            raise e
 
         self.log.debug("Path of this test is: {}".format(self.path))
 
@@ -44,26 +40,37 @@ class test():
     def read_settings(self):
         self.config = configparser.ConfigParser()
         self.config.read(self.settings_file)
-        self.name = self.config["DEFAULT"]["Name"]
-        self.description = self.config["DEFAULT"]["Description"]
-        self.copy_to = self.config["DEFAULT"]["Copy_to"]
-        self.copy_from = self.config["DEFAULT"]["Copy_from"]
+        self.name = self.config["DEFAULT"]["name"]
+        self.description = self.config["DEFAULT"]["description"]
+        self.copy_to = self.config["DEFAULT"]["copy_to"]
+        self.copy_from = self.config["DEFAULT"]["copy_from"]
         self.copy_from = self.copy_from.split(",")
 
         tmp = []
         for file in self.copy_from:
             file = file.strip()
-            file = os.path.normpath(self.path + "/" + file)
-            tmp.append(file)
+            # If file is empty we do not want to add it to the list
+            if not file == "":
+                # If we get an absolut path we do nothing
+                # If not we add self.path to get an absolut path
+                if not os.path.isabs(file):
+                    file = os.path.normpath(self.path + "/" + file)
+
+                # We need to check if file is a valid file or dir
+                if not (os.path.isdir(file) or os.path.isfile(file)):
+                    raise TestException("'{}' is not a valid file nor a valid directory".format(file))
+
+                self.log.debug("'{}' will be copied into all images".format(file))
+                tmp.append(file)
 
         self.copy_from = tmp
 
-        self.virtual_environ_name = self.config["VIRTUAL_ENVIRONMENT"]["Name"]
-        self.virtual_environ_path = self.config["VIRTUAL_ENVIRONMENT"]["Path"]
+        self.virtual_environ_name = self.config["VIRTUAL_ENVIRONMENT"]["name"]
+        self.virtual_environ_path = self.config["VIRTUAL_ENVIRONMENT"]["path"]
         self.virtual_environ_path = os.path.normpath(self.path + "/" + self.virtual_environ_path)
 
     def virtual_environ_setup(self):
-        self.virtual_environ = virtual_environ(self.virtual_environ_path)
+        self.virtual_environ = virtual_environ.virtual_environ(self.virtual_environ_path)
 
         self.virtual_networks = self.virtual_environ.get_networks()
 
@@ -86,9 +93,9 @@ class test():
         # Number of chars of the longest machine name
         longest_machine_name = self.virtual_environ.longest_machine_name
 
-        self.log.debug("Try to login on all machines")
+        self.log.info("Try to login on all machines")
         for name in self.virtual_environ.machine_names:
-            self.log.debug("Try to login on {}".format(name))
+            self.log.info("Try to login on {}".format(name))
             self.virtual_machines[name].login("{}/test.log".format(self.log_path),
                                                 log_start_time=log_start_time,
                                                 longest_machine_name=longest_machine_name)
@@ -96,7 +103,7 @@ class test():
     def load_recipe(self):
         self.log.info("Going to load the recipe")
         try:
-            self.recipe = recipe(self.recipe_file)
+            self.recipe = recipe.recipe(self.recipe_file, machines=self.virtual_environ.machine_names)
             for line in self.recipe.recipe:
                 self.log.debug(line)
 
@@ -118,12 +125,18 @@ class test():
 
     def virtual_environ_stop(self):
         for name in self.virtual_environ.machine_names:
-            self.virtual_machines[name].shutdown()
-            self.virtual_machines[name].revert_snapshot()
-            self.virtual_machines[name].undefine()
+            # We just catch exception here to avoid
+            # that we stop the cleanup process if only  one command fails
+            try:
+                self.virtual_machines[name].shutdown()
+                self.virtual_machines[name].revert_snapshot()
+                self.virtual_machines[name].undefine()
+            except BaseException as e:
+                self.log.exception(e)
 
         for name in self.virtual_environ.network_names:
-            self.virtual_networks[name].undefine()
-
-
+            try:
+                self.virtual_networks[name].undefine()
+            except BaseException as e:
+                 self.log.exception(e)