]> git.ipfire.org Git - people/ms/nitsi.git/blobdiff - src/nitsi/test.py
Sort imports: part 1
[people/ms/nitsi.git] / src / nitsi / test.py
index 96ce841083b01a965d8ecc2b3b9f79be4414b7df..95db2136a047f96fc652d6e028b11da2dd5cab75 100755 (executable)
@@ -1,18 +1,20 @@
 #!/usr/bin/python3
 
-
+import configparser
 import libvirt
-
+import logging
 import os
+import time
 
-import configparser
+from .recipe import recipe
+from .virtual_environ import virtual_environ
 
-from nitsi.virtual_environ import virtual_environ
-from nitsi.recipe import recipe
+logger = logging.getLogger("nitsi.test")
 
-import logging
 
-logger = logging.getLogger("nitsi.test")
+class TestException(Exception):
+    def __init__(self, message):
+        self.message = message
 
 class test():
     def __init__(self, path, log_path):
@@ -73,10 +75,18 @@ class test():
             self.virtual_machines[name].copy_in(self.copy_from, self.copy_to)
             self.virtual_machines[name].start()
 
+        # Time to which all serial output log entries are relativ
+        log_start_time = time.time()
+
+        # 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")
         for name in self.virtual_environ.machine_names:
             self.log.debug("Try to login on {}".format(name))
-            self.virtual_machines[name].login("{}/test.log".format(self.log_path))
+            self.virtual_machines[name].login("{}/test.log".format(self.log_path),
+                                                log_start_time=log_start_time,
+                                                longest_machine_name=longest_machine_name)
 
     def load_recipe(self):
         self.log.info("Going to load the recipe")
@@ -95,11 +105,9 @@ 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))
 
@@ -111,6 +119,3 @@ class test():
 
         for name in self.virtual_environ.network_names:
             self.virtual_networks[name].undefine()
-
-
-