From 74a403464b0bb4c2a64ed3dc4f11127e3870fa05 Mon Sep 17 00:00:00 2001 From: Benny Zlotnik Date: Dec 04 2020 10:33:21 +0000 Subject: tests: add a test for LVB operation This patch tests writing and reading to LVB via python bindings. Signed-off-by: Benny Zlotnik --- diff --git a/tests/python_test.py b/tests/python_test.py index abd459e..28fd27f 100644 --- a/tests/python_test.py +++ b/tests/python_test.py @@ -764,3 +764,75 @@ def test_acquire_path_length(no_sanlock_daemon): path = "x" * (constants.SANLK_PATH_LEN - 1) with raises_sanlock_errno(): sanlock.acquire(b"ls_name", b"res_name", [(path, 0)], pid=os.getpid()) + + +def test_lvb(tmpdir, sanlock_daemon): + ls_path = str(tmpdir.join("ls_name")) + util.create_file(ls_path, MiB) + + res_path = str(tmpdir.join("res_name")) + util.create_file(res_path, MiB) + + sanlock.write_lockspace(b"ls_name", ls_path, offset=0, iotimeout=1) + sanlock.add_lockspace(b"ls_name", 1, ls_path, offset=0, iotimeout=1) + + disks = [(res_path, 0)] + sanlock.write_resource(b"ls_name", b"res_name", disks) + + fd = sanlock.register() + + sanlock.acquire(b"ls_name", b"res_name", disks, slkfd=fd, lvb=True) + sanlock.set_lvb(b"ls_name", b"res_name", disks, b"{gen:0}") + + result = sanlock.get_lvb(b"ls_name", b"res_name", disks) + sanlock.release(b"ls_name", b"res_name", disks, slkfd=fd) + + assert result == b"{gen:0}" + + +def test_lvb_value_too_long(tmpdir, sanlock_daemon): + ls_path = str(tmpdir.join("ls_name")) + util.create_file(ls_path, MiB) + + res_path = str(tmpdir.join("res_name")) + util.create_file(res_path, MiB) + + sanlock.write_lockspace(b"ls_name", ls_path, offset=0, iotimeout=1) + sanlock.add_lockspace(b"ls_name", 1, ls_path, offset=0, iotimeout=1) + + disks = [(res_path, 0)] + sanlock.write_resource(b"ls_name", b"res_name", disks) + + fd = sanlock.register() + + long_val = b"a" * 513 + sanlock.acquire(b"ls_name", b"res_name", disks, slkfd=fd, lvb=True) + with raises_sanlock_errno(errno.E2BIG): + sanlock.set_lvb(b"ls_name", b"res_name", disks, long_val) + + sanlock.release(b"ls_name", b"res_name", disks, slkfd=fd) + + +def test_lvb_null_bytes(tmpdir, sanlock_daemon): + ls_path = str(tmpdir.join("ls_name")) + util.create_file(ls_path, MiB) + + res_path = str(tmpdir.join("res_name")) + util.create_file(res_path, MiB) + + sanlock.write_lockspace(b"ls_name", ls_path, offset=0, iotimeout=1) + sanlock.add_lockspace(b"ls_name", 1, ls_path, offset=0, iotimeout=1) + + disks = [(res_path, 0)] + sanlock.write_resource(b"ls_name", b"res_name", disks) + + fd = sanlock.register() + + sanlock.acquire(b"ls_name", b"res_name", disks, slkfd=fd, lvb=True) + sanlock.set_lvb(b"ls_name", b"res_name", disks, b"{ge\x00:0}") + + result = sanlock.get_lvb(b"ls_name", b"res_name", disks) + sanlock.release(b"ls_name", b"res_name", disks, slkfd=fd) + + # Check that the string we passed is terminated by the null-byte + assert result == b"{ge"