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


Change subject: testenv: build package=no components with osmo-dev
......................................................................

testenv: build package=no components with osmo-dev

Handle the case of running with --binary-repo, but setting some test
components to package=no to have them built from source with osmo-dev.
For this to work, the envtype needs to be adjusted and passed through
related functions.

Related: OS#6638#note-12
Change-Id: I060421a0e79aa4d16a0c6f91f5e153f54d0ab825
---
M _testenv/README.md
M _testenv/testenv/cmd.py
M _testenv/testenv/daemons.py
M _testenv/testenv/osmo_dev.py
M _testenv/testenv/podman.py
5 files changed, 19 insertions(+), 12 deletions(-)



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

diff --git a/_testenv/README.md b/_testenv/README.md
index 047abc0..f10d349 100644
--- a/_testenv/README.md
+++ b/_testenv/README.md
@@ -105,7 +105,10 @@

 * `package=`: debian package(s) to be installed for running a test component
   and the script in `prepare=`. Multiple values separated by spaces. Set to
-  `package=no` to not install any package.
+  `package=no` to not install any package, in which case osmo-dev will be used
+  to build the `make=` target. With both `package=no` and `make=no`, testenv
+  assumes that nothing needs to be installed or built before the test component
+  can be started.

 * `prepare=`: optional script to run before staring the program (after files
   are copied to the test directory). Typically this is used to create configs
diff --git a/_testenv/testenv/cmd.py b/_testenv/testenv/cmd.py
index 0e35d2a..bf4f4f8 100644
--- a/_testenv/testenv/cmd.py
+++ b/_testenv/testenv/cmd.py
@@ -144,7 +144,7 @@
         envtype = "binary_repo" if getattr(testenv.args, "binary_repo", True) 
else "osmo_dev"

     if not no_podman and testenv.args.podman:
-        return testenv.podman.exec_cmd(cmd, check=check, env=env, **kwargs)
+        return testenv.podman.exec_cmd(cmd, check=check, env=env, 
envtype=envtype, **kwargs)

     logging.debug(f"+ {cmd}")

diff --git a/_testenv/testenv/daemons.py b/_testenv/testenv/daemons.py
index 2abe8c8..0c402e9 100644
--- a/_testenv/testenv/daemons.py
+++ b/_testenv/testenv/daemons.py
@@ -59,11 +59,15 @@
         if testenv.args.io_uring:
             env["LIBOSMO_IO_BACKEND"] = "IO_URING"

+        envtype = "osmo_dev"
+        if testenv.args.binary_repo and section_data["package"] != "no":
+            envtype = "binary_repo"
+
         if testenv.args.podman:
-            daemons[section] = testenv.podman.exec_cmd_background(cmd, 
cwd=cwd, env=env)
+            daemons[section] = testenv.podman.exec_cmd_background(cmd, 
cwd=cwd, env=env, envtype=envtype)
         else:
             logging.debug(f"+ {cmd}")
-            daemons[section] = subprocess.Popen(cmd, cwd=cwd, 
env=testenv.cmd.generate_env(env))
+            daemons[section] = subprocess.Popen(cmd, cwd=cwd, 
env=testenv.cmd.generate_env(env, envtype))

         # Wait 200ms and check if it is still running
         time.sleep(0.2)
diff --git a/_testenv/testenv/osmo_dev.py b/_testenv/testenv/osmo_dev.py
index 65dbfcc..edbe1b2 100644
--- a/_testenv/testenv/osmo_dev.py
+++ b/_testenv/testenv/osmo_dev.py
@@ -111,7 +111,7 @@
     ] + extra_opts

     cwd = get_osmo_dev_dir()
-    if testenv.cmd.run(cmd, cwd=cwd, check=False).returncode:
+    if testenv.cmd.run(cmd, cwd=cwd, check=False, 
envtype="osmo_dev").returncode:
         logging.critical("gen_makefile.py from osmo-dev failed!")
         logging.critical("Your osmo-dev.git clone might be outdated, try:")
         logging.critical(f"$ git -C {shlex.quote(cwd)} pull")
@@ -141,4 +141,4 @@
         sys.exit(1)

     logging.info("Building test components")
-    testenv.cmd.run(["make"] + targets, cwd=testenv.cmd.make_dir)
+    testenv.cmd.run(["make"] + targets, cwd=testenv.cmd.make_dir, 
envtype="osmo_dev")
diff --git a/_testenv/testenv/podman.py b/_testenv/testenv/podman.py
index b7ed29d..f78b844 100644
--- a/_testenv/testenv/podman.py
+++ b/_testenv/testenv/podman.py
@@ -80,11 +80,11 @@
     )


-def generate_env_podman(env=None):
+def generate_env_podman(env=None, envtype="binary_repo"):
     env = env or {}
     ret = []

-    for key, val in testenv.cmd.generate_env(env, True).items():
+    for key, val in testenv.cmd.generate_env(env, True, 
envtype=envtype).items():
         ret += ["-e", f"{key}={val}"]

     return ret
@@ -135,7 +135,7 @@
         run_shell_on_stop = True


-def exec_cmd(cmd, podman_opts=None, cwd=None, env=None, **kwargs):
+def exec_cmd(cmd, podman_opts=None, cwd=None, env=None, envtype="binary_repo", 
**kwargs):
     podman_opts = podman_opts or []
     env = env or {}

@@ -143,7 +143,7 @@
         raise RuntimeError(f"Attempting to execute a command in podman, but 
the container isn't running anymore: {cmd}")

     podman_opts = list(podman_opts)
-    podman_opts += generate_env_podman(env)
+    podman_opts += generate_env_podman(env, envtype)
     # Attach a fake tty (eclipse-titan won't print colored output otherwise)
     podman_opts += ["-t"]

@@ -160,11 +160,11 @@
     )


-def exec_cmd_background(cmd, podman_opts=None, cwd=None, env=None):
+def exec_cmd_background(cmd, podman_opts=None, cwd=None, env=None, 
envtype="binary_repo"):
     podman_opts = podman_opts or []
     env = env or {}

-    podman_opts = list(podman_opts) + generate_env_podman(env)
+    podman_opts = list(podman_opts) + generate_env_podman(env, envtype)

     if cwd:
         podman_opts += ["-w", cwd]

--
To view, visit https://gerrit.osmocom.org/c/osmo-ttcn3-hacks/+/43774?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: I060421a0e79aa4d16a0c6f91f5e153f54d0ab825
Gerrit-Change-Number: 43774
Gerrit-PatchSet: 1
Gerrit-Owner: osmith <[email protected]>

Reply via email to