More cleanups patches based on my last cleanups series.
The path legnth validation fix is a very old issue, but it can be nice to deliver in 3.8.1. More fixes are needed for truncating silently lockspace path, lockspace name and resource name.
These are only the new patches since v1. I will combine all pathes in v3.
v1 was here: https://lists.fedorahosted.org/archives/list/sanlock-devel@lists.fedorahoste...
The changes are also availale in: https://github.com/nirs/sanlock/tree/cleanups-v2
Based on commit 50a6590db428769e653282f11eb3051c31938a92 (python: Unify resource variables names).
Nir Soffer (8): python: Use Py_BuildValue to create event dicts python: Use Py_CLEAR python: Streamline initexception python: Extract create_resource() helper python: Replace memset() with initializer python: Add missing arg parsing tests python: Add failing tests for long disk path python: Fail with ValueError if disk path is too long
python/sanlock.c | 191 ++++++++++++++++--------------------------- tests/constants.py | 4 + tests/python_test.py | 98 ++++++++++++++++++++++ 3 files changed, 172 insertions(+), 121 deletions(-)
Replace complex and error prone code to build event dict with Py_BuildValue().
Signed-off-by: Nir Soffer nsoffer@redhat.com --- python/sanlock.c | 58 ++++++++---------------------------------------- 1 file changed, 9 insertions(+), 49 deletions(-)
diff --git a/python/sanlock.c b/python/sanlock.c index 9192395..e740f89 100644 --- a/python/sanlock.c +++ b/python/sanlock.c @@ -1525,11 +1525,10 @@ py_get_event(PyObject *self __unused, PyObject *args) struct sanlk_host_event he; uint64_t from_host_id; uint64_t from_generation; PyObject *events = NULL; PyObject *item = NULL; - PyObject *value = NULL; int rv;
if (!PyArg_ParseTuple(args, "i", &fd)) return NULL;
@@ -1547,59 +1546,20 @@ py_get_event(PyObject *self __unused, PyObject *args) if (rv != 0) { set_sanlock_error(rv, "Unable to get events"); goto exit_fail; }
- if ((item = PyDict_New()) == NULL) - goto exit_fail; + item = Py_BuildValue( + "{s:K,s:K,s:K,s:K,s:K,s:K}", + "from_host_id", from_host_id, + "from_generation", from_generation, + "host_id", he.host_id, + "generation", he.generation, + "event", he.event, + "data", he.data);
- /* from_host_id */ - if ((value = PyLong_FromUnsignedLongLong(from_host_id)) == NULL) - goto exit_fail; - rv = PyDict_SetItemString(item, "from_host_id", value); - Py_DECREF(value); - if (rv != 0) - goto exit_fail; - - /* from_generation */ - if ((value = PyLong_FromUnsignedLongLong(from_generation)) == NULL) - goto exit_fail; - rv = PyDict_SetItemString(item, "from_generation", value); - Py_DECREF(value); - if (rv != 0) - goto exit_fail; - - /* host_id */ - if ((value = PyLong_FromUnsignedLongLong(he.host_id)) == NULL) - goto exit_fail; - rv = PyDict_SetItemString(item, "host_id", value); - Py_DECREF(value); - if (rv != 0) - goto exit_fail; - - /* generation */ - if ((value = PyLong_FromUnsignedLongLong(he.generation)) == NULL) - goto exit_fail; - rv = PyDict_SetItemString(item, "generation", value); - Py_DECREF(value); - if (rv != 0) - goto exit_fail; - - /* event */ - if ((value = PyLong_FromUnsignedLongLong(he.event)) == NULL) - goto exit_fail; - rv = PyDict_SetItemString(item, "event", value); - Py_DECREF(value); - if (rv != 0) - goto exit_fail; - - /* data */ - if ((value = PyLong_FromUnsignedLongLong(he.data)) == NULL) - goto exit_fail; - rv = PyDict_SetItemString(item, "data", value); - Py_DECREF(value); - if (rv != 0) + if (item == NULL) goto exit_fail;
if (PyList_Append(events, item) != 0) goto exit_fail;
Instead of:
Py_DECREF(obj); obj = NULL;
We can use:
Py_CLEAR(obj);
Signed-off-by: Nir Soffer nsoffer@redhat.com --- python/sanlock.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/python/sanlock.c b/python/sanlock.c index e740f89..21a7a76 100644 --- a/python/sanlock.c +++ b/python/sanlock.c @@ -1561,12 +1561,11 @@ py_get_event(PyObject *self __unused, PyObject *args) goto exit_fail;
if (PyList_Append(events, item) != 0) goto exit_fail;
- Py_DECREF(item); - item = NULL; + Py_CLEAR(item); }
return events;
exit_fail:
When we create the sanlock expcetion we create a function, create a method from the function, create a dict from the method, and finally create an exception from the dict. This simple flow does not require goto for cleanup.
Creating a dict is simpler and less error prone using Py_BuildValue().
When we finish with unused pointers, it is safer to set them to NULL using Py_CLEAR(), ensuring that we don't access freed memory.
Signed-off-by: Nir Soffer nsoffer@redhat.com --- python/sanlock.c | 31 ++++++++++++------------------- 1 file changed, 12 insertions(+), 19 deletions(-)
diff --git a/python/sanlock.c b/python/sanlock.c index 21a7a76..5c2fd1a 100644 --- a/python/sanlock.c +++ b/python/sanlock.c @@ -1741,33 +1741,26 @@ sanlock_exception = { };
static PyObject * initexception(void) { - int rv; - PyObject *dict, *func, *meth, *excp = NULL; - - if ((dict = PyDict_New()) == NULL) - goto exit_fail; - - if ((func = PyCFunction_New(&sanlock_exception, NULL)) == NULL) - goto exit_fail; + PyObject *func = PyCFunction_New(&sanlock_exception, NULL); + if (func == NULL) + return NULL;
- meth = PyObject_CallFunction((PyObject *) &PyProperty_Type, "O", func); - Py_DECREF(func); + PyObject *meth = PyObject_CallFunction((PyObject *) &PyProperty_Type, "O", func); + Py_CLEAR(func); if (meth == NULL) - goto exit_fail; - - rv = PyDict_SetItemString(dict, sanlock_exception.ml_name, meth); - Py_DECREF(meth); - if (rv < 0) - goto exit_fail; + return NULL;
- excp = PyErr_NewException("sanlock.SanlockException", NULL, dict); + PyObject *dict = Py_BuildValue("{s:O}", sanlock_exception.ml_name, meth); + Py_CLEAR(meth); + if (dict == NULL) + return NULL;
-exit_fail: - Py_XDECREF(dict); + PyObject *excp = PyErr_NewException("sanlock.SanlockException", NULL, dict); + Py_CLEAR(dict);
return excp; }
static int
Replace duplicate code for allocating and initializing sanlk_resource struct with a helper.
Signed-off-by: Nir Soffer nsoffer@redhat.com --- python/sanlock.c | 46 +++++++++++++++++++++++----------------------- 1 file changed, 23 insertions(+), 23 deletions(-)
diff --git a/python/sanlock.c b/python/sanlock.c index 5c2fd1a..6824e01 100644 --- a/python/sanlock.c +++ b/python/sanlock.c @@ -170,29 +170,38 @@ parse_single_disk(PyObject* disk, struct sanlk_disk* res_disk) finally: Py_XDECREF(path); return rv; }
+static struct sanlk_resource * +create_resource(int num_disks) +{ + size_t size = sizeof(struct sanlk_resource) + + sizeof(struct sanlk_disk) * num_disks; + + struct sanlk_resource *res = calloc(1, size); + if (res == NULL) { + PyErr_NoMemory(); + return NULL; + } + + res->num_disks = num_disks; + + return res; +} + static int parse_disks(PyObject *obj, struct sanlk_resource **res_ret) { - int num_disks, res_len; + int num_disks; struct sanlk_resource *res;
num_disks = PyList_Size(obj);
- res_len = sizeof(struct sanlk_resource) + - (sizeof(struct sanlk_disk) * num_disks); - res = malloc(res_len); - - if (res == NULL) { - PyErr_NoMemory(); + res = create_resource(num_disks); + if (res == NULL) return -1; - } - - memset(res, 0, res_len); - res->num_disks = num_disks;
for (int i = 0; i < num_disks; i++) { PyObject *disk = PyList_GetItem(obj,i);
if (!parse_single_disk(disk, &(res->disks[i]))) { @@ -637,30 +646,21 @@ Align can be one of (1048576, 2097152, 4194304, 8388608).\n\ Sector can be one of (512, 4096).");
static PyObject * py_read_resource(PyObject *self __unused, PyObject *args, PyObject *keywds) { - int rv = -1, res_len, sector = SECTOR_SIZE_512; + int rv = -1, sector = SECTOR_SIZE_512; long align = ALIGNMENT_1M; PyObject *path = NULL; struct sanlk_resource *res; PyObject *res_info = NULL;
static char *kwlist[] = {"path", "offset", "align", "sector", NULL};
- /* allocate the needed memory for the resource and one disk */ - res_len = sizeof(struct sanlk_resource) + sizeof(struct sanlk_disk); - res = malloc(res_len); - - if (res == NULL) { - PyErr_NoMemory(); + res = create_resource(1 /* num_disks */); + if (res == NULL) return NULL; - } - - /* initialize resource and disk structures */ - memset(res, 0, res_len); - res->num_disks = 1;
/* parse python tuple */ if (!PyArg_ParseTupleAndKeywords(args, keywds, "O&|kli", kwlist, pypath_converter, &path, &(res->disks[0].offset), &align, §or)) { goto finally;
C99 ensures that all fields of a struct are initialized to zero when initializing to {0} and all characters are initialized to zero when initializing to "";
Signed-off-by: Nir Soffer nsoffer@redhat.com --- python/sanlock.c | 36 ++++++++---------------------------- 1 file changed, 8 insertions(+), 28 deletions(-)
diff --git a/python/sanlock.c b/python/sanlock.c index 6824e01..ca3713d 100644 --- a/python/sanlock.c +++ b/python/sanlock.c @@ -341,18 +341,17 @@ Get device alignment."); static PyObject * py_get_alignment(PyObject *self __unused, PyObject *args) { int rv = -1; PyObject *path = NULL; - struct sanlk_disk disk; + struct sanlk_disk disk = {0};
/* parse python tuple */ if (!PyArg_ParseTuple(args, "O&", pypath_converter, &path)) { goto finally; }
- memset(&disk, 0, sizeof(struct sanlk_disk)); strncpy(disk.path, PyBytes_AsString(path), SANLK_PATH_LEN - 1);
/* get device alignment (gil disabled) */ Py_BEGIN_ALLOW_THREADS rv = sanlock_direct_align(&disk); @@ -418,18 +417,15 @@ static PyObject * py_init_lockspace(PyObject *self __unused, PyObject *args, PyObject *keywds) { int rv = -1, max_hosts = 0, num_hosts = 0, use_aio = 1; PyObject *lockspace = NULL; PyObject *path = NULL; - struct sanlk_lockspace ls; + struct sanlk_lockspace ls = {0};
static char *kwlist[] = {"lockspace", "path", "offset", "max_hosts", "num_hosts", "use_aio", NULL};
- /* initialize lockspace structure */ - memset(&ls, 0, sizeof(struct sanlk_lockspace)); - /* parse python tuple */ if (!PyArg_ParseTupleAndKeywords(args, keywds, "O&O&|kiii", kwlist, convert_to_pybytes, &lockspace, pypath_converter, &path, &ls.host_id_disk.offset, &max_hosts, &num_hosts, &use_aio)) { goto finally; @@ -525,18 +521,15 @@ py_write_lockspace(PyObject *self __unused, PyObject *args, PyObject *keywds) int rv = -1, max_hosts = 0, sector = SECTOR_SIZE_512; long align = ALIGNMENT_1M; uint32_t io_timeout = 0; PyObject *lockspace = NULL; PyObject *path = NULL; - struct sanlk_lockspace ls; + struct sanlk_lockspace ls = {0};
static char *kwlist[] = {"lockspace", "path", "offset", "max_hosts", "iotimeout", "align", "sector", NULL};
- /* initialize lockspace structure */ - memset(&ls, 0, sizeof(struct sanlk_lockspace)); - /* parse python tuple */ if (!PyArg_ParseTupleAndKeywords(args, keywds, "O&O&|kiIli", kwlist, convert_to_pybytes, &lockspace, pypath_converter, &path, &ls.host_id_disk.offset, &max_hosts, &io_timeout, &align, §or)) { goto finally; @@ -583,18 +576,15 @@ py_read_lockspace(PyObject *self __unused, PyObject *args, PyObject *keywds) { int rv = -1, sector = SECTOR_SIZE_512; long align = ALIGNMENT_1M; uint32_t io_timeout = 0; PyObject *path = NULL; - struct sanlk_lockspace ls; + struct sanlk_lockspace ls = {0}; PyObject *ls_info = NULL;
static char *kwlist[] = {"path", "offset", "align", "sector", NULL};
- /* initialize lockspace structure */ - memset(&ls, 0, sizeof(struct sanlk_lockspace)); - /* parse python tuple */ if (!PyArg_ParseTupleAndKeywords(args, keywds, "O&|kli", kwlist, pypath_converter, &path, &ls.host_id_disk.offset, &align, §or)) { goto finally; } @@ -793,18 +783,15 @@ py_add_lockspace(PyObject *self __unused, PyObject *args, PyObject *keywds) int rv = -1, flags = 0; int wait = 1; uint32_t iotimeout = 0; PyObject *lockspace = NULL; PyObject *path = NULL; - struct sanlk_lockspace ls; + struct sanlk_lockspace ls = {0};
static char *kwlist[] = {"lockspace", "host_id", "path", "offset", "iotimeout", "wait", NULL};
- /* initialize lockspace structure */ - memset(&ls, 0, sizeof(struct sanlk_lockspace)); - /* parse python tuple */ if (!PyArg_ParseTupleAndKeywords(args, keywds, "O&kO&|kIi", kwlist, convert_to_pybytes, &lockspace, &ls.host_id, pypath_converter, &path, &ls.host_id_disk.offset, &iotimeout, &wait)) { goto finally; @@ -850,18 +837,15 @@ static PyObject * py_inq_lockspace(PyObject *self __unused, PyObject *args, PyObject *keywds) { int rv = BIND_ERROR, waitrs = 0, flags = 0; PyObject *lockspace = NULL; PyObject *path = NULL; - struct sanlk_lockspace ls; + struct sanlk_lockspace ls = {0};
static char *kwlist[] = {"lockspace", "host_id", "path", "offset", "wait", NULL};
- /* initialize lockspace structure */ - memset(&ls, 0, sizeof(struct sanlk_lockspace)); - /* parse python tuple */ if (!PyArg_ParseTupleAndKeywords(args, keywds, "O&kO&|ki", kwlist, convert_to_pybytes, &lockspace, &ls.host_id, pypath_converter, &path, &ls.host_id_disk.offset, &waitrs)) { goto finally; @@ -914,18 +898,15 @@ py_rem_lockspace(PyObject *self __unused, PyObject *args, PyObject *keywds) { int rv = -1, unused = 0, flags = 0; int wait = 1; PyObject *lockspace = NULL; PyObject *path = NULL; - struct sanlk_lockspace ls; + struct sanlk_lockspace ls = {0};
static char *kwlist[] = {"lockspace", "host_id", "path", "offset", "wait", "unused", NULL};
- /* initialize lockspace structure */ - memset(&ls, 0, sizeof(struct sanlk_lockspace)); - /* parse python tuple */ if (!PyArg_ParseTupleAndKeywords(args, keywds, "O&kO&|kii", kwlist, convert_to_pybytes, &lockspace, &ls.host_id, pypath_converter, &path, &ls.host_id_disk.offset, &wait, &unused)) { @@ -1405,11 +1386,11 @@ The arguments must be in the format: ["arg1", "arg2", ...]"); static PyObject * py_killpath(PyObject *self __unused, PyObject *args, PyObject *keywds) { int rv = -1, num_args, sanlockfd = -1; size_t kplen = 0; - char kpargs[SANLK_HELPER_ARGS_LEN]; + char kpargs[SANLK_HELPER_ARGS_LEN] = ""; PyObject *path = NULL; PyObject *argslist;
static char *kwlist[] = {"path", "args", "slkfd", NULL};
@@ -1424,11 +1405,10 @@ py_killpath(PyObject *self __unused, PyObject *args, PyObject *keywds) set_sanlock_error(EINVAL, "Killpath path argument too long"); goto finally; }
num_args = PyList_Size(argslist); - memset(kpargs, 0, SANLK_HELPER_ARGS_LEN);
/* creating the arguments string from a python list */ for (int i = 0; i < num_args; i++) { PyObject *item = PyList_GetItem(argslist, i); if (!parse_killpath_item(item, kpargs, &kplen)) {
Add argument parsing tests for sanlock.acquire() and sanlock.request().
Signed-off-by: Nir Soffer nsoffer@redhat.com --- tests/python_test.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+)
diff --git a/tests/python_test.py b/tests/python_test.py index 4320dad..cd8a82f 100644 --- a/tests/python_test.py +++ b/tests/python_test.py @@ -9,10 +9,11 @@ Test sanlock python binding with sanlock daemon. """ from __future__ import absolute_import
import errno import io +import os import struct import time
from contextlib import contextmanager
@@ -641,5 +642,30 @@ def test_read_lockspace_parse_args(no_sanlock_daemon, filename, encoding): def test_read_resource_parse_args(no_sanlock_daemon, filename, encoding): path = util.generate_path("/tmp/", filename, encoding) 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): + path = util.generate_path("/tmp/", filename, encoding) + disks = [(path, 0)] + + with raises_sanlock_errno(): + sanlock.request(b"ls_name", name, disks) + + with raises_sanlock_errno(): + sanlock.request(name, b"res_name", disks) + + +@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): + path = util.generate_path("/tmp/", filename, encoding) + disks = [(path, 0)] + + with raises_sanlock_errno(): + sanlock.acquire(b"ls_name", name, disks, pid=os.getpid()) + + with raises_sanlock_errno(): + sanlock.acquire(name, b"res_name", disks, pid=os.getpid())
LGTM
On Sun, Jun 16, 2019 at 11:50 PM Nir Soffer nirsof@gmail.com wrote:
Add argument parsing tests for sanlock.acquire() and sanlock.request().
Signed-off-by: Nir Soffer nsoffer@redhat.com
tests/python_test.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+)
diff --git a/tests/python_test.py b/tests/python_test.py index 4320dad..cd8a82f 100644 --- a/tests/python_test.py +++ b/tests/python_test.py @@ -9,10 +9,11 @@ Test sanlock python binding with sanlock daemon. """ from __future__ import absolute_import
import errno import io +import os import struct import time
from contextlib import contextmanager
@@ -641,5 +642,30 @@ def test_read_lockspace_parse_args(no_sanlock_daemon, filename, encoding): def test_read_resource_parse_args(no_sanlock_daemon, filename, encoding): path = util.generate_path("/tmp/", filename, encoding) 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):
- path = util.generate_path("/tmp/", filename, encoding)
- disks = [(path, 0)]
- with raises_sanlock_errno():
sanlock.request(b"ls_name", name, disks)- with raises_sanlock_errno():
sanlock.request(name, b"res_name", disks)+@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):
- path = util.generate_path("/tmp/", filename, encoding)
- disks = [(path, 0)]
- with raises_sanlock_errno():
sanlock.acquire(b"ls_name", name, disks, pid=os.getpid())- with raises_sanlock_errno():
sanlock.acquire(name, b"res_name", disks, pid=os.getpid())-- 2.17.2
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@redhat.com --- tests/constants.py | 4 +++ tests/python_test.py | 79 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 83 insertions(+)
diff --git a/tests/constants.py b/tests/constants.py index 4f45d13..2371fed 100644 --- a/tests/constants.py +++ b/tests/constants.py @@ -21,5 +21,9 @@ RINDEX_DISK_MAGIC = 0x01042018 # src/rindex_disk.h # Copied from the docs module comment.
RINDEX_ENTRY_SIZE = 64 RINDEX_ENTRIES_SECTORS = 2000 + +# src/sanlock.h + +SANLK_PATH_LEN = 1024 diff --git a/tests/python_test.py b/tests/python_test.py index cd8a82f..5624f60 100644 --- a/tests/python_test.py +++ b/tests/python_test.py @@ -550,10 +550,21 @@ def test_write_resource_parse_args(no_sanlock_daemon, name, filename, encoding):
with raises_sanlock_errno(): sanlock.write_resource(b"ls_name", name, disks)
+@pytest.mark.xfail(reason="path truncated silently") +def test_write_resource_path_length(no_sanlock_daemon): + with pytest.raises(ValueError): + path = "x" * constants.SANLK_PATH_LEN + sanlock.write_resource(b"ls_name", b"res_name", [(path, 0)]) + + with raises_sanlock_errno(): + path = "x" * (constants.SANLK_PATH_LEN - 1) + 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(no_sanlock_daemon, name, filename, encoding): path = util.generate_path("/tmp/", filename, encoding) disks = [(path, 0)] @@ -562,10 +573,21 @@ def test_release_resource_parse_args(no_sanlock_daemon, name, filename, encoding
with raises_sanlock_errno(): sanlock.release(b"ls_name", name, disks)
+@pytest.mark.xfail(reason="path truncated silently") +def test_release_resource_path_length(no_sanlock_daemon): + with pytest.raises(ValueError): + path = "x" * constants.SANLK_PATH_LEN + sanlock.release(b"ls_name", b"res_name", [(path, 0)]) + + with raises_sanlock_errno(): + path = "x" * (constants.SANLK_PATH_LEN - 1) + 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(no_sanlock_daemon, name, filename, encoding): path = util.generate_path("/tmp/", filename, encoding) disks = [(path, 0)] @@ -574,10 +596,21 @@ def test_read_resource_owners_parse_args(no_sanlock_daemon, name, filename, enco
with raises_sanlock_errno(): sanlock.read_resource_owners(b"ls_name", name, disks)
+@pytest.mark.xfail(reason="path truncated silently") +def test_read_resource_owners_path_length(no_sanlock_daemon): + with pytest.raises(ValueError): + path = "x" * constants.SANLK_PATH_LEN + sanlock.read_resource_owners(b"ls_name", b"res_name", [(path, 0)]) + + with raises_sanlock_errno(): + path = "x" * (constants.SANLK_PATH_LEN - 1) + 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(): sanlock.get_hosts(name, 1)
@@ -624,10 +657,23 @@ def test_init_resource_parse_args(no_sanlock_daemon, name, filename, encoding): with raises_sanlock_errno(errno.ENOENT): sanlock.init_resource(b"ls_name", name, disks) with raises_sanlock_errno(errno.ENOENT): sanlock.init_resource(name, b"res_name", disks)
+ +@pytest.mark.xfail(reason="path truncated silently") +def test_init_resource_path_length(no_sanlock_daemon): + with pytest.raises(ValueError): + path = "x" * constants.SANLK_PATH_LEN + sanlock.init_resource(b"ls_name", b"res_name", [(path, 0)]) + + # init_resource access storage directly. + with raises_sanlock_errno(errno.ENAMETOOLONG): + path = "x" * (constants.SANLK_PATH_LEN - 1) + 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) with raises_sanlock_errno(errno.ENOENT): sanlock.get_alignment(path) @@ -643,10 +689,21 @@ def test_read_resource_parse_args(no_sanlock_daemon, filename, encoding): path = util.generate_path("/tmp/", filename, encoding) with raises_sanlock_errno(): sanlock.read_resource(path)
+@pytest.mark.xfail(reason="path truncated silently") +def test_read_resource_path_length(no_sanlock_daemon): + with pytest.raises(ValueError): + path = "x" * constants.SANLK_PATH_LEN + sanlock.read_resource(path) + + with raises_sanlock_errno(): + path = "x" * (constants.SANLK_PATH_LEN - 1) + 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): path = util.generate_path("/tmp/", filename, encoding) disks = [(path, 0)] @@ -656,10 +713,21 @@ def test_request_parse_args(no_sanlock_daemon, name, filename, encoding):
with raises_sanlock_errno(): sanlock.request(name, b"res_name", disks)
+@pytest.mark.xfail(reason="path truncated silently") +def test_request_path_length(no_sanlock_daemon): + with pytest.raises(ValueError): + path = "x" * constants.SANLK_PATH_LEN + sanlock.request(b"ls_name", b"res_name", [(path, 0)]) + + with raises_sanlock_errno(): + path = "x" * (constants.SANLK_PATH_LEN - 1) + 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): path = util.generate_path("/tmp/", filename, encoding) disks = [(path, 0)] @@ -667,5 +735,16 @@ def test_acquire_parse_args(no_sanlock_daemon, name, filename, encoding): with raises_sanlock_errno(): sanlock.acquire(b"ls_name", name, disks, pid=os.getpid())
with raises_sanlock_errno(): sanlock.acquire(name, b"res_name", disks, pid=os.getpid()) + + +@pytest.mark.xfail(reason="path truncated silently") +def test_acquire_path_length(no_sanlock_daemon): + with pytest.raises(ValueError): + path = "x" * constants.SANLK_PATH_LEN + sanlock.acquire(b"ls_name", b"res_name", [(path, 0)], pid=os.getpid()) + + with raises_sanlock_errno(): + path = "x" * (constants.SANLK_PATH_LEN - 1) + sanlock.acquire(b"ls_name", b"res_name", [(path, 0)], pid=os.getpid())
Previously if a path was too long, we truncated the path silently. This probably fail when sanlock try to access non-existing path with "No such path or directory" error. If you are unlucky, this could try to access the wrong path, failing with bogus error, returning wrong data, or worse, writing a resource into the wrong location, destroying existing data.
Now we fail immediately with:
ValueError: Path is too long: '/too/long/path/...'
Signed-off-by: Nir Soffer nsoffer@redhat.com --- python/sanlock.c | 17 +++++++++++++++++ tests/python_test.py | 7 ------- 2 files changed, 17 insertions(+), 7 deletions(-)
diff --git a/python/sanlock.c b/python/sanlock.c index ca3713d..7c50aba 100644 --- a/python/sanlock.c +++ b/python/sanlock.c @@ -143,10 +143,21 @@ pystring_as_cstring(PyObject *obj) #else return PyUnicode_AsUTF8(obj); #endif }
+static int +validate_path(PyObject *path) +{ + if (PyBytes_Size(path) > SANLK_PATH_LEN - 1) { + set_error(PyExc_ValueError, "Path is too long: %s", path); + return 0; + } + + return 1; +} + static int parse_single_disk(PyObject* disk, struct sanlk_disk* res_disk) { int rv = 0; PyObject *path = NULL; @@ -161,10 +172,13 @@ parse_single_disk(PyObject* disk, struct sanlk_disk* res_disk) /* Override the error since it confusing in this context. */ set_error(PyExc_ValueError, "Invalid disk %s", disk); goto finally; }
+ if (!validate_path(path)) + goto finally; + strncpy(res_disk->path, PyBytes_AsString(path), SANLK_PATH_LEN - 1); res_disk->offset = offset; rv = 1;
finally: @@ -654,10 +668,13 @@ py_read_resource(PyObject *self __unused, PyObject *args, PyObject *keywds) if (!PyArg_ParseTupleAndKeywords(args, keywds, "O&|kli", kwlist, pypath_converter, &path, &(res->disks[0].offset), &align, §or)) { goto finally; }
+ if (!validate_path(path)) + goto finally; + /* prepare the resource disk path */ strncpy(res->disks[0].path, PyBytes_AsString(path), SANLK_PATH_LEN - 1);
/* set alignment/sector flags */ if (add_align_flag(align, &res->flags) == -1) diff --git a/tests/python_test.py b/tests/python_test.py index 5624f60..47788e4 100644 --- a/tests/python_test.py +++ b/tests/python_test.py @@ -550,11 +550,10 @@ def test_write_resource_parse_args(no_sanlock_daemon, name, filename, encoding):
with raises_sanlock_errno(): sanlock.write_resource(b"ls_name", name, disks)
-@pytest.mark.xfail(reason="path truncated silently") def test_write_resource_path_length(no_sanlock_daemon): with pytest.raises(ValueError): path = "x" * constants.SANLK_PATH_LEN sanlock.write_resource(b"ls_name", b"res_name", [(path, 0)])
@@ -573,11 +572,10 @@ def test_release_resource_parse_args(no_sanlock_daemon, name, filename, encoding
with raises_sanlock_errno(): sanlock.release(b"ls_name", name, disks)
-@pytest.mark.xfail(reason="path truncated silently") def test_release_resource_path_length(no_sanlock_daemon): with pytest.raises(ValueError): path = "x" * constants.SANLK_PATH_LEN sanlock.release(b"ls_name", b"res_name", [(path, 0)])
@@ -596,11 +594,10 @@ def test_read_resource_owners_parse_args(no_sanlock_daemon, name, filename, enco
with raises_sanlock_errno(): sanlock.read_resource_owners(b"ls_name", name, disks)
-@pytest.mark.xfail(reason="path truncated silently") def test_read_resource_owners_path_length(no_sanlock_daemon): with pytest.raises(ValueError): path = "x" * constants.SANLK_PATH_LEN sanlock.read_resource_owners(b"ls_name", b"res_name", [(path, 0)])
@@ -658,11 +655,10 @@ def test_init_resource_parse_args(no_sanlock_daemon, name, filename, encoding): sanlock.init_resource(b"ls_name", name, disks) with raises_sanlock_errno(errno.ENOENT): sanlock.init_resource(name, b"res_name", disks)
-@pytest.mark.xfail(reason="path truncated silently") def test_init_resource_path_length(no_sanlock_daemon): with pytest.raises(ValueError): path = "x" * constants.SANLK_PATH_LEN sanlock.init_resource(b"ls_name", b"res_name", [(path, 0)])
@@ -689,11 +685,10 @@ def test_read_resource_parse_args(no_sanlock_daemon, filename, encoding): path = util.generate_path("/tmp/", filename, encoding) with raises_sanlock_errno(): sanlock.read_resource(path)
-@pytest.mark.xfail(reason="path truncated silently") def test_read_resource_path_length(no_sanlock_daemon): with pytest.raises(ValueError): path = "x" * constants.SANLK_PATH_LEN sanlock.read_resource(path)
@@ -713,11 +708,10 @@ def test_request_parse_args(no_sanlock_daemon, name, filename, encoding):
with raises_sanlock_errno(): sanlock.request(name, b"res_name", disks)
-@pytest.mark.xfail(reason="path truncated silently") def test_request_path_length(no_sanlock_daemon): with pytest.raises(ValueError): path = "x" * constants.SANLK_PATH_LEN sanlock.request(b"ls_name", b"res_name", [(path, 0)])
@@ -737,11 +731,10 @@ 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())
-@pytest.mark.xfail(reason="path truncated silently") def test_acquire_path_length(no_sanlock_daemon): with pytest.raises(ValueError): path = "x" * constants.SANLK_PATH_LEN sanlock.acquire(b"ls_name", b"res_name", [(path, 0)], pid=os.getpid())
We have same limitation for lockspace paths as well, maybe we need to add this validation as part of the path converter to cover all path usages.
On Sun, Jun 16, 2019 at 11:50 PM Nir Soffer nirsof@gmail.com wrote:
Previously if a path was too long, we truncated the path silently. This probably fail when sanlock try to access non-existing path with "No such path or directory" error. If you are unlucky, this could try to access the wrong path, failing with bogus error, returning wrong data, or worse, writing a resource into the wrong location, destroying existing data.
Now we fail immediately with:
ValueError: Path is too long: '/too/long/path/...'Signed-off-by: Nir Soffer nsoffer@redhat.com
python/sanlock.c | 17 +++++++++++++++++ tests/python_test.py | 7 ------- 2 files changed, 17 insertions(+), 7 deletions(-)
diff --git a/python/sanlock.c b/python/sanlock.c index ca3713d..7c50aba 100644 --- a/python/sanlock.c +++ b/python/sanlock.c @@ -143,10 +143,21 @@ pystring_as_cstring(PyObject *obj) #else return PyUnicode_AsUTF8(obj); #endif }
+static int +validate_path(PyObject *path) +{
- if (PyBytes_Size(path) > SANLK_PATH_LEN - 1) {
set_error(PyExc_ValueError, "Path is too long: %s", path);return 0;- }
- return 1;
+}
static int parse_single_disk(PyObject* disk, struct sanlk_disk* res_disk) { int rv = 0; PyObject *path = NULL; @@ -161,10 +172,13 @@ parse_single_disk(PyObject* disk, struct sanlk_disk* res_disk) /* Override the error since it confusing in this context. */ set_error(PyExc_ValueError, "Invalid disk %s", disk); goto finally; }
- if (!validate_path(path))
goto finally;- strncpy(res_disk->path, PyBytes_AsString(path), SANLK_PATH_LEN - 1); res_disk->offset = offset; rv = 1;
finally: @@ -654,10 +668,13 @@ py_read_resource(PyObject *self __unused, PyObject *args, PyObject *keywds) if (!PyArg_ParseTupleAndKeywords(args, keywds, "O&|kli", kwlist, pypath_converter, &path, &(res->disks[0].offset), &align, §or)) { goto finally; }
- if (!validate_path(path))
goto finally;- /* prepare the resource disk path */ strncpy(res->disks[0].path, PyBytes_AsString(path), SANLK_PATH_LEN -
1);
/* set alignment/sector flags */ if (add_align_flag(align, &res->flags) == -1)diff --git a/tests/python_test.py b/tests/python_test.py index 5624f60..47788e4 100644 --- a/tests/python_test.py +++ b/tests/python_test.py @@ -550,11 +550,10 @@ def test_write_resource_parse_args(no_sanlock_daemon, name, filename, encoding):
with raises_sanlock_errno(): sanlock.write_resource(b"ls_name", name, disks)-@pytest.mark.xfail(reason="path truncated silently") def test_write_resource_path_length(no_sanlock_daemon): with pytest.raises(ValueError): path = "x" * constants.SANLK_PATH_LEN sanlock.write_resource(b"ls_name", b"res_name", [(path, 0)])
@@ -573,11 +572,10 @@ def test_release_resource_parse_args(no_sanlock_daemon, name, filename, encoding
with raises_sanlock_errno(): sanlock.release(b"ls_name", name, disks)-@pytest.mark.xfail(reason="path truncated silently") def test_release_resource_path_length(no_sanlock_daemon): with pytest.raises(ValueError): path = "x" * constants.SANLK_PATH_LEN sanlock.release(b"ls_name", b"res_name", [(path, 0)])
@@ -596,11 +594,10 @@ def test_read_resource_owners_parse_args(no_sanlock_daemon, name, filename, enco
with raises_sanlock_errno(): sanlock.read_resource_owners(b"ls_name", name, disks)-@pytest.mark.xfail(reason="path truncated silently") def test_read_resource_owners_path_length(no_sanlock_daemon): with pytest.raises(ValueError): path = "x" * constants.SANLK_PATH_LEN sanlock.read_resource_owners(b"ls_name", b"res_name", [(path, 0)])
@@ -658,11 +655,10 @@ def test_init_resource_parse_args(no_sanlock_daemon, name, filename, encoding): sanlock.init_resource(b"ls_name", name, disks) with raises_sanlock_errno(errno.ENOENT): sanlock.init_resource(name, b"res_name", disks)
-@pytest.mark.xfail(reason="path truncated silently") def test_init_resource_path_length(no_sanlock_daemon): with pytest.raises(ValueError): path = "x" * constants.SANLK_PATH_LEN sanlock.init_resource(b"ls_name", b"res_name", [(path, 0)])
@@ -689,11 +685,10 @@ def test_read_resource_parse_args(no_sanlock_daemon, filename, encoding): path = util.generate_path("/tmp/", filename, encoding) with raises_sanlock_errno(): sanlock.read_resource(path)
-@pytest.mark.xfail(reason="path truncated silently") def test_read_resource_path_length(no_sanlock_daemon): with pytest.raises(ValueError): path = "x" * constants.SANLK_PATH_LEN sanlock.read_resource(path)
@@ -713,11 +708,10 @@ def test_request_parse_args(no_sanlock_daemon, name, filename, encoding):
with raises_sanlock_errno(): sanlock.request(name, b"res_name", disks)-@pytest.mark.xfail(reason="path truncated silently") def test_request_path_length(no_sanlock_daemon): with pytest.raises(ValueError): path = "x" * constants.SANLK_PATH_LEN sanlock.request(b"ls_name", b"res_name", [(path, 0)])
@@ -737,11 +731,10 @@ 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())-@pytest.mark.xfail(reason="path truncated silently") def test_acquire_path_length(no_sanlock_daemon): with pytest.raises(ValueError): path = "x" * constants.SANLK_PATH_LEN sanlock.acquire(b"ls_name", b"res_name", [(path, 0)], pid=os.getpid())
-- 2.17.2
On Thu, Jun 20, 2019 at 4:37 PM Amit Bawer abawer@redhat.com wrote:
We have same limitation for lockspace paths as well, maybe we need to add this validation as part of the path converter to cover all path usages.
Sanlock have different length limitations for paths, so I think this should be solved in the API level.
In the next version I will handle also lockspace paths.
On Sun, Jun 16, 2019 at 11:50 PM Nir Soffer nirsof@gmail.com wrote:
Previously if a path was too long, we truncated the path silently. This probably fail when sanlock try to access non-existing path with "No such path or directory" error. If you are unlucky, this could try to access the wrong path, failing with bogus error, returning wrong data, or worse, writing a resource into the wrong location, destroying existing data.
Now we fail immediately with:
ValueError: Path is too long: '/too/long/path/...'Signed-off-by: Nir Soffer nsoffer@redhat.com
python/sanlock.c | 17 +++++++++++++++++ tests/python_test.py | 7 ------- 2 files changed, 17 insertions(+), 7 deletions(-)
diff --git a/python/sanlock.c b/python/sanlock.c index ca3713d..7c50aba 100644 --- a/python/sanlock.c +++ b/python/sanlock.c @@ -143,10 +143,21 @@ pystring_as_cstring(PyObject *obj) #else return PyUnicode_AsUTF8(obj); #endif }
+static int +validate_path(PyObject *path) +{
- if (PyBytes_Size(path) > SANLK_PATH_LEN - 1) {
set_error(PyExc_ValueError, "Path is too long: %s", path);return 0;- }
- return 1;
+}
static int parse_single_disk(PyObject* disk, struct sanlk_disk* res_disk) { int rv = 0; PyObject *path = NULL; @@ -161,10 +172,13 @@ parse_single_disk(PyObject* disk, struct sanlk_disk* res_disk) /* Override the error since it confusing in this context. */ set_error(PyExc_ValueError, "Invalid disk %s", disk); goto finally; }
- if (!validate_path(path))
goto finally;- strncpy(res_disk->path, PyBytes_AsString(path), SANLK_PATH_LEN - 1); res_disk->offset = offset; rv = 1;
finally: @@ -654,10 +668,13 @@ py_read_resource(PyObject *self __unused, PyObject *args, PyObject *keywds) if (!PyArg_ParseTupleAndKeywords(args, keywds, "O&|kli", kwlist, pypath_converter, &path, &(res->disks[0].offset), &align, §or)) { goto finally; }
- if (!validate_path(path))
goto finally;- /* prepare the resource disk path */ strncpy(res->disks[0].path, PyBytes_AsString(path), SANLK_PATH_LEN -
1);
/* set alignment/sector flags */ if (add_align_flag(align, &res->flags) == -1)diff --git a/tests/python_test.py b/tests/python_test.py index 5624f60..47788e4 100644 --- a/tests/python_test.py +++ b/tests/python_test.py @@ -550,11 +550,10 @@ def test_write_resource_parse_args(no_sanlock_daemon, name, filename, encoding):
with raises_sanlock_errno(): sanlock.write_resource(b"ls_name", name, disks)-@pytest.mark.xfail(reason="path truncated silently") def test_write_resource_path_length(no_sanlock_daemon): with pytest.raises(ValueError): path = "x" * constants.SANLK_PATH_LEN sanlock.write_resource(b"ls_name", b"res_name", [(path, 0)])
@@ -573,11 +572,10 @@ def test_release_resource_parse_args(no_sanlock_daemon, name, filename, encoding
with raises_sanlock_errno(): sanlock.release(b"ls_name", name, disks)-@pytest.mark.xfail(reason="path truncated silently") def test_release_resource_path_length(no_sanlock_daemon): with pytest.raises(ValueError): path = "x" * constants.SANLK_PATH_LEN sanlock.release(b"ls_name", b"res_name", [(path, 0)])
@@ -596,11 +594,10 @@ def test_read_resource_owners_parse_args(no_sanlock_daemon, name, filename, enco
with raises_sanlock_errno(): sanlock.read_resource_owners(b"ls_name", name, disks)-@pytest.mark.xfail(reason="path truncated silently") def test_read_resource_owners_path_length(no_sanlock_daemon): with pytest.raises(ValueError): path = "x" * constants.SANLK_PATH_LEN sanlock.read_resource_owners(b"ls_name", b"res_name", [(path, 0)])
@@ -658,11 +655,10 @@ def test_init_resource_parse_args(no_sanlock_daemon, name, filename, encoding): sanlock.init_resource(b"ls_name", name, disks) with raises_sanlock_errno(errno.ENOENT): sanlock.init_resource(name, b"res_name", disks)
-@pytest.mark.xfail(reason="path truncated silently") def test_init_resource_path_length(no_sanlock_daemon): with pytest.raises(ValueError): path = "x" * constants.SANLK_PATH_LEN sanlock.init_resource(b"ls_name", b"res_name", [(path, 0)])
@@ -689,11 +685,10 @@ def test_read_resource_parse_args(no_sanlock_daemon, filename, encoding): path = util.generate_path("/tmp/", filename, encoding) with raises_sanlock_errno(): sanlock.read_resource(path)
-@pytest.mark.xfail(reason="path truncated silently") def test_read_resource_path_length(no_sanlock_daemon): with pytest.raises(ValueError): path = "x" * constants.SANLK_PATH_LEN sanlock.read_resource(path)
@@ -713,11 +708,10 @@ def test_request_parse_args(no_sanlock_daemon, name, filename, encoding):
with raises_sanlock_errno(): sanlock.request(name, b"res_name", disks)-@pytest.mark.xfail(reason="path truncated silently") def test_request_path_length(no_sanlock_daemon): with pytest.raises(ValueError): path = "x" * constants.SANLK_PATH_LEN sanlock.request(b"ls_name", b"res_name", [(path, 0)])
@@ -737,11 +731,10 @@ 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())-@pytest.mark.xfail(reason="path truncated silently") def test_acquire_path_length(no_sanlock_daemon): with pytest.raises(ValueError): path = "x" * constants.SANLK_PATH_LEN sanlock.acquire(b"ls_name", b"res_name", [(path, 0)], pid=os.getpid())
-- 2.17.2
Cool, thanks!
On Thu, Jun 20, 2019 at 5:25 PM Nir Soffer nirsof@gmail.com wrote:
On Thu, Jun 20, 2019 at 4:37 PM Amit Bawer abawer@redhat.com wrote:
We have same limitation for lockspace paths as well, maybe we need to add this validation as part of the path converter to cover all path usages.
Sanlock have different length limitations for paths, so I think this should be solved in the API level.
In the next version I will handle also lockspace paths.
On Sun, Jun 16, 2019 at 11:50 PM Nir Soffer nirsof@gmail.com wrote:
Previously if a path was too long, we truncated the path silently. This probably fail when sanlock try to access non-existing path with "No such path or directory" error. If you are unlucky, this could try to access the wrong path, failing with bogus error, returning wrong data, or worse, writing a resource into the wrong location, destroying existing data.
Now we fail immediately with:
ValueError: Path is too long: '/too/long/path/...'Signed-off-by: Nir Soffer nsoffer@redhat.com
python/sanlock.c | 17 +++++++++++++++++ tests/python_test.py | 7 ------- 2 files changed, 17 insertions(+), 7 deletions(-)
diff --git a/python/sanlock.c b/python/sanlock.c index ca3713d..7c50aba 100644 --- a/python/sanlock.c +++ b/python/sanlock.c @@ -143,10 +143,21 @@ pystring_as_cstring(PyObject *obj) #else return PyUnicode_AsUTF8(obj); #endif }
+static int +validate_path(PyObject *path) +{
- if (PyBytes_Size(path) > SANLK_PATH_LEN - 1) {
set_error(PyExc_ValueError, "Path is too long: %s", path);return 0;- }
- return 1;
+}
static int parse_single_disk(PyObject* disk, struct sanlk_disk* res_disk) { int rv = 0; PyObject *path = NULL; @@ -161,10 +172,13 @@ parse_single_disk(PyObject* disk, struct sanlk_disk* res_disk) /* Override the error since it confusing in this context. */ set_error(PyExc_ValueError, "Invalid disk %s", disk); goto finally; }
- if (!validate_path(path))
goto finally;- strncpy(res_disk->path, PyBytes_AsString(path), SANLK_PATH_LEN - 1); res_disk->offset = offset; rv = 1;
finally: @@ -654,10 +668,13 @@ py_read_resource(PyObject *self __unused, PyObject *args, PyObject *keywds) if (!PyArg_ParseTupleAndKeywords(args, keywds, "O&|kli", kwlist, pypath_converter, &path, &(res->disks[0].offset), &align, §or)) { goto finally; }
- if (!validate_path(path))
goto finally;- /* prepare the resource disk path */ strncpy(res->disks[0].path, PyBytes_AsString(path), SANLK_PATH_LEN
1);
/* set alignment/sector flags */ if (add_align_flag(align, &res->flags) == -1)
diff --git a/tests/python_test.py b/tests/python_test.py index 5624f60..47788e4 100644 --- a/tests/python_test.py +++ b/tests/python_test.py @@ -550,11 +550,10 @@ def test_write_resource_parse_args(no_sanlock_daemon, name, filename, encoding):
with raises_sanlock_errno(): sanlock.write_resource(b"ls_name", name, disks)-@pytest.mark.xfail(reason="path truncated silently") def test_write_resource_path_length(no_sanlock_daemon): with pytest.raises(ValueError): path = "x" * constants.SANLK_PATH_LEN sanlock.write_resource(b"ls_name", b"res_name", [(path, 0)])
@@ -573,11 +572,10 @@ def test_release_resource_parse_args(no_sanlock_daemon, name, filename, encoding
with raises_sanlock_errno(): sanlock.release(b"ls_name", name, disks)-@pytest.mark.xfail(reason="path truncated silently") def test_release_resource_path_length(no_sanlock_daemon): with pytest.raises(ValueError): path = "x" * constants.SANLK_PATH_LEN sanlock.release(b"ls_name", b"res_name", [(path, 0)])
@@ -596,11 +594,10 @@ def test_read_resource_owners_parse_args(no_sanlock_daemon, name, filename, enco
with raises_sanlock_errno(): sanlock.read_resource_owners(b"ls_name", name, disks)-@pytest.mark.xfail(reason="path truncated silently") def test_read_resource_owners_path_length(no_sanlock_daemon): with pytest.raises(ValueError): path = "x" * constants.SANLK_PATH_LEN sanlock.read_resource_owners(b"ls_name", b"res_name", [(path, 0)])
@@ -658,11 +655,10 @@ def test_init_resource_parse_args(no_sanlock_daemon, name, filename, encoding): sanlock.init_resource(b"ls_name", name, disks) with raises_sanlock_errno(errno.ENOENT): sanlock.init_resource(name, b"res_name", disks)
-@pytest.mark.xfail(reason="path truncated silently") def test_init_resource_path_length(no_sanlock_daemon): with pytest.raises(ValueError): path = "x" * constants.SANLK_PATH_LEN sanlock.init_resource(b"ls_name", b"res_name", [(path, 0)])
@@ -689,11 +685,10 @@ def test_read_resource_parse_args(no_sanlock_daemon, filename, encoding): path = util.generate_path("/tmp/", filename, encoding) with raises_sanlock_errno(): sanlock.read_resource(path)
-@pytest.mark.xfail(reason="path truncated silently") def test_read_resource_path_length(no_sanlock_daemon): with pytest.raises(ValueError): path = "x" * constants.SANLK_PATH_LEN sanlock.read_resource(path)
@@ -713,11 +708,10 @@ def test_request_parse_args(no_sanlock_daemon, name, filename, encoding):
with raises_sanlock_errno(): sanlock.request(name, b"res_name", disks)-@pytest.mark.xfail(reason="path truncated silently") def test_request_path_length(no_sanlock_daemon): with pytest.raises(ValueError): path = "x" * constants.SANLK_PATH_LEN sanlock.request(b"ls_name", b"res_name", [(path, 0)])
@@ -737,11 +731,10 @@ 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())-@pytest.mark.xfail(reason="path truncated silently") def test_acquire_path_length(no_sanlock_daemon): with pytest.raises(ValueError): path = "x" * constants.SANLK_PATH_LEN sanlock.acquire(b"ls_name", b"res_name", [(path, 0)], pid=os.getpid())
-- 2.17.2
sanlock-devel@lists.fedorahosted.org