Vdsm is going to use "sanlock direct dump". Improve testing to make sure we don't introduce regressions in this area.
Nir Soffer (2): tests: Tests dumping lockspace and resources tests: Test handling paths with colons
tests/direct_test.py | 90 +++++++++++++++++++++++++++++++++++++++++++- tests/util.py | 5 ++- 2 files changed, 92 insertions(+), 3 deletions(-)
Add tests for dumping: - empty lockspace - resources with a hole - start before first resource
Signed-off-by: Nir Soffer nsoffer@redhat.com --- tests/direct_test.py | 66 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 65 insertions(+), 1 deletion(-)
diff --git a/tests/direct_test.py b/tests/direct_test.py index 579f228..bc66526 100644 --- a/tests/direct_test.py +++ b/tests/direct_test.py @@ -34,7 +34,27 @@ def test_init_lockspace(tmpdir): util.check_guard(str(path), size)
-def test_init_resource(tmpdir, sanlock_daemon): +def test_dump_lockspace_empty(tmpdir): + path = tmpdir.join("lockspace") + size = MiB + util.create_file(str(path), size) + + lockspace = "name:1:%s:0" % path + util.sanlock("direct", "init", "-s", lockspace) + + dump = "%s:0:1M" % path + out = util.sanlock("direct", "dump", dump) + + lines = out.decode("utf-8").splitlines() + spaces = [line.split() for line in lines] + + # Empty lockspace has no hosts. + assert spaces == [ + ['offset', 'lockspace', 'resource', 'timestamp', 'own', 'gen', 'lver'] + ] + + +def test_init_resource(tmpdir): path = tmpdir.join("resources") size = MiB util.create_file(str(path), size) @@ -49,3 +69,47 @@ def test_init_resource(tmpdir, sanlock_daemon): # TODO: check more stuff here...
util.check_guard(str(path), size) + + +def test_dump_resources(tmpdir): + path = tmpdir.join("resources") + size = 8 * MiB + util.create_file(str(path), size) + + # Write 2 resources with a hole between them. + for i in [0, 2]: + res = "ls_name:res_%d:%s:%dM" % (i, path, i) + util.sanlock("direct", "init", "-r", res) + + dump = "%s:0:8M" % path + out = util.sanlock("direct", "dump", dump) + + lines = out.decode("utf-8").splitlines() + resources = [line.split() for line in lines] + assert resources == [ + ['offset', 'lockspace', 'resource', 'timestamp', 'own', 'gen', 'lver'], + ['00000000', 'ls_name', 'res_0', '0000000000', '0000', '0000', '0'], + ['02097152', 'ls_name', 'res_2', '0000000000', '0000', '0000', '0'], + ] + + +def test_dump_resources_start_before(tmpdir): + path = tmpdir.join("resources") + size = 8 * MiB + util.create_file(str(path), size) + + # Write 2 resources at middle. + for i in [4, 5]: + res = "ls_name:res_%d:%s:%dM" % (i, path, i) + util.sanlock("direct", "init", "-r", res) + + dump = "%s:2M:8M" % path + out = util.sanlock("direct", "dump", dump) + + lines = out.decode("utf-8").splitlines() + resources = [line.split() for line in lines] + assert resources == [ + ['offset', 'lockspace', 'resource', 'timestamp', 'own', 'gen', 'lver'], + ['04194304', 'ls_name', 'res_4', '0000000000', '0000', '0000', '0'], + ['05242880', 'ls_name', 'res_5', '0000000000', '0000', '0000', '0'], + ]
"sanlock direct dump" supports now escaped colons in path. Add a test to verify this behaviour. Unfortunately, "sanlock direct init" does not support that yet.
Signed-off-by: Nir Soffer nsoffer@redhat.com --- tests/direct_test.py | 24 ++++++++++++++++++++++++ tests/util.py | 5 +++-- 2 files changed, 27 insertions(+), 2 deletions(-)
diff --git a/tests/direct_test.py b/tests/direct_test.py index bc66526..a7ad014 100644 --- a/tests/direct_test.py +++ b/tests/direct_test.py @@ -10,6 +10,7 @@ Test sanlock direct options. from __future__ import absolute_import
import io +import os import struct
from . import constants @@ -113,3 +114,26 @@ def test_dump_resources_start_before(tmpdir): ['04194304', 'ls_name', 'res_4', '0000000000', '0000', '0000', '0'], ['05242880', 'ls_name', 'res_5', '0000000000', '0000', '0000', '0'], ] + + +def test_path_with_colon(tmpdir): + path = str(tmpdir.mkdir("with:colon").join("resources")) + size = 8 * MiB + util.create_file(path, size) + + # sanlock direct init does not support escaped colons in path. + dirname, filename = os.path.split(path) + res = "ls_name:res_0:%s:0M" % filename + util.sanlock("direct", "init", "-r", res, cwd=dirname) + + # sanlock direct dump supports escaped colons in path. + escaped_path = path.replace(":", "\:") + dump = "%s:0:8M" % escaped_path + out = util.sanlock("direct", "dump", dump) + + lines = out.decode("utf-8").splitlines() + resources = [line.split() for line in lines] + assert resources == [ + ['offset', 'lockspace', 'resource', 'timestamp', 'own', 'gen', 'lver'], + ['00000000', 'ls_name', 'res_0', '0000000000', '0000', '0000', '0'], + ] diff --git a/tests/util.py b/tests/util.py index 12f2702..df36ebb 100644 --- a/tests/util.py +++ b/tests/util.py @@ -82,14 +82,15 @@ def wait_for_daemon(timeout): s.close()
-def sanlock(*args): +def sanlock(*args, cwd=None): """ Run sanlock returning the process stdout, or raising util.CommandError on failures. """ cmd = [SANLOCK] cmd.extend(args) - p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + p = subprocess.Popen( + cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=cwd) out, err = p.communicate() if p.returncode: raise CommandError(cmd, p.returncode, out, err)
Vdsm is going to use "sanlock direct dump". Improve testing to make sure we
don't introduce regressions in this area.
Nir Soffer (2):
tests: Tests dumping lockspace and resources
tests: Test handling paths with colons
+1 to both of the patches
tests/direct_test.py | 90 +++++++++++++++++++++++++++++++++++++++++++-
tests/util.py | 5 ++-
2 files changed, 92 insertions(+), 3 deletions(-)
--
2.25.4
sanlock-devel mailing list -- sanlock-devel@lists.fedorahosted.org To unsubscribe send an email to sanlock-devel-leave@lists.fedorahosted.org Fedora Code of Conduct: https://docs.fedoraproject.org/en-US/project/code-of-conduct/ List Guidelines: https://fedoraproject.org/wiki/Mailing_list_guidelines List Archives: https://lists.fedorahosted.org/archives/list/sanlock-devel@lists.fedorahost ed.org
sanlock-devel@lists.fedorahosted.org