[sanlock] 08/14: python: Apply pypath_converter to read_resource API
by pagure@pagure.io
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.
4 years, 9 months
[sanlock] 07/14: python: Apply pypath_converter to read_lockspace
API
by pagure@pagure.io
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.
4 years, 9 months
[sanlock] 06/14: python: Apply pypath_converter to write_lockspace
API
by pagure@pagure.io
This is an automated email from the git hooks/post-receive script.
nsoffer pushed a commit to branch master
in repository sanlock.
commit 1ec25a7e2a6e599980b117b085963e755f6973fb
Author: Amit Bawer <abawer(a)redhat.com>
AuthorDate: Tue Jun 4 00:27:27 2019 +0300
python: Apply pypath_converter to write_lockspace API
We should be able to parse lockspace path as either unicode or bytes.
Stub for write_lockspace test was set with additional permutations
over paths with no expected xfails.
---
python/sanlock.c | 9 +++++----
tests/python_test.py | 2 +-
2 files changed, 6 insertions(+), 5 deletions(-)
diff --git a/python/sanlock.c b/python/sanlock.c
index 2b64b35..6be0e64 100644
--- a/python/sanlock.c
+++ b/python/sanlock.c
@@ -537,7 +537,7 @@ py_write_lockspace(PyObject *self __unused, PyObject *args, PyObject *keywds)
long align = ALIGNMENT_1M;
uint32_t io_timeout = 0;
PyObject *lockspace = NULL;
- const char *path;
+ PyObject *path = NULL;
struct sanlk_lockspace ls;
static char *kwlist[] = {"lockspace", "path", "offset", "max_hosts",
@@ -547,15 +547,15 @@ py_write_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|kiIli", kwlist,
- convert_to_pybytes, &lockspace, &path, &ls.host_id_disk.offset,
+ if (!PyArg_ParseTupleAndKeywords(args, keywds, "O&O&|kiIli", kwlist,
+ convert_to_pybytes, &lockspace, pypath_converter, &path, &ls.host_id_disk.offset,
&max_hosts, &io_timeout, &align, §or)) {
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);
/* set alignment/sector flags */
if (add_align_flag(align, &ls.flags) == -1)
@@ -576,6 +576,7 @@ py_write_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 fb95977..23851df 100644
--- a/tests/python_test.py
+++ b/tests/python_test.py
@@ -543,7 +543,7 @@ def test_add_lockspace_parse_args(no_sanlock_daemon, name, filename, encoding):
@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_write_lockspace_parse_args(no_sanlock_daemon, name, 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.
4 years, 9 months
[sanlock] 05/14: python: Add pypath_converter to init_lockspace API
by pagure@pagure.io
This is an automated email from the git hooks/post-receive script.
nsoffer pushed a commit to branch master
in repository sanlock.
commit 4db3d82c86f4b0897d80f3580cf575e39b54636a
Author: Amit Bawer <abawer(a)redhat.com>
AuthorDate: Tue Jun 4 00:22:48 2019 +0300
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.
---
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
@@ -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)
-(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):
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
4 years, 9 months
[sanlock] 04/14: python: Apply pypath_converter to get_alignment API
by pagure@pagure.io
This is an automated email from the git hooks/post-receive script.
nsoffer pushed a commit to branch master
in repository sanlock.
commit 7c697440cb0946926402a02a7534cf2272226853
Author: Amit Bawer <abawer(a)redhat.com>
AuthorDate: Tue Jun 4 00:15:37 2019 +0300
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.
---
python/sanlock.c | 16 ++++++++++------
tests/python_test.py | 2 +-
2 files changed, 11 insertions(+), 7 deletions(-)
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)
-(a)pytest.mark.parametrize("filename,encoding", FILE_NAMES)
+(a)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):
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
4 years, 9 months
[sanlock] 03/14: python: Apply pypath_converter to parse_resource
util function
by pagure@pagure.io
This is an automated email from the git hooks/post-receive script.
nsoffer pushed a commit to branch master
in repository sanlock.
commit 5453f0795d688fb6a8aa0b62a3c1d3815807b72c
Author: Amit Bawer <abawer(a)redhat.com>
AuthorDate: Tue Jun 4 00:03:25 2019 +0300
python: Apply pypath_converter to parse_resource util function
We should be able to parse resource paths as either unicode or bytes.
Stub tests involving valid arguments parsing of resources paths
are set with additional permutations with no xfails expected.
---
python/sanlock.c | 46 +++++++++++++++++++++++++++++-----------------
tests/python_test.py | 16 ++++++++++++----
2 files changed, 41 insertions(+), 21 deletions(-)
diff --git a/python/sanlock.c b/python/sanlock.c
index aaeaa86..1a983ee 100644
--- a/python/sanlock.c
+++ b/python/sanlock.c
@@ -160,6 +160,33 @@ pystring_as_cstring(PyObject *obj)
}
static int
+parse_single_disk(PyObject* disk, struct sanlk_disk* res_disk)
+{
+ int rv = 0;
+ PyObject *path = NULL;
+ uint64_t offset;
+
+ if (!PyTuple_Check(disk)) {
+ set_error(PyExc_ValueError, "Invalid disk %s", disk);
+ goto finally;
+ }
+
+ if (!PyArg_ParseTuple(disk, "O&K", pypath_converter, &path, &offset)) {
+ /* Override the error since it confusing in this context. */
+ set_error(PyExc_ValueError, "Invalid disk %s", disk);
+ goto finally;
+ }
+
+ strncpy(res_disk->path, PyBytes_AsString(path), SANLK_PATH_LEN - 1);
+ res_disk->offset = offset;
+ rv = 1;
+
+finally:
+ Py_XDECREF(path);
+ return rv;
+}
+
+static int
__parse_resource(PyObject *obj, struct sanlk_resource **res_ret)
{
int i, num_disks, res_len;
@@ -180,26 +207,11 @@ __parse_resource(PyObject *obj, struct sanlk_resource **res_ret)
res->num_disks = num_disks;
for (i = 0; i < num_disks; i++) {
- PyObject *disk;
- const char *path;
- uint64_t offset;
+ PyObject *disk = PyList_GetItem(obj,i);
- disk = PyList_GetItem(obj, i);
-
- if (!PyTuple_Check(disk)) {
- set_error(PyExc_ValueError, "Invalid disk %s", disk);
+ if (!parse_single_disk(disk, &(res->disks[i]))) {
goto exit_fail;
-
}
-
- if (!PyArg_ParseTuple(disk, "sK", &path, &offset)) {
- /* Override the error since it confusing in this context. */
- set_error(PyExc_ValueError, "Invalid disk %s", disk);
- goto exit_fail;
- }
-
- strncpy(res->disks[i].path, path, SANLK_PATH_LEN - 1);
- res->disks[i].offset = offset;
}
*res_ret = res;
diff --git a/tests/python_test.py b/tests/python_test.py
index 5218435..56d0c99 100644
--- a/tests/python_test.py
+++ b/tests/python_test.py
@@ -51,6 +51,14 @@ FILE_NAMES = [
reason="currently not supporting bytes paths")),
]
+FILE_NAMES_NO_XFAILS = [
+ #name, encoding
+ ("ascii", None),
+ (u"ascii", None),
+ (u"\u05d0", None),
+ (u"\u05d0", "utf-8"),
+]
+
LOCKSPACE_OR_RESOURCE_NAMES = [
# Bytes are supported with python 2 and 3.
pytest.param(b"\xd7\x90"),
@@ -543,7 +551,7 @@ def test_write_lockspace_parse_args(no_sanlock_daemon, name, filename, encoding)
@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_write_resource_parse_args(no_sanlock_daemon, name, filename, encoding):
path = util.generate_path("/tmp/", filename, encoding)
disks = [(path, 0)]
@@ -555,7 +563,7 @@ def test_write_resource_parse_args(no_sanlock_daemon, name, filename, encoding):
@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_release_resource_parse_args(no_sanlock_daemon, name, filename, encoding):
path = util.generate_path("/tmp/", filename, encoding)
disks = [(path, 0)]
@@ -567,7 +575,7 @@ def test_release_resource_parse_args(no_sanlock_daemon, name, filename, encoding
@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_read_resource_owners_parse_args(no_sanlock_daemon, name, filename, encoding):
path = util.generate_path("/tmp/", filename, encoding)
disks = [(path, 0)]
@@ -619,7 +627,7 @@ def test_init_lockspace_parse_args(no_sanlock_daemon, name, filename, encoding):
@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_resource_parse_args(no_sanlock_daemon, name, filename, encoding):
path = util.generate_path("/tmp/", filename, encoding)
disks = [(path, 0)]
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
4 years, 9 months
[sanlock] 02/14: python: Add pypath_converter
by pagure@pagure.io
This is an automated email from the git hooks/post-receive script.
nsoffer pushed a commit to branch master
in repository sanlock.
commit b8770c3bebb2e77c2b1d1e23b77a93f14dac72df
Author: Amit Bawer <abawer(a)redhat.com>
AuthorDate: Mon Jun 3 23:11:33 2019 +0300
python: Add pypath_converter
In Python 3 we would like to handle paths as either unicode strings
or bytes. For this purpose we have a c-API called PyUnicode_FSConverter.
In this patch the missing API is implemented for Py2 based on Py3 [1]
and a unified no-cleanup behavior is enforced for Py3 path conversion as well.
[1] https://github.com/python/cpython/blob/master/Objects/unicodeobject.c#L3818
---
python/sanlock.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 54 insertions(+)
diff --git a/python/sanlock.c b/python/sanlock.c
index 39a9fb6..aaeaa86 100644
--- a/python/sanlock.c
+++ b/python/sanlock.c
@@ -73,6 +73,60 @@ __set_exception(int en, char *msg)
}
}
+
+/*
+ * Converts a unicode path into PyBytes object.
+ * If conversion succeeds addr will hold a reference to a new
+ * PyBytes object containing bytes represenation of the system path
+ * given in arg object.
+ * Returns 1 on successful operation, 0 otherwise.
+ * Py2 implementation is based on Py3's PyUnicode_FSConverter[1].
+ * Py3 implementation wraps call PyUnicode_FSConverter and eliminates
+ * the cleanup support in order to make usage flow the same between
+ * versions.
+ * [1] https://github.com/python/cpython/blob/master/Objects/unicodeobject.c#L3818
+ */
+static int
+pypath_converter(PyObject* arg, void* addr)
+{
+ assert(arg && "path converter does not support cleanup (arg is NULL)");
+
+#if PY_MAJOR_VERSION == 2
+ /* python 2 implementation */
+ PyObject *output = NULL;
+ Py_ssize_t size;
+ const char *data;
+
+ if (PyBytes_Check(arg)) {
+ Py_INCREF(arg);
+ output = arg;
+ } else {
+ output = PyUnicode_AsEncodedString(arg, Py_FileSystemDefaultEncoding, NULL);
+ if (!output)
+ return 0;
+ assert(PyBytes_Check(output));
+ }
+
+ size = PyBytes_GET_SIZE(output);
+ data = PyBytes_AS_STRING(output);
+ if ((size_t)size != strlen(data)) {
+ PyErr_Format(PyExc_ValueError, "Embedded null byte");
+ Py_DECREF(output);
+ return 0;
+ }
+
+ *(PyObject**)addr = output;
+ return 1;
+#else
+ /* python 3 call wrapper */
+ int rv = PyUnicode_FSConverter(arg, addr);
+ /* python 2 does not suppot cleanups - same applies here */
+ if (rv == Py_CLEANUP_SUPPORTED)
+ rv = 1;
+ return rv;
+#endif
+}
+
static uint64_t
pyinteger_as_unsigned_long_long_mask(PyObject *obj)
{
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
4 years, 9 months
[sanlock] 01/14: tests: Add path conversion tests to stub tests
section
by pagure@pagure.io
This is an automated email from the git hooks/post-receive script.
nsoffer pushed a commit to branch master
in repository sanlock.
commit f4eefcf68229a308a0cae453d2511353a3d49822
Author: Amit Bawer <abawer(a)redhat.com>
AuthorDate: Wed Jun 5 15:49:49 2019 +0300
tests: Add path conversion tests to stub tests section
We add tests for path permutations involving xfail secnarios
to stub argument parsing tests. Also adding missing API tests.
Once we apply all patches involving the new path converter, we
expect all of them to pass with no fails in both python versions.
---
tests/python_test.py | 82 ++++++++++++++++++++++++++++++++++++++--------------
1 file changed, 61 insertions(+), 21 deletions(-)
diff --git a/tests/python_test.py b/tests/python_test.py
index 926a0f0..5218435 100644
--- a/tests/python_test.py
+++ b/tests/python_test.py
@@ -519,48 +519,63 @@ def raises_sanlock_errno(expected_errno=errno.ECONNREFUSED):
@pytest.mark.parametrize("name", LOCKSPACE_OR_RESOURCE_NAMES)
-def test_rem_lockspace_parse_args(no_sanlock_daemon, name):
+(a)pytest.mark.parametrize("filename,encoding", FILE_NAMES)
+def test_rem_lockspace_parse_args(no_sanlock_daemon, name, filename, encoding):
+ path = util.generate_path("/tmp/", filename, encoding)
with raises_sanlock_errno():
- sanlock.rem_lockspace(name, 1, "ls_path", 0)
+ sanlock.rem_lockspace(name, 1, path, 0)
@pytest.mark.parametrize("name", LOCKSPACE_OR_RESOURCE_NAMES)
-def test_add_lockspace_parse_args(no_sanlock_daemon, name):
+(a)pytest.mark.parametrize("filename,encoding", FILE_NAMES)
+def test_add_lockspace_parse_args(no_sanlock_daemon, name, filename, encoding):
+ path = util.generate_path("/tmp/", filename, encoding)
with raises_sanlock_errno():
- sanlock.add_lockspace(name, 1, "ls_path", 0)
+ sanlock.add_lockspace(name, 1, path, 0)
@pytest.mark.parametrize("name", LOCKSPACE_OR_RESOURCE_NAMES)
-def test_write_lockspace_parse_args(no_sanlock_daemon, name):
+(a)pytest.mark.parametrize("filename,encoding", FILE_NAMES)
+def test_write_lockspace_parse_args(no_sanlock_daemon, name, filename, encoding):
+ path = util.generate_path("/tmp/", filename, encoding)
with raises_sanlock_errno():
- sanlock.write_lockspace(name, "ls_path")
+ sanlock.write_lockspace(name, path)
@pytest.mark.parametrize("name", LOCKSPACE_OR_RESOURCE_NAMES)
-def test_write_resource_parse_args(no_sanlock_daemon, name):
+(a)pytest.mark.parametrize("filename,encoding", FILE_NAMES)
+def test_write_resource_parse_args(no_sanlock_daemon, name, filename, encoding):
+ path = util.generate_path("/tmp/", filename, encoding)
+ disks = [(path, 0)]
with raises_sanlock_errno():
- sanlock.write_resource(name, b"res_name", [("disk_path",0)])
+ sanlock.write_resource(name, b"res_name", disks)
with raises_sanlock_errno():
- sanlock.write_resource(b"ls_name", name, [("disk_path",0)])
+ sanlock.write_resource(b"ls_name", name, disks)
@pytest.mark.parametrize("name", LOCKSPACE_OR_RESOURCE_NAMES)
-def test_release_resource_parse_args(no_sanlock_daemon, name):
+(a)pytest.mark.parametrize("filename,encoding", FILE_NAMES)
+def test_release_resource_parse_args(no_sanlock_daemon, name, filename, encoding):
+ path = util.generate_path("/tmp/", filename, encoding)
+ disks = [(path, 0)]
with raises_sanlock_errno():
- sanlock.release(name, b"res_name", [("disk_path",0)])
+ sanlock.release(name, b"res_name", disks)
with raises_sanlock_errno():
- sanlock.release(b"ls_name", name, [("disk_path",0)])
+ sanlock.release(b"ls_name", name, disks)
@pytest.mark.parametrize("name", LOCKSPACE_OR_RESOURCE_NAMES)
-def test_read_resource_owners_parse_args(no_sanlock_daemon, name):
+(a)pytest.mark.parametrize("filename,encoding", FILE_NAMES)
+def test_read_resource_owners_parse_args(no_sanlock_daemon, name, filename, encoding):
+ path = util.generate_path("/tmp/", filename, encoding)
+ disks = [(path, 0)]
with raises_sanlock_errno():
- sanlock.read_resource_owners(name, b"res_name", [("disk_path",0)])
+ sanlock.read_resource_owners(name, b"res_name", disks)
with raises_sanlock_errno():
- sanlock.read_resource_owners(b"ls_name", name, [("disk_path",0)])
+ sanlock.read_resource_owners(b"ls_name", name, disks)
@pytest.mark.parametrize("name", LOCKSPACE_OR_RESOURCE_NAMES)
@@ -570,9 +585,11 @@ def test_get_hosts_parse_args(no_sanlock_daemon, name):
@pytest.mark.parametrize("name", LOCKSPACE_OR_RESOURCE_NAMES)
-def test_inq_lockspace_parse_args(no_sanlock_daemon, name):
+(a)pytest.mark.parametrize("filename,encoding", FILE_NAMES)
+def test_inq_lockspace_parse_args(no_sanlock_daemon, name, filename, encoding):
+ path = util.generate_path("/tmp/", filename, encoding)
with raises_sanlock_errno():
- sanlock.inq_lockspace(name, 1, "path", wait=False)
+ sanlock.inq_lockspace(name, 1, path, wait=False)
@pytest.mark.parametrize("name", LOCKSPACE_OR_RESOURCE_NAMES)
@@ -594,15 +611,38 @@ def test_set_event_parse_args(no_sanlock_daemon, name):
@pytest.mark.parametrize("name", LOCKSPACE_OR_RESOURCE_NAMES)
-def test_init_lockspace_parse_args(no_sanlock_daemon, name):
+(a)pytest.mark.parametrize("filename,encoding", FILE_NAMES)
+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")
+ sanlock.init_lockspace(name, path)
@pytest.mark.parametrize("name", LOCKSPACE_OR_RESOURCE_NAMES)
-def test_init_resource_parse_args(no_sanlock_daemon, name):
- disks = [("path", 0)]
+(a)pytest.mark.parametrize("filename,encoding", FILE_NAMES)
+def test_init_resource_parse_args(no_sanlock_daemon, name, filename, encoding):
+ path = util.generate_path("/tmp/", filename, encoding)
+ disks = [(path, 0)]
with raises_sanlock_errno(errno.ENOENT):
sanlock.init_resource(b"ls_name", name, disks)
with raises_sanlock_errno(errno.ENOENT):
sanlock.init_resource(name, b"res_name", disks)
+
+(a)pytest.mark.parametrize("filename,encoding", FILE_NAMES)
+def test_get_alignment_parse_args(no_sanlock_daemon, filename, encoding):
+ path = util.generate_path("/tmp/", filename, encoding)
+ with raises_sanlock_errno(errno.ENOENT):
+ sanlock.get_alignment(path)
+
+(a)pytest.mark.parametrize("filename,encoding", FILE_NAMES)
+def test_read_lockspace_parse_args(no_sanlock_daemon, filename, encoding):
+ path = util.generate_path("/tmp/", filename, encoding)
+ with raises_sanlock_errno():
+ sanlock.read_lockspace(path)
+
+(a)pytest.mark.parametrize("filename,encoding", FILE_NAMES)
+def test_read_resource_parse_args(no_sanlock_daemon, filename, encoding):
+ path = util.generate_path("/tmp/", filename, encoding)
+ with raises_sanlock_errno():
+ sanlock.read_resource(path)
+
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
4 years, 9 months
[PATCH] python: Replace async with wait
by Nir Soffer
The async argument to add_lockspace and rem_lockspace is not valid
syntax in python 3.7, since async is a keyword now.
Replace async=False with wait=True, already used in other sanlock
methods.
This change break compatibility with python 2, but we need to release
version for python 3 now, so we don't have time to finish a python 2
compatible version.
Once we release 3.8.0, we will have more time to work on python 2
compatibility to help users like vdsm, which can be released in 3.8.1.
[1] https://github.com/nirs/sanlock/pull/16
Signed-off-by: Nir Soffer <nsoffer(a)redhat.com>
---
python/sanlock.c | 26 ++++++++++++++------------
tests/python_test.py | 8 ++++----
2 files changed, 18 insertions(+), 16 deletions(-)
diff --git a/python/sanlock.c b/python/sanlock.c
index d122c8e..7f0916a 100644
--- a/python/sanlock.c
+++ b/python/sanlock.c
@@ -799,40 +799,41 @@ finally:
Py_RETURN_NONE;
}
/* add_lockspace */
PyDoc_STRVAR(pydoc_add_lockspace, "\
-add_lockspace(lockspace, host_id, path, offset=0, iotimeout=0, async=False)\n\
-Add a lockspace, acquiring a host_id in it. If async is True the function\n\
+add_lockspace(lockspace, host_id, path, offset=0, iotimeout=0, wait=True)\n\
+Add a lockspace, acquiring a host_id in it. If wait is False the function\n\
will return immediatly and the status can be checked using inq_lockspace.\n\
The iotimeout option configures the io timeout for the specific lockspace,\n\
overriding the default value (see the sanlock daemon parameter -o).");
static PyObject *
py_add_lockspace(PyObject *self __unused, PyObject *args, PyObject *keywds)
{
- int rv = -1, async = 0, flags = 0;
+ int rv = -1, flags = 0;
+ int wait = 1;
uint32_t iotimeout = 0;
PyObject *lockspace = NULL;
PyObject *path = NULL;
struct sanlk_lockspace ls;
static char *kwlist[] = {"lockspace", "host_id", "path", "offset",
- "iotimeout", "async", NULL};
+ "iotimeout", "wait", NULL};
/* initialize lockspace structure */
memset(&ls, 0, sizeof(struct sanlk_lockspace));
/* parse python tuple */
if (!PyArg_ParseTupleAndKeywords(args, keywds, "O&kO&|kIi", kwlist,
convert_to_pybytes, &lockspace, &ls.host_id, pypath_converter, &path,
- &ls.host_id_disk.offset, &iotimeout, &async)) {
+ &ls.host_id_disk.offset, &iotimeout, &wait)) {
goto finally;
}
/* prepare sanlock_add_lockspace flags */
- if (async) {
+ if (!wait) {
flags |= SANLK_ADD_ASYNC;
}
/* prepare sanlock names */
strncpy(ls.name, PyBytes_AsString(lockspace), SANLK_NAME_LEN);
@@ -918,46 +919,47 @@ finally:
return NULL;
}
/* rem_lockspace */
PyDoc_STRVAR(pydoc_rem_lockspace, "\
-rem_lockspace(lockspace, host_id, path, offset=0, async=False, unused=False)\n\
-Remove a lockspace, releasing the acquired host_id. If async is True the\n\
+rem_lockspace(lockspace, host_id, path, offset=0, wait=True, unused=False)\n\
+Remove a lockspace, releasing the acquired host_id. If wait is False the\n\
function will return immediately and the status can be checked using\n\
inq_lockspace. If unused is True the command will fail (EBUSY) if there is\n\
at least one acquired resource in the lockspace. Otherwise (the default)\n\
sanlock will try to terminate processes holding resource leases and upon\n\
successful termination these leases will be released.");
static PyObject *
py_rem_lockspace(PyObject *self __unused, PyObject *args, PyObject *keywds)
{
- int rv = -1, async = 0, unused = 0, flags = 0;
+ int rv = -1, unused = 0, flags = 0;
+ int wait = 1;
PyObject *lockspace = NULL;
PyObject *path = NULL;
struct sanlk_lockspace ls;
static char *kwlist[] = {"lockspace", "host_id", "path", "offset",
- "async", "unused", NULL};
+ "wait", "unused", NULL};
/* initialize lockspace structure */
memset(&ls, 0, sizeof(struct sanlk_lockspace));
/* parse python tuple */
if (!PyArg_ParseTupleAndKeywords(args, keywds, "O&kO&|kii", kwlist,
convert_to_pybytes, &lockspace, &ls.host_id, pypath_converter, &path,
&ls.host_id_disk.offset,
- &async, &unused)) {
+ &wait, &unused)) {
goto finally;
}
/* prepare sanlock names */
strncpy(ls.name, PyBytes_AsString(lockspace), SANLK_NAME_LEN);
strncpy(ls.host_id_disk.path, PyBytes_AsString(path), SANLK_PATH_LEN - 1);
/* prepare sanlock_rem_lockspace flags */
- if (async) {
+ if (!wait) {
flags |= SANLK_REM_ASYNC;
}
if (unused) {
flags |= SANLK_REM_UNUSED;
diff --git a/tests/python_test.py b/tests/python_test.py
index a2e25fb..3242f57 100644
--- a/tests/python_test.py
+++ b/tests/python_test.py
@@ -339,11 +339,11 @@ def test_add_rem_lockspace_async(tmpdir, sanlock_daemon):
sanlock.write_lockspace(b"ls_name", path, iotimeout=1)
acquired = sanlock.inq_lockspace(b"ls_name", 1, path, wait=False)
assert acquired is False
# This will take 3 seconds.
- sanlock.add_lockspace(b"ls_name", 1, path, iotimeout=1, **{"async": True})
+ sanlock.add_lockspace(b"ls_name", 1, path, iotimeout=1, wait=False)
# While the lockspace is being aquired, we expect to get None.
time.sleep(1)
acquired = sanlock.inq_lockspace(b"ls_name", 1, path, wait=False)
assert acquired is None
@@ -351,11 +351,11 @@ def test_add_rem_lockspace_async(tmpdir, sanlock_daemon):
# Once the lockspace is acquired, we exepect to get True.
acquired = sanlock.inq_lockspace(b"ls_name", 1, path, wait=True)
assert acquired is True
# This will take about 3 seconds.
- sanlock.rem_lockspace(b"ls_name", 1, path, **{"async": True})
+ sanlock.rem_lockspace(b"ls_name", 1, path, wait=False)
# Wait until the lockspace change state from True to None.
while sanlock.inq_lockspace(b"ls_name", 1, path, wait=False):
time.sleep(1)
@@ -512,19 +512,19 @@ def raises_sanlock_errno(expected_errno=errno.ECONNREFUSED):
@pytest.mark.parametrize("name", LOCKSPACE_OR_RESOURCE_NAMES)
@pytest.mark.parametrize("filename,encoding", FILE_NAMES)
def test_rem_lockspace_parse_args(no_sanlock_daemon, name, filename, encoding):
path = util.generate_path("/tmp/", filename, encoding)
with raises_sanlock_errno():
- sanlock.rem_lockspace(name, 1, path, 0)
+ sanlock.rem_lockspace(name, 1, path, 0, wait=False)
@pytest.mark.parametrize("name", LOCKSPACE_OR_RESOURCE_NAMES)
@pytest.mark.parametrize("filename,encoding", FILE_NAMES)
def test_add_lockspace_parse_args(no_sanlock_daemon, name, filename, encoding):
path = util.generate_path("/tmp/", filename, encoding)
with raises_sanlock_errno():
- sanlock.add_lockspace(name, 1, path, 0)
+ sanlock.add_lockspace(name, 1, path, 0, wait=False)
@pytest.mark.parametrize("name", LOCKSPACE_OR_RESOURCE_NAMES)
@pytest.mark.parametrize("filename,encoding", FILE_NAMES)
def test_write_lockspace_parse_args(no_sanlock_daemon, name, filename, encoding):
--
2.17.2
4 years, 9 months
[PATCH 00/13] Fix path handling
by Nir Soffer
Path arguments are handled now similar to the standard library,
supporting both bytes and Unicode paths. Unicode paths are encoded using
the file system encoding.
sanlock.killpath() argumnets are handled now in the same way as the path
argument, supporting non-ascii arguments.
For simplicity, python 2 version behave like python 3, supporting
Unicode paths with non-ascii content.
Amit Bawer (13):
tests: Add path conversion tests to stub tests section
python: Add pypath_converter
python: Apply pypath_converter to parse_resource util function
python: Apply pypath_converter to get_alignment API
python: Add pypath_converter to init_lockspace API
python: Apply pypath_converter to write_lockspace API
python: Apply pypath_converter to read_lockspace API
python: Apply pypath_converter to read_resource API
python: Apply pypath_converter to add_lockspace
python: Apply pypath_converter to inq_lockspace API
python: Apply pypath_converter to rem_lockspace API
python: Add pypath_converter to killpath API
tests: Remove xfail marks from path file names
python/sanlock.c | 335 ++++++++++++++++++++++++++++---------------
tests/python_test.py | 94 ++++++++----
2 files changed, 280 insertions(+), 149 deletions(-)
--
2.17.2
4 years, 9 months