osmith submitted this change.

View Change

Approvals: fixeria: Looks good to me, approved Jenkins Builder: Verified pespin: Looks good to me, but someone else must approve
testenv: cmd: init_env: split up by envtype

osmo-dev commands and components built with osmo-dev need to run with
other environment variables (e.g. PATH, PKG_CONFIG_PATH) compared to
test components that were installed from binary packages.

Until now it was not possible to mix both, which means testenv would
decide on startup which of the two it is and set everything accordingly.

Split init_env and related variables up so we can do both at the same
time. This is again needed to run the bts testsuite with binary packages
except for osmo-trx-proxy and trxcon.

This patch keeps the current behavior of using the binary_repo envtype
if --binary-repo is set, and the osmo_dev envtype otherwise. The next
patch makes mixing both possible.

Related: OS#6638#note-12
Change-Id: Ib5532d8eab0a05d5390a92e88dcc67f5ab00eba9
---
M _testenv/testenv.py
M _testenv/testenv/cmd.py
M _testenv/testenv/osmo_dev.py
3 files changed, 82 insertions(+), 59 deletions(-)

diff --git a/_testenv/testenv.py b/_testenv/testenv.py
index 5d6b043..695a857 100755
--- a/_testenv/testenv.py
+++ b/_testenv/testenv.py
@@ -40,7 +40,10 @@
testenv.osmo_dev.check_init_needed()

testenv.podman_install.init()
- testenv.cmd.init_env()
+ if osmo_dev_has_any_targets:
+ testenv.cmd.init_env_osmo_dev()
+ if testenv.args.binary_repo:
+ testenv.cmd.init_env_binary_repo()
testenv.testdir.init()
testenv.daemons.init()

diff --git a/_testenv/testenv/cmd.py b/_testenv/testenv/cmd.py
index 4da2360..0e35d2a 100644
--- a/_testenv/testenv/cmd.py
+++ b/_testenv/testenv/cmd.py
@@ -8,8 +8,8 @@
import testenv
import testenv.testsuite

-env_extra = {}
-install_dir = None
+env_extra = {"binary_repo": {}, "osmo_dev": {}}
+install_dir = {"binary_repo": None, "osmo_dev": None}
make_dir = None
# osmo-dev make dir version, bump when making incompatible changes
make_dir_version = 4
@@ -21,62 +21,78 @@
return f"-{re.sub('[^a-zA-Z0-9]', '-', testenv.args.distro)}"


