From 4db3d82c86f4b0897d80f3580cf575e39b54636a Mon Sep 17 00:00:00 2001 From: Amit Bawer Date: Jun 05 2019 13:29:13 +0000 Subject: python: Add pypath_converter to init_lockspace API 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. --- diff --git a/python/sanlock.c b/python/sanlock.c index 334b237..2b64b35 100644 --- a/python/sanlock.c +++ b/python/sanlock.c @@ -430,7 +430,7 @@ 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", @@ -440,15 +440,15 @@ py_init_lockspace(PyObject *self __unused, PyObject *args, PyObject *keywds) 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 @@ -462,6 +462,7 @@ py_init_lockspace(PyObject *self __unused, PyObject *args, PyObject *keywds) 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 @@ -619,7 +619,7 @@ def test_set_event_parse_args(no_sanlock_daemon, name): @pytest.mark.parametrize("name", LOCKSPACE_OR_RESOURCE_NAMES) -@pytest.mark.parametrize("filename,encoding", FILE_NAMES) +@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):