From 7c697440cb0946926402a02a7534cf2272226853 Mon Sep 17 00:00:00 2001 From: Amit Bawer Date: Jun 05 2019 13:26:27 +0000 Subject: python: Apply pypath_converter to get_alignment API We should be able to parse device path as either unicode or bytes. New stub test was added for get_alignment API for path premutations with no xfails expected. --- diff --git a/python/sanlock.c b/python/sanlock.c index 1a983ee..334b237 100644 --- a/python/sanlock.c +++ b/python/sanlock.c @@ -352,17 +352,17 @@ Get device alignment."); static PyObject * py_get_alignment(PyObject *self __unused, PyObject *args) { - int rv; - const char *path; + int rv = -1; + PyObject *path = NULL; struct sanlk_disk disk; /* parse python tuple */ - if (!PyArg_ParseTuple(args, "s", &path)) { - return NULL; + if (!PyArg_ParseTuple(args, "O&", pypath_converter, &path)) { + goto finally; } memset(&disk, 0, sizeof(struct sanlk_disk)); - strncpy(disk.path, path, SANLK_PATH_LEN - 1); + strncpy(disk.path, PyBytes_AsString(path), SANLK_PATH_LEN - 1); /* get device alignment (gil disabled) */ Py_BEGIN_ALLOW_THREADS @@ -371,9 +371,13 @@ py_get_alignment(PyObject *self __unused, PyObject *args) if (rv < 0) { __set_exception(rv, "Unable to get device alignment"); - return NULL; + goto finally; } +finally: + Py_XDECREF(path); + if (rv < 0) + return NULL; return Py_BuildValue("i", rv); } diff --git a/tests/python_test.py b/tests/python_test.py index 56d0c99..b251c07 100644 --- a/tests/python_test.py +++ b/tests/python_test.py @@ -636,7 +636,7 @@ def test_init_resource_parse_args(no_sanlock_daemon, name, filename, encoding): with raises_sanlock_errno(errno.ENOENT): sanlock.init_resource(name, b"res_name", disks) -@pytest.mark.parametrize("filename,encoding", FILE_NAMES) +@pytest.mark.parametrize("filename,encoding", FILE_NAMES_NO_XFAILS) def test_get_alignment_parse_args(no_sanlock_daemon, filename, encoding): path = util.generate_path("/tmp/", filename, encoding) with raises_sanlock_errno(errno.ENOENT):