]> git.ipfire.org Git - nitsi.git/blobdiff - test.py
Recipe: split only at the first occurrence of :
[nitsi.git] / test.py
diff --git a/test.py b/test.py
index 26b483a7712138fb9c433994120ea896ecf7e5e2..9ea57981e5b4a47acad742d593c40fe1e965e44f 100755 (executable)
--- a/test.py
+++ b/test.py
@@ -7,54 +7,20 @@ import os
 
 import configparser
 
-from disk import disk
-
-class log():
-    def __init__(self, log_level):
-        self.log_level = log_level
-
-    def debug(self, string):
-        if self.log_level >= 4:
-            print("DEBUG: {}".format(string))
-
-    def error(self, string):
-        print("ERROR: {}".format(string))
-
-class libvirt_con():
-    def __init__(self, uri):
-        self.log = log(4)
-        self.uri = uri
-        self.connection = None
-
-    def get_domain_from_name(self, name):
-        dom = self.con.lookupByName(name)
-
-        if dom == None:
-            raise BaseException
-        return dom
-
-    @property
-    def con(self):
-        if self.connection == None:
-            try:
-                self.connection = libvirt.open(self.uri)
-            except BaseException as error:
-                self.log.error("Could not connect to: {}".format(self.uri))
-
-            self.log.debug("Connected to: {}".format(self.uri))
-            return self.connection
-
-        return self.connection
+from virtual_environ import virtual_environ
+from recipe import recipe
 
+import logging
 
+logger = logging.getLogger("nitsi.test")
 
 class test():
     def __init__(self, path):
-        self.log = log(4)
         try:
             self.path = os.path.abspath(path)
+            self.log = logger.getChild(os.path.basename(self.path))
         except BaseException as e:
-            self.log.error("Could not get absolute path")
+            logger.error("Could not get absolute path")
 
         self.log.debug(self.path)
 
@@ -107,14 +73,17 @@ class test():
 
         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()
 
     def load_recipe(self):
         try:
             self.recipe = recipe(self.recipe_file)
-        except BaseException:
+            for line in self.recipe.recipe:
+                self.log.debug(line)
+        except BaseException as e:
             self.log.error("Failed to load recipe")
-            exit(1)
+            raise e
 
     def run_recipe(self):
         for line in self.recipe.recipe:
@@ -139,24 +108,4 @@ class test():
             self.virtual_networks[name].undefine()
 
 
-if __name__ == "__main__":
-    import argparse
-
-    parser = argparse.ArgumentParser()
-
-    parser.add_argument("-d", "--directory", dest="dir")
-
-    args = parser.parse_args()
-
-    currenttest = test(args.dir)
-    currenttest.read_settings()
-    currenttest.virtual_environ_setup()
-    currenttest.load_recipe()
-    try:
-        currenttest.virtual_environ_start()
-        currenttest.run_recipe()
-    except BaseException as e:
-        print(e)
-    finally:
-        currenttest.virtual_environ_stop()