From 6be1f4f59824b1f356863807c7c9f22a46579a0e Mon Sep 17 00:00:00 2001 From: Nir Soffer Date: Jan 15 2018 16:30:04 +0000 Subject: Move environment setup to a shell script The environment variables are required both the sanlock executable running from the tests, and for the testing modules. For example, sanlock python binding will look for sanlock socket using SANLOCK_RUN_DIR. Signed-off-by: Nir Soffer --- diff --git a/.travis.yml b/.travis.yml index 883840b..56261cd 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,10 +4,8 @@ before_install: - sudo apt-get -qq update - sudo apt-get install -y make gcc libaio-dev libblkid-dev -env: - - LD_LIBRARY_PATH=$PWD/src:$PWD/wdmd - script: - make -C wdmd - make -C src + - source tests/env.sh - pytest diff --git a/README.dev b/README.dev index 52bc828..0ffae81 100644 --- a/README.dev +++ b/README.dev @@ -11,9 +11,10 @@ Before running the tests, you need to build sanlock and wdmd: $ make -C wdmd $ make -C src -To use libsanlock.so and libwdmd.so from the source tree: +Setup the environment for testing sanlock running sanlcok from source as +current user: - $ export LD_LIBRARY_PATH=$PWD/src:$PWD/wdmd + $ source tests/env.sh To run the tests: diff --git a/tests/env.sh b/tests/env.sh new file mode 100644 index 0000000..39a3dd2 --- /dev/null +++ b/tests/env.sh @@ -0,0 +1,16 @@ +# Setup the environment for testing sanlock. + +# Use built libraries from source +export LD_LIBRARY_PATH=$PWD/wdmd:$PWD/src + +# Disable privileged operations, allowing to run sanlock daemon as +# non-privileged user. +export SANLOCK_PRIVILEGED=0 + +# Use temporary sanlock run dir, usable for non-privileged user. This +# is used by sanlock daemon to create a lockfile and socket, and by +# sanlock clients for communicating with the daemon. +export SANLOCK_RUN_DIR=/tmp/sanlock + +# Import sanlock extension module from source. +export PYTHONPATH=$PWD/python diff --git a/tests/util.py b/tests/util.py index 002425b..157624a 100644 --- a/tests/util.py +++ b/tests/util.py @@ -11,10 +11,6 @@ import time TESTDIR = os.path.dirname(__file__) SANLOCK = os.path.join(TESTDIR, os.pardir, "src", "sanlock") -ENV = dict(os.environ) -ENV["SANLOCK_RUN_DIR"] = "/tmp/sanlock" -ENV["SANLOCK_PRIVILEGED"] = "0" - class TimeoutExpired(Exception): """ Raised when timeout expired """ @@ -31,9 +27,9 @@ def start_daemon(): # don't use high priority (RR) scheduling "-h", "0", # run as current user instead of "sanlock" - "-U", ENV["USER"], - "-G", ENV["USER"]] - return subprocess.Popen(cmd, env=ENV) + "-U", os.environ["USER"], + "-G", os.environ["USER"]] + return subprocess.Popen(cmd) def wait_for_daemon(timeout): @@ -41,7 +37,7 @@ def wait_for_daemon(timeout): Wait until deamon is accepting connections """ deadline = time.time() + timeout - path = os.path.join(ENV["SANLOCK_RUN_DIR"], "sanlock.sock") + path = os.path.join(os.environ["SANLOCK_RUN_DIR"], "sanlock.sock") s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) try: while True: @@ -65,7 +61,7 @@ def sanlock(*args): """ cmd = [SANLOCK] cmd.extend(args) - return subprocess.check_output(cmd, env=ENV) + return subprocess.check_output(cmd) def wait_for_termination(p, timeout):