Add default settings file
authorJonatan Schlag <jonatan.schlag@ipfire.org>
Sun, 9 Sep 2018 10:36:03 +0000 (12:36 +0200)
committerJonatan Schlag <jonatan.schlag@ipfire.org>
Sun, 9 Sep 2018 10:36:03 +0000 (12:36 +0200)
This new settings file makes it possible to set settings which are equal
for many test in a global file. These settings are overriden by the
settings file of the test and the command line arguments.

Signed-off-by: Jonatan Schlag <jonatan.schlag@ipfire.org>
nitsi.in
src/nitsi/test.py

index 80d3231..f5944d9 100755 (executable)
--- a/nitsi.in
+++ b/nitsi.in
@@ -33,6 +33,7 @@ def main():
     parser_run_test.add_argument("-d", "--directory", dest="dir", default=None)
     parser_run_test.add_argument("-r", "--recipe", dest="recipe", default=None)
     parser_run_test.add_argument("-s", "--settings", dest="settings", default=None)
+    parser_run_test.add_argument("--default-settings", dest="default_settings", default=None)
     parser_run_test.add_argument("--name", dest="name", default=None)
     parser_run_test.add_argument("--description", dest="desc", default=None)
     parser_run_test.add_argument("--copy-to", dest="copy_to", default=None)
@@ -82,7 +83,7 @@ def main():
         logger.debug("We now logging everything to {}/general.log".format(log_dir))
 
         # Build up settings
-        settings = nitsi.settings.NitsiSettings(priority_list=["cmd", "settings-file", "nitsi-default"])
+        settings = nitsi.settings.NitsiSettings(priority_list=["cmd", "settings-file", "default-settings-file", "nitsi-default"])
 
         if args.name:
             settings.set_config_value("name", args.name, type="cmd")
@@ -107,7 +108,8 @@ def main():
                 dir=args.dir,
                 recipe_file=args.recipe,
                 settings_file=args.settings,
-                settings=settings)
+                settings=settings,
+                default_settings_file=args.default_settings)
             currenttest.virtual_environ_setup_stage_1()
             currenttest.load_recipe()
             currenttest.virtual_environ_setup_stage_2()
index 196b2fb..8c454a5 100755 (executable)
@@ -19,7 +19,7 @@ class TestException(Exception):
         self.message = message
 
 class Test():
-    def __init__(self, log_path, dir=None, recipe_file=None, settings_file=None, settings=None):
+    def __init__(self, log_path, dir=None, recipe_file=None, settings_file=None, settings=None, default_settings_file=None):
         # init settings var
         self.settings = settings
 
@@ -30,6 +30,8 @@ class Test():
         self.recipe_file = None
         self.path = None
 
+        self.default_settings_file = default_settings_file
+
         # We need at least a path to a recipe file or a dir to a test
         if not dir and not recipe:
             raise TestException("Did not get a path to a test or to a recipe file")
@@ -59,6 +61,7 @@ class Test():
         if not self.recipe_file:
             raise TestException("No recipe file found")
 
+        self.default_settings_file = self.check_file(self.default_settings_file)
 
         # Init logging
         if dir:
@@ -69,7 +72,10 @@ class Test():
 
         # Parse config and settings:
         if self.settings_file:
-            self.settings.set_config_values_from_file(self.settings_file, type="settings-file")#
+            self.settings.set_config_values_from_file(self.settings_file, type="settings-file")
+
+        if self.default_settings_file:
+            self.settings.set_config_values_from_file(self.default_settings_file, type="default-settings-file")
 
         # Check settings
         self.settings.check_config_values()