[prev in list] [next in list] [prev in thread] [next in thread]
List: sanlock-devel
Subject: Re: [PATCH v3 1/2] tests: replace reading of magic number by helper function
From: Amit Bawer <abawer () redhat ! com>
Date: 2019-06-20 13:25:23
Message-ID: CAOfZdw_MJ=yFuEc-=saZJgbG2NSkAdPbOGnvXJK78M14yRiu4Q () mail ! gmail ! com
[Download RAW message or body]
[Attachment #2 (multipart/alternative)]
LGTM
On Mon, Jun 17, 2019 at 1:39 PM Vojtech Juranek <vjuranek@redhat.com> wrote:
> Introduce helper function for reading sanlock magic numbers. This
> helper function seeks to specified offset in given file and reads
> unsigned int from this position.
> ---
> tests/python_test.py | 25 +++++++++----------------
> tests/util.py | 11 +++++++++++
> 2 files changed, 20 insertions(+), 16 deletions(-)
>
> diff --git a/tests/python_test.py b/tests/python_test.py
> index 3242f57..58d94c9 100644
> --- a/tests/python_test.py
> +++ b/tests/python_test.py
> @@ -86,12 +86,9 @@ def test_write_lockspace(tmpdir, sanlock_daemon,
> filename, encoding, size, offse
> b"ls_name", 1, path, offset=offset, wait=False)
> assert acquired is False
>
> - with io.open(path, "rb") as f:
> - f.seek(offset)
> - magic, = struct.unpack("< I", f.read(4))
> - assert magic == constants.DELTA_DISK_MAGIC
> -
> - # TODO: check more stuff here...
> + magic = util.read_magic(path, offset)
> + assert magic == constants.DELTA_DISK_MAGIC
> + # TODO: check more stuff here...
>
> util.check_guard(path, size)
>
> @@ -117,9 +114,8 @@ def test_write_lockspace_4k(user_4k_path,
> sanlock_daemon, align):
> assert acquired is False
>
> # Verify that lockspace was written.
> - with io.open(user_4k_path, "rb") as f:
> - magic, = struct.unpack("< I", f.read(4))
> - assert magic == constants.DELTA_DISK_MAGIC
> + magic = util.read_magic(user_4k_path)
> + assert magic == constants.DELTA_DISK_MAGIC
>
> # Check that sanlock did not write beyond the lockspace area.
> util.check_guard(user_4k_path, align)
> @@ -179,10 +175,8 @@ def test_write_resource(tmpdir, sanlock_daemon,
> filename, encoding, size, offset
> owners = sanlock.read_resource_owners(b"ls_name", b"res_name", disks)
> assert owners == []
>
> - with io.open(path, "rb") as f:
> - f.seek(offset)
> - magic, = struct.unpack("< I", f.read(4))
> - assert magic == constants.PAXOS_DISK_MAGIC
> + magic = util.read_magic(path, offset)
> + assert magic == constants.PAXOS_DISK_MAGIC
>
> # TODO: check more stuff here...
>
> @@ -216,9 +210,8 @@ def test_write_resource_4k(sanlock_daemon,
> user_4k_path, align):
> assert owners == []
>
> # Verify that resource was written.
> - with io.open(user_4k_path, "rb") as f:
> - magic, = struct.unpack("< I", f.read(4))
> - assert magic == constants.PAXOS_DISK_MAGIC
> + magic = util.read_magic(user_4k_path)
> + assert magic == constants.PAXOS_DISK_MAGIC
>
> # Check that sanlock did not write beyond the lockspace area.
> util.check_guard(user_4k_path, align)
> diff --git a/tests/util.py b/tests/util.py
> index 08db236..243b1d3 100644
> --- a/tests/util.py
> +++ b/tests/util.py
> @@ -177,3 +177,14 @@ def sanlock_is_running():
> if e.errno != errno.ENOENT:
> raise
> return False
> +
> +
> +def read_magic(path, offset=0):
> + """
> + Read and return unsigned int from specified file at given offset.
> + Typical usage is to read sanlock magic number.
> + """
> + with io.open(path, "rb") as f:
> + f.seek(offset)
> + uint, = struct.unpack("< I", f.read(4))
> + return uint
> --
> 2.20.1
>
>
[Attachment #5 (text/html)]
<div dir="ltr">LGTM</div><br><div class="gmail_quote"><div dir="ltr" \
class="gmail_attr">On Mon, Jun 17, 2019 at 1:39 PM Vojtech Juranek <<a \
href="mailto:vjuranek@redhat.com">vjuranek@redhat.com</a>> \
wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px \
0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Introduce helper \
function for reading sanlock magic numbers. This<br> helper function seeks to \
specified offset in given file and reads<br> unsigned int from this position.<br>
---<br>
tests/python_test.py | 25 +++++++++----------------<br>
tests/util.py | 11 +++++++++++<br>
2 files changed, 20 insertions(+), 16 deletions(-)<br>
<br>
diff --git a/tests/python_test.py b/tests/python_test.py<br>
index 3242f57..58d94c9 100644<br>
--- a/tests/python_test.py<br>
+++ b/tests/python_test.py<br>
@@ -86,12 +86,9 @@ def test_write_lockspace(tmpdir, sanlock_daemon, filename, \
encoding, size, offse<br>
b"ls_name", 1, path, offset=offset, wait=False)<br>
assert acquired is False<br>
<br>
- with io.open(path, "rb") as f:<br>
- f.seek(offset)<br>
- magic, = struct.unpack("< I", f.read(4))<br>
- assert magic == constants.DELTA_DISK_MAGIC<br>
-<br>
- # TODO: check more stuff here...<br>
+ magic = util.read_magic(path, offset)<br>
+ assert magic == constants.DELTA_DISK_MAGIC<br>
+ # TODO: check more stuff here...<br>
<br>
util.check_guard(path, size)<br>
<br>
@@ -117,9 +114,8 @@ def test_write_lockspace_4k(user_4k_path, sanlock_daemon, \
align):<br> assert acquired is False<br>
<br>
# Verify that lockspace was written.<br>
- with io.open(user_4k_path, "rb") as f:<br>
- magic, = struct.unpack("< I", f.read(4))<br>
- assert magic == constants.DELTA_DISK_MAGIC<br>
+ magic = util.read_magic(user_4k_path)<br>
+ assert magic == constants.DELTA_DISK_MAGIC<br>
<br>
# Check that sanlock did not write beyond the lockspace area.<br>
util.check_guard(user_4k_path, align)<br>
@@ -179,10 +175,8 @@ def test_write_resource(tmpdir, sanlock_daemon, filename, \
encoding, size, offset<br>
owners = sanlock.read_resource_owners(b"ls_name", \
b"res_name", disks)<br> assert owners == []<br>
<br>
- with io.open(path, "rb") as f:<br>
- f.seek(offset)<br>
- magic, = struct.unpack("< I", f.read(4))<br>
- assert magic == constants.PAXOS_DISK_MAGIC<br>
+ magic = util.read_magic(path, offset)<br>
+ assert magic == constants.PAXOS_DISK_MAGIC<br>
<br>
# TODO: check more stuff here...<br>
<br>
@@ -216,9 +210,8 @@ def test_write_resource_4k(sanlock_daemon, user_4k_path, \
align):<br> assert owners == []<br>
<br>
# Verify that resource was written.<br>
- with io.open(user_4k_path, "rb") as f:<br>
- magic, = struct.unpack("< I", f.read(4))<br>
- assert magic == constants.PAXOS_DISK_MAGIC<br>
+ magic = util.read_magic(user_4k_path)<br>
+ assert magic == constants.PAXOS_DISK_MAGIC<br>
<br>
# Check that sanlock did not write beyond the lockspace area.<br>
util.check_guard(user_4k_path, align)<br>
diff --git a/tests/util.py b/tests/util.py<br>
index 08db236..243b1d3 100644<br>
--- a/tests/util.py<br>
+++ b/tests/util.py<br>
@@ -177,3 +177,14 @@ def sanlock_is_running():<br>
if e.errno != errno.ENOENT:<br>
raise<br>
return False<br>
+<br>
+<br>
+def read_magic(path, offset=0):<br>
+ """<br>
+ Read and return unsigned int from specified file at given offset.<br>
+ Typical usage is to read sanlock magic number.<br>
+ """<br>
+ with io.open(path, "rb") as f:<br>
+ f.seek(offset)<br>
+ uint, = struct.unpack("< I", f.read(4))<br>
+ return uint<br>
-- <br>
2.20.1<br>
<br>
</blockquote></div>
[Attachment #6 (text/plain)]
_______________________________________________
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.fedorahosted.org
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic