This is an automated email from the git hooks/post-receive script.
teigland pushed a commit to branch master
in repository sanlock.
commit 90b2ffa77edd46bea007b7bb39bfd4d2db2ff7af
Author: Nir Soffer <nsoffer(a)redhat.com>
Date: Sun Feb 25 22:35:24 2018 +0200
Start rindex tests
Add couple of tests for the new lookup command using the daemon.
To make the tests faster, we use 1 second io timeout. This is much
faster then real usage, but still takes about 3 seconds per test when we
add a lockspace. Need to check how to make this faster.
Unfinished: cover all commands.
Signed-off-by: Nir Soffer <nsoffer(a)redhat.com>
---
tests/constants.py | 10 ++++
tests/daemon_test.py | 158 ++++++++++++++++++++++++++++++++++++++++++++++++++-
tests/util.py | 15 +++++
3 files changed, 180 insertions(+), 3 deletions(-)
diff --git a/tests/constants.py b/tests/constants.py
index 70f4226..a7eb16b 100644
--- a/tests/constants.py
+++ b/tests/constants.py
@@ -7,3 +7,13 @@ Constants copied from sanlock source.
PAXOS_DISK_MAGIC = 0x06152010
PAXOS_DISK_CLEAR = 0x11282016
DELTA_DISK_MAGIC = 0x12212010
+
+# src/rindex_disk.h
+
+RINDEX_DISK_MAGIC = 0x01042018
+
+# src/rindex_disk.h
+# Copied from the docs module comment.
+
+RINDEX_ENTRY_SIZE = 64
+RINDEX_ENTRIES_SECTORS = 2000
diff --git a/tests/daemon_test.py b/tests/daemon_test.py
index dc5aadd..8896fb2 100644
--- a/tests/daemon_test.py
+++ b/tests/daemon_test.py
@@ -8,7 +8,7 @@ import struct
import pytest
-from . import constants
+from . constants import *
from . import util
@@ -52,7 +52,7 @@ def test_init_lockspace(tmpdir, sanlock_daemon):
with io.open(str(path), "rb") as f:
magic, = struct.unpack("< I", f.read(4))
- assert magic == constants.DELTA_DISK_MAGIC
+ assert magic == DELTA_DISK_MAGIC
# TODO: check more stuff here...
@@ -69,8 +69,160 @@ def test_init_resource(tmpdir, sanlock_daemon):
with io.open(str(path), "rb") as f:
magic, = struct.unpack("< I", f.read(4))
- assert magic == constants.PAXOS_DISK_MAGIC
+ assert magic == PAXOS_DISK_MAGIC
# TODO: check more stuff here...
util.check_guard(str(path), size)
+
+
+def test_format(tmpdir, sanlock_daemon):
+ path = tmpdir.join("rindex")
+ size = 1024**2 * 3
+ util.create_file(str(path), size)
+
+ rindex = "ls_name:%s:1M" % path
+ util.sanlock("client", "format", "-x", rindex)
+
+ with io.open(str(path), "rb") as f:
+ # The first slot should contain the rindex header sector.
+ f.seek(1024**2)
+ magic, = struct.unpack("< I", f.read(4))
+ assert magic == RINDEX_DISK_MAGIC
+
+ # The rindex entries starts at the second rindex slot sector. All
+ # entries should be zeroed.
+ f.seek(1024**2 + 512)
+ entries_size = 512 * RINDEX_ENTRIES_SECTORS
+ assert f.read(entries_size) == b"\0" * entries_size
+
+ # The next slot should contain the internal lease.
+ f.seek(1024**2 * 2)
+ magic, = struct.unpack("< I", f.read(4))
+ assert magic == PAXOS_DISK_MAGIC
+
+ util.check_guard(str(path), size)
+
+
+def test_create(tmpdir, sanlock_daemon):
+ path = tmpdir.join("rindex")
+ # Slots: lockspace rindex master-lease user-lease-1
+ size = 1024**2 * 4
+ util.create_file(str(path), size)
+
+ # Note: using 1 second io timeout (-o 1) for quicker tests.
+ lockspace = "ls_name:1:%s:0" % path
+ util.sanlock("client", "init", "-s", lockspace,
"-o", "1")
+
+ rindex = "ls_name:%s:1M" % path
+ util.sanlock("client", "format", "-x", rindex)
+
+ util.sanlock("client", "add_lockspace", "-s",
lockspace, "-o", "1")
+ util.sanlock("client", "create", "-x", rindex,
"-e", "res")
+
+ with io.open(str(path), "rb") as f:
+ # New entry should be created at the first slot
+ # The first rindex sector is used by the rindex header.
+ f.seek(1024**2 + 512)
+ util.check_rindex_entry(f.read(RINDEX_ENTRY_SIZE),
+ b"res", 1024**2 * 3, 0)
+
+ # The rest of the entries should not be modified.
+ rest = 512 * RINDEX_ENTRIES_SECTORS - RINDEX_ENTRY_SIZE
+ assert f.read(rest) == b"\0" * rest
+
+ # The next slot should contain the internal lease.
+ f.seek(1024**2 * 3)
+ magic, = struct.unpack("< I", f.read(4))
+ assert magic == PAXOS_DISK_MAGIC
+
+ util.check_guard(str(path), size)
+
+
+def test_delete(tmpdir, sanlock_daemon):
+ path = tmpdir.join("rindex")
+ # Slots: lockspace rindex master-lease user-lease-1
+ size = 1024**2 * 4
+ util.create_file(str(path), size)
+
+ # Note: using 1 second io timeout (-o 1) for quicker tests.
+ lockspace = "ls_name:1:%s:0" % path
+ util.sanlock("client", "init", "-s", lockspace,
"-o", "1")
+
+ rindex = "ls_name:%s:1M" % path
+ util.sanlock("client", "format", "-x", rindex)
+
+ util.sanlock("client", "add_lockspace", "-s",
lockspace, "-o", "1")
+ util.sanlock("client", "create", "-x", rindex,
"-e", "res")
+ util.sanlock("client", "delete", "-x", rindex,
"-e", "res")
+
+ with io.open(str(path), "rb") as f:
+ # First entry should be cleared.
+ f.seek(1024**2 + 512)
+ util.check_rindex_entry(f.read(RINDEX_ENTRY_SIZE), b"", 0, 0)
+
+ # Rest of entires should not be modified.
+ rest = 512 * RINDEX_ENTRIES_SECTORS - RINDEX_ENTRY_SIZE
+ assert f.read(rest) == b"\0" * rest
+
+ # The next slot should contain a cleared lease.
+ f.seek(1024**2 * 3)
+ magic, = struct.unpack("< I", f.read(4))
+ assert magic == PAXOS_DISK_CLEAR
+
+ util.check_guard(str(path), size)
+
+
+def test_lookup(tmpdir, sanlock_daemon):
+ path = tmpdir.join("rindex")
+ # Slots: lockspace rindex master-lease user-lease-1 ... user-lease-7
+ size = 1024**2 * 10
+ util.create_file(str(path), size)
+
+ # Note: using 1 second io timeout (-o 1) for quicker tests.
+ lockspace = "ls_name:1:%s:0" % path
+ util.sanlock("client", "init", "-s", lockspace,
"-o", "1")
+
+ rindex = "ls_name:%s:1M" % path
+ util.sanlock("client", "format", "-x", rindex)
+
+ util.sanlock("client", "add_lockspace", "-s",
lockspace, "-o", "1")
+ util.sanlock("client", "create", "-x", rindex,
"-e", "res")
+ lookup = util.sanlock("client", "lookup", "-x", rindex,
"-e", "res")
+
+ assert lookup == "lookup done 0\nname res offset 3145728\n"
+
+
+def test_lookup_uninitialized(tmpdir, sanlock_daemon):
+ path = tmpdir.join("rindex")
+ util.create_file(str(path), 1024**2)
+ rindex = "ls_name:%s:1M" % path
+
+ with pytest.raises(util.CommandError) as e:
+ util.sanlock("client", "lookup", "-x", rindex,
"-e", "res")
+
+ assert e.value.returncode == 1
+ assert e.value.stdout == "lookup done -2\n"
+ assert e.value.stderr == ""
+
+
+def test_lookup_missing(tmpdir, sanlock_daemon):
+ path = tmpdir.join("rindex")
+ # Slots: lockspace rindex master-lease user-lease-1 ... user-lease-7
+ size = 1024**2 * 10
+ util.create_file(str(path), size)
+
+ # Note: using 1 second io timeout (-o 1) for quicker tests.
+ lockspace = "ls_name:1:%s:0" % path
+ util.sanlock("client", "init", "-s", lockspace,
"-o", "1")
+
+ rindex = "ls_name:%s:1M" % path
+ util.sanlock("client", "format", "-x", rindex)
+
+ util.sanlock("client", "add_lockspace", "-s",
lockspace, "-o", "1")
+ with pytest.raises(util.CommandError) as e:
+ util.sanlock("client", "lookup", "-x", rindex,
"-e", "res")
+
+ assert e.value.returncode == 1
+ assert e.value.stdout == "lookup done -2\n"
+ assert e.value.stderr == ""
diff --git a/tests/util.py b/tests/util.py
index 98f1d14..2259473 100644
--- a/tests/util.py
+++ b/tests/util.py
@@ -6,6 +6,7 @@ import errno
import io
import os
import socket
+import struct
import subprocess
import time
@@ -122,3 +123,17 @@ def check_guard(path, size, guard=b"X", guard_size=4096):
with io.open(path, "rb") as f:
f.seek(size)
assert f.read() == guard * guard_size
+
+
+def check_rindex_entry(entry, name, offset=None, flags=None):
+ # See src/ondisk.c rindex_entry_in()
+ e_offset, e_flags, e_unused, e_name = struct.unpack("<Q L L 48s",
entry)
+
+ padding = b"\0" * (48 - len(name))
+ assert e_name == name + padding
+
+ if offset is not None:
+ assert e_offset == offset
+
+ if flags is not None:
+ assert e_flags == flags
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.