[PATCH] spec: Convert development spec to python 3
by Nir Soffer
The development spec creates now only python 3 packages. This will be
the base for Fedora 30 and CentOS 8.1 spec.
Also make rpmlint happy about mixing tabs and spaces by using only
spaces.
Signed-off-by: Nir Soffer <nsoffer(a)redhat.com>
---
sanlock.spec.in | 42 +++++++++++++++++-------------------------
1 file changed, 17 insertions(+), 25 deletions(-)
diff --git a/sanlock.spec.in b/sanlock.spec.in
index 9ad2985..087076c 100644
--- a/sanlock.spec.in
+++ b/sanlock.spec.in
@@ -16,30 +16,23 @@ URL: https://pagure.io/sanlock/
BuildRequires: gcc
BuildRequires: libaio-devel
BuildRequires: libblkid-devel
BuildRequires: libuuid-devel
BuildRequires: make
-BuildRequires: python2
-BuildRequires: python2-devel
+BuildRequires: python3
+BuildRequires: python3-devel
BuildRequires: systemd-units
Requires: %{name}-lib = %{version}-%{release}
Requires(pre): /usr/sbin/groupadd
Requires(pre): /usr/sbin/useradd
Requires(post): systemd-units
Requires(post): systemd-sysv
Requires(preun): systemd-units
Requires(postun): systemd-units
Source0: https://releases.pagure.org/sanlock/%{name}-%{version}.tar.gz
-# On Fedora we switched sanlock-python to python2-sanlock, as part of python 3
-# porting. This change was not done yet for RHEL.
-# TODO: remove when RHEL switches to pythonN-sanlock.
-%if 0%{?fedora}
-%global python_package python2-%{name}
-%else # centos/rhel
-%global python_package %{name}-python
-%endif
+%global python_package python3-%{name}
%description
The sanlock daemon manages leases for applications on hosts using shared storage.
%prep
@@ -51,11 +44,11 @@ The sanlock daemon manages leases for applications on hosts using shared storage
%endif
# upstream does not require configure
# upstream does not support _smp_mflags
CFLAGS=$RPM_OPT_FLAGS make -C wdmd
CFLAGS=$RPM_OPT_FLAGS make -C src
-CFLAGS=$RPM_OPT_FLAGS make -C python
+CFLAGS=$RPM_OPT_FLAGS make -C python PY_VERSION=3.6
CFLAGS=$RPM_OPT_FLAGS make -C reset
%install
rm -rf $RPM_BUILD_ROOT
make -C src \
@@ -65,11 +58,11 @@ make -C wdmd \
install LIBDIR=%{_libdir} \
DESTDIR=$RPM_BUILD_ROOT
make -C python \
install LIBDIR=%{_libdir} \
DESTDIR=$RPM_BUILD_ROOT \
- PY_VERSION=2.7 # TODO: fix PY_VERSION to 3.6 when 2020 will arrive
+ PY_VERSION=3.6
make -C reset \
install LIBDIR=%{_libdir} \
DESTDIR=$RPM_BUILD_ROOT
@@ -77,28 +70,28 @@ install -D -m 0644 init.d/sanlock.service.native $RPM_BUILD_ROOT/%{_unitdir}/san
install -D -m 0755 init.d/wdmd $RPM_BUILD_ROOT/usr/lib/systemd/systemd-wdmd
install -D -m 0644 init.d/wdmd.service.native $RPM_BUILD_ROOT/%{_unitdir}/wdmd.service
install -D -m 0644 init.d/sanlk-resetd.service $RPM_BUILD_ROOT/%{_unitdir}/sanlk-resetd.service
install -D -m 0644 src/logrotate.sanlock \
- $RPM_BUILD_ROOT/etc/logrotate.d/sanlock
+ $RPM_BUILD_ROOT/etc/logrotate.d/sanlock
install -D -m 0644 src/sanlock.conf \
- $RPM_BUILD_ROOT/etc/sanlock/sanlock.conf
+ $RPM_BUILD_ROOT/etc/sanlock/sanlock.conf
install -D -m 0644 init.d/wdmd.sysconfig \
- $RPM_BUILD_ROOT/etc/sysconfig/wdmd
+ $RPM_BUILD_ROOT/etc/sysconfig/wdmd
install -Dd -m 0755 $RPM_BUILD_ROOT/etc/wdmd.d
install -Dd -m 0775 $RPM_BUILD_ROOT/%{_rundir}/sanlock
install -Dd -m 0775 $RPM_BUILD_ROOT/%{_rundir}/sanlk-resetd
%pre
getent group sanlock > /dev/null || /usr/sbin/groupadd \
- -g 179 sanlock
+ -g 179 sanlock
getent passwd sanlock > /dev/null || /usr/sbin/useradd \
- -u 179 -c "sanlock" -s /sbin/nologin -r \
- -g 179 -d /run/sanlock sanlock
+ -u 179 -c "sanlock" -s /sbin/nologin -r \
+ -g 179 -d /run/sanlock sanlock
/usr/sbin/usermod -a -G disk sanlock
%post
%systemd_post wdmd.service sanlock.service
@@ -144,25 +137,21 @@ access to the shared disks.
%package -n %{python_package}
Summary: Python bindings for the sanlock library
Requires: %{name}-lib = %{version}-%{release}
%if 0%{?fedora}
-%{?python_provide:%python_provide python2-%{name}}
-# Remove before F30
-Provides: %{name}-python = %{version}-%{release}
-Provides: %{name}-python%{?_isa} = %{version}-%{release}
-Obsoletes: %{name}-python < %{version}-%{release}
+%{?python_provide:%python_provide %{python_package}}
%endif # fedora
%description -n %{python_package}
The %{python_package} package contains a module that permits applications
written in the Python programming language to use the interface
supplied by the sanlock library.
%files -n %{python_package}
-%{python2_sitearch}/sanlock_python-*.egg-info
-%{python2_sitearch}/sanlock.so
+%{python3_sitearch}/sanlock_python-*.egg-info
+%{python3_sitearch}/sanlock*.so
%package devel
Summary: Development files for %{name}
Requires: %{name}-lib = %{version}-%{release}
@@ -201,8 +190,11 @@ common sanlock lockspace.
%dir %attr(-,root,root) %{_rundir}/sanlk-resetd
%{_mandir}/man8/sanlk-reset*
%changelog
+* Wed Jun 12 2019 Nir Soffer <nsoffer(a)redhat.com> - 3.8.0-1
+- Convert spec to python 3
+
* Mon Mar 25 2019 Nir Soffer <nsoffer(a)redhat.com> - 3.7.0-1
- Import spec from Fedora master branch (371e11a)
- Fix spec to work on CentOS (20efe91)
--
2.17.2
4 years, 10 months
[sanlock] branch master updated: python: Replace async with wait
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.
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.
4 years, 10 months
Re: [PATCH v2] python: Replace async with wait
by Amit Bawer
Even if its accidental, those tests are stubs, so it has no effect other
than checking that argument parsing works as expected.
On Wed, Jun 12, 2019 at 11:11 AM Pavel Bar <pbar(a)redhat.com> wrote:
>
>
> On Wed, Jun 12, 2019 at 1:13 AM Nir Soffer <nirsof(a)gmail.com> wrote:
>
>> 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
>> @@ -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)
>>
>
> Just wanted to be sure that this is intentional:
> Previously "async" was not passed and it's default value was "async=False"
> that now has changed to "wait=True". But now you explicitly pass
> "wait=False".
> Is it on purpose?
> The same question about the below "test_add_lockspace_parse_args()".
>
>>
>>
>> @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, 10 months
[PATCH v2] 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 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
@@ -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, 10 months
[sanlock] 14/14: tests: Remove forgotten xfail for unsupported
locksapce names in bytes
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 d923f07a9e8c0de2c8be520081a96efce87393fd
Author: Amit Bawer <abawer(a)redhat.com>
AuthorDate: Tue Jun 11 15:08:43 2019 +0300
tests: Remove forgotten xfail for unsupported locksapce names in bytes
This situation is already handled now for both Python versions.
---
tests/python_test.py | 1 -
1 file changed, 1 deletion(-)
diff --git a/tests/python_test.py b/tests/python_test.py
index af75020..a2e25fb 100644
--- a/tests/python_test.py
+++ b/tests/python_test.py
@@ -132,7 +132,6 @@ def test_write_lockspace_4k_invalid_sector_size(sanlock_daemon, user_4k_path):
assert e.value.errno == errno.EINVAL
-(a)pytest.mark.xfail(six.PY3, reason="lockspace/resource names in bytes are unsupported yet")
def test_read_lockspace_4k_invalid_sector_size(sanlock_daemon, user_4k_path):
sanlock.write_lockspace(
b"ls_name", user_4k_path, iotimeout=1, sector=SECTOR_SIZE_4K)
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
4 years, 10 months
[sanlock] 13/14: tests: Remove xfail marks from path file names
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 94b7423028f897a5d6eadec45c533dc8484e50f1
Author: Amit Bawer <abawer(a)redhat.com>
AuthorDate: Wed Jun 5 16:51:31 2019 +0300
tests: Remove xfail marks from path file names
At this point we expect all API calls to handle file paths
as either unicode strings or bytes. This applies to both python
versions.
XPASS/xfail expected for test_write_resource_4k_invalid_sector_size.
---
tests/python_test.py | 42 +++++++++++++-----------------------------
1 file changed, 13 insertions(+), 29 deletions(-)
diff --git a/tests/python_test.py b/tests/python_test.py
index b072d6a..af75020 100644
--- a/tests/python_test.py
+++ b/tests/python_test.py
@@ -39,22 +39,6 @@ FILE_NAMES = [
#name, encoding
("ascii", None),
(u"ascii", None),
- pytest.param(
- u"\u05d0", None,
- marks=pytest.mark.xfail(
- six.PY2,
- reason="currently not supporting non-ascii paths")),
- pytest.param(
- u"\u05d0", "utf-8",
- marks=pytest.mark.xfail(
- six.PY3,
- reason="currently not supporting bytes paths")),
-]
-
-FILE_NAMES_NO_XFAILS = [
- #name, encoding
- ("ascii", None),
- (u"ascii", None),
(u"\u05d0", None),
(u"\u05d0", "utf-8"),
]
@@ -512,7 +496,7 @@ def test_write_resource_invalid_disk(tmpdir, sanlock_daemon, disk):
assert repr(disk) in str(e.value)
-(a)pytest.mark.parametrize("filename,encoding", FILE_NAMES_NO_XFAILS)
+(a)pytest.mark.parametrize("filename,encoding", FILE_NAMES)
def test_killpath(tmpdir, sanlock_daemon, filename, encoding):
cmd_path = util.generate_path(tmpdir, filename, encoding)
fd = sanlock.register()
@@ -527,7 +511,7 @@ def raises_sanlock_errno(expected_errno=errno.ECONNREFUSED):
@pytest.mark.parametrize("name", LOCKSPACE_OR_RESOURCE_NAMES)
-(a)pytest.mark.parametrize("filename,encoding", FILE_NAMES_NO_XFAILS)
+(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():
@@ -535,7 +519,7 @@ def test_rem_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_NO_XFAILS)
+(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():
@@ -543,7 +527,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_NO_XFAILS)
+(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():
@@ -551,7 +535,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_NO_XFAILS)
+(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)]
@@ -563,7 +547,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_NO_XFAILS)
+(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)]
@@ -575,7 +559,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_NO_XFAILS)
+(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)]
@@ -593,7 +577,7 @@ def test_get_hosts_parse_args(no_sanlock_daemon, name):
@pytest.mark.parametrize("name", LOCKSPACE_OR_RESOURCE_NAMES)
-(a)pytest.mark.parametrize("filename,encoding", FILE_NAMES_NO_XFAILS)
+(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():
@@ -619,7 +603,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_NO_XFAILS)
+(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):
@@ -627,7 +611,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_NO_XFAILS)
+(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)]
@@ -636,19 +620,19 @@ 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_NO_XFAILS)
+(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_NO_XFAILS)
+(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_NO_XFAILS)
+(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():
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
4 years, 10 months
[sanlock] 12/14: python: Add pypath_converter to killpath 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 6ab4074acbe0e91d66b7690903641bef3881666c
Author: Amit Bawer <abawer(a)redhat.com>
AuthorDate: Tue Jun 4 19:13:54 2019 +0300
python: Add pypath_converter to killpath API
We would like killpath to be able to handle paths as either unicode
and bytes, as well as the ones given in the command args.
Stub test for killpath API was modified to permutate over all paths
without expected xfails.
---
python/sanlock.c | 109 ++++++++++++++++++++++++++++++---------------------
tests/python_test.py | 2 +-
2 files changed, 66 insertions(+), 45 deletions(-)
diff --git a/python/sanlock.c b/python/sanlock.c
index b7ffa28..d122c8e 100644
--- a/python/sanlock.c
+++ b/python/sanlock.c
@@ -1363,6 +1363,51 @@ finally:
return ls_list;
}
+static int
+parse_killpath_item(PyObject *item, char *kpargs, size_t *kplen)
+{
+ int rv = 0, i;
+ size_t arg_len;
+ PyObject *path = NULL;
+ const char *p = NULL;
+
+ if (!pypath_converter(item, &path)) {
+ goto finally;
+ }
+ p = PyBytes_AsString(path);
+ if (!p) {
+ goto finally;
+ }
+ /* computing the argument length considering the escape chars */
+ for (i = 0, arg_len = 0; p[i]; i++, arg_len++) {
+ if (p[i] == ' ' || p[i] == '\\') arg_len++;
+ }
+
+ /* adding 2 for the space separator ' ' and the '\0' terminator */
+ if (*kplen + arg_len + 2 > SANLK_HELPER_ARGS_LEN) {
+ __set_exception(EINVAL, "Killpath arguments are too long");
+ goto finally;
+ }
+
+ /* adding the space separator between arguments */
+ if (*kplen > 0) {
+ kpargs[(*kplen)++] = ' ';
+ }
+
+ while (*p) {
+ if (*p == ' ' || *p == '\\') {
+ kpargs[(*kplen)++] = '\\';
+ }
+
+ kpargs[(*kplen)++] = *p++;
+ }
+ rv = 1;
+
+finally:
+ Py_XDECREF(path);
+ return rv;
+}
+
/* killpath */
PyDoc_STRVAR(pydoc_killpath, "\
killpath(path, args [, slkfd=fd])\n\
@@ -1374,75 +1419,51 @@ The arguments must be in the format: [\"arg1\", \"arg2\", ...]");
static PyObject *
py_killpath(PyObject *self __unused, PyObject *args, PyObject *keywds)
{
- int rv, i, j, n, num_args, sanlockfd = -1;
+ int rv = -1, i, num_args, sanlockfd = -1;
+ size_t kplen;
char kpargs[SANLK_HELPER_ARGS_LEN];
- const char *p, *path;
- PyObject *argslist, *item;
+ PyObject *path = NULL;
+ PyObject *argslist;
static char *kwlist[] = {"path", "args", "slkfd", NULL};
/* parse python tuple */
- if (!PyArg_ParseTupleAndKeywords(args, keywds, "sO!|i", kwlist,
- &path, &PyList_Type, &argslist, &sanlockfd)) {
- return NULL;
+ if (!PyArg_ParseTupleAndKeywords(args, keywds, "O&O!|i", kwlist,
+ pypath_converter, &path, &PyList_Type, &argslist, &sanlockfd)) {
+ goto finally;
}
/* checking the path length */
- if (strlen(path) + 1 > SANLK_HELPER_PATH_LEN) {
+ if (PyBytes_Size(path) + 1 > SANLK_HELPER_PATH_LEN) {
__set_exception(EINVAL, "Killpath path argument too long");
- return NULL;
+ goto finally;
}
num_args = PyList_Size(argslist);
memset(kpargs, 0, SANLK_HELPER_ARGS_LEN);
/* creating the arguments string from a python list */
- for (i = 0, n = 0; i < num_args; i++) {
- size_t arg_len;
-
- item = PyList_GetItem(argslist, i);
- p = pystring_as_cstring(item);
-
- if (p == NULL) {
- __set_exception(EINVAL, "Killpath argument not a string");
- return NULL;
- }
-
- /* computing the argument length considering the escape chars */
- for (j = 0, arg_len = 0; p[j]; j++, arg_len++) {
- if (p[j] == ' ' || p[j] == '\\') arg_len++;
- }
-
- /* adding 2 for the space separator ' ' and the '\0' terminator */
- if (n + arg_len + 2 > SANLK_HELPER_ARGS_LEN) {
- __set_exception(EINVAL, "Killpath arguments are too long");
- return NULL;
- }
-
- /* adding the space separator between arguments */
- if (n > 0) {
- kpargs[n++] = ' ';
- }
-
- while (*p) {
- if (*p == ' ' || *p == '\\') {
- kpargs[n++] = '\\';
- }
-
- kpargs[n++] = *p++;
+ for (i = 0, kplen = 0; i < num_args; i++) {
+ PyObject *item = PyList_GetItem(argslist, i);
+ if (!parse_killpath_item(item, kpargs, &kplen)) {
+ goto finally;
}
}
/* configure killpath (gil disabled) */
Py_BEGIN_ALLOW_THREADS
- rv = sanlock_killpath(sanlockfd, 0, path, kpargs);
+ rv = sanlock_killpath(sanlockfd, 0, PyBytes_AsString(path), kpargs);
Py_END_ALLOW_THREADS
if (rv != 0) {
- __set_exception(rv, "Killpath script not configured");
- return NULL;
+ __set_exception(rv, "Killpath script not configured");
+ goto finally;
}
+finally:
+ Py_XDECREF(path);
+ if (rv != 0)
+ return NULL;
Py_RETURN_NONE;
}
diff --git a/tests/python_test.py b/tests/python_test.py
index a23d2ec..b072d6a 100644
--- a/tests/python_test.py
+++ b/tests/python_test.py
@@ -512,7 +512,7 @@ def test_write_resource_invalid_disk(tmpdir, sanlock_daemon, disk):
assert repr(disk) in str(e.value)
-(a)pytest.mark.parametrize("filename,encoding", FILE_NAMES)
+(a)pytest.mark.parametrize("filename,encoding", FILE_NAMES_NO_XFAILS)
def test_killpath(tmpdir, sanlock_daemon, filename, encoding):
cmd_path = util.generate_path(tmpdir, filename, encoding)
fd = sanlock.register()
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
4 years, 10 months
[sanlock] 11/14: python: Apply pypath_converter to rem_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 083e0236b900564415016db856bccfc22dc409d3
Author: Amit Bawer <abawer(a)redhat.com>
AuthorDate: Tue Jun 4 01:01:02 2019 +0300
python: Apply pypath_converter to rem_lockspace API
We would like to parse lockspace path as either unicode or bytes.
Stub test for rem_lockspace API is set with additional permutation
over path with no expected xfails.
---
python/sanlock.c | 10 ++++++----
tests/python_test.py | 2 +-
2 files changed, 7 insertions(+), 5 deletions(-)
diff --git a/python/sanlock.c b/python/sanlock.c
index e3b63a7..b7ffa28 100644
--- a/python/sanlock.c
+++ b/python/sanlock.c
@@ -933,7 +933,7 @@ py_rem_lockspace(PyObject *self __unused, PyObject *args, PyObject *keywds)
{
int rv = -1, async = 0, unused = 0, flags = 0;
PyObject *lockspace = NULL;
- const char *path;
+ PyObject *path = NULL;
struct sanlk_lockspace ls;
static char *kwlist[] = {"lockspace", "host_id", "path", "offset",
@@ -943,15 +943,16 @@ py_rem_lockspace(PyObject *self __unused, PyObject *args, PyObject *keywds)
memset(&ls, 0, sizeof(struct sanlk_lockspace));
/* parse python tuple */
- if (!PyArg_ParseTupleAndKeywords(args, keywds, "O&ks|kii", kwlist,
- convert_to_pybytes, &lockspace, &ls.host_id, &path, &ls.host_id_disk.offset,
+ 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)) {
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);
/* prepare sanlock_rem_lockspace flags */
if (async) {
@@ -974,6 +975,7 @@ py_rem_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 2be57e0..a23d2ec 100644
--- a/tests/python_test.py
+++ b/tests/python_test.py
@@ -527,7 +527,7 @@ def raises_sanlock_errno(expected_errno=errno.ECONNREFUSED):
@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_rem_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, 10 months
[sanlock] 10/14: python: Apply pypath_converter to inq_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 d105239b7a3c9bce3f39fd11807af038b4ff0fff
Author: Amit Bawer <abawer(a)redhat.com>
AuthorDate: Tue Jun 4 00:56:07 2019 +0300
python: Apply pypath_converter to inq_lockspace API
We would like to parse lockspace path as either unicode or bytes.
Stub test for inq_lockspace API is set with additional permutation
for paths with no xfails expected.
---
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 4b7c810..e3b63a7 100644
--- a/python/sanlock.c
+++ b/python/sanlock.c
@@ -870,7 +870,7 @@ py_inq_lockspace(PyObject *self __unused, PyObject *args, PyObject *keywds)
{
int rv = BIND_ERROR, waitrs = 0, flags = 0;
PyObject *lockspace = NULL;
- const char *path;
+ PyObject *path = NULL;
struct sanlk_lockspace ls;
static char *kwlist[] = {"lockspace", "host_id", "path", "offset",
@@ -880,9 +880,9 @@ py_inq_lockspace(PyObject *self __unused, PyObject *args, PyObject *keywds)
memset(&ls, 0, sizeof(struct sanlk_lockspace));
/* parse python tuple */
- if (!PyArg_ParseTupleAndKeywords(args, keywds, "O&ks|ki", kwlist,
- convert_to_pybytes, &lockspace, &ls.host_id, &path, &ls.host_id_disk.offset,
- &waitrs)) {
+ if (!PyArg_ParseTupleAndKeywords(args, keywds, "O&kO&|ki", kwlist,
+ convert_to_pybytes, &lockspace, &ls.host_id, pypath_converter, &path,
+ &ls.host_id_disk.offset, &waitrs)) {
goto finally;
}
@@ -893,7 +893,7 @@ py_inq_lockspace(PyObject *self __unused, PyObject *args, PyObject *keywds)
/* 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);
/* add sanlock lockspace (gil disabled) */
Py_BEGIN_ALLOW_THREADS
@@ -902,6 +902,7 @@ py_inq_lockspace(PyObject *self __unused, PyObject *args, PyObject *keywds)
finally:
Py_XDECREF(lockspace);
+ Py_XDECREF(path);
if (rv == BIND_ERROR) {
return NULL;
diff --git a/tests/python_test.py b/tests/python_test.py
index a9933f4..2be57e0 100644
--- a/tests/python_test.py
+++ b/tests/python_test.py
@@ -593,7 +593,7 @@ def test_get_hosts_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_inq_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, 10 months
[sanlock] 09/14: python: Apply pypath_converter to add_lockspace
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 aa7011dea8ca4a0b1f8bc8cc35daf78d3d79b37e
Author: Amit Bawer <abawer(a)redhat.com>
AuthorDate: Tue Jun 4 00:52:00 2019 +0300
python: Apply pypath_converter to add_lockspace
We should be able to parse lockspace path as either unicode or bytes.
New stub test is added for add_lockpace API with path permutation
with no xfails expected.
---
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 a846570..4b7c810 100644
--- a/python/sanlock.c
+++ b/python/sanlock.c
@@ -813,7 +813,7 @@ py_add_lockspace(PyObject *self __unused, PyObject *args, PyObject *keywds)
int rv = -1, async = 0, flags = 0;
uint32_t iotimeout = 0;
PyObject *lockspace = NULL;
- const char *path;
+ PyObject *path = NULL;
struct sanlk_lockspace ls;
static char *kwlist[] = {"lockspace", "host_id", "path", "offset",
@@ -823,9 +823,9 @@ py_add_lockspace(PyObject *self __unused, PyObject *args, PyObject *keywds)
memset(&ls, 0, sizeof(struct sanlk_lockspace));
/* parse python tuple */
- if (!PyArg_ParseTupleAndKeywords(args, keywds, "O&ks|kIi", kwlist,
- convert_to_pybytes, &lockspace, &ls.host_id, &path, &ls.host_id_disk.offset,
- &iotimeout, &async)) {
+ 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)) {
goto finally;
}
@@ -836,7 +836,7 @@ py_add_lockspace(PyObject *self __unused, PyObject *args, PyObject *keywds)
/* 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);
/* add sanlock lockspace (gil disabled) */
Py_BEGIN_ALLOW_THREADS
@@ -850,6 +850,7 @@ py_add_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 3ce1301..a9933f4 100644
--- a/tests/python_test.py
+++ b/tests/python_test.py
@@ -535,7 +535,7 @@ def test_rem_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_add_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, 10 months