-def init_env():
+def init_env_common(envtype):
"""Adjust "Environment variables set by testenv" in README.md when making
- changes here."""
+ changes here or in other init_env_* functions below."""
+ global env_extra
+
+ env_extra[envtype]["TESTENV_INSTALL_DIR"] = install_dir[envtype]
+
+ env_extra[envtype]["CCACHE_DIR"] = testenv.args.ccache
+ env_extra[envtype]["TESTENV_CACHE_DIR"] = testenv.args.cache
+ env_extra[envtype]["TESTENV_SRC_DIR"] = testenv.src_dir
+
+ env_extra[envtype]["TERM"] = os.environ.get("TERM", "dumb")
+
+ if testenv.args.kernel == "debian":
+ env_extra[envtype]["TESTENV_QEMU_KERNEL"] = "debian"
+ elif testenv.args.kernel == "custom":
+ env_extra[envtype]["TESTENV_QEMU_KERNEL"] = testenv.custom_kernel_path
+ if testenv.args.kernel:
+ env_extra[envtype]["TESTENV_QEMU_SCRIPTS"] = os.path.join(testenv.data_dir, "scripts/qemu")
+
+
+def init_env_binary_repo():
+ global install_dir
+
+ if testenv.args.podman:
+ install_dir["binary_repo"] = "/"
+ else:
+ install_dir["binary_repo"] = os.path.join(testenv.args.cache, "host/install")
+
+ init_env_common("binary_repo")
+
+
+def init_env_osmo_dev():
global env_extra
global install_dir
global make_dir

+ # install_dir
if testenv.args.podman:
- if testenv.args.binary_repo:
- install_dir = "/"
- else:
- install_dir = os.path.join(testenv.args.cache, "podman/install")
- if testenv.args.asan:
- install_dir += "-asan"
- install_dir += distro_cache_suffix()
- else:
- install_dir = os.path.join(testenv.args.cache, "host/install")
-
- if not testenv.args.binary_repo:
- pkg_config_path = os.path.join(install_dir, "lib/pkgconfig")
- if "PKG_CONFIG_PATH" in os.environ:
- pkg_config_path += f":{os.environ.get('PKG_CONFIG_PATH')}"
- pkg_config_path += ":/usr/lib/pkgconfig"
-
- ld_library_path = os.path.join(install_dir, "lib")
- if "LD_LIBRARY_PATH" in os.environ:
- ld_library_path += f":{os.environ.get('LD_LIBRARY_PATH')}"
- ld_library_path += ":/usr/lib"
-
- env_extra["PKG_CONFIG_PATH"] = pkg_config_path
- env_extra["LD_LIBRARY_PATH"] = ld_library_path
-
- env_extra["CCACHE_DIR"] = testenv.args.ccache
- env_extra["TESTENV_CACHE_DIR"] = testenv.args.cache
- env_extra["TESTENV_SRC_DIR"] = testenv.src_dir
- env_extra["TESTENV_INSTALL_DIR"] = install_dir
-
- env_extra["TERM"] = os.environ.get("TERM", "dumb")
-
- if not testenv.args.binary_repo:
- if testenv.args.podman:
- make_dir = os.path.join(testenv.args.cache, "podman", "make")
- else:
- make_dir = os.path.join(testenv.args.cache, "host", "make")
- make_dir += str(make_dir_version)
+ install_dir["osmo_dev"] = os.path.join(testenv.args.cache, "podman/install")
if testenv.args.asan:
- make_dir += "-asan"
- make_dir += distro_cache_suffix()
- env_extra["OSMO_DEV_MAKE_DIR"] = make_dir
+ install_dir["osmo_dev"] += "-asan"
+ install_dir["osmo_dev"] += distro_cache_suffix()
+ else:
+ install_dir["osmo_dev"] = os.path.join(testenv.args.cache, "host/install")

- if testenv.args.kernel == "debian":
- env_extra["TESTENV_QEMU_KERNEL"] = "debian"
- elif testenv.args.kernel == "custom":
- env_extra["TESTENV_QEMU_KERNEL"] = testenv.custom_kernel_path
- if testenv.args.kernel:
- env_extra["TESTENV_QEMU_SCRIPTS"] = os.path.join(testenv.data_dir, "scripts/qemu")
+ # pkgconfig_path
+ pkg_config_path = os.path.join(install_dir["osmo_dev"], "lib/pkgconfig")
+ if "PKG_CONFIG_PATH" in os.environ:
+ pkg_config_path += f":{os.environ.get('PKG_CONFIG_PATH')}"
+ pkg_config_path += ":/usr/lib/pkgconfig"
+ env_extra["osmo_dev"]["PKG_CONFIG_PATH"] = pkg_config_path
+
+ # ld_library_path
+ ld_library_path = os.path.join(install_dir["osmo_dev"], "lib")
+ if "LD_LIBRARY_PATH" in os.environ:
+ ld_library_path += f":{os.environ.get('LD_LIBRARY_PATH')}"
+ ld_library_path += ":/usr/lib"
+ env_extra["osmo_dev"]["LD_LIBRARY_PATH"] = ld_library_path
+
+ # make_dir
+ if testenv.args.podman:
+ make_dir = os.path.join(testenv.args.cache, "podman", "make")
+ else:
+ make_dir = os.path.join(testenv.args.cache, "host", "make")
+ make_dir += str(make_dir_version)
+ if testenv.args.asan:
+ make_dir += "-asan"
+ make_dir += distro_cache_suffix()
+ env_extra["osmo_dev"]["OSMO_DEV_MAKE_DIR"] = make_dir
+
+ init_env_common("osmo_dev")


def exit_error_cmd(completed, error_msg):
@@ -88,17 +104,17 @@
raise RuntimeError("shell command related error, find details right above this python trace")


-def generate_env(env=None, podman=False):
+def generate_env(env=None, podman=False, envtype="binary_repo"):
env = env or {}
- ret = dict(env_extra)
+ ret = dict(env_extra[envtype])
path = os.path.join(testenv.data_dir, "scripts")
path += f":{os.path.join(testenv.data_dir, 'scripts/qemu')}"
if testenv.args.action == "run" and testenv.ttcn3_hacks_dir:
path += f":{os.path.join(testenv.ttcn3_hacks_dir, testenv.args.testsuite)}"

- if install_dir and install_dir != "/":
- path += f":{os.path.join(install_dir, 'bin')}"
- path += f":{os.path.join(install_dir, 'usr/bin')}"
+ if install_dir[envtype] and install_dir[envtype] != "/":
+ path += f":{os.path.join(install_dir[envtype], 'bin')}"
+ path += f":{os.path.join(install_dir[envtype], 'usr/bin')}"

if podman:
path += ":/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
@@ -121,8 +137,12 @@
return ret


-def run(cmd, check=True, env=None, no_podman=False, stdin=subprocess.DEVNULL, **kwargs):
+def run(cmd, check=True, env=None, no_podman=False, stdin=subprocess.DEVNULL, envtype=None, **kwargs):
env = env or {}
+
+ if not envtype:
+ 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)

@@ -131,7 +151,7 @@
# Set stdin to /dev/null by default so we can still capture ^C with testenv
p = subprocess.run(
cmd,
- env=generate_env(env),
+ env=generate_env(env, envtype=envtype),
shell=isinstance(cmd, str),
stdin=stdin,
check=False,
diff --git a/_testenv/testenv/osmo_dev.py b/_testenv/testenv/osmo_dev.py
index d67c5eb..65dbfcc 100644
--- a/_testenv/testenv/osmo_dev.py
+++ b/_testenv/testenv/osmo_dev.py
@@ -86,7 +86,7 @@
"--build-debug",
"--no-make-check",
"--install-prefix",
- testenv.cmd.install_dir,
+ testenv.cmd.install_dir["osmo_dev"],
"--make-dir",
testenv.cmd.make_dir,
"--no-ldconfig",

To view, visit change 43773. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-MessageType: merged
Gerrit-Project: osmo-ttcn3-hacks
Gerrit-Branch: master
Gerrit-Change-Id: Ib5532d8eab0a05d5390a92e88dcc67f5ab00eba9
Gerrit-Change-Number: 43773
Gerrit-PatchSet: 3
Gerrit-Owner: osmith <osmith@sysmocom.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: fixeria <vyanitskiy@sysmocom.de>
Gerrit-Reviewer: osmith <osmith@sysmocom.de>
Gerrit-Reviewer: pespin <pespin@sysmocom.de>