[sanlock] 13/23: tests: Add parameterized tests for file paths
encodings
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 040d287eb3b267f06492af3ecc4911a587a4bfa8
Author: Amit Bawer <abawer(a)redhat.com>
AuthorDate: Thu May 16 15:29:51 2019 +0300
tests: Add parameterized tests for file paths encodings
Currently we have two tests expecting to fail, this holds until we add
the path converter funcationality.
- Py2: currenlty not supporing non-ascii paths
- Py3: currently not supporting bytes paths
---
tests/python_test.py | 27 +++++++++++++++++++++++----
1 file changed, 23 insertions(+), 4 deletions(-)
diff --git a/tests/python_test.py b/tests/python_test.py
index e721fe8..a24990d 100644
--- a/tests/python_test.py
+++ b/tests/python_test.py
@@ -8,6 +8,7 @@ import io
import struct
import time
+import six
import pytest
import sanlock
@@ -32,14 +33,31 @@ SECTOR_SIZE_512 = 512
SECTOR_SIZE_4K = 4 * KiB
+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")),
+]
+
+(a)pytest.mark.parametrize("filename, encoding" , FILE_NAMES)
@pytest.mark.parametrize("size,offset", [
# Smallest offset.
(LOCKSPACE_SIZE, 0),
# Large offset.
(LARGE_FILE_SIZE, LARGE_FILE_SIZE - LOCKSPACE_SIZE),
])
-def test_write_lockspace(tmpdir, sanlock_daemon, size, offset):
- path = str(tmpdir.join("lockspace"))
+def test_write_lockspace(tmpdir, sanlock_daemon, filename, encoding, size, offset):
+ path = util.generate_path(tmpdir, filename, encoding)
util.create_file(path, size)
# Test read and write with default alignment and sector size values.
@@ -116,14 +134,15 @@ def test_read_lockspace_4k_invalid_sector_size(sanlock_daemon, user_4k_path):
assert e.value.errno == errno.EINVAL
+(a)pytest.mark.parametrize("filename,encoding", FILE_NAMES)
@pytest.mark.parametrize("size,offset", [
# Smallest offset.
(MIN_RES_SIZE, 0),
# Large offset.
(LARGE_FILE_SIZE, LARGE_FILE_SIZE - MIN_RES_SIZE),
])
-def test_write_resource(tmpdir, sanlock_daemon, size, offset):
- path = str(tmpdir.join("resources"))
+def test_write_resource(tmpdir, sanlock_daemon, filename, encoding, size, offset):
+ path = util.generate_path(tmpdir, filename, encoding)
util.create_file(path, size)
disks = [(path, offset)]
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
4 years, 11 months
[sanlock] 12/23: tests: Add util.generate_path for generating file
paths by encoding
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 99018463c965b95e11eec73eee027a2d451ad61d
Author: Amit Bawer <abawer(a)redhat.com>
AuthorDate: Thu May 16 13:52:24 2019 +0300
tests: Add util.generate_path for generating file paths by encoding
The path generation utility function will be used for testing API's
ability to handle the different encoded path strings/bytes in
upcoming changes related to path argument parsing and conversion.
---
tests/util.py | 12 ++++++++++++
1 file changed, 12 insertions(+)
diff --git a/tests/util.py b/tests/util.py
index 86c6447..d944611 100644
--- a/tests/util.py
+++ b/tests/util.py
@@ -148,3 +148,15 @@ def check_rindex_entry(entry, name, offset=None, flags=None):
if flags is not None:
assert e_flags == flags
+
+
+def generate_path(dirname, filename, encoding=None):
+ """
+ Return path by joining dirname and filename.
+ The resulting path is either string if encoding is None,
+ or bytes encoded according to given encoding parameter.
+ """
+ path = os.path.join(str(dirname), filename)
+ if encoding:
+ path = path.encode(encoding)
+ return path
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
4 years, 11 months
[sanlock] 09/23: sanlock: Provide internal common module init
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 2a147dd9521dbc339549400c9a541e0d49d11455
Author: Amit Bawer <abawer(a)redhat.com>
AuthorDate: Mon May 6 15:34:48 2019 +0300
sanlock: Provide internal common module init function
This will serve python 3 porting in future patches to come.
Signed-off-by: Amit Bawer <abawer(a)redhat.com>
---
python/sanlock.c | 103 ++++++++++++++++++++++++++++++++-----------------------
1 file changed, 60 insertions(+), 43 deletions(-)
diff --git a/python/sanlock.c b/python/sanlock.c
index 446a4b5..420b4ba 100644
--- a/python/sanlock.c
+++ b/python/sanlock.c
@@ -30,6 +30,8 @@
#define __neg_sets_exception
#endif
+#define MODULE_NAME "sanlock"
+
/* 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;
@@ -1702,77 +1704,92 @@ exit_fail:
return excp;
}
-PyMODINIT_FUNC
-initsanlock(void)
+static int
+module_init(PyObject* m)
{
- PyObject *py_module, *sk_constant;
-
- py_module = Py_InitModule4("sanlock",
- sanlock_methods, pydoc_sanlock, NULL, PYTHON_API_VERSION);
-
- if (py_module == NULL)
- return;
-
if (py_exception == NULL) {
py_exception = initexception();
if (py_exception == NULL)
- return;
+ return -1;
}
Py_INCREF(py_exception);
- if (PyModule_AddObject(py_module, "SanlockException", py_exception)) {
+ if (PyModule_AddObject(m, "SanlockException", py_exception)) {
Py_DECREF(py_exception);
- return;
- }
-
-#define PYSNLK_INIT_ADD_CONSTANT(x, y) \
- if ((sk_constant = PyInt_FromLong(x)) != NULL) { \
- if (PyModule_AddObject(py_module, y, sk_constant)) { \
- Py_DECREF(sk_constant); \
- } \
+ return -1;
}
/* lockspaces list flags */
- PYSNLK_INIT_ADD_CONSTANT(SANLK_LSF_ADD, "LSFLAG_ADD");
- PYSNLK_INIT_ADD_CONSTANT(SANLK_LSF_REM, "LSFLAG_REM");
+ if (PyModule_AddIntConstant(m, "LSFLAG_ADD", SANLK_LSF_ADD))
+ return -1;
+ if (PyModule_AddIntConstant(m, "LSFLAG_REM", SANLK_LSF_REM))
+ return -1;
/* resource request flags */
- PYSNLK_INIT_ADD_CONSTANT(SANLK_REQ_FORCE, "REQ_FORCE");
- PYSNLK_INIT_ADD_CONSTANT(SANLK_REQ_GRACEFUL, "REQ_GRACEFUL");
+ if (PyModule_AddIntConstant(m, "REQ_FORCE", SANLK_REQ_FORCE))
+ return -1;
+ if (PyModule_AddIntConstant(m, "REQ_GRACEFUL", SANLK_REQ_GRACEFUL))
+ return -1;
/* hosts list flags */
- PYSNLK_INIT_ADD_CONSTANT(SANLK_HOST_FREE, "HOST_FREE");
- PYSNLK_INIT_ADD_CONSTANT(SANLK_HOST_LIVE, "HOST_LIVE");
- PYSNLK_INIT_ADD_CONSTANT(SANLK_HOST_FAIL, "HOST_FAIL");
- PYSNLK_INIT_ADD_CONSTANT(SANLK_HOST_DEAD, "HOST_DEAD");
- PYSNLK_INIT_ADD_CONSTANT(SANLK_HOST_UNKNOWN, "HOST_UNKNOWN");
+ if (PyModule_AddIntConstant(m, "HOST_FREE", SANLK_HOST_FREE))
+ return -1;
+ if (PyModule_AddIntConstant(m, "HOST_LIVE", SANLK_HOST_LIVE))
+ return -1;
+ if (PyModule_AddIntConstant(m, "HOST_FAIL", SANLK_HOST_FAIL))
+ return -1;
+ if (PyModule_AddIntConstant(m, "HOST_DEAD", SANLK_HOST_DEAD))
+ return -1;
+ if (PyModule_AddIntConstant(m, "HOST_UNKNOWN", SANLK_HOST_UNKNOWN))
+ return -1;
/* set event flags */
- PYSNLK_INIT_ADD_CONSTANT(SANLK_SETEV_CUR_GENERATION, "SETEV_CUR_GENERATION");
- PYSNLK_INIT_ADD_CONSTANT(SANLK_SETEV_CLEAR_HOSTID, "SETEV_CLEAR_HOSTID");
- PYSNLK_INIT_ADD_CONSTANT(SANLK_SETEV_CLEAR_EVENT, "SETEV_CLEAR_EVENT");
- PYSNLK_INIT_ADD_CONSTANT(SANLK_SETEV_REPLACE_EVENT, "SETEV_REPLACE_EVENT");
- PYSNLK_INIT_ADD_CONSTANT(SANLK_SETEV_ALL_HOSTS, "SETEV_ALL_HOSTS");
-
-#undef PYSNLK_INIT_ADD_CONSTANT
+ if (PyModule_AddIntConstant(m, "SETEV_CUR_GENERATION", SANLK_SETEV_CUR_GENERATION))
+ return -1;
+ if (PyModule_AddIntConstant(m, "SETEV_CLEAR_HOSTID", SANLK_SETEV_CLEAR_HOSTID))
+ return -1;
+ if (PyModule_AddIntConstant(m, "SETEV_CLEAR_EVENT", SANLK_SETEV_CLEAR_EVENT))
+ return -1;
+ if (PyModule_AddIntConstant(m, "SETEV_REPLACE_EVENT", SANLK_SETEV_REPLACE_EVENT))
+ return -1;
+ if (PyModule_AddIntConstant(m, "SETEV_ALL_HOSTS", SANLK_SETEV_ALL_HOSTS))
+ return -1;
/* Tuples with supported sector size and alignment values */
+
PyObject *sector = Py_BuildValue("ii", SECTOR_SIZE_512, SECTOR_SIZE_4K);
if (!sector)
- return;
- if (PyModule_AddObject(py_module, "SECTOR_SIZE", sector)) {
+ return -1;
+ if (PyModule_AddObject(m, "SECTOR_SIZE", sector)) {
Py_DECREF(sector);
- return;
+ return -1;
}
- PyObject *align = Py_BuildValue("llll", ALIGNMENT_1M, ALIGNMENT_2M, ALIGNMENT_4M, ALIGNMENT_8M);
+ PyObject *align = Py_BuildValue(
+ "llll", ALIGNMENT_1M, ALIGNMENT_2M, ALIGNMENT_4M, ALIGNMENT_8M);
if (!align)
- return;
- if (PyModule_AddObject(py_module, "ALIGN_SIZE", align)) {
+ return -1;
+ if (PyModule_AddObject(m, "ALIGN_SIZE", align)) {
Py_DECREF(align);
- return;
+ return -1;
}
+ return 0;
+}
+
+PyMODINIT_FUNC
+initsanlock(void)
+{
+ PyObject *m = Py_InitModule3(
+ MODULE_NAME,
+ sanlock_methods,
+ pydoc_sanlock);
+
+ if (m == NULL)
+ return;
+
+ /* We don't have anything to do if module_init() fails. */
+ module_init(m);
}
/* vim: set expandtab shiftwidth=4 tabstop=4 : */
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
4 years, 11 months
[sanlock] 08/23: tests: Test parsing a resource which is not a list
of tuples
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 b8a9a88d4ffa47214adc10bd52ac19ecc0a4e3fb
Author: Amit Bawer <abawer(a)redhat.com>
AuthorDate: Mon May 6 13:03:27 2019 +0300
tests: Test parsing a resource which is not a list of tuples
Expecting to get ValueError for resource argument which
is not a list of tuples (disk, offset).
Signed-off-by: Amit Bawer <abawer(a)redhat.com>
---
tests/python_test.py | 15 +++++++++++++++
1 file changed, 15 insertions(+)
diff --git a/tests/python_test.py b/tests/python_test.py
index d7ec0fb..28827d6 100644
--- a/tests/python_test.py
+++ b/tests/python_test.py
@@ -431,3 +431,18 @@ def test_write_resource_invalid_align_sector(
with pytest.raises(ValueError):
sanlock.write_resource(
"ls_name", "res_name", disks, align=align, sector=sector)
+
+
+(a)pytest.mark.parametrize("resource", [
+ "invalid resource tuple",
+ b"invalid resource tuple",
+ u'\u05e9\u05dc\u05d5\u05dd',
+ b"\xd7\x90"
+])
+def test_write_resource_invalid_path(tmpdir, sanlock_daemon, resource):
+ # Test parsing a resource which is not a list of tuples
+ disks = [resource]
+ with pytest.raises(ValueError) as e:
+ sanlock.write_resource("ls_name", "res_name", disks)
+ assert repr(resource) in str(e.value)
+
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
4 years, 11 months
[sanlock] 07/23: sanlock: Resource API should only support disks as
a tuple
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 c58fb9fc3eeffcf1f94a3df4df3061219cbc4b3a
Author: Amit Bawer <abawer(a)redhat.com>
AuthorDate: Sun May 5 16:29:31 2019 +0300
sanlock: Resource API should only support disks as a tuple
As stated in sanlock module help:
The disks must be in the format: [(path, offset), ... ]
Signed-off-by: Amit Bawer <abawer(a)redhat.com>
---
python/sanlock.c | 18 ++++++++++++++++--
1 file changed, 16 insertions(+), 2 deletions(-)
diff --git a/python/sanlock.c b/python/sanlock.c
index e710f89..446a4b5 100644
--- a/python/sanlock.c
+++ b/python/sanlock.c
@@ -33,6 +33,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);
/* Sanlock module */
PyDoc_STRVAR(pydoc_sanlock, "\
@@ -109,8 +110,10 @@ __parse_resource(PyObject *obj, struct sanlk_resource **res_ret)
__set_exception(EINVAL, "Invalid resource offset");
goto exit_fail;
}
- } else if (PyString_Check(tuple)) {
- p = PyString_AsString(tuple);
+ } else {
+ /* handle invalid non-tuple resource input */
+ set_value_error("invalid disk value: %s", tuple);
+ goto exit_fail;
}
if (p == NULL) {
@@ -184,6 +187,17 @@ add_align_flag(long align, uint32_t *flags)
return 0;
}
+static void
+set_value_error(const char* format, PyObject* obj)
+{
+ const char* str_rep = "";
+ PyObject* rep = PyObject_Repr(obj);
+ if (rep)
+ str_rep = PyString_AsString(rep);
+ PyErr_Format(PyExc_ValueError, format, str_rep);
+ Py_XDECREF(rep);
+}
+
static PyObject *
__hosts_to_list(struct sanlk_host *hss, int hss_count)
{
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
4 years, 11 months
[sanlock] 05/23: tests: Update lockspace and resource tests
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 915f6768e9d7ae975a158889b218eed6a1656540
Author: Nir Soffer <nsoffer(a)redhat.com>
AuthorDate: Wed May 15 14:57:50 2019 +0300
tests: Update lockspace and resource tests
We introduced new assertions about lockspace and resource names in the
4k branch. Update the assertions to check for b"name" instead of "name".
Signed-off-by: Nir Soffer <nsoffer(a)redhat.com>
---
tests/python_test.py | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/tests/python_test.py b/tests/python_test.py
index 7e3910b..b2f903b 100644
--- a/tests/python_test.py
+++ b/tests/python_test.py
@@ -52,7 +52,7 @@ def test_write_lockspace(tmpdir, sanlock_daemon, size, offset):
ls = sanlock.read_lockspace(
path, offset=offset, align=ALIGNMENT_1M, sector=SECTOR_SIZE_512)
- assert ls == {"iotimeout": 1, "lockspace": "name"}
+ assert ls == {"iotimeout": 1, "lockspace": b"name"}
acquired = sanlock.inq_lockspace(
"name", 1, path, offset=offset, wait=False)
@@ -83,7 +83,7 @@ def test_write_lockspace_4k(user_4k_path, sanlock_daemon, align):
ls = sanlock.read_lockspace(
user_4k_path, align=align, sector=SECTOR_SIZE_4K)
- assert ls == {"iotimeout": 1, "lockspace": "name"}
+ assert ls == {"iotimeout": 1, "lockspace": b"name"}
acquired = sanlock.inq_lockspace("name", 1, user_4k_path, wait=False)
assert acquired is False
@@ -142,8 +142,8 @@ def test_write_resource(tmpdir, sanlock_daemon, size, offset):
res = sanlock.read_resource(
path, offset=offset, align=ALIGNMENT_1M, sector=SECTOR_SIZE_512)
assert res == {
- "lockspace": "ls_name",
- "resource": "res_name",
+ "lockspace": b"ls_name",
+ "resource": b"res_name",
"version": 0
}
@@ -177,8 +177,8 @@ def test_write_resource_4k(sanlock_daemon, user_4k_path, align):
user_4k_path, align=align, sector=SECTOR_SIZE_4K)
assert res == {
- "lockspace": "ls_name",
- "resource": "res_name",
+ "lockspace": b"ls_name",
+ "resource": b"res_name",
"version": 0
}
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
4 years, 11 months
[PATCH v2 00/23] Initial python 3 support
by Nir Soffer
The first phase of python 3 porting is done:
All the tests pass now in python 2.7, 3.6, 3.7 and 3.8.
I plan to push this once we cut python 3.7.3 for EL 7.7.
More work is needed:
- accept only bytes for resource and lockspaces names on python 3
- support both unicode and bytes for paths on python 3, same as posix module
- add missing tests (request, killpath, xxx_event)
- spec for python 3
The patches are also available in this branch:
https://github.com/nirs/sanlock/commits/py3
commit: 3c03d8672d8589219def0133b188a1ac31d41615
Amit Bawer (18):
readme: Add prerequisites section
tox: Add python version as make argument
tests: Use python3 and python2 compatible socket exception type
tests: Lockspace and resource names should be read as bytes
tests: Enforce absolute import behavior for python2 tests
sanlock: Resource API should only support disks as a tuple
tests: Test parsing a resource which is not a list of tuples
sanlock: Provide internal common module init function
tests: Add util.generate_path for generating file paths by encoding
tests: Add parameterized tests for file paths encodings
sanlock: Add module init for Python 3
python: Add pystring_as_cstring function
python: Provide helper for Py{Int,Long}_AsUnsignedLongLongMask
python: Refactor build of dictionary entries for hosts_to_list
python: Refactor build of dictionary entries for py_get_lockspaces
python: Refactor build of dictionary entries for py_read_lockspace
python: Refactor build of dictionary entries for py_read_resource
python: Use Py_BuildValue("i", ...) to create py integers
Nir Soffer (3):
tests: Update lockspace and resource tests
python: Simplify parse_resource() with PyArg_ParseTuple
travis: Add python 3 builds
Pavel Bar (2):
Fix typos in debug logs and comments.
Adding constants for Kibibyte, Mebibyte, Gibibyte, Tebibyte & Pebibyte
and using them everywhere in tests.
.travis.yml | 8 +-
README.dev | 12 ++
python/Makefile | 6 +-
python/sanlock.c | 409 +++++++++++++++++++++----------------------
sanlock.spec.in | 3 +-
src/direct.c | 2 +-
src/resource.c | 2 +-
tests/conftest.py | 1 +
tests/daemon_test.py | 44 ++---
tests/direct_test.py | 6 +-
tests/python_test.py | 111 ++++++++----
tests/units.py | 9 +
tests/util.py | 21 ++-
tox.ini | 3 +-
14 files changed, 361 insertions(+), 276 deletions(-)
create mode 100644 tests/units.py
--
2.17.2
4 years, 11 months
[sanlock] branch master updated: tests: Simplify 4k tests setup and
teardown
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 7abb5e8 tests: Simplify 4k tests setup and teardown
7abb5e8 is described below
commit 7abb5e848b3ea06e9b73c3bcf702150d6b3e5851
Author: Nir Soffer <nsoffer(a)redhat.com>
AuthorDate: Sat May 18 19:26:37 2019 +0300
tests: Simplify 4k tests setup and teardown
Previously you had to setup the environment manually to enable the 4k
tests, and pass environment variable to tests. The tests used single
path, so you had to run the tests twice to test both 4k block device and
filesystem backed by a 4k block device.
Add storage helper script to make it easier to setup storage for the
tests.
To setup 4k storage for the tests, run:
$ python tests/storage.py setup
This script creates both a 4k block device and filesystem backed by a 4k
device. The user_4k_path() fixture enables the tests if the device and
mount exist, and runs the test twice, once with the loop device, and
once with the filesystem.
To clean up the environment, run:
$ python tests/storage.py teardown
Signed-off-by: Nir Soffer <nsoffer(a)redhat.com>
---
README.dev | 44 +++++------------
tests/conftest.py | 38 +++++----------
tests/storage.py | 142 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 165 insertions(+), 59 deletions(-)
diff --git a/README.dev b/README.dev
index bfb170c..439b7b4 100644
--- a/README.dev
+++ b/README.dev
@@ -29,42 +29,20 @@ To run only tests matching the substring "foo":
Testing 4K support
==================
-This requires manual setup for creating a block device using 4k sector size,
-optionally creating and mounting a file system, and passing the test path to
-tests. The setup must be done as root, but the tests can run later as the
-current user.
+To enable the 4k tests, you need to setup 4k stroage for the tests:
-Common setup
-------------
+ $ python tests/storage.py setup
-1. Create a backing file:
+This creates two loop devices with 4k sector size; one for testing sanlock with
+4k block device, and the other for testing with a filesystem backed by a 4k
+block device.
- $ truncate -s 1G /var/tmp/backing
+To teardown the storage:
-2. Create a loop device with 4k sector size:
+ $ python tests/storage.py teardown
- $ sudo losetup -f /var/tmp/backing --show --sector-size=4096
- /dev/loop2
+The script unmounts the filesystem and detaches the loop devices.
-3. Change the device (or mountpoint) owner to current user
-
- $ sudo chown $USER:$USER /dev/loop2
-
-Testing 4k block device
------------------------
-
-Run the tests with USER_4K_PATH environment variable:
-
- $ USER_4K_PATH=/dev/loop2 tox -e py27
-
-Testing 4k file system
-----------------------
-
-To test file system on top of 4k block device, create a file system on the
-device, mount it, and create a file for testing lockspace or resources:
-
- $ sudo mkfs.xfs /dev/loop2
- $ sudo mount /dev/loop2 /tmp/sanlock-4k
- $ sudo chown $USER:$USER /tmp/sanlock-4k
- $ truncate -s 128m /tmp/sanlock-4k/disk
- $ USER_4K_PATH=/tmp/sanlock-4k/disk tox -e py27
+The storage helper script uses sudo to perform privileged operations. The best
+way to use it is to setup the environment once at the start of the session, and
+teardown when you finish.
diff --git a/tests/conftest.py b/tests/conftest.py
index bb95d45..5212679 100644
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -7,6 +7,7 @@ import stat
import pytest
+from . import storage
from . import util
@@ -26,34 +27,19 @@ def sanlock_daemon():
p.wait()
-(a)pytest.fixture
-def user_4k_path():
+(a)pytest.fixture(params=[
+ pytest.param(storage.BLOCK, id="block"),
+ pytest.param(storage.FILE, id="file"),
+])
+def user_4k_path(request):
"""
A path to block device or file on file system on top of 4k block device,
provided by the user.
- The user must create the block device or the file system before running the
- tests, and specify the path to the file in the USER_4K_PATH environment
- variable.
-
- If USER_4K_PATH was not specified, tests using this fixture will be skipped.
- If USER_4K_PATH was specified but does not exist, or is not a file or block
- device, RuntimeError is raised.
-
- Return path to the user specified file.
+ If storage is not available, skip the tests.
"""
- path = os.environ.get("USER_4K_PATH")
- if path is None:
- pytest.skip("USER_4K_PATH pointing to a 4k block device or file was "
- "not specified")
-
- if not os.path.exists(path):
- raise RuntimeError("USER_4K_PATH {!r} does not exist".format(path))
-
- mode = os.stat(path).st_mode
- if not (stat.S_ISBLK(mode) or stat.S_ISREG(mode)):
- raise RuntimeError(
- "USER_4K_PATH {!r} is not a block device or regular file"
- .format(path))
-
- return path
+ if not os.path.exists(request.param):
+ pytest.skip(
+ "user storage available - run 'python tests/strorage.py setup' "
+ "to enable 4k storage tests")
+ return request.param
diff --git a/tests/storage.py b/tests/storage.py
new file mode 100644
index 0000000..3258ed4
--- /dev/null
+++ b/tests/storage.py
@@ -0,0 +1,142 @@
+"""
+storage - provide storage for sanlock tests.
+"""
+
+import argparse
+import errno
+import logging
+import os
+import subprocess
+
+BASE_DIR = "/var/tmp/sanlock-storage"
+MOUNTPOINT = os.path.join(BASE_DIR, "mnt")
+
+# For testing sanlock with 4k block device.
+LOOP1 = os.path.join(BASE_DIR, "loop1")
+BACKING1 = os.path.join(BASE_DIR, "backing1")
+
+# For testing sanlock with a filesystem backed by 4k block device.
+LOOP2 = os.path.join(BASE_DIR, "loop2")
+BACKING2 = os.path.join(BASE_DIR, "backing2")
+
+# Test paths.
+BLOCK = LOOP1
+FILE = os.path.join(MOUNTPOINT, "file")
+
+log = logging.getLogger("storage")
+
+
+def main():
+ parser = argparse.ArgumentParser(
+ description='Storage helper for sanlock tests')
+ parser.add_argument("command", choices=["setup", "teardown"])
+ args = parser.parse_args()
+
+ logging.basicConfig(level=logging.INFO, format="storage: %(message)s")
+
+ if args.command == "setup":
+ setup()
+ elif args.command == "teardown":
+ teardown()
+
+
+def setup():
+ create_dir(BASE_DIR)
+
+ if not os.path.exists(LOOP1):
+ create_loop_device(LOOP1, BACKING1)
+
+ if not os.path.exists(LOOP2):
+ create_loop_device(LOOP2, BACKING2)
+ create_dir(MOUNTPOINT)
+ create_filesystem(LOOP2, MOUNTPOINT)
+
+ # Sanlock allocates spaces as needed.
+ with open(FILE, "wb") as f:
+ f.truncate(0)
+
+
+def teardown():
+ if is_mounted(MOUNTPOINT):
+ remove_filesystem(MOUNTPOINT)
+
+ if os.path.exists(LOOP2):
+ remove_loop_device(LOOP2, BACKING2)
+
+ if os.path.exists(LOOP1):
+ remove_loop_device(LOOP1, BACKING1)
+
+
+def create_loop_device(link_path, backing_file, size=1024**3,
+ sector_size=4096):
+ log.info("Creating loop device %s", link_path)
+
+ with open(backing_file, "wb") as f:
+ f.truncate(size)
+
+ out = subprocess.check_output([
+ "sudo",
+ "losetup",
+ "-f", backing_file,
+ "--sector-size", str(sector_size),
+ "--show",
+ ])
+
+ device = out.decode("utf-8").strip()
+
+ os.symlink(device, link_path)
+ chown(link_path)
+
+
+def remove_loop_device(link_path, backing_file):
+ log.info("Removing loop device %s", link_path)
+
+ subprocess.check_call(["sudo", "losetup", "-d", link_path])
+ remove_file(link_path)
+ remove_file(backing_file)
+
+
+def create_filesystem(device, mountpoint):
+ log.info("Creating filesystem %s", mountpoint)
+
+ subprocess.check_call(["sudo", "mkfs.xfs", "-q", device])
+ subprocess.check_call(["sudo", "mount", device, mountpoint])
+ chown(mountpoint)
+
+
+def remove_filesystem(mountpoint):
+ log.info("Removing filesystem %s", mountpoint)
+ subprocess.check_call(["sudo", "umount", mountpoint])
+
+
+def is_mounted(mountpoint):
+ with open("/proc/self/mounts") as f:
+ for line in f:
+ if mountpoint in line:
+ return True
+ return False
+
+
+def chown(path):
+ user_group = "%(USER)s:%(USER)s" % os.environ
+ subprocess.check_call(["sudo", "chown", user_group, path])
+
+
+def create_dir(path):
+ try:
+ os.makedirs(path)
+ except EnvironmentError as e:
+ if e.errno != errno.EEXIST:
+ raise
+
+
+def remove_file(path):
+ try:
+ os.remove(path)
+ except EnvironmentError as e:
+ if e.errno != errno.ENOENT:
+ raise
+
+
+if __name__ == "__main__":
+ main()
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
4 years, 11 months
[sanlock] branch master updated: release 3.7.3
by pagure@pagure.io
This is an automated email from the git hooks/post-receive script.
teigland pushed a commit to branch master
in repository sanlock.
The following commit(s) were added to refs/heads/master by this push:
new d8ecf69 release 3.7.3
d8ecf69 is described below
commit d8ecf69d6b0a03f1c1068206b42ba9548d8eb32d
Author: David Teigland <teigland(a)redhat.com>
AuthorDate: Mon May 20 09:07:46 2019 -0500
release 3.7.3
---
VERSION | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/VERSION b/VERSION
index 0b2eb36..c1e43e6 100644
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-3.7.2
+3.7.3
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
4 years, 11 months
[sanlock] branch master updated: gitignore: Add python related files
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 e54aa54 gitignore: Add python related files
e54aa54 is described below
commit e54aa54500ae86c3de82e909be229c17beb7c118
Author: Nir Soffer <nsoffer(a)redhat.com>
AuthorDate: Sat May 18 21:18:30 2019 +0300
gitignore: Add python related files
Ignore files generated when building and running the tests.
Signed-off-by: Nir Soffer <nsoffer(a)redhat.com>
---
.gitignore | 25 ++++++++++++++++---------
1 file changed, 16 insertions(+), 9 deletions(-)
diff --git a/.gitignore b/.gitignore
index dec4e89..d506b71 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,20 +1,27 @@
-*.swp
*.co
+*.swp
+*.tar.gz
+.tox/
.vimdir
cscope.*
-wdmd/libwdmd.so*
-wdmd/wdmd
-wdmd/wdmd_client
+python/*.so
+python/build/
+python/usr/
+reset/sanlk-reset
+reset/sanlk-resetd
+sanlock.spec
+src/libsanlock.pc
src/libsanlock.so*
+src/libsanlock_client.pc
src/libsanlock_client.so*
src/sanlock
-python/build/
-python/usr/
+tests/*.pyc
+tests/__pycache__/
tests/devcount
tests/killpath
tests/sanlk_client
tests/sanlk_load
tests/sanlk_path
-tests/__pycache__/
-sanlock.spec
-*.tar
+wdmd/libwdmd.so*
+wdmd/wdmd
+wdmd/wdmd_client
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
4 years, 11 months