This is an automated email from the git hooks/post-receive script.
nsoffer pushed a commit to branch master in repository sanlock.
commit 78ea6ae55a1d4979def3e1edc129f3beaa3c48aa Author: Amit Bawer abawer@redhat.com AuthorDate: Sun Jun 2 13:20:19 2019 +0300
tests: Set lockspace and resource names as bytes
This patch is a preparation for next changes in sanlock where lockspace and resource names will be parsed as bytes in both python versions and also as ascii string in python 2 for back compatibility.
Implications:
- Py2: no difference, ascii strings and bytes are parsed the same - Py3: marked as xfail as currently expecting only unicode string --- tests/python_test.py | 138 +++++++++++++++++++++++++++++---------------------- 1 file changed, 78 insertions(+), 60 deletions(-)
diff --git a/tests/python_test.py b/tests/python_test.py index db77862..f831c15 100644 --- a/tests/python_test.py +++ b/tests/python_test.py @@ -66,6 +66,7 @@ LOCKSPACE_OR_RESOURCE_NAMES = [ marks=pytest.mark.skipif(six.PY3, reason="python 3 supports only bytes")), ]
+@pytest.mark.xfail(six.PY3, reason="lockspace/resource names in bytes are unsupported yet") @pytest.mark.parametrize("filename, encoding" , FILE_NAMES) @pytest.mark.parametrize("size,offset", [ # Smallest offset. @@ -78,22 +79,22 @@ def test_write_lockspace(tmpdir, sanlock_daemon, filename, encoding, size, offse util.create_file(path, size)
# Test read and write with default alignment and sector size values. - sanlock.write_lockspace("name", path, offset=offset, iotimeout=1) + sanlock.write_lockspace(b"ls_name", path, offset=offset, iotimeout=1)
ls = sanlock.read_lockspace(path, offset=offset) - assert ls == {"iotimeout": 1, "lockspace": b"name"} + assert ls == {"iotimeout": 1, "lockspace": b"ls_name"}
# Test read and write with explicit alignment and sector size values. sanlock.write_lockspace( - "name", path, offset=offset, iotimeout=1, align=ALIGNMENT_1M, + b"ls_name", path, offset=offset, iotimeout=1, align=ALIGNMENT_1M, sector=SECTOR_SIZE_512)
ls = sanlock.read_lockspace( path, offset=offset, align=ALIGNMENT_1M, sector=SECTOR_SIZE_512) - assert ls == {"iotimeout": 1, "lockspace": b"name"} + assert ls == {"iotimeout": 1, "lockspace": b"ls_name"}
acquired = sanlock.inq_lockspace( - "name", 1, path, offset=offset, wait=False) + b"ls_name", 1, path, offset=offset, wait=False) assert acquired is False
with io.open(path, "rb") as f: @@ -106,6 +107,7 @@ def test_write_lockspace(tmpdir, sanlock_daemon, filename, encoding, size, offse util.check_guard(path, size)
+@pytest.mark.xfail(six.PY3, reason="lockspace/resource names in bytes are unsupported yet") @pytest.mark.parametrize("align", sanlock.ALIGN_SIZE) def test_write_lockspace_4k(user_4k_path, sanlock_daemon, align):
@@ -116,14 +118,14 @@ def test_write_lockspace_4k(user_4k_path, sanlock_daemon, align): util.write_guard(user_4k_path, align)
sanlock.write_lockspace( - "name", user_4k_path, iotimeout=1, align=align, sector=SECTOR_SIZE_4K) + b"ls_name", user_4k_path, iotimeout=1, align=align, sector=SECTOR_SIZE_4K)
ls = sanlock.read_lockspace( user_4k_path, align=align, sector=SECTOR_SIZE_4K)
- assert ls == {"iotimeout": 1, "lockspace": b"name"} + assert ls == {"iotimeout": 1, "lockspace": b"ls_name"}
- acquired = sanlock.inq_lockspace("name", 1, user_4k_path, wait=False) + acquired = sanlock.inq_lockspace(b"ls_name", 1, user_4k_path, wait=False) assert acquired is False
# Verify that lockspace was written. @@ -135,22 +137,25 @@ def test_write_lockspace_4k(user_4k_path, sanlock_daemon, align): util.check_guard(user_4k_path, align)
+@pytest.mark.xfail(six.PY3, reason="lockspace/resource names in bytes are unsupported yet") def test_write_lockspace_4k_invalid_sector_size(sanlock_daemon, user_4k_path): with pytest.raises(sanlock.SanlockException) as e: sanlock.write_lockspace( - "name", user_4k_path, iotimeout=1, sector=SECTOR_SIZE_512) + b"ls_name", user_4k_path, iotimeout=1, sector=SECTOR_SIZE_512) assert e.value.errno == errno.EINVAL
+@pytest.mark.xfail(six.PY3, reason="lockspace/resource names in bytes are unsupported yet") def test_read_lockspace_4k_invalid_sector_size(sanlock_daemon, user_4k_path): sanlock.write_lockspace( - "name", user_4k_path, iotimeout=1, sector=SECTOR_SIZE_4K) + b"ls_name", user_4k_path, iotimeout=1, sector=SECTOR_SIZE_4K)
with pytest.raises(sanlock.SanlockException) as e: sanlock.read_lockspace(user_4k_path, sector=SECTOR_SIZE_512) assert e.value.errno == errno.EINVAL
+@pytest.mark.xfail(six.PY3, reason="lockspace/resource names in bytes are unsupported yet") @pytest.mark.parametrize("filename,encoding", FILE_NAMES) @pytest.mark.parametrize("size,offset", [ # Smallest offset. @@ -164,7 +169,7 @@ def test_write_resource(tmpdir, sanlock_daemon, filename, encoding, size, offset disks = [(path, offset)]
# Test read and write with default alignment and sector size values. - sanlock.write_resource("ls_name", "res_name", disks) + sanlock.write_resource(b"ls_name", b"res_name", disks)
res = sanlock.read_resource(path, offset=offset) assert res == { @@ -175,7 +180,7 @@ def test_write_resource(tmpdir, sanlock_daemon, filename, encoding, size, offset
# Test read and write with explicit alignment and sector size values. sanlock.write_resource( - "ls_name", "res_name", disks, align=ALIGNMENT_1M, + b"ls_name", b"res_name", disks, align=ALIGNMENT_1M, sector=SECTOR_SIZE_512)
res = sanlock.read_resource( @@ -186,7 +191,7 @@ def test_write_resource(tmpdir, sanlock_daemon, filename, encoding, size, offset "version": 0 }
- owners = sanlock.read_resource_owners("ls_name", "res_name", disks) + owners = sanlock.read_resource_owners(b"ls_name", b"res_name", disks) assert owners == []
with io.open(path, "rb") as f: @@ -199,6 +204,7 @@ def test_write_resource(tmpdir, sanlock_daemon, filename, encoding, size, offset util.check_guard(path, size)
+@pytest.mark.xfail(six.PY3, reason="lockspace/resource names in bytes are unsupported yet") @pytest.mark.parametrize("align", sanlock.ALIGN_SIZE) def test_write_resource_4k(sanlock_daemon, user_4k_path, align): disks = [(user_4k_path, 0)] @@ -210,7 +216,7 @@ def test_write_resource_4k(sanlock_daemon, user_4k_path, align): util.write_guard(user_4k_path, align)
sanlock.write_resource( - "ls_name", "res_name", disks, align=align, sector=SECTOR_SIZE_4K) + b"ls_name", b"res_name", disks, align=align, sector=SECTOR_SIZE_4K)
res = sanlock.read_resource( user_4k_path, align=align, sector=SECTOR_SIZE_4K) @@ -222,7 +228,7 @@ def test_write_resource_4k(sanlock_daemon, user_4k_path, align): }
owners = sanlock.read_resource_owners( - "ls_name", "res_name", disks, align=align, sector=SECTOR_SIZE_4K) + b"ls_name", b"res_name", disks, align=align, sector=SECTOR_SIZE_4K) assert owners == []
# Verify that resource was written. @@ -240,16 +246,17 @@ def test_write_resource_4k_invalid_sector_size(sanlock_daemon, user_4k_path):
with pytest.raises(sanlock.SanlockException) as e: sanlock.write_resource( - "ls_name", "res_name", disks, sector=SECTOR_SIZE_512) + b"ls_name", b"res_name", disks, sector=SECTOR_SIZE_512) assert e.value.errno == errno.EINVAL
+@pytest.mark.xfail(six.PY3, reason="lockspace/resource names in bytes are unsupported yet") def test_read_resource_4k_invalid_sector_size(sanlock_daemon, user_4k_path): disks = [(user_4k_path, 0)]
sanlock.write_resource( - "ls_name", - "res_name", + b"ls_name", + b"res_name", disks, align=ALIGNMENT_1M, sector=SECTOR_SIZE_4K) @@ -259,45 +266,48 @@ def test_read_resource_4k_invalid_sector_size(sanlock_daemon, user_4k_path): assert e.value.errno == errno.EINVAL
+@pytest.mark.xfail(six.PY3, reason="lockspace/resource names in bytes are unsupported yet") def test_read_resource_owners_4k_invalid_sector_size( sanlock_daemon, user_4k_path): disks = [(user_4k_path, 0)]
sanlock.write_resource( - "ls_name", - "res_name", + b"ls_name", + b"res_name", disks, align=ALIGNMENT_1M, sector=SECTOR_SIZE_4K)
with pytest.raises(sanlock.SanlockException) as e: sanlock.read_resource_owners( - "ls_name", "res_name", disks, sector=SECTOR_SIZE_512) + b"ls_name", b"res_name", disks, sector=SECTOR_SIZE_512) assert e.value.errno == errno.EINVAL
+@pytest.mark.xfail(six.PY3, reason="lockspace/resource names in bytes are unsupported yet") def test_read_resource_owners_invalid_align_size(tmpdir, sanlock_daemon): path = str(tmpdir.join("path")) util.create_file(path, GiB) disks = [(path, 0)]
sanlock.write_resource( - "ls_name", - "res_name", + b"ls_name", + b"res_name", disks, align=ALIGNMENT_1M, sector=SECTOR_SIZE_512)
with pytest.raises(sanlock.SanlockException) as e: sanlock.read_resource_owners( - "ls_name", - "res_name", + b"ls_name", + b"res_name", disks, align=ALIGNMENT_2M, sector=SECTOR_SIZE_512) assert e.value.errno == errno.EINVAL
+@pytest.mark.xfail(six.PY3, reason="lockspace/resource names in bytes are unsupported yet") @pytest.mark.parametrize("size,offset", [ # Smallest offset. (MIN_RES_SIZE, 0), @@ -308,18 +318,18 @@ def test_add_rem_lockspace(tmpdir, sanlock_daemon, size, offset): path = str(tmpdir.join("ls_name")) util.create_file(path, size)
- sanlock.write_lockspace("ls_name", path, offset=offset, iotimeout=1) + sanlock.write_lockspace(b"ls_name", path, offset=offset, iotimeout=1)
# Since the lockspace is not acquired, we exepect to get False. acquired = sanlock.inq_lockspace( - "ls_name", 1, path, offset=offset, wait=False) + b"ls_name", 1, path, offset=offset, wait=False) assert acquired is False
- sanlock.add_lockspace("ls_name", 1, path, offset=offset, iotimeout=1) + sanlock.add_lockspace(b"ls_name", 1, path, offset=offset, iotimeout=1)
# Once the lockspace is acquired, we exepect to get True. acquired = sanlock.inq_lockspace( - "ls_name", 1, path, offset=offset, wait=False) + b"ls_name", 1, path, offset=offset, wait=False) assert acquired is True
lockspaces = sanlock.get_lockspaces() @@ -331,53 +341,55 @@ def test_add_rem_lockspace(tmpdir, sanlock_daemon, size, offset): 'path': path }]
- sanlock.rem_lockspace("ls_name", 1, path, offset=offset) + sanlock.rem_lockspace(b"ls_name", 1, path, offset=offset)
# Once the lockspace is released, we exepect to get False. acquired = sanlock.inq_lockspace( - "ls_name", 1, path, offset=offset, wait=False) + b"ls_name", 1, path, offset=offset, wait=False) assert acquired is False
lockspaces = sanlock.get_lockspaces() assert lockspaces == []
+@pytest.mark.xfail(six.PY3, reason="lockspace/resource names in bytes are unsupported yet") def test_add_rem_lockspace_async(tmpdir, sanlock_daemon): path = str(tmpdir.join("ls_name")) util.create_file(path, MiB)
- sanlock.write_lockspace("ls_name", path, iotimeout=1) - acquired = sanlock.inq_lockspace("ls_name", 1, path, wait=False) + sanlock.write_lockspace(b"ls_name", path, iotimeout=1) + acquired = sanlock.inq_lockspace(b"ls_name", 1, path, wait=False) assert acquired is False
# This will take 3 seconds. - sanlock.add_lockspace("ls_name", 1, path, iotimeout=1, **{"async": True}) + sanlock.add_lockspace(b"ls_name", 1, path, iotimeout=1, **{"async": True})
# While the lockspace is being aquired, we expect to get None. time.sleep(1) - acquired = sanlock.inq_lockspace("ls_name", 1, path, wait=False) + acquired = sanlock.inq_lockspace(b"ls_name", 1, path, wait=False) assert acquired is None
# Once the lockspace is acquired, we exepect to get True. - acquired = sanlock.inq_lockspace("ls_name", 1, path, wait=True) + acquired = sanlock.inq_lockspace(b"ls_name", 1, path, wait=True) assert acquired is True
# This will take about 3 seconds. - sanlock.rem_lockspace("ls_name", 1, path, **{"async": True}) + sanlock.rem_lockspace(b"ls_name", 1, path, **{"async": True})
# Wait until the lockspace change state from True to None. - while sanlock.inq_lockspace("ls_name", 1, path, wait=False): + while sanlock.inq_lockspace(b"ls_name", 1, path, wait=False): time.sleep(1)
# While the lockspace is being released, we expect to get None. - acquired = sanlock.inq_lockspace("ls_name", 1, path, wait=False) + acquired = sanlock.inq_lockspace(b"ls_name", 1, path, wait=False) assert acquired is None
# Once the lockspace was released, we expect to get False. - acquired = sanlock.inq_lockspace("ls_name", 1, path, wait=True) + acquired = sanlock.inq_lockspace(b"ls_name", 1, path, wait=True) assert acquired is False
+@pytest.mark.xfail(six.PY3, reason="lockspace/resource names in bytes are unsupported yet") @pytest.mark.parametrize("size,offset", [ # Smallest offset. (MIN_RES_SIZE, 0), @@ -391,20 +403,20 @@ def test_acquire_release_resource(tmpdir, sanlock_daemon, size, offset): res_path = str(tmpdir.join("res_name")) util.create_file(res_path, size)
- sanlock.write_lockspace("ls_name", ls_path, offset=offset, iotimeout=1) - sanlock.add_lockspace("ls_name", 1, ls_path, offset=offset, iotimeout=1) + sanlock.write_lockspace(b"ls_name", ls_path, offset=offset, iotimeout=1) + sanlock.add_lockspace(b"ls_name", 1, ls_path, offset=offset, iotimeout=1)
# Host status is not available until the first renewal. with pytest.raises(sanlock.SanlockException) as e: - sanlock.get_hosts("ls_name", 1) + sanlock.get_hosts(b"ls_name", 1) assert e.value.errno == errno.EAGAIN
time.sleep(1) - host = sanlock.get_hosts("ls_name", 1)[0] + host = sanlock.get_hosts(b"ls_name", 1)[0] assert host["flags"] == sanlock.HOST_LIVE
disks = [(res_path, offset)] - sanlock.write_resource("ls_name", "res_name", disks) + sanlock.write_resource(b"ls_name", b"res_name", disks)
res = sanlock.read_resource(res_path, offset=offset) assert res == { @@ -413,11 +425,11 @@ def test_acquire_release_resource(tmpdir, sanlock_daemon, size, offset): "version": 0 }
- owners = sanlock.read_resource_owners("ls_name", "res_name", disks) + owners = sanlock.read_resource_owners(b"ls_name", b"res_name", disks) assert owners == []
fd = sanlock.register() - sanlock.acquire("ls_name", "res_name", disks, slkfd=fd) + sanlock.acquire(b"ls_name", b"res_name", disks, slkfd=fd)
res = sanlock.read_resource(res_path, offset=offset) assert res == { @@ -426,7 +438,7 @@ def test_acquire_release_resource(tmpdir, sanlock_daemon, size, offset): "version": 1 }
- owner = sanlock.read_resource_owners("ls_name", "res_name", disks)[0] + owner = sanlock.read_resource_owners(b"ls_name", b"res_name", disks)[0]
assert owner["host_id"] == 1 assert owner["flags"] == 0 @@ -434,11 +446,11 @@ def test_acquire_release_resource(tmpdir, sanlock_daemon, size, offset): assert owner["io_timeout"] == 0 # Why 0? # TODO: check timestamp.
- host = sanlock.get_hosts("ls_name", 1)[0] + host = sanlock.get_hosts(b"ls_name", 1)[0] assert host["flags"] == sanlock.HOST_LIVE assert host["generation"] == owner["generation"]
- sanlock.release("ls_name", "res_name", disks, slkfd=fd) + sanlock.release(b"ls_name", b"res_name", disks, slkfd=fd)
res = sanlock.read_resource(res_path, offset=offset) assert res == { @@ -447,10 +459,11 @@ def test_acquire_release_resource(tmpdir, sanlock_daemon, size, offset): "version": 1 }
- owners = sanlock.read_resource_owners("ls_name", "res_name", disks) + owners = sanlock.read_resource_owners(b"ls_name", b"res_name", disks) assert owners == []
+@pytest.mark.xfail(six.PY3, reason="lockspace/resource names in bytes are unsupported yet") @pytest.mark.parametrize("align, sector", [ # Invalid alignment (KiB, sanlock.SECTOR_SIZE[0]), @@ -463,9 +476,10 @@ def test_write_lockspace_invalid_align_sector( util.create_file(path, LOCKSPACE_SIZE)
with pytest.raises(ValueError): - sanlock.write_lockspace("name", path, align=align, sector=sector) + sanlock.write_lockspace(b"ls_name", path, align=align, sector=sector)
+@pytest.mark.xfail(six.PY3, reason="lockspace/resource names in bytes are unsupported yet") @pytest.mark.parametrize("align, sector", [ # Invalid alignment (KiB, sanlock.SECTOR_SIZE[0]), @@ -480,9 +494,10 @@ def test_write_resource_invalid_align_sector(
with pytest.raises(ValueError): sanlock.write_resource( - "ls_name", "res_name", disks, align=align, sector=sector) + b"ls_name", b"res_name", disks, align=align, sector=sector)
+@pytest.mark.xfail(six.PY3, reason="lockspace/resource names in bytes are unsupported yet") @pytest.mark.parametrize("disk", [ # Not a tuple - unicode and bytes: "not a tuple", @@ -501,7 +516,7 @@ def test_write_resource_invalid_disk(tmpdir, sanlock_daemon, disk): # Test parsing disks list with invalid content. disks = [disk] with pytest.raises(ValueError) as e: - sanlock.write_resource("ls_name", "res_name", disks) + sanlock.write_resource(b"ls_name", b"res_name", disks) assert repr(disk) in str(e.value)
@@ -537,31 +552,34 @@ def test_write_lockspace_parse_args(no_sanlock_daemon, name): sanlock.write_lockspace(name, "ls_path")
+@pytest.mark.xfail(six.PY3, reason="lockspace/resource names in bytes are unsupported yet") @pytest.mark.parametrize("name", LOCKSPACE_OR_RESOURCE_NAMES) def test_write_resource_parse_args(no_sanlock_daemon, name): with raises_sanlock_errno(): - sanlock.write_resource(name, "res_name", [("disk_path",0)]) + sanlock.write_resource(name, b"res_name", [("disk_path",0)])
with raises_sanlock_errno(): - sanlock.write_resource("ls_name", name, [("disk_path",0)]) + sanlock.write_resource(b"ls_name", name, [("disk_path",0)])
+@pytest.mark.xfail(six.PY3, reason="lockspace/resource names in bytes are unsupported yet") @pytest.mark.parametrize("name", LOCKSPACE_OR_RESOURCE_NAMES) def test_release_resource_parse_args(no_sanlock_daemon, name): with raises_sanlock_errno(): - sanlock.release(name, "res_name", [("disk_path",0)]) + sanlock.release(name, b"res_name", [("disk_path",0)])
with raises_sanlock_errno(): - sanlock.release("ls_name", name, [("disk_path",0)]) + sanlock.release(b"ls_name", name, [("disk_path",0)])
+@pytest.mark.xfail(six.PY3, reason="lockspace/resource names in bytes are unsupported yet") @pytest.mark.parametrize("name", LOCKSPACE_OR_RESOURCE_NAMES) def test_read_resource_owners_parse_args(no_sanlock_daemon, name): with raises_sanlock_errno(): - sanlock.read_resource_owners(name, "res_name", [("disk_path",0)]) + sanlock.read_resource_owners(name, b"res_name", [("disk_path",0)])
with raises_sanlock_errno(): - sanlock.read_resource_owners("ls_name", name, [("disk_path",0)]) + sanlock.read_resource_owners(b"ls_name", name, [("disk_path",0)])
@pytest.mark.parametrize("name", LOCKSPACE_OR_RESOURCE_NAMES)
sanlock-devel@lists.fedorahosted.org