[sanlock] branch master updated: tests: Remove stale symlinks
before linking loop device
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 800a22d tests: Remove stale symlinks before linking loop device
800a22d is described below
commit 800a22d37ec4420d5e0757a80fbb551075a981ab
Author: Amit Bawer <abawer(a)redhat.com>
AuthorDate: Tue May 28 20:50:13 2019 +0300
tests: Remove stale symlinks before linking loop device
On storage setup we can have stale symlinks to loop devices
which were created before reboot and now are gone. Re-running the
setup will fail on creating the symlink again. In this patch we
add removal of the stale symlink, if there is such, before symlinking
the new loop device.
Signed-off-by: Amit Bawer <abawer(a)redhat.com>
---
tests/storage.py | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/tests/storage.py b/tests/storage.py
index 3258ed4..b7fcb2a 100644
--- a/tests/storage.py
+++ b/tests/storage.py
@@ -84,6 +84,10 @@ def create_loop_device(link_path, backing_file, size=1024**3,
device = out.decode("utf-8").strip()
+ # Remove stale symlink.
+ if os.path.islink(link_path):
+ os.unlink(link_path)
+
os.symlink(device, link_path)
chown(link_path)
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
4 years, 9 months
[PATCH] tests: Remove stale symlinks before linking loop device
by Nir Soffer
From: Amit Bawer <abawer(a)redhat.com>
On storage setup we can have stale symlinks to loop devices
which were created before reboot and now are gone. Re-running the
setup will fail on creating the symlink again. In this patch we
add removal of the pre-existing symlink, if there is such, before
symlinking the new loop device.
---
tests/storage.py | 3 +++
1 file changed, 3 insertions(+)
diff --git a/tests/storage.py b/tests/storage.py
index 3258ed4..ef40f08 100644
--- a/tests/storage.py
+++ b/tests/storage.py
@@ -82,10 +82,13 @@ def create_loop_device(link_path, backing_file, size=1024**3,
"--show",
])
device = out.decode("utf-8").strip()
+ #remove stale symlink
+ if os.path.islink(link_path):
+ os.unlink(link_path)
os.symlink(device, link_path)
chown(link_path)
def remove_loop_device(link_path, backing_file):
--
2.17.2
4 years, 9 months
[sanlock] 05/05: tests: Add tests for parsing lockspace and
resource 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 818a0dbc98a8704c269a0cb4c098c102f31d044a
Author: Amit Bawer <abawer(a)redhat.com>
AuthorDate: Mon May 20 12:27:56 2019 +0300
tests: Add tests for parsing lockspace and resource names
We add fast tests for sanlock API stubs only to test their
argument parsing. It is expected that if argument parsing
succeed, the API call itself will fail with errno since those
are only stubs so we add helper to assert on the proper errno.
---
tests/python_test.py | 95 +++++++++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 94 insertions(+), 1 deletion(-)
diff --git a/tests/python_test.py b/tests/python_test.py
index 6eb027c..db77862 100644
--- a/tests/python_test.py
+++ b/tests/python_test.py
@@ -8,8 +8,10 @@ import io
import struct
import time
-import six
+from contextlib import contextmanager
+
import pytest
+import six
import sanlock
@@ -49,6 +51,21 @@ FILE_NAMES = [
reason="currently not supporting bytes paths")),
]
+LOCKSPACE_OR_RESOURCE_NAMES = [
+ # Bytes are supported with python 2 and 3.
+ pytest.param(
+ b"\xd7\x90",
+ marks=pytest.mark.xfail(six.PY3, reason="bytes support not implemented yet")),
+ # Python 2 also supports str.
+ pytest.param(
+ "\xd7\x90",
+ marks=pytest.mark.skipif(six.PY3, reason="python 3 supports only bytes")),
+ # Python 2 also supports unicode with ascii content.
+ pytest.param(
+ u"ascii",
+ marks=pytest.mark.skipif(six.PY3, reason="python 3 supports only bytes")),
+]
+
@pytest.mark.parametrize("filename, encoding" , FILE_NAMES)
@pytest.mark.parametrize("size,offset", [
# Smallest offset.
@@ -487,8 +504,84 @@ def test_write_resource_invalid_disk(tmpdir, sanlock_daemon, disk):
sanlock.write_resource("ls_name", "res_name", disks)
assert repr(disk) in str(e.value)
+
@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()
sanlock.killpath(cmd_path, [cmd_path], fd)
+
+
+@contextmanager
+def raises_sanlock_errno(expected_errno=errno.ECONNREFUSED):
+ with pytest.raises(sanlock.SanlockException) as e:
+ yield
+ assert e.value.errno == expected_errno
+
+
+(a)pytest.mark.parametrize("name", LOCKSPACE_OR_RESOURCE_NAMES)
+def test_rem_lockspace_parse_args(no_sanlock_daemon, name):
+ with raises_sanlock_errno():
+ sanlock.rem_lockspace(name, 1, "ls_path", 0)
+
+
+(a)pytest.mark.parametrize("name", LOCKSPACE_OR_RESOURCE_NAMES)
+def test_add_lockspace_parse_args(no_sanlock_daemon, name):
+ with raises_sanlock_errno():
+ sanlock.add_lockspace(name, 1, "ls_path", 0)
+
+
+(a)pytest.mark.parametrize("name", LOCKSPACE_OR_RESOURCE_NAMES)
+def test_write_lockspace_parse_args(no_sanlock_daemon, name):
+ with raises_sanlock_errno():
+ sanlock.write_lockspace(name, "ls_path")
+
+
+(a)pytest.mark.parametrize("name", LOCKSPACE_OR_RESOURCE_NAMES)
+def test_write_resource_parse_args(no_sanlock_daemon, name):
+ with raises_sanlock_errno():
+ sanlock.write_resource(name, "res_name", [("disk_path",0)])
+
+ with raises_sanlock_errno():
+ sanlock.write_resource("ls_name", name, [("disk_path",0)])
+
+
+(a)pytest.mark.parametrize("name", LOCKSPACE_OR_RESOURCE_NAMES)
+def test_release_resource_parse_args(no_sanlock_daemon, name):
+ with raises_sanlock_errno():
+ sanlock.release(name, "res_name", [("disk_path",0)])
+
+ with raises_sanlock_errno():
+ sanlock.release("ls_name", name, [("disk_path",0)])
+
+
+(a)pytest.mark.parametrize("name", LOCKSPACE_OR_RESOURCE_NAMES)
+def test_read_resource_owners_parse_args(no_sanlock_daemon, name):
+ with raises_sanlock_errno():
+ sanlock.read_resource_owners(name, "res_name", [("disk_path",0)])
+
+ with raises_sanlock_errno():
+ sanlock.read_resource_owners("ls_name", name, [("disk_path",0)])
+
+
+(a)pytest.mark.parametrize("name", LOCKSPACE_OR_RESOURCE_NAMES)
+def test_get_hosts_parse_args(no_sanlock_daemon, name):
+ with raises_sanlock_errno():
+ sanlock.get_hosts(name, 1)
+
+
+(a)pytest.mark.parametrize("name", LOCKSPACE_OR_RESOURCE_NAMES)
+def test_inq_lockspace_parse_args(no_sanlock_daemon, name):
+ with raises_sanlock_errno():
+ sanlock.inq_lockspace(name, 1, "path", wait=False)
+
+
+(a)pytest.mark.parametrize("name", LOCKSPACE_OR_RESOURCE_NAMES)
+def test_reg_event_parse_args(no_sanlock_daemon, name):
+ with raises_sanlock_errno():
+ sanlock.reg_event(name)
+
+(a)pytest.mark.parametrize("name", LOCKSPACE_OR_RESOURCE_NAMES)
+def test_end_event_parse_args(no_sanlock_daemon, name):
+ with raises_sanlock_errno(errno.EALREADY):
+ sanlock.end_event(-1, name)
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
4 years, 9 months
[sanlock] 04/05: tests: Add test for killpath(...)
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 a6223003f7b3a3e071218fcafa0ae632587cfa1c
Author: Amit Bawer <abawer(a)redhat.com>
AuthorDate: Mon May 20 11:27:47 2019 +0300
tests: Add test for killpath(...)
Current status:
- Py2: Accept command paths in bytes or ascii strings.
- Py3: Accept command paths in unicode/ascii strings only.
---
tests/python_test.py | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/tests/python_test.py b/tests/python_test.py
index 2d50537..6eb027c 100644
--- a/tests/python_test.py
+++ b/tests/python_test.py
@@ -487,3 +487,8 @@ def test_write_resource_invalid_disk(tmpdir, sanlock_daemon, disk):
sanlock.write_resource("ls_name", "res_name", disks)
assert repr(disk) in str(e.value)
+(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()
+ sanlock.killpath(cmd_path, [cmd_path], fd)
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
4 years, 9 months
[sanlock] 03/05: python: Generalize set_value_error as set_error
utility 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 96e7b39164ae69403c5e0b26ce57a6f70e16df18
Author: Amit Bawer <abawer(a)redhat.com>
AuthorDate: Thu May 23 21:00:38 2019 +0300
python: Generalize set_value_error as set_error utility function
Allow to pass it PyExc_XXX object as well for raising different
exception types along with message and tested object for printout.
---
python/sanlock.c | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/python/sanlock.c b/python/sanlock.c
index 5d228e8..cec5c9b 100644
--- a/python/sanlock.c
+++ b/python/sanlock.c
@@ -35,7 +35,7 @@
/* Functions prototypes */
static void __set_exception(int en, char *msg) __sets_exception;
static int __parse_resource(PyObject *obj, struct sanlk_resource **res_ret) __neg_sets_exception;
-static void set_value_error(const char* format, PyObject* obj);
+static void set_error(PyObject *exception, const char* format, PyObject* obj);
/* Sanlock module */
PyDoc_STRVAR(pydoc_sanlock, "\
@@ -131,14 +131,14 @@ __parse_resource(PyObject *obj, struct sanlk_resource **res_ret)
disk = PyList_GetItem(obj, i);
if (!PyTuple_Check(disk)) {
- set_value_error("Invalid disk %s", disk);
+ set_error(PyExc_ValueError, "Invalid disk %s", disk);
goto exit_fail;
}
if (!PyArg_ParseTuple(disk, "sK", &path, &offset)) {
/* Override the error since it confusing in this context. */
- set_value_error("Invalid disk %s", disk);
+ set_error(PyExc_ValueError, "Invalid disk %s", disk);
goto exit_fail;
}
@@ -204,13 +204,13 @@ add_align_flag(long align, uint32_t *flags)
}
static void
-set_value_error(const char* format, PyObject* obj)
+set_error(PyObject* exception, const char* format, PyObject* obj)
{
const char* str_rep = "";
PyObject* rep = PyObject_Repr(obj);
if (rep)
str_rep = pystring_as_cstring(rep);
- PyErr_Format(PyExc_ValueError, format, str_rep);
+ PyErr_Format(exception, format, str_rep);
Py_XDECREF(rep);
}
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
4 years, 9 months
[sanlock] 02/05: tests: Add test calls for sanlock.get_lockspaces()
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 23e23a0b4f0d7801bb4b87baaea72eea1273f8f5
Author: Amit Bawer <abawer(a)redhat.com>
AuthorDate: Sun May 19 15:41:42 2019 +0300
tests: Add test calls for sanlock.get_lockspaces()
We expect to get acquired/added lockspaces details on list.
Applies to both Py2 and Py3.
---
tests/python_test.py | 12 ++++++++++++
1 file changed, 12 insertions(+)
diff --git a/tests/python_test.py b/tests/python_test.py
index cfbdf9c..2d50537 100644
--- a/tests/python_test.py
+++ b/tests/python_test.py
@@ -305,6 +305,15 @@ def test_add_rem_lockspace(tmpdir, sanlock_daemon, size, offset):
"ls_name", 1, path, offset=offset, wait=False)
assert acquired is True
+ lockspaces = sanlock.get_lockspaces()
+ assert lockspaces == [{
+ 'flags': 0,
+ 'host_id': 1,
+ 'lockspace': b'ls_name',
+ 'offset': offset,
+ 'path': path
+ }]
+
sanlock.rem_lockspace("ls_name", 1, path, offset=offset)
# Once the lockspace is released, we exepect to get False.
@@ -312,6 +321,9 @@ def test_add_rem_lockspace(tmpdir, sanlock_daemon, size, offset):
"ls_name", 1, path, offset=offset, wait=False)
assert acquired is False
+ lockspaces = sanlock.get_lockspaces()
+ assert lockspaces == []
+
def test_add_rem_lockspace_async(tmpdir, sanlock_daemon):
path = str(tmpdir.join("ls_name"))
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
4 years, 9 months
[sanlock] 01/05: tests: Add pytest.fixture of no_sanlock_daemon
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 f0f2a0ff50687cb06510582a845c970ab493c8f1
Author: Amit Bawer <abawer(a)redhat.com>
AuthorDate: Tue May 21 14:35:40 2019 +0300
tests: Add pytest.fixture of no_sanlock_daemon
New fixture calls util.sanlock_is_running() to check if the
pid showing in sanlock.pid file (if file exists) leads to local
sanlock executable file to conclude if sanlock is currenlty
running in test env. In case sanlock is running, a SunlockIsRunning
exception will be raised from test.
---
tests/conftest.py | 9 +++++++++
tests/util.py | 17 +++++++++++++++++
2 files changed, 26 insertions(+)
diff --git a/tests/conftest.py b/tests/conftest.py
index 93201bb..70e83d4 100644
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -44,3 +44,12 @@ def user_4k_path(request):
"user storage available - run 'python tests/strorage.py setup' "
"to enable 4k storage tests")
return request.param
+
+
+(a)pytest.fixture
+def no_sanlock_daemon():
+ if util.sanlock_is_running():
+ raise SanlockIsRunning
+
+class SanlockIsRunning(Exception):
+ pass
diff --git a/tests/util.py b/tests/util.py
index d944611..08db236 100644
--- a/tests/util.py
+++ b/tests/util.py
@@ -160,3 +160,20 @@ def generate_path(dirname, filename, encoding=None):
if encoding:
path = path.encode(encoding)
return path
+
+
+def sanlock_is_running():
+ """
+ Return boolean value indicating whether sanlock process
+ is currently executing within pytests run dir.
+ """
+ pid_file = os.path.join(os.environ["SANLOCK_RUN_DIR"], "sanlock.pid")
+ try:
+ with open(pid_file, "r") as f:
+ pid = f.readline().strip()
+ executable = os.readlink("/proc/{}/exe".format(pid))
+ return os.path.samefile(executable, SANLOCK)
+ except OSError as e:
+ if e.errno != errno.ENOENT:
+ raise
+ return False
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
4 years, 9 months
[PATCH 0/5] Test improvemnts for python 3
by Nir Soffer
These patches improve tests infrastructure for testing strings and bytes
support, and add missing tests for argument parsing.
If nobody objects, I will push these patches later this week.
The tests pass on all python versions:
https://travis-ci.org/nirs/sanlock/builds/538240633
Amit Bawer (5):
tests: Add pytest.fixture of no_sanlock_daemon
tests: Add test calls for sanlock.get_lockspaces()
python: Generalize set_value_error as set_error utility function
tests: Add test for killpath(...)
tests: Add tests for parsing lockspace and resource names
python/sanlock.c | 10 ++--
tests/conftest.py | 9 ++++
tests/python_test.py | 112 ++++++++++++++++++++++++++++++++++++++++++-
tests/util.py | 17 +++++++
4 files changed, 142 insertions(+), 6 deletions(-)
--
2.17.2
4 years, 9 months
Re: [PATCH 0/3] Spec cleanups
by Nir Soffer
On Thu, May 23, 2019 at 3:59 PM Pavel Bar <pbar(a)redhat.com> wrote:
> All 3 patches look OK to me.
>
Thanks for reviewing, pushed.
>
> On Wed, May 22, 2019 at 11:15 PM Nir Soffer <nirsof(a)gmail.com> wrote:
>
>> Cleanup the development spec. We need to backport some of these changes
>> to Fedora and RHEL.
>>
>> Nir Soffer (3):
>> build: Replace %{_localstatedir}/run with %{_rundir}
>> spec: Use one requirement per line
>> spec: Add missing build requirements
>>
>> sanlock.spec.in | 15 ++++++++++-----
>> 1 file changed, 10 insertions(+), 5 deletions(-)
>>
>> --
>> 2.17.2
>>
>>
4 years, 10 months
[sanlock] 03/03: spec: Add missing build requirements
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 634690bbe673ad962fe09a4f6a1cc5f341b0f6ca
Author: Nir Soffer <nsoffer(a)redhat.com>
AuthorDate: Wed May 22 23:03:47 2019 +0300
spec: Add missing build requirements
Keeping correct build requirement help developers to setup their
environment using dnf builddep.
libuuid-devel is also required now on Fedora 31.
Signed-off-by: Nir Soffer <nsoffer(a)redhat.com>
---
sanlock.spec.in | 2 ++
1 file changed, 2 insertions(+)
diff --git a/sanlock.spec.in b/sanlock.spec.in
index 14729cf..9ad2985 100644
--- a/sanlock.spec.in
+++ b/sanlock.spec.in
@@ -16,6 +16,8 @@ URL: https://pagure.io/sanlock/
BuildRequires: gcc
BuildRequires: libaio-devel
BuildRequires: libblkid-devel
+BuildRequires: libuuid-devel
+BuildRequires: make
BuildRequires: python2
BuildRequires: python2-devel
BuildRequires: systemd-units
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
4 years, 10 months