From: Nir Soffer <nsoffer(a)redhat.com>
This module allows testing sanlock daemon via the sanlock python
bindings.
Signed-off-by: Nir Soffer <nsoffer(a)redhat.com>
---
.travis.yml | 1 +
README.dev | 4 +++-
python/Makefile | 3 +++
tests/python_test.py | 27 +++++++++++++++++++++++++++
4 files changed, 34 insertions(+), 1 deletion(-)
create mode 100644 tests/python_test.py
diff --git a/.travis.yml b/.travis.yml
index 56261cd..9668e82 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -7,5 +7,6 @@ before_install:
script:
- make -C wdmd
- make -C src
+ - make -C python inplace
- source tests/env.sh
- pytest
diff --git a/README.dev b/README.dev
index 0ffae81..04fbb02 100644
--- a/README.dev
+++ b/README.dev
@@ -6,10 +6,12 @@ recent version is to use pip:
$ pip install pytest
-Before running the tests, you need to build sanlock and wdmd:
+Before running the tests, you need to build wdmd, sanlock, and sanlock
+python bindings:
$ make -C wdmd
$ make -C src
+ $ make -C python inplace
Setup the environment for testing sanlock running sanlcok from source as
current user:
diff --git a/python/Makefile b/python/Makefile
index 92b0c28..ff24e1d 100644
--- a/python/Makefile
+++ b/python/Makefile
@@ -7,6 +7,9 @@
all:
python setup.py build
+inplace:
+ python setup.py build_ext --inplace
+
install:
python setup.py install --root=$(DESTDIR)
diff --git a/tests/python_test.py b/tests/python_test.py
new file mode 100644
index 0000000..e455e11
--- /dev/null
+++ b/tests/python_test.py
@@ -0,0 +1,27 @@
+"""
+Test sanlock python binding with sanlock daemon.
+"""
+
+import io
+import struct
+
+import sanlock
+
+
+def test_write_lockspace(tmpdir, sanlock_daemon):
+ path = tmpdir.join("lockspace")
+ with io.open(str(path), "wb") as f:
+ # Poison with junk data.
+ f.write(b"x" * 1024**2 + b"X" * 512)
+
+ sanlock.write_lockspace("name", str(path), offset=0)
+
+ with io.open(str(path), "rb") as f:
+ magic, = struct.unpack("< I", f.read(4))
+ assert magic == 0x12212010
+
+ # TODO: check more stuff here...
+
+ # Do not modify data after the lockspace area.
+ f.seek(1024**2, io.SEEK_SET)
+ assert f.read(512) == b"X" * 512
--
2.9.5