From 058ad1c7e4566696475241ea0897bbf799144d1c Mon Sep 17 00:00:00 2001 From: Benny Zlotnik Date: Jan 26 2021 16:06:26 +0000 Subject: python: improve lvb tests - Remove null byte test, it is now tested in the basic test - Add test for reading less than sector size Testing storage with 4k sector size needs more work. Signed-off-by: Benny Zlotnik Signed-off-by: Nir Soffer --- diff --git a/tests/python_test.py b/tests/python_test.py index 5e034a7..448b043 100644 --- a/tests/python_test.py +++ b/tests/python_test.py @@ -800,70 +800,50 @@ 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}") + lvb_data = b"first\0second" + lvb_sector = lvb_data.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_sector) sanlock.release(b"ls_name", b"res_name", disks, slkfd=fd) - assert result == b"{gen:0}" + # Test reading complete sector (typical usage). + sanlock.acquire(b"ls_name", b"res_name", disks, slkfd=fd, lvb=True) + result = sanlock.get_lvb(b"ls_name", b"res_name", disks, len(lvb_sector)) + sanlock.release(b"ls_name", b"res_name", disks, slkfd=fd) -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) + assert result == lvb_sector - fd = sanlock.register() + # Test reading less than sector size. - 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) - + result = sanlock.get_lvb(b"ls_name", b"res_name", disks, len(lvb_data)) sanlock.release(b"ls_name", b"res_name", disks, slkfd=fd) + assert result == lvb_data -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) + # Test failure to write more then sector size. - disks = [(res_path, 0)] - sanlock.write_resource(b"ls_name", b"res_name", disks) + 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, lvb_sector + b"x") - 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}") +def test_lvb_invalid_value(): + disks = [("/no/such/path", 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, 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, 4097)