From: Amit Bawer <abawer(a)redhat.com>
We would like to parse lockspace path as either unicode or bytes.
Stub test for inq_lockspace API is set with additional permutation
for paths with no xfails expected.
---
python/sanlock.c | 11 ++++++-----
tests/python_test.py | 2 +-
2 files changed, 7 insertions(+), 6 deletions(-)
diff --git a/python/sanlock.c b/python/sanlock.c
index 4b7c810..e3b63a7 100644
--- a/python/sanlock.c
+++ b/python/sanlock.c
@@ -868,42 +868,43 @@ acquired or released.");
static PyObject *
py_inq_lockspace(PyObject *self __unused, PyObject *args, PyObject *keywds)
{
int rv = BIND_ERROR, waitrs = 0, flags = 0;
PyObject *lockspace = NULL;
- const char *path;
+ PyObject *path = NULL;
struct sanlk_lockspace ls;
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&ks|ki", kwlist,
- convert_to_pybytes, &lockspace, &ls.host_id, &path,
&ls.host_id_disk.offset,
- &waitrs)) {
+ 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;
}
/* prepare sanlock_inq_lockspace flags */
if (waitrs) {
flags |= SANLK_INQ_WAIT;
}
/* prepare sanlock names */
strncpy(ls.name, PyBytes_AsString(lockspace), SANLK_NAME_LEN);
- strncpy(ls.host_id_disk.path, path, SANLK_PATH_LEN - 1);
+ strncpy(ls.host_id_disk.path, PyBytes_AsString(path), SANLK_PATH_LEN - 1);
/* add sanlock lockspace (gil disabled) */
Py_BEGIN_ALLOW_THREADS
rv = sanlock_inq_lockspace(&ls, flags);
Py_END_ALLOW_THREADS
finally:
Py_XDECREF(lockspace);
+ Py_XDECREF(path);
if (rv == BIND_ERROR) {
return NULL;
} else if (rv == 0) {
Py_RETURN_TRUE;
diff --git a/tests/python_test.py b/tests/python_test.py
index a9933f4..2be57e0 100644
--- a/tests/python_test.py
+++ b/tests/python_test.py
@@ -591,11 +591,11 @@ def test_get_hosts_parse_args(no_sanlock_daemon, name):
with raises_sanlock_errno():
sanlock.get_hosts(name, 1)
@pytest.mark.parametrize("name", LOCKSPACE_OR_RESOURCE_NAMES)
-(a)pytest.mark.parametrize("filename,encoding", FILE_NAMES)
+(a)pytest.mark.parametrize("filename,encoding", FILE_NAMES_NO_XFAILS)
def test_inq_lockspace_parse_args(no_sanlock_daemon, name, filename, encoding):
path = util.generate_path("/tmp/", filename, encoding)
with raises_sanlock_errno():
sanlock.inq_lockspace(name, 1, path, wait=False)
--
2.17.2