This is an automated email from the git hooks/post-receive script.
nsoffer pushed a commit to branch master
in repository sanlock.
commit b0634b270bdeb88e2301859e46a80a9be95c89d3
Author: Nir Soffer <nsoffer(a)redhat.com>
AuthorDate: Sun Jun 16 22:33:16 2019 +0300
python: Add failing tests for long disk path
Sanlock allow up to 1023 characters in a disk path. We used to truncate
invalid long path silently instead of failing. Add failing tests for the
expected behaviour.
Signed-off-by: Nir Soffer <nsoffer(a)redhat.com>
---
tests/constants.py | 4 +++
tests/python_test.py | 78 ++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 82 insertions(+)
diff --git a/tests/constants.py b/tests/constants.py
index 3d9c332..4a98b3d 100644
--- a/tests/constants.py
+++ b/tests/constants.py
@@ -27,3 +27,7 @@ RINDEX_ENTRIES_SECTORS = 2000
# src/sanlock_rv.h
SANLK_LEADER_MAGIC = -223
+
+# src/sanlock.h
+
+SANLK_PATH_LEN = 1024
diff --git a/tests/python_test.py b/tests/python_test.py
index 86e60b1..4ea1589 100644
--- a/tests/python_test.py
+++ b/tests/python_test.py
@@ -601,6 +601,17 @@ def test_write_resource_parse_args(
sanlock.write_resource(b"ls_name", name, disks)
+(a)pytest.mark.xfail(reason="path truncated silently")
+def test_write_resource_path_length(no_sanlock_daemon):
+ path = "x" * constants.SANLK_PATH_LEN
+ with pytest.raises(ValueError):
+ sanlock.write_resource(b"ls_name", b"res_name", [(path, 0)])
+
+ path = "x" * (constants.SANLK_PATH_LEN - 1)
+ with raises_sanlock_errno():
+ sanlock.write_resource(b"ls_name", b"res_name", [(path, 0)])
+
+
@pytest.mark.parametrize("name", LOCKSPACE_OR_RESOURCE_NAMES)
@pytest.mark.parametrize("filename,encoding", FILE_NAMES)
def test_release_resource_parse_args(
@@ -614,6 +625,17 @@ def test_release_resource_parse_args(
sanlock.release(b"ls_name", name, disks)
+(a)pytest.mark.xfail(reason="path truncated silently")
+def test_release_resource_path_length(no_sanlock_daemon):
+ path = "x" * constants.SANLK_PATH_LEN
+ with pytest.raises(ValueError):
+ sanlock.release(b"ls_name", b"res_name", [(path, 0)])
+
+ path = "x" * (constants.SANLK_PATH_LEN - 1)
+ with raises_sanlock_errno():
+ sanlock.release(b"ls_name", b"res_name", [(path, 0)])
+
+
@pytest.mark.parametrize("name", LOCKSPACE_OR_RESOURCE_NAMES)
@pytest.mark.parametrize("filename,encoding", FILE_NAMES)
def test_read_resource_owners_parse_args(
@@ -627,6 +649,17 @@ def test_read_resource_owners_parse_args(
sanlock.read_resource_owners(b"ls_name", name, disks)
+(a)pytest.mark.xfail(reason="path truncated silently")
+def test_read_resource_owners_path_length(no_sanlock_daemon):
+ path = "x" * constants.SANLK_PATH_LEN
+ with pytest.raises(ValueError):
+ sanlock.read_resource_owners(b"ls_name", b"res_name", [(path,
0)])
+
+ path = "x" * (constants.SANLK_PATH_LEN - 1)
+ with raises_sanlock_errno():
+ sanlock.read_resource_owners(b"ls_name", b"res_name", [(path,
0)])
+
+
@pytest.mark.parametrize("name", LOCKSPACE_OR_RESOURCE_NAMES)
def test_get_hosts_parse_args(no_sanlock_daemon, name):
with raises_sanlock_errno():
@@ -679,6 +712,18 @@ def test_init_resource_parse_args(no_sanlock_daemon, name, filename,
encoding):
sanlock.init_resource(name, b"res_name", disks)
+(a)pytest.mark.xfail(reason="path truncated silently")
+def test_init_resource_path_length(no_sanlock_daemon):
+ path = "x" * constants.SANLK_PATH_LEN
+ with pytest.raises(ValueError):
+ sanlock.init_resource(b"ls_name", b"res_name", [(path, 0)])
+
+ # init_resource access storage directly.
+ path = "x" * (constants.SANLK_PATH_LEN - 1)
+ with raises_sanlock_errno(errno.ENAMETOOLONG):
+ sanlock.init_resource(b"ls_name", b"res_name", [(path, 0)])
+
+
@pytest.mark.parametrize("filename,encoding", FILE_NAMES)
def test_get_alignment_parse_args(no_sanlock_daemon, filename, encoding):
path = util.generate_path("/tmp/", filename, encoding)
@@ -700,6 +745,17 @@ def test_read_resource_parse_args(no_sanlock_daemon, filename,
encoding):
sanlock.read_resource(path)
+(a)pytest.mark.xfail(reason="path truncated silently")
+def test_read_resource_path_length(no_sanlock_daemon):
+ path = "x" * constants.SANLK_PATH_LEN
+ with pytest.raises(ValueError):
+ sanlock.read_resource(path)
+
+ path = "x" * (constants.SANLK_PATH_LEN - 1)
+ with raises_sanlock_errno():
+ sanlock.read_resource(path)
+
+
@pytest.mark.parametrize("name", LOCKSPACE_OR_RESOURCE_NAMES)
@pytest.mark.parametrize("filename,encoding", FILE_NAMES)
def test_request_parse_args(no_sanlock_daemon, name, filename, encoding):
@@ -713,6 +769,17 @@ def test_request_parse_args(no_sanlock_daemon, name, filename,
encoding):
sanlock.request(name, b"res_name", disks)
+(a)pytest.mark.xfail(reason="path truncated silently")
+def test_request_path_length(no_sanlock_daemon):
+ path = "x" * constants.SANLK_PATH_LEN
+ with pytest.raises(ValueError):
+ sanlock.request(b"ls_name", b"res_name", [(path, 0)])
+
+ path = "x" * (constants.SANLK_PATH_LEN - 1)
+ with raises_sanlock_errno():
+ sanlock.request(b"ls_name", b"res_name", [(path, 0)])
+
+
@pytest.mark.parametrize("name", LOCKSPACE_OR_RESOURCE_NAMES)
@pytest.mark.parametrize("filename,encoding", FILE_NAMES)
def test_acquire_parse_args(no_sanlock_daemon, name, filename, encoding):
@@ -724,3 +791,14 @@ def test_acquire_parse_args(no_sanlock_daemon, name, filename,
encoding):
with raises_sanlock_errno():
sanlock.acquire(name, b"res_name", disks, pid=os.getpid())
+
+
+(a)pytest.mark.xfail(reason="path truncated silently")
+def test_acquire_path_length(no_sanlock_daemon):
+ path = "x" * constants.SANLK_PATH_LEN
+ with pytest.raises(ValueError):
+ sanlock.acquire(b"ls_name", b"res_name", [(path, 0)],
pid=os.getpid())
+
+ path = "x" * (constants.SANLK_PATH_LEN - 1)
+ with raises_sanlock_errno():
+ sanlock.acquire(b"ls_name", b"res_name", [(path, 0)],
pid=os.getpid())
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.