[sanlock] 03/18: python: Use PyBytes converter for init_lockspace
API
by pagure@pagure.io
This is an automated email from the git hooks/post-receive script.
nsoffer pushed a commit to branch master
in repository sanlock.
commit e09a07369443025bccd4dea414765f7ec7ebb6f2
Author: Amit Bawer <abawer(a)redhat.com>
AuthorDate: Sun Jun 2 13:52:44 2019 +0300
python: Use PyBytes converter for init_lockspace API
This API was deprecated by write_lockspace but we want the
lockspace/resource name as bytes change to be uniform so we
modify it as well for sake of old use cases.
Also added stub test for argument parsing.
Implications:
- Py2 : no difference
- Py3 : if used, only accept bytes for lockspace name.
---
python/sanlock.c | 19 ++++++++++++-------
tests/python_test.py | 7 +++++++
2 files changed, 19 insertions(+), 7 deletions(-)
diff --git a/python/sanlock.c b/python/sanlock.c
index 86aec94..f73c507 100644
--- a/python/sanlock.c
+++ b/python/sanlock.c
@@ -356,8 +356,9 @@ Initialize a device to be used as sanlock lockspace.");
static PyObject *
py_init_lockspace(PyObject *self __unused, PyObject *args, PyObject *keywds)
{
- int rv, max_hosts = 0, num_hosts = 0, use_aio = 1;
- const char *lockspace, *path;
+ int rv = -1, max_hosts = 0, num_hosts = 0, use_aio = 1;
+ PyObject *lockspace = NULL;
+ const char *path;
struct sanlk_lockspace ls;
static char *kwlist[] = {"lockspace", "path", "offset",
@@ -367,14 +368,14 @@ py_init_lockspace(PyObject *self __unused, PyObject *args, PyObject *keywds)
memset(&ls, 0, sizeof(struct sanlk_lockspace));
/* parse python tuple */
- if (!PyArg_ParseTupleAndKeywords(args, keywds, "ss|kiii", kwlist,
- &lockspace, &path, &ls.host_id_disk.offset, &max_hosts,
+ if (!PyArg_ParseTupleAndKeywords(args, keywds, "O&s|kiii", kwlist,
+ convert_to_pybytes, &lockspace, &path, &ls.host_id_disk.offset, &max_hosts,
&num_hosts, &use_aio)) {
- return NULL;
+ goto finally;
}
/* prepare sanlock names */
- strncpy(ls.name, lockspace, SANLK_NAME_LEN);
+ strncpy(ls.name, PyBytes_AsString(lockspace), SANLK_NAME_LEN);
strncpy(ls.host_id_disk.path, path, SANLK_PATH_LEN - 1);
/* init sanlock lockspace (gil disabled) */
@@ -384,9 +385,13 @@ py_init_lockspace(PyObject *self __unused, PyObject *args, PyObject *keywds)
if (rv != 0) {
__set_exception(rv, "Sanlock lockspace init failure");
- return NULL;
+ goto finally;
}
+finally:
+ Py_XDECREF(lockspace);
+ if (rv != 0)
+ return NULL;
Py_RETURN_NONE;
}
diff --git a/tests/python_test.py b/tests/python_test.py
index f831c15..0d97cb9 100644
--- a/tests/python_test.py
+++ b/tests/python_test.py
@@ -599,7 +599,14 @@ def test_reg_event_parse_args(no_sanlock_daemon, name):
with raises_sanlock_errno():
sanlock.reg_event(name)
+
@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)
+
+
+(a)pytest.mark.parametrize("name", LOCKSPACE_OR_RESOURCE_NAMES)
+def test_init_lockspace_parse_args(no_sanlock_daemon, name):
+ with raises_sanlock_errno(errno.ENODEV):
+ sanlock.init_lockspace(name, "path")
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
4 years, 10 months
[sanlock] 02/18: python: Add PyBytes argument converter
by pagure@pagure.io
This is an automated email from the git hooks/post-receive script.
nsoffer pushed a commit to branch master
in repository sanlock.
commit ddc424a4ade10e5c7c5e1305cbce23285d39d046
Author: Amit Bawer <abawer(a)redhat.com>
AuthorDate: Sun Jun 2 13:37:46 2019 +0300
python: Add PyBytes argument converter
Provide converter for parsing PyBytes argument with
no-regression behavior for Py2, allowing it to accept
unicode string object within ascii chars range.
Usage implications:
- Py2 : no-regression in accepting both PyBytes and
Unicodes within ascii range. TypeError will be
raised otherwise.
- Py3 : will accept only bytes. TypeError will be raised
otherwise.
---
python/sanlock.c | 37 +++++++++++++++++++++++++++++++++++++
1 file changed, 37 insertions(+)
diff --git a/python/sanlock.c b/python/sanlock.c
index cec5c9b..86aec94 100644
--- a/python/sanlock.c
+++ b/python/sanlock.c
@@ -309,6 +309,43 @@ py_get_alignment(PyObject *self __unused, PyObject *args)
return Py_BuildValue("i", rv);
}
+/*
+ * Convert parsed arg into PyBytes object.
+ * For Python 2:
+ * If arg is unicode onject, ascii encode it to new PyBytes object passed by addr.
+ * If arg is a bytes object, inc its refcount and pass it in addr.
+ * Set TypeError and return 0 if arg doens not comply to any of the above.
+ * Return 1 on a successful conversion.
+ * For Python 3:
+ * If arg is a bytes object, inc its refcount and pass it in addr.
+ * Set TypeError and return 0 otherwise.
+ * Return 1 on a successful conversion.
+*/
+static int
+convert_to_pybytes(PyObject* arg, void *addr)
+{
+ assert(arg && "convert_to_pybytes called with NULL arg");
+
+#if PY_MAJOR_VERSION == 2
+ if (PyUnicode_Check(arg)) {
+ PyObject *bytes = PyUnicode_AsASCIIString(arg);
+ if (bytes == NULL)
+ return 0;
+ *(PyObject **)addr = bytes;
+ return 1;
+ }
+#endif
+
+ if (PyBytes_Check(arg)) {
+ Py_INCREF(arg);
+ *(PyObject **)addr = arg;
+ return 1;
+ }
+
+ set_error(PyExc_TypeError, "Argument type is not bytes: %s", arg);
+ return 0;
+}
+
/* init_lockspace */
PyDoc_STRVAR(pydoc_init_lockspace, "\
init_lockspace(lockspace, path, offset=0, max_hosts=0, num_hosts=0, \
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
4 years, 10 months
[sanlock] 01/18: tests: Set lockspace and resource names as 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 78ea6ae55a1d4979def3e1edc129f3beaa3c48aa
Author: Amit Bawer <abawer(a)redhat.com>
AuthorDate: Sun Jun 2 13:20:19 2019 +0300
tests: Set lockspace and resource names as bytes
This patch is a preparation for next changes in sanlock
where lockspace and resource names will be parsed as bytes
in both python versions and also as ascii string in python 2
for back compatibility.
Implications:
- Py2: no difference, ascii strings and bytes are parsed the same
- Py3: marked as xfail as currently expecting only unicode string
---
tests/python_test.py | 138 +++++++++++++++++++++++++++++----------------------
1 file changed, 78 insertions(+), 60 deletions(-)
diff --git a/tests/python_test.py b/tests/python_test.py
index db77862..f831c15 100644
--- a/tests/python_test.py
+++ b/tests/python_test.py
@@ -66,6 +66,7 @@ LOCKSPACE_OR_RESOURCE_NAMES = [
marks=pytest.mark.skipif(six.PY3, reason="python 3 supports only bytes")),
]
+(a)pytest.mark.xfail(six.PY3, reason="lockspace/resource names in bytes are unsupported yet")
@pytest.mark.parametrize("filename, encoding" , FILE_NAMES)
@pytest.mark.parametrize("size,offset", [
# Smallest offset.
@@ -78,22 +79,22 @@ def test_write_lockspace(tmpdir, sanlock_daemon, filename, encoding, size, offse
util.create_file(path, size)
# Test read and write with default alignment and sector size values.
- sanlock.write_lockspace("name", path, offset=offset, iotimeout=1)
+ sanlock.write_lockspace(b"ls_name", path, offset=offset, iotimeout=1)
ls = sanlock.read_lockspace(path, offset=offset)
- assert ls == {"iotimeout": 1, "lockspace": b"name"}
+ assert ls == {"iotimeout": 1, "lockspace": b"ls_name"}
# Test read and write with explicit alignment and sector size values.
sanlock.write_lockspace(
- "name", path, offset=offset, iotimeout=1, align=ALIGNMENT_1M,
+ b"ls_name", path, offset=offset, iotimeout=1, align=ALIGNMENT_1M,
sector=SECTOR_SIZE_512)
ls = sanlock.read_lockspace(
path, offset=offset, align=ALIGNMENT_1M, sector=SECTOR_SIZE_512)
- assert ls == {"iotimeout": 1, "lockspace": b"name"}
+ assert ls == {"iotimeout": 1, "lockspace": b"ls_name"}
acquired = sanlock.inq_lockspace(
- "name", 1, path, offset=offset, wait=False)
+ b"ls_name", 1, path, offset=offset, wait=False)
assert acquired is False
with io.open(path, "rb") as f:
@@ -106,6 +107,7 @@ def test_write_lockspace(tmpdir, sanlock_daemon, filename, encoding, size, offse
util.check_guard(path, size)
+(a)pytest.mark.xfail(six.PY3, reason="lockspace/resource names in bytes are unsupported yet")
@pytest.mark.parametrize("align", sanlock.ALIGN_SIZE)
def test_write_lockspace_4k(user_4k_path, sanlock_daemon, align):
@@ -116,14 +118,14 @@ def test_write_lockspace_4k(user_4k_path, sanlock_daemon, align):
util.write_guard(user_4k_path, align)
sanlock.write_lockspace(
- "name", user_4k_path, iotimeout=1, align=align, sector=SECTOR_SIZE_4K)
+ b"ls_name", user_4k_path, iotimeout=1, align=align, sector=SECTOR_SIZE_4K)
ls = sanlock.read_lockspace(
user_4k_path, align=align, sector=SECTOR_SIZE_4K)
- assert ls == {"iotimeout": 1, "lockspace": b"name"}
+ assert ls == {"iotimeout": 1, "lockspace": b"ls_name"}
- acquired = sanlock.inq_lockspace("name", 1, user_4k_path, wait=False)
+ acquired = sanlock.inq_lockspace(b"ls_name", 1, user_4k_path, wait=False)
assert acquired is False
# Verify that lockspace was written.
@@ -135,22 +137,25 @@ def test_write_lockspace_4k(user_4k_path, sanlock_daemon, align):
util.check_guard(user_4k_path, align)
+(a)pytest.mark.xfail(six.PY3, reason="lockspace/resource names in bytes are unsupported yet")
def test_write_lockspace_4k_invalid_sector_size(sanlock_daemon, user_4k_path):
with pytest.raises(sanlock.SanlockException) as e:
sanlock.write_lockspace(
- "name", user_4k_path, iotimeout=1, sector=SECTOR_SIZE_512)
+ b"ls_name", user_4k_path, iotimeout=1, sector=SECTOR_SIZE_512)
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(
- "name", user_4k_path, iotimeout=1, sector=SECTOR_SIZE_4K)
+ b"ls_name", user_4k_path, iotimeout=1, sector=SECTOR_SIZE_4K)
with pytest.raises(sanlock.SanlockException) as e:
sanlock.read_lockspace(user_4k_path, sector=SECTOR_SIZE_512)
assert e.value.errno == errno.EINVAL
+(a)pytest.mark.xfail(six.PY3, reason="lockspace/resource names in bytes are unsupported yet")
@pytest.mark.parametrize("filename,encoding", FILE_NAMES)
@pytest.mark.parametrize("size,offset", [
# Smallest offset.
@@ -164,7 +169,7 @@ def test_write_resource(tmpdir, sanlock_daemon, filename, encoding, size, offset
disks = [(path, offset)]
# Test read and write with default alignment and sector size values.
- sanlock.write_resource("ls_name", "res_name", disks)
+ sanlock.write_resource(b"ls_name", b"res_name", disks)
res = sanlock.read_resource(path, offset=offset)
assert res == {
@@ -175,7 +180,7 @@ def test_write_resource(tmpdir, sanlock_daemon, filename, encoding, size, offset
# Test read and write with explicit alignment and sector size values.
sanlock.write_resource(
- "ls_name", "res_name", disks, align=ALIGNMENT_1M,
+ b"ls_name", b"res_name", disks, align=ALIGNMENT_1M,
sector=SECTOR_SIZE_512)
res = sanlock.read_resource(
@@ -186,7 +191,7 @@ def test_write_resource(tmpdir, sanlock_daemon, filename, encoding, size, offset
"version": 0
}
- owners = sanlock.read_resource_owners("ls_name", "res_name", disks)
+ owners = sanlock.read_resource_owners(b"ls_name", b"res_name", disks)
assert owners == []
with io.open(path, "rb") as f:
@@ -199,6 +204,7 @@ def test_write_resource(tmpdir, sanlock_daemon, filename, encoding, size, offset
util.check_guard(path, size)
+(a)pytest.mark.xfail(six.PY3, reason="lockspace/resource names in bytes are unsupported yet")
@pytest.mark.parametrize("align", sanlock.ALIGN_SIZE)
def test_write_resource_4k(sanlock_daemon, user_4k_path, align):
disks = [(user_4k_path, 0)]
@@ -210,7 +216,7 @@ def test_write_resource_4k(sanlock_daemon, user_4k_path, align):
util.write_guard(user_4k_path, align)
sanlock.write_resource(
- "ls_name", "res_name", disks, align=align, sector=SECTOR_SIZE_4K)
+ b"ls_name", b"res_name", disks, align=align, sector=SECTOR_SIZE_4K)
res = sanlock.read_resource(
user_4k_path, align=align, sector=SECTOR_SIZE_4K)
@@ -222,7 +228,7 @@ def test_write_resource_4k(sanlock_daemon, user_4k_path, align):
}
owners = sanlock.read_resource_owners(
- "ls_name", "res_name", disks, align=align, sector=SECTOR_SIZE_4K)
+ b"ls_name", b"res_name", disks, align=align, sector=SECTOR_SIZE_4K)
assert owners == []
# Verify that resource was written.
@@ -240,16 +246,17 @@ def test_write_resource_4k_invalid_sector_size(sanlock_daemon, user_4k_path):
with pytest.raises(sanlock.SanlockException) as e:
sanlock.write_resource(
- "ls_name", "res_name", disks, sector=SECTOR_SIZE_512)
+ b"ls_name", b"res_name", disks, sector=SECTOR_SIZE_512)
assert e.value.errno == errno.EINVAL
+(a)pytest.mark.xfail(six.PY3, reason="lockspace/resource names in bytes are unsupported yet")
def test_read_resource_4k_invalid_sector_size(sanlock_daemon, user_4k_path):
disks = [(user_4k_path, 0)]
sanlock.write_resource(
- "ls_name",
- "res_name",
+ b"ls_name",
+ b"res_name",
disks,
align=ALIGNMENT_1M,
sector=SECTOR_SIZE_4K)
@@ -259,45 +266,48 @@ def test_read_resource_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_resource_owners_4k_invalid_sector_size(
sanlock_daemon, user_4k_path):
disks = [(user_4k_path, 0)]
sanlock.write_resource(
- "ls_name",
- "res_name",
+ b"ls_name",
+ b"res_name",
disks,
align=ALIGNMENT_1M,
sector=SECTOR_SIZE_4K)
with pytest.raises(sanlock.SanlockException) as e:
sanlock.read_resource_owners(
- "ls_name", "res_name", disks, sector=SECTOR_SIZE_512)
+ b"ls_name", b"res_name", disks, sector=SECTOR_SIZE_512)
assert e.value.errno == errno.EINVAL
+(a)pytest.mark.xfail(six.PY3, reason="lockspace/resource names in bytes are unsupported yet")
def test_read_resource_owners_invalid_align_size(tmpdir, sanlock_daemon):
path = str(tmpdir.join("path"))
util.create_file(path, GiB)
disks = [(path, 0)]
sanlock.write_resource(
- "ls_name",
- "res_name",
+ b"ls_name",
+ b"res_name",
disks,
align=ALIGNMENT_1M,
sector=SECTOR_SIZE_512)
with pytest.raises(sanlock.SanlockException) as e:
sanlock.read_resource_owners(
- "ls_name",
- "res_name",
+ b"ls_name",
+ b"res_name",
disks,
align=ALIGNMENT_2M,
sector=SECTOR_SIZE_512)
assert e.value.errno == errno.EINVAL
+(a)pytest.mark.xfail(six.PY3, reason="lockspace/resource names in bytes are unsupported yet")
@pytest.mark.parametrize("size,offset", [
# Smallest offset.
(MIN_RES_SIZE, 0),
@@ -308,18 +318,18 @@ def test_add_rem_lockspace(tmpdir, sanlock_daemon, size, offset):
path = str(tmpdir.join("ls_name"))
util.create_file(path, size)
- sanlock.write_lockspace("ls_name", path, offset=offset, iotimeout=1)
+ sanlock.write_lockspace(b"ls_name", path, offset=offset, iotimeout=1)
# Since the lockspace is not acquired, we exepect to get False.
acquired = sanlock.inq_lockspace(
- "ls_name", 1, path, offset=offset, wait=False)
+ b"ls_name", 1, path, offset=offset, wait=False)
assert acquired is False
- sanlock.add_lockspace("ls_name", 1, path, offset=offset, iotimeout=1)
+ sanlock.add_lockspace(b"ls_name", 1, path, offset=offset, iotimeout=1)
# Once the lockspace is acquired, we exepect to get True.
acquired = sanlock.inq_lockspace(
- "ls_name", 1, path, offset=offset, wait=False)
+ b"ls_name", 1, path, offset=offset, wait=False)
assert acquired is True
lockspaces = sanlock.get_lockspaces()
@@ -331,53 +341,55 @@ def test_add_rem_lockspace(tmpdir, sanlock_daemon, size, offset):
'path': path
}]
- sanlock.rem_lockspace("ls_name", 1, path, offset=offset)
+ sanlock.rem_lockspace(b"ls_name", 1, path, offset=offset)
# Once the lockspace is released, we exepect to get False.
acquired = sanlock.inq_lockspace(
- "ls_name", 1, path, offset=offset, wait=False)
+ b"ls_name", 1, path, offset=offset, wait=False)
assert acquired is False
lockspaces = sanlock.get_lockspaces()
assert lockspaces == []
+(a)pytest.mark.xfail(six.PY3, reason="lockspace/resource names in bytes are unsupported yet")
def test_add_rem_lockspace_async(tmpdir, sanlock_daemon):
path = str(tmpdir.join("ls_name"))
util.create_file(path, MiB)
- sanlock.write_lockspace("ls_name", path, iotimeout=1)
- acquired = sanlock.inq_lockspace("ls_name", 1, path, wait=False)
+ 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("ls_name", 1, path, iotimeout=1, **{"async": True})
+ sanlock.add_lockspace(b"ls_name", 1, path, iotimeout=1, **{"async": True})
# While the lockspace is being aquired, we expect to get None.
time.sleep(1)
- acquired = sanlock.inq_lockspace("ls_name", 1, path, wait=False)
+ acquired = sanlock.inq_lockspace(b"ls_name", 1, path, wait=False)
assert acquired is None
# Once the lockspace is acquired, we exepect to get True.
- acquired = sanlock.inq_lockspace("ls_name", 1, path, wait=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("ls_name", 1, path, **{"async": True})
+ sanlock.rem_lockspace(b"ls_name", 1, path, **{"async": True})
# Wait until the lockspace change state from True to None.
- while sanlock.inq_lockspace("ls_name", 1, path, wait=False):
+ while sanlock.inq_lockspace(b"ls_name", 1, path, wait=False):
time.sleep(1)
# While the lockspace is being released, we expect to get None.
- acquired = sanlock.inq_lockspace("ls_name", 1, path, wait=False)
+ acquired = sanlock.inq_lockspace(b"ls_name", 1, path, wait=False)
assert acquired is None
# Once the lockspace was released, we expect to get False.
- acquired = sanlock.inq_lockspace("ls_name", 1, path, wait=True)
+ acquired = sanlock.inq_lockspace(b"ls_name", 1, path, wait=True)
assert acquired is False
+(a)pytest.mark.xfail(six.PY3, reason="lockspace/resource names in bytes are unsupported yet")
@pytest.mark.parametrize("size,offset", [
# Smallest offset.
(MIN_RES_SIZE, 0),
@@ -391,20 +403,20 @@ def test_acquire_release_resource(tmpdir, sanlock_daemon, size, offset):
res_path = str(tmpdir.join("res_name"))
util.create_file(res_path, size)
- sanlock.write_lockspace("ls_name", ls_path, offset=offset, iotimeout=1)
- sanlock.add_lockspace("ls_name", 1, ls_path, offset=offset, iotimeout=1)
+ sanlock.write_lockspace(b"ls_name", ls_path, offset=offset, iotimeout=1)
+ sanlock.add_lockspace(b"ls_name", 1, ls_path, offset=offset, iotimeout=1)
# Host status is not available until the first renewal.
with pytest.raises(sanlock.SanlockException) as e:
- sanlock.get_hosts("ls_name", 1)
+ sanlock.get_hosts(b"ls_name", 1)
assert e.value.errno == errno.EAGAIN
time.sleep(1)
- host = sanlock.get_hosts("ls_name", 1)[0]
+ host = sanlock.get_hosts(b"ls_name", 1)[0]
assert host["flags"] == sanlock.HOST_LIVE
disks = [(res_path, offset)]
- sanlock.write_resource("ls_name", "res_name", disks)
+ sanlock.write_resource(b"ls_name", b"res_name", disks)
res = sanlock.read_resource(res_path, offset=offset)
assert res == {
@@ -413,11 +425,11 @@ def test_acquire_release_resource(tmpdir, sanlock_daemon, size, offset):
"version": 0
}
- owners = sanlock.read_resource_owners("ls_name", "res_name", disks)
+ owners = sanlock.read_resource_owners(b"ls_name", b"res_name", disks)
assert owners == []
fd = sanlock.register()
- sanlock.acquire("ls_name", "res_name", disks, slkfd=fd)
+ sanlock.acquire(b"ls_name", b"res_name", disks, slkfd=fd)
res = sanlock.read_resource(res_path, offset=offset)
assert res == {
@@ -426,7 +438,7 @@ def test_acquire_release_resource(tmpdir, sanlock_daemon, size, offset):
"version": 1
}
- owner = sanlock.read_resource_owners("ls_name", "res_name", disks)[0]
+ owner = sanlock.read_resource_owners(b"ls_name", b"res_name", disks)[0]
assert owner["host_id"] == 1
assert owner["flags"] == 0
@@ -434,11 +446,11 @@ def test_acquire_release_resource(tmpdir, sanlock_daemon, size, offset):
assert owner["io_timeout"] == 0 # Why 0?
# TODO: check timestamp.
- host = sanlock.get_hosts("ls_name", 1)[0]
+ host = sanlock.get_hosts(b"ls_name", 1)[0]
assert host["flags"] == sanlock.HOST_LIVE
assert host["generation"] == owner["generation"]
- sanlock.release("ls_name", "res_name", disks, slkfd=fd)
+ sanlock.release(b"ls_name", b"res_name", disks, slkfd=fd)
res = sanlock.read_resource(res_path, offset=offset)
assert res == {
@@ -447,10 +459,11 @@ def test_acquire_release_resource(tmpdir, sanlock_daemon, size, offset):
"version": 1
}
- owners = sanlock.read_resource_owners("ls_name", "res_name", disks)
+ owners = sanlock.read_resource_owners(b"ls_name", b"res_name", disks)
assert owners == []
+(a)pytest.mark.xfail(six.PY3, reason="lockspace/resource names in bytes are unsupported yet")
@pytest.mark.parametrize("align, sector", [
# Invalid alignment
(KiB, sanlock.SECTOR_SIZE[0]),
@@ -463,9 +476,10 @@ def test_write_lockspace_invalid_align_sector(
util.create_file(path, LOCKSPACE_SIZE)
with pytest.raises(ValueError):
- sanlock.write_lockspace("name", path, align=align, sector=sector)
+ sanlock.write_lockspace(b"ls_name", path, align=align, sector=sector)
+(a)pytest.mark.xfail(six.PY3, reason="lockspace/resource names in bytes are unsupported yet")
@pytest.mark.parametrize("align, sector", [
# Invalid alignment
(KiB, sanlock.SECTOR_SIZE[0]),
@@ -480,9 +494,10 @@ def test_write_resource_invalid_align_sector(
with pytest.raises(ValueError):
sanlock.write_resource(
- "ls_name", "res_name", disks, align=align, sector=sector)
+ b"ls_name", b"res_name", disks, align=align, sector=sector)
+(a)pytest.mark.xfail(six.PY3, reason="lockspace/resource names in bytes are unsupported yet")
@pytest.mark.parametrize("disk", [
# Not a tuple - unicode and bytes:
"not a tuple",
@@ -501,7 +516,7 @@ def test_write_resource_invalid_disk(tmpdir, sanlock_daemon, disk):
# Test parsing disks list with invalid content.
disks = [disk]
with pytest.raises(ValueError) as e:
- sanlock.write_resource("ls_name", "res_name", disks)
+ sanlock.write_resource(b"ls_name", b"res_name", disks)
assert repr(disk) in str(e.value)
@@ -537,31 +552,34 @@ def test_write_lockspace_parse_args(no_sanlock_daemon, name):
sanlock.write_lockspace(name, "ls_path")
+(a)pytest.mark.xfail(six.PY3, reason="lockspace/resource names in bytes are unsupported yet")
@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)])
+ sanlock.write_resource(name, b"res_name", [("disk_path",0)])
with raises_sanlock_errno():
- sanlock.write_resource("ls_name", name, [("disk_path",0)])
+ sanlock.write_resource(b"ls_name", name, [("disk_path",0)])
+(a)pytest.mark.xfail(six.PY3, reason="lockspace/resource names in bytes are unsupported yet")
@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)])
+ sanlock.release(name, b"res_name", [("disk_path",0)])
with raises_sanlock_errno():
- sanlock.release("ls_name", name, [("disk_path",0)])
+ sanlock.release(b"ls_name", name, [("disk_path",0)])
+(a)pytest.mark.xfail(six.PY3, reason="lockspace/resource names in bytes are unsupported yet")
@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)])
+ sanlock.read_resource_owners(name, b"res_name", [("disk_path",0)])
with raises_sanlock_errno():
- sanlock.read_resource_owners("ls_name", name, [("disk_path",0)])
+ sanlock.read_resource_owners(b"ls_name", name, [("disk_path",0)])
@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
[PATCH 00/18] Fix lockspace and resource names on python 3
by Nir Soffer
On python 2 we accepted Unicode strings with ascii content (e.g.
u"ascii") for lockspace and resource names. The values were converted
automatically to bytes (e.g. "ascii") using the "s" format string.
On python 3 these automatic conversions should not happen. Since we
don't control what was written on storage in previous sanlock versions,
and sanlock running on python 3 must be compatible with sanlock running
on python 2 (e.g. during upgrade from oVirt 4.3 to 4.4), we can accept
and return only bytes.
Code that used Unicode strings for lockspace and resource names in
python 2, like:
sanlock.write_lockspace(ls_name, path)
Must changed to encode the string to bytes before calling sanlock:
sanlock.write_lockspace(ls_name.encode("utf-8"), path)
There is no change on output, we always returned encoded bytes as they
are written on storage.
Amit Bawer (18):
tests: Set lockspace and resource names as bytes
python: Add PyBytes argument converter
python: Use PyBytes converter for init_lockspace API
python: Use PyBytes converter for init_resource API
python: Use PyBytes converter for write_lockspace API
python: Use PyBytes converter for write_resource API
python: Use PyBytes converter for add_lockspace API
python: Use PyBytes converter for inq_lockspace API
python: Use PyBytes converter for rem_lockspace API
python: Use PyBytes converter for get_hosts API
python: Use PyBytes converter for resource acquire API
python: Use PyBytes converter for resource release API
python: Use PyBytes converter for resource owner request API
python: Use PyBytes converter for read_resource_owners API
python: Use PyBytes converter for reg_event API
python: Use PyBytes converter for end_event API
python: Use PyBytes converter for set_event API
tests: Remove xfail marks for unsupported lockspace/res names as bytes
python/sanlock.c | 414 ++++++++++++++++++++++++++-----------------
tests/python_test.py | 147 ++++++++-------
2 files changed, 338 insertions(+), 223 deletions(-)
--
2.17.2
4 years, 10 months
Re: [PATCH] tests: Remove stale symlinks before linking loop device
by Amit Bawer
we check first that it is a link and only then we unlink it. so it should
be fine anyway.
On Sun, Jun 2, 2019 at 3:50 PM Pavel Bar <pbar(a)redhat.com> wrote:
>
>
> On Fri, May 31, 2019 at 4:14 AM Nir Soffer <nirsof(a)gmail.com> wrote:
>
>> 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)
>>
>
> As far as I remember in Nir's commits the recommended paradigm was to do a
> File System action and catch an exception if failed.
> Thus it can't happen that between testing for the condition and performing
> an action based on this condition another process already performed the
> action.
> Although according to the docs "os.unlink" doesn't throw an exception if
> the link doesn't exist, also not sure that such a protection is needed here
> at all.
>
>
>> os.symlink(device, link_path)
>> chown(link_path)
>>
>>
>> def remove_loop_device(link_path, backing_file):
>> --
>> 2.17.2
>>
>>
4 years, 10 months