This is an automated email from the git hooks/post-receive script.
nsoffer pushed a commit to branch master
in repository sanlock.
commit e7d716d17f434175ba734bc3abfc96809d25f15b
Author: Amit Bawer <abawer(a)redhat.com>
AuthorDate: Tue Jun 4 00:46:16 2019 +0300
python: Apply pypath_converter to read_resource API
We should be able to parse resource path as either unicode or bytes.
New stub test for read_resource API is added with path premutations
with no expected xfails.
---
python/sanlock.c | 33 ++++++++++++++++-----------------
tests/python_test.py | 2 +-
2 files changed, 17 insertions(+), 18 deletions(-)
diff --git a/python/sanlock.c b/python/sanlock.c
index f5051b3..a846570 100644
--- a/python/sanlock.c
+++ b/python/sanlock.c
@@ -659,9 +659,9 @@ Sector can be one of (512, 4096).");
static PyObject *
py_read_resource(PyObject *self __unused, PyObject *args, PyObject *keywds)
{
- int rv, rs_len, sector = SECTOR_SIZE_512;
+ int rv = -1, rs_len, sector = SECTOR_SIZE_512;
long align = ALIGNMENT_1M;
- const char *path;
+ PyObject *path = NULL;
struct sanlk_resource *rs;
PyObject *rs_info = NULL;
@@ -681,20 +681,20 @@ py_read_resource(PyObject *self __unused, PyObject *args, PyObject
*keywds)
rs->num_disks = 1;
/* parse python tuple */
- if (!PyArg_ParseTupleAndKeywords(args, keywds, "s|kli", kwlist,
- &path, &(rs->disks[0].offset), &align, §or)) {
- goto exit_fail;
+ if (!PyArg_ParseTupleAndKeywords(args, keywds, "O&|kli", kwlist,
+ pypath_converter, &path, &(rs->disks[0].offset), &align,
§or)) {
+ goto finally;
}
/* prepare the resource disk path */
- strncpy(rs->disks[0].path, path, SANLK_PATH_LEN - 1);
+ strncpy(rs->disks[0].path, PyBytes_AsString(path), SANLK_PATH_LEN - 1);
/* set alignment/sector flags */
if (add_align_flag(align, &rs->flags) == -1)
- goto exit_fail;
+ goto finally;
if (add_sector_flag(sector, &rs->flags) == -1)
- goto exit_fail;
+ goto finally;
/* read sanlock resource (gil disabled) */
Py_BEGIN_ALLOW_THREADS
@@ -703,7 +703,7 @@ py_read_resource(PyObject *self __unused, PyObject *args, PyObject
*keywds)
if (rv != 0) {
__set_exception(rv, "Sanlock resource read failure");
- goto exit_fail;
+ goto finally;
}
/* prepare the dictionary holding the information */
@@ -717,17 +717,16 @@ py_read_resource(PyObject *self __unused, PyObject *args, PyObject
*keywds)
"resource", rs->name,
"version", rs->lver);
if (rs_info == NULL)
- goto exit_fail;
+ goto finally;
- /* success */
+finally:
free(rs);
+ Py_XDECREF(path);
+ if (rv != 0) {
+ Py_XDECREF(rs_info);
+ return NULL;
+ }
return rs_info;
-
- /* failure */
-exit_fail:
- free(rs);
- Py_XDECREF(rs_info);
- return NULL;
}
/* write_resource */
diff --git a/tests/python_test.py b/tests/python_test.py
index 66e2b94..3ce1301 100644
--- a/tests/python_test.py
+++ b/tests/python_test.py
@@ -648,7 +648,7 @@ def test_read_lockspace_parse_args(no_sanlock_daemon, filename,
encoding):
with raises_sanlock_errno():
sanlock.read_lockspace(path)
-(a)pytest.mark.parametrize("filename,encoding", FILE_NAMES)
+(a)pytest.mark.parametrize("filename,encoding", FILE_NAMES_NO_XFAILS)
def test_read_resource_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.