This is an automated email from the git hooks/post-receive script.
nsoffer pushed a commit to branch master
in repository sanlock.
commit 1b230a8da337cb2ff386f02007b668a4e7fb467c
Author: Nir Soffer <nsoffer(a)redhat.com>
AuthorDate: Fri Jun 14 20:04:54 2019 +0300
python: Fix style issues
Fix style issues:
- 2 blank lines around functions and classes
- classes at the top of the module
- reformat to avoid long hard to read lines
- whitespace before ','
- whitespace after #
- unused imports
- unexpected indenation
- remove blank line at end of file
Signed-off-by: Nir Soffer <nsoffer(a)redhat.com>
---
python/example.py | 28 ++++++++++++++++++++--------
tests/conftest.py | 8 ++++----
tests/python_test.py | 50 ++++++++++++++++++++++++++++++++------------------
3 files changed, 56 insertions(+), 30 deletions(-)
diff --git a/python/example.py b/python/example.py
index 6ef9f7d..1be7e66 100644
--- a/python/example.py
+++ b/python/example.py
@@ -10,9 +10,11 @@ HOST_ID = 1
LOCKSPACE_NAME = "lockspace1"
RESOURCE_NAME = "resource1"
+
def sigTermHandler():
print "SIGTERM signal received"
+
def main():
signal.signal(signal.SIGTERM, sigTermHandler)
@@ -20,7 +22,8 @@ def main():
fd, disk = tempfile.mkstemp()
os.close(fd)
- os.chown(disk, pwd.getpwnam("sanlock").pw_uid,
grp.getgrnam("sanlock").gr_gid)
+ os.chown(
+ disk, pwd.getpwnam("sanlock").pw_uid,
grp.getgrnam("sanlock").gr_gid)
offset = sanlock.get_alignment(disk)
SNLK_DISKS = [(disk, offset)]
@@ -29,18 +32,20 @@ def main():
fd = sanlock.register()
print "Initializing '%s'" % (LOCKSPACE_NAME,)
- sanlock.write_lockspace(LOCKSPACE_NAME, disk, max_hosts=0, iotimeout=0,
align=1048576, sector=512)
+ sanlock.write_lockspace(LOCKSPACE_NAME, disk, align=1048576, sector=512)
print "Initializing '%s' on '%s'" % (RESOURCE_NAME,
LOCKSPACE_NAME)
- sanlock.write_resource(LOCKSPACE_NAME, RESOURCE_NAME, SNLK_DISKS, align=1048576,
sector=512)
+ sanlock.write_resource(
+ LOCKSPACE_NAME, RESOURCE_NAME, SNLK_DISKS, align=1048576, sector=512)
print "Acquiring the id '%i' on '%s'" % (HOST_ID,
LOCKSPACE_NAME)
sanlock.add_lockspace(LOCKSPACE_NAME, HOST_ID, disk)
try:
print "Acquiring '%s' on '%s'" % (RESOURCE_NAME,
LOCKSPACE_NAME)
- sanlock.acquire(LOCKSPACE_NAME, RESOURCE_NAME, SNLK_DISKS, slkfd=fd,
- version=0)
+ sanlock.acquire(
+ LOCKSPACE_NAME, RESOURCE_NAME, SNLK_DISKS, slkfd=fd, version=0)
+
while True:
print "Trying to get lockspace '%s' hosts" %
LOCKSPACE_NAME
try:
@@ -52,9 +57,15 @@ def main():
print "Lockspace '%s' hosts: " % LOCKSPACE_NAME,
hosts_list
break
time.sleep(5)
- print "Resource '%s' owners: " % RESOURCE_NAME, \
- sanlock.read_resource_owners(
- LOCKSPACE_NAME, RESOURCE_NAME, SNLK_DISKS, align=1048576, sector=512)
+
+ owners = sanlock.read_resource_owners(
+ LOCKSPACE_NAME,
+ RESOURCE_NAME,
+ SNLK_DISKS,
+ align=1048576,
+ sector=512)
+ print "Resource '%s' owners: %s" % (RESOURCE_NAME, owners)
+
print "Releasing '%s' on '%s'" % (RESOURCE_NAME,
LOCKSPACE_NAME)
sanlock.release(LOCKSPACE_NAME, RESOURCE_NAME, SNLK_DISKS, slkfd=fd)
except Exception as e:
@@ -66,5 +77,6 @@ def main():
print "Removing the sanlock disk"
os.remove(disk)
+
if __name__ == '__main__':
main()
diff --git a/tests/conftest.py b/tests/conftest.py
index 70e83d4..868ae46 100644
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -4,7 +4,6 @@ Fixtures for sanlock testing.
from __future__ import absolute_import
import os
-import stat
import pytest
@@ -12,6 +11,10 @@ from . import storage
from . import util
+class SanlockIsRunning(Exception):
+ """ Raised if sanlock running when it should not """
+
+
@pytest.fixture
def sanlock_daemon():
"""
@@ -50,6 +53,3 @@ def user_4k_path(request):
def no_sanlock_daemon():
if util.sanlock_is_running():
raise SanlockIsRunning
-
-class SanlockIsRunning(Exception):
- pass
diff --git a/tests/python_test.py b/tests/python_test.py
index a032951..331e901 100644
--- a/tests/python_test.py
+++ b/tests/python_test.py
@@ -5,7 +5,6 @@ from __future__ import absolute_import
import errno
import io
-import struct
import time
from contextlib import contextmanager
@@ -36,7 +35,7 @@ SECTOR_SIZE_4K = 4 * KiB
FILE_NAMES = [
- #name, encoding
+ # name, encoding
("ascii", None),
(u"ascii", None),
(u"\u05d0", None),
@@ -49,21 +48,27 @@ LOCKSPACE_OR_RESOURCE_NAMES = [
# Python 2 also supports str.
pytest.param(
"\xd7\x90",
- marks=pytest.mark.skipif(six.PY3, reason="python 3 supports only
bytes")),
+ marks=pytest.mark.skipif(
+ six.PY3,
+ reason="python 3 supports only bytes")),
# Python 2 also supports unicode with ascii content.
pytest.param(
u"ascii",
- marks=pytest.mark.skipif(six.PY3, reason="python 3 supports only
bytes")),
+ marks=pytest.mark.skipif(
+ six.PY3,
+ reason="python 3 supports only bytes")),
]
-(a)pytest.mark.parametrize("filename, encoding" , FILE_NAMES)
-(a)pytest.mark.parametrize("size,offset", [
+
+(a)pytest.mark.parametrize("filename, encoding", FILE_NAMES)
+(a)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, filename, encoding, size, offset):
+def test_write_lockspace(
+ tmpdir, sanlock_daemon, filename, encoding, size, offset):
path = util.generate_path(tmpdir, filename, encoding)
util.create_file(path, size)
@@ -103,7 +108,11 @@ def test_write_lockspace_4k(user_4k_path, sanlock_daemon, align):
util.write_guard(user_4k_path, align)
sanlock.write_lockspace(
- b"ls_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)
@@ -144,7 +153,8 @@ def test_read_lockspace_4k_invalid_sector_size(sanlock_daemon,
user_4k_path):
# Large offset.
(LARGE_FILE_SIZE, LARGE_FILE_SIZE - MIN_RES_SIZE),
])
-def test_write_resource(tmpdir, sanlock_daemon, filename, encoding, size, offset):
+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)]
@@ -177,9 +187,6 @@ def test_write_resource(tmpdir, sanlock_daemon, filename, encoding,
size, offset
magic = util.read_magic(path, offset)
assert magic == constants.PAXOS_DISK_MAGIC
-
- # TODO: check more stuff here...
-
util.check_guard(path, size)
@@ -567,7 +574,8 @@ def test_add_lockspace_parse_args(no_sanlock_daemon, name, filename,
encoding):
@pytest.mark.parametrize("name", LOCKSPACE_OR_RESOURCE_NAMES)
@pytest.mark.parametrize("filename,encoding", FILE_NAMES)
-def test_write_lockspace_parse_args(no_sanlock_daemon, name, filename, encoding):
+def test_write_lockspace_parse_args(
+ no_sanlock_daemon, name, filename, encoding):
path = util.generate_path("/tmp/", filename, encoding)
with raises_sanlock_errno():
sanlock.write_lockspace(name, path)
@@ -575,7 +583,8 @@ def test_write_lockspace_parse_args(no_sanlock_daemon, name, filename,
encoding)
@pytest.mark.parametrize("name", LOCKSPACE_OR_RESOURCE_NAMES)
@pytest.mark.parametrize("filename,encoding", FILE_NAMES)
-def test_write_resource_parse_args(no_sanlock_daemon, name, filename, encoding):
+def test_write_resource_parse_args(
+ no_sanlock_daemon, name, filename, encoding):
path = util.generate_path("/tmp/", filename, encoding)
disks = [(path, 0)]
with raises_sanlock_errno():
@@ -587,7 +596,8 @@ def test_write_resource_parse_args(no_sanlock_daemon, name, filename,
encoding):
@pytest.mark.parametrize("name", LOCKSPACE_OR_RESOURCE_NAMES)
@pytest.mark.parametrize("filename,encoding", FILE_NAMES)
-def test_release_resource_parse_args(no_sanlock_daemon, name, filename, encoding):
+def test_release_resource_parse_args(
+ no_sanlock_daemon, name, filename, encoding):
path = util.generate_path("/tmp/", filename, encoding)
disks = [(path, 0)]
with raises_sanlock_errno():
@@ -599,7 +609,8 @@ def test_release_resource_parse_args(no_sanlock_daemon, name,
filename, encoding
@pytest.mark.parametrize("name", LOCKSPACE_OR_RESOURCE_NAMES)
@pytest.mark.parametrize("filename,encoding", FILE_NAMES)
-def test_read_resource_owners_parse_args(no_sanlock_daemon, name, filename, encoding):
+def test_read_resource_owners_parse_args(
+ no_sanlock_daemon, name, filename, encoding):
path = util.generate_path("/tmp/", filename, encoding)
disks = [(path, 0)]
with raises_sanlock_errno():
@@ -643,7 +654,8 @@ def test_set_event_parse_args(no_sanlock_daemon, name):
@pytest.mark.parametrize("name", LOCKSPACE_OR_RESOURCE_NAMES)
@pytest.mark.parametrize("filename,encoding", FILE_NAMES)
-def test_init_lockspace_parse_args(no_sanlock_daemon, name, filename, encoding):
+def test_init_lockspace_parse_args(
+ no_sanlock_daemon, name, filename, encoding):
path = util.generate_path("/tmp/", filename, encoding)
with raises_sanlock_errno(errno.ENODEV):
sanlock.init_lockspace(name, path)
@@ -659,21 +671,23 @@ def test_init_resource_parse_args(no_sanlock_daemon, name, filename,
encoding):
with raises_sanlock_errno(errno.ENOENT):
sanlock.init_resource(name, b"res_name", disks)
+
@pytest.mark.parametrize("filename,encoding", FILE_NAMES)
def test_get_alignment_parse_args(no_sanlock_daemon, filename, encoding):
path = util.generate_path("/tmp/", filename, encoding)
with raises_sanlock_errno(errno.ENOENT):
sanlock.get_alignment(path)
+
@pytest.mark.parametrize("filename,encoding", FILE_NAMES)
def test_read_lockspace_parse_args(no_sanlock_daemon, filename, encoding):
path = util.generate_path("/tmp/", filename, encoding)
with raises_sanlock_errno():
sanlock.read_lockspace(path)
+
@pytest.mark.parametrize("filename,encoding", FILE_NAMES)
def test_read_resource_parse_args(no_sanlock_daemon, filename, encoding):
path = util.generate_path("/tmp/", filename, encoding)
with raises_sanlock_errno():
sanlock.read_resource(path)
-
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.