osmith has uploaded this change for review. ( 
https://gerrit.osmocom.org/c/osmo-ttcn3-hacks/+/38532?usp=email )


Change subject: testenv: add proper [testsuite] prepare= support
......................................................................

testenv: add proper [testsuite] prepare= support

Support using prepare= in the [testsuite] section to e.g. change module
parameters:

  [testsuite]
  prepare=sed -i 's/mp_my_parameter := false/mp_my_parameter := true/' 
Testsuite.cfg

Move the execution time of prepare and clean scripts in
testdir.prepare() after the testsuite config has been copied to the
testdir, so it can be modified by the prepare script.

Change-Id: Ia78a4eba061e5e070f156f75eae1dfa4cede1ee3
---
M _testenv/README.md
M _testenv/testenv/testdir.py
M _testenv/testenv/testenv_cfg.py
3 files changed, 23 insertions(+), 10 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/osmo-ttcn3-hacks 
refs/changes/32/38532/1

diff --git a/_testenv/README.md b/_testenv/README.md
index 3fed9c9..bd102a8 100644
--- a/_testenv/README.md
+++ b/_testenv/README.md
@@ -70,6 +70,10 @@
   directory, useful for include files mentioned in the config. Multiple values
   are separated by spaces.

+* `prepare=`: optional script to run before staring the testsuite (after files
+  are copied to the test directory). This can be used to change module
+  parameters in the testsuite's config.
+
 * `clean=`: optional script to run before running the testsuite and on exit.
   This can be used to clean up network devices for example, or to fix name
   collisions when running a test with multiple configs
diff --git a/_testenv/testenv/testdir.py b/_testenv/testenv/testdir.py
index aa0ba47..88a2dca 100644
--- a/_testenv/testenv/testdir.py
+++ b/_testenv/testenv/testdir.py
@@ -94,16 +94,6 @@
                     mode = 755 if os.access(path, os.X_OK) else 644
                     testenv.cmd.run(["install", f"-Dm{mode}", path, path_dest])

-        if "clean" in section_data:
-            logging.info(f"Running {section} clean script (reason: prepare)")
-            clean_scripts[section] = section_data["clean"]
-            env = {"TESTENV_CLEAN_REASON": "prepare"}
-            testenv.cmd.run(section_data["clean"], cwd=section_dir, env=env)
-
-        if "prepare" in section_data:
-            logging.info(f"Running {section} prepare script")
-            testenv.cmd.run(section_data["prepare"], cwd=section_dir)
-
     # Referenced in testsuite cfgs: *.default
     pattern = os.path.join(testsuite_dir, "*.default")
     for path in glob.glob(pattern):
@@ -147,6 +137,24 @@
                 ]
             )

+    # Run prepare and clean scripts
+    for section in cfg:
+        if section in ["DEFAULT"]:
+            continue
+
+        section_data = cfg[section]
+        section_dir = os.path.join(testdir, section)
+
+        if "clean" in section_data:
+            logging.info(f"Running {section} clean script (reason: prepare)")
+            clean_scripts[section] = section_data["clean"]
+            env = {"TESTENV_CLEAN_REASON": "prepare"}
+            testenv.cmd.run(section_data["clean"], cwd=section_dir, env=env)
+
+        if "prepare" in section_data:
+            logging.info(f"Running {section} prepare script")
+            testenv.cmd.run(section_data["prepare"], cwd=section_dir)
+

 def clean():
     """Don't leave behind an empty testdir_topdir, e.g. if testenv.py aborted
diff --git a/_testenv/testenv/testenv_cfg.py b/_testenv/testenv/testenv_cfg.py
index ea25614..fefaf5c 100644
--- a/_testenv/testenv/testenv_cfg.py
+++ b/_testenv/testenv/testenv_cfg.py
@@ -109,6 +109,7 @@
         "clean",
         "config",
         "copy",
+        "prepare",
         "program",
     ]
     keys_valid_component = [

--
To view, visit https://gerrit.osmocom.org/c/osmo-ttcn3-hacks/+/38532?usp=email
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings?usp=email

Gerrit-MessageType: newchange
Gerrit-Project: osmo-ttcn3-hacks
Gerrit-Branch: master
Gerrit-Change-Id: Ia78a4eba061e5e070f156f75eae1dfa4cede1ee3
Gerrit-Change-Number: 38532
Gerrit-PatchSet: 1
Gerrit-Owner: osmith <[email protected]>

Reply via email to