]> git.ipfire.org Git - nitsi.git/blobdiff - src/nitsi/test.py
Set log level of login to info
[nitsi.git] / src / nitsi / test.py
index ecbe5f059795731ab1151520b655eefdcc2c6d96..c49c0f395d21b16e132ffe2cfe9199e370cb7712 100755 (executable)
@@ -1,21 +1,21 @@
 #!/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")
 
+
+class TestException(Exception):
+    def __init__(self, message):
+        self.message = message
+
 class test():
     def __init__(self, path, log_path):
         try:
@@ -23,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))
 
@@ -58,7 +59,7 @@ class test():
         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()
 
@@ -81,9 +82,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)
@@ -91,7 +92,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)
             for line in self.recipe.recipe:
                 self.log.debug(line)
 
@@ -105,22 +106,26 @@ class test():
             return_value = self.virtual_machines[line[0]].cmd(line[2])
             self.log.debug("Return value is: {}".format(return_value))
             if return_value != "0" and line[1] == "":
-                self.log.error("Failed to execute command '{}' on {}, return code: {}".format(line[2],line[0], return_value))
-                return False
+                raise TestException("Failed to execute command '{}' on {}, return code: {}".format(line[2],line[0], return_value))
             elif return_value == "0" and line[1] == "!":
-                self.log.error("Succeded to execute command '{}' on {}, return code: {}".format(line[2],line[0],return_value))
-                return False
+                raise TestException("Succeded to execute command '{}' on {}, return code: {}".format(line[2],line[0],return_value))
             else:
                 self.log.debug("Command '{}' on {} returned with: {}".format(line[2],line[0],return_value))
 
     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)