On Thu, Dec 10, 2020 at 7:23 PM Benny Zlotnik <bzlotnik(a)redhat.com> wrote:
- Remove null byte test, it is now tested in the basic test
- Add 4k tests for E2BIG failure
- Add test for writing entire 4k sector
We don't have 4k tests yet, I'll update the commit message.
- Add test for reading less than sector size
Signed-off-by: Benny Zlotnik <bzlotnik(a)redhat.com>
---
Changes in v2:
- Consolidate all writing tests to test_lvb
- Improve invalid values test by not using daemon and only testing
binding failure
tests/python_test.py | 63 +++++++++++++++-----------------------------
1 file changed, 21 insertions(+), 42 deletions(-)
diff --git a/tests/python_test.py b/tests/python_test.py
index 28fd27f..2cc7d25 100644
--- a/tests/python_test.py
+++ b/tests/python_test.py
@@ -769,70 +769,49 @@ def test_acquire_path_length(no_sanlock_daemon):
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}")
+ # Test full cluster write.
+ lvb_data = b"first\0second".ljust(512, b"\0")
- result = sanlock.get_lvb(b"ls_name", b"res_name", disks)
+ sanlock.acquire(b"ls_name", b"res_name", disks, slkfd=fd,
lvb=True)
+ sanlock.set_lvb(b"ls_name", b"res_name", disks, lvb_data)
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)
+ sanlock.acquire(b"ls_name", b"res_name", disks, slkfd=fd,
lvb=True)
+ result = sanlock.get_lvb(b"ls_name", b"res_name", disks,
size=512)
+ sanlock.release(b"ls_name", b"res_name", disks, slkfd=fd)
- res_path = str(tmpdir.join("res_name"))
- util.create_file(res_path, MiB)
+ assert result == lvb_data
- 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)
+ # Test read sess than cluster size.
+ sanlock.acquire(b"ls_name", b"res_name", disks, slkfd=fd,
lvb=True)
+ result = sanlock.get_lvb(b"ls_name", b"res_name", disks,
+ size=len(lvb_data))
This tests the same data, I'll fix this before merging.
+ sanlock.release(b"ls_name", b"res_name",
disks, slkfd=fd)
- disks = [(res_path, 0)]
- sanlock.write_resource(b"ls_name", b"res_name", disks)
+ assert result == lvb_data
- fd = sanlock.register()
-
- long_val = b"a" * 513
+ # Test failure to write data larger than cluster size.
+ long_val = b"a" * (SECTOR_SIZE_512 + 1)
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)
+def test_lvb_invalid_value_512(tmpdir):
res_path = str(tmpdir.join("res_name"))
We don't need tmpdir, since we don't reach storage in this test. Also
tmpdir.join() does not create the file, so we can just use "/no/such/path".
I'll fix it before merge.
- 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)
+ with pytest.raises(ValueError):
+ sanlock.get_lvb(b"ls_name", b"res_name", disks, size=0)
- # Check that the string we passed is terminated by the null-byte
- assert result == b"{ge"
+ with pytest.raises(ValueError):
+ sanlock.get_lvb(b"ls_name", b"res_name", disks, size=4097)
--
2.28.0