From: Amit Bawer <abawer(a)redhat.com>
We should be able to parse lockspace path as either unicode or bytes.
Stub test for init_lockspace was set with additional permutations
over lockspace path with no expected xfails.
---
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 334b237..2b64b35 100644
--- a/python/sanlock.c
+++ b/python/sanlock.c
@@ -428,29 +428,29 @@ Initialize a device to be used as sanlock lockspace.");
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;
- const char *path;
+ PyObject *path = NULL;
struct sanlk_lockspace ls;
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&s|kiii", kwlist,
- convert_to_pybytes, &lockspace, &path, &ls.host_id_disk.offset,
&max_hosts,
- &num_hosts, &use_aio)) {
+ 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;
}
/* 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);
/* init sanlock lockspace (gil disabled) */
Py_BEGIN_ALLOW_THREADS
rv = sanlock_direct_init(&ls, NULL, max_hosts, num_hosts, use_aio);
Py_END_ALLOW_THREADS
@@ -460,10 +460,11 @@ py_init_lockspace(PyObject *self __unused, PyObject *args, PyObject
*keywds)
goto finally;
}
finally:
Py_XDECREF(lockspace);
+ Py_XDECREF(path);
if (rv != 0)
return NULL;
Py_RETURN_NONE;
}
diff --git a/tests/python_test.py b/tests/python_test.py
index b251c07..fb95977 100644
--- a/tests/python_test.py
+++ b/tests/python_test.py
@@ -617,11 +617,11 @@ def test_set_event_parse_args(no_sanlock_daemon, name):
with raises_sanlock_errno():
sanlock.set_event(name, 1, 1, 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_init_lockspace_parse_args(no_sanlock_daemon, name, filename, encoding):
path = util.generate_path("/tmp/", filename, encoding)
with raises_sanlock_errno(errno.ENODEV):
sanlock.init_lockspace(name, path)
--
2.17.2