This is an automated email from the git hooks/post-receive script.
nsoffer pushed a commit to branch master
in repository sanlock.
commit 876143e598fdcbb9ebf42002effa84de6aa19e37
Author: Amit Bawer <abawer(a)redhat.com>
AuthorDate: Tue Jun 4 00:36:18 2019 +0300
python: Apply pypath_converter to read_lockspace API
We should be able to parse lockspace path as either unicode or bytes.
New stub test for read_lockspace API was added with path permutations
with no xfails expected.
---
python/sanlock.c | 25 ++++++++++++++-----------
tests/python_test.py | 2 +-
2 files changed, 15 insertions(+), 12 deletions(-)
diff --git a/python/sanlock.c b/python/sanlock.c
index 6be0e64..f5051b3 100644
--- a/python/sanlock.c
+++ b/python/sanlock.c
@@ -592,10 +592,10 @@ Sector can be one of (512, 4096).");
static PyObject *
py_read_lockspace(PyObject *self __unused, PyObject *args, PyObject *keywds)
{
- int rv, sector = SECTOR_SIZE_512;
+ int rv = -1, sector = SECTOR_SIZE_512;
long align = ALIGNMENT_1M;
uint32_t io_timeout = 0;
- const char *path;
+ PyObject *path = NULL;
struct sanlk_lockspace ls;
PyObject *ls_info = NULL;
@@ -605,20 +605,20 @@ py_read_lockspace(PyObject *self __unused, PyObject *args, PyObject
*keywds)
memset(&ls, 0, sizeof(struct sanlk_lockspace));
/* parse python tuple */
- if (!PyArg_ParseTupleAndKeywords(args, keywds, "s|kli", kwlist,
- &path, &ls.host_id_disk.offset, &align, §or)) {
- return NULL;
+ if (!PyArg_ParseTupleAndKeywords(args, keywds, "O&|kli", kwlist,
+ pypath_converter, &path, &ls.host_id_disk.offset, &align,
§or)) {
+ goto finally;
}
/* prepare sanlock names */
- strncpy(ls.host_id_disk.path, path, SANLK_PATH_LEN - 1);
+ strncpy(ls.host_id_disk.path, PyBytes_AsString(path), SANLK_PATH_LEN - 1);
/* set alignment/sector flags */
if (add_align_flag(align, &ls.flags) == -1)
- return NULL;
+ goto finally;
if (add_sector_flag(sector, &ls.flags) == -1)
- return NULL;
+ goto finally;
/* read sanlock lockspace (gil disabled) */
Py_BEGIN_ALLOW_THREADS
@@ -627,7 +627,7 @@ py_read_lockspace(PyObject *self __unused, PyObject *args, PyObject
*keywds)
if (rv != 0) {
__set_exception(rv, "Sanlock lockspace read failure");
- return NULL;
+ goto finally;
}
/* fill the information dictionary */
@@ -640,9 +640,12 @@ py_read_lockspace(PyObject *self __unused, PyObject *args, PyObject
*keywds)
"lockspace", ls.name,
"iotimeout", io_timeout);
if (ls_info == NULL)
- return NULL;
+ goto finally;
- /* success */
+finally:
+ Py_XDECREF(path);
+ if (rv != 0)
+ return NULL;
return ls_info;
}
diff --git a/tests/python_test.py b/tests/python_test.py
index 23851df..66e2b94 100644
--- a/tests/python_test.py
+++ b/tests/python_test.py
@@ -642,7 +642,7 @@ def test_get_alignment_parse_args(no_sanlock_daemon, filename,
encoding):
with raises_sanlock_errno(errno.ENOENT):
sanlock.get_alignment(path)
-(a)pytest.mark.parametrize("filename,encoding", FILE_NAMES)
+(a)pytest.mark.parametrize("filename,encoding", FILE_NAMES_NO_XFAILS)
def test_read_lockspace_parse_args(no_sanlock_daemon, filename, encoding):
path = util.generate_path("/tmp/", filename, encoding)
with raises_sanlock_errno():
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.