This is an automated email from the git hooks/post-receive script.
nsoffer pushed a commit to branch master
in repository sanlock.
The following commit(s) were added to refs/heads/master by this push:
new d8020e3 python: Replace async with wait
d8020e3 is described below
commit d8020e3e65b4340ac7e312ceae4bd6aca9069bae
Author: Nir Soffer <nsoffer(a)redhat.com>
AuthorDate: Tue Jun 11 20:18:04 2019 +0300
python: Replace async with wait
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 breaks compatibility with existing python 2 code, but we
plan to ship sanlock 3.8 with python 3 support only on Fedora 30 and
EL 8.1 which do not support python 2, so this does not break existing
users.
Python code that wants to support both sanlock 3.7 and 3.8 will have to
change the behaviour based on python version.
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
@@ -801,8 +801,8 @@ finally:
/* 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).");
@@ -810,14 +810,15 @@ 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));
@@ -825,12 +826,12 @@ py_add_lockspace(PyObject *self __unused, PyObject *args, PyObject
*keywds)
/* 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;
}
@@ -920,8 +921,8 @@ finally:
/* 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\
@@ -931,13 +932,14 @@ 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));
@@ -946,7 +948,7 @@ py_rem_lockspace(PyObject *self __unused, PyObject *args, PyObject
*keywds)
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;
}
@@ -955,7 +957,7 @@ py_rem_lockspace(PyObject *self __unused, PyObject *args, PyObject
*keywds)
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;
}
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
@@ -341,7 +341,7 @@ def test_add_rem_lockspace_async(tmpdir, sanlock_daemon):
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)
@@ -353,7 +353,7 @@ def test_add_rem_lockspace_async(tmpdir, sanlock_daemon):
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):
@@ -514,7 +514,7 @@ def raises_sanlock_errno(expected_errno=errno.ECONNREFUSED):
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)
@@ -522,7 +522,7 @@ def test_rem_lockspace_parse_args(no_sanlock_daemon, name, filename,
encoding):
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)
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.