Skip to content

Commit

Permalink
Move environment setup to a shell script
Browse files Browse the repository at this point in the history
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 <nsoffer@redhat.com>
  • Loading branch information
nirs authored and teigland committed Jan 15, 2018
1 parent 95093da commit 6be1f4f
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 14 deletions.
4 changes: 1 addition & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 3 additions & 2 deletions README.dev
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
16 changes: 16 additions & 0 deletions tests/env.sh
Original file line number Diff line number Diff line change
@@ -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
14 changes: 5 additions & 9 deletions tests/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,6 @@
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 """
Expand All @@ -31,17 +27,17 @@ 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):
"""
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:
Expand All @@ -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):
Expand Down

0 comments on commit 6be1f4f

Please sign in to comment.