Fix lint
diff --git a/staffeln/common/lock.py b/staffeln/common/lock.py
index 8006fd1..5568bfe 100644
--- a/staffeln/common/lock.py
+++ b/staffeln/common/lock.py
@@ -3,18 +3,13 @@
import os
import re
import sys
-from typing import Optional # noqa: H301
import uuid
+from typing import Optional # noqa: H301
-from oslo_config import cfg
from oslo_log import log
-from oslo_utils import timeutils
-from oslo_utils import uuidutils
+from staffeln import conf, exception
from tooz import coordination
-from staffeln import conf
-from staffeln import exception
-
CONF = conf.CONF
LOG = log.getLogger(__name__)
@@ -67,7 +62,7 @@
meaningful prefix.
"""
- def __init__(self, agent_id: Optional[str] = None, prefix: str = ''):
+ def __init__(self, agent_id: Optional[str] = None, prefix: str = ""):
self.coordinator = None
self.agent_id = agent_id or str(uuid.uuid4())
self.started = False
@@ -75,11 +70,11 @@
self._file_path = None
def _get_file_path(self, backend_url):
- if backend_url.startswith('file://'):
+ if backend_url.startswith("file://"):
path = backend_url[7:]
# Copied from TooZ's _normalize_path to get the same path they use
- if sys.platform == 'win32':
- path = re.sub(r'\\(?=\w:\\)', '', os.path.normpath(path))
+ if sys.platform == "win32":
+ path = re.sub(r"\\(?=\w:\\)", "", os.path.normpath(path))
return os.path.abspath(os.path.join(path, self.prefix))
return None
@@ -90,7 +85,7 @@
backend_url = CONF.coordination.backend_url
# member_id should be bytes
- member_id = (self.prefix + self.agent_id).encode('ascii')
+ member_id = (self.prefix + self.agent_id).encode("ascii")
self.coordinator = coordination.get_coordinator(backend_url, member_id)
assert self.coordinator is not None
self.coordinator.start(start_heart=True)
@@ -112,19 +107,18 @@
across all nodes.
"""
# lock name should be bytes
- lock_name = (self.prefix + name).encode('ascii')
+ lock_name = (self.prefix + name).encode("ascii")
if self.coordinator is not None:
return self.coordinator.get_lock(lock_name)
else:
- raise exception.LockCreationFailed('Coordinator uninitialized.')
+ raise exception.LockCreationFailed("Coordinator uninitialized.")
def remove_lock(self, glob_name):
# Most locks clean up on release, but not the file lock, so we manually
# clean them.
def _err(file_name: str, exc: Exception) -> None:
- LOG.warning('Failed to cleanup lock %(name)s: %(exc)s',
- {'name': file_name, 'exc': exc})
+ LOG.warning(f"Failed to cleanup lock {file_name}: {exc}")
if self._file_path:
files = glob.glob(self._file_path + glob_name)
@@ -132,10 +126,10 @@
try:
os.remove(file_name)
except OSError as exc:
- if (exc.errno != errno.ENOENT):
+ if exc.errno != errno.ENOENT:
_err(file_name, exc)
except Exception as exc:
_err(file_name, exc)
-COORDINATOR = Coordinator(prefix='staffeln-')
+COORDINATOR = Coordinator(prefix="staffeln-")
diff --git a/staffeln/conductor/manager.py b/staffeln/conductor/manager.py
index 6e04e2a..380c2f7 100755
--- a/staffeln/conductor/manager.py
+++ b/staffeln/conductor/manager.py
@@ -60,7 +60,9 @@
LOG.debug(
f"try to get lock and run task for volume: {queue.volume_id}."
)
- with lock.Lock(self.lock_mgt, queue.volume_id, remove_lock=True) as q_lock:
+ with lock.Lock(
+ self.lock_mgt, queue.volume_id, remove_lock=True
+ ) as q_lock:
if q_lock.acquired:
self.controller.check_volume_backup_status(queue)
else: # time out
@@ -110,7 +112,9 @@
)
if len(tasks_to_start) != 0:
for task in tasks_to_start:
- with lock.Lock(self.lock_mgt, task.volume_id, remove_lock=True) as t_lock:
+ with lock.Lock(
+ self.lock_mgt, task.volume_id, remove_lock=True
+ ) as t_lock:
if t_lock.acquired:
# Re-pulling status and make it's up-to-date
task = self.controller.get_queue_task_by_id(task_id=task.id)
diff --git a/staffeln/conf/conductor.py b/staffeln/conf/conductor.py
index 33160cf..ff39f13 100755
--- a/staffeln/conf/conductor.py
+++ b/staffeln/conf/conductor.py
@@ -115,7 +115,9 @@
coordination_opts = [
- cfg.StrOpt("backend_url", default="", help=_("lock coordination connection backend URL.")),
+ cfg.StrOpt(
+ "backend_url", default="", help=_("lock coordination connection backend URL.")
+ ),
]
@@ -133,5 +135,5 @@
return {
"DEFAULT": rotation_opts,
conductor_group: backup_opts,
- coordination_group: coordination_opts
+ coordination_group: coordination_opts,
}
diff --git a/staffeln/exception.py b/staffeln/exception.py
index 2faf951..e561506 100644
--- a/staffeln/exception.py
+++ b/staffeln/exception.py
@@ -17,8 +17,8 @@
"""Staffeln base exception handling."""
from typing import Optional, Union # noqa: H301
-from oslo_log import log as logging
+from oslo_log import log as logging
LOG = logging.getLogger(__name__)
@@ -27,10 +27,11 @@
"""Base Staffeln Exception
To correctly use this class, inherit from it and define
- a 'message' property. That message will get printf'd
+ a "message" property. That message will get printf'd
with the keyword arguments provided to the constructor.
"""
+
message = "An unknown exception occurred."
code = 500
headers: dict = {}
@@ -38,11 +39,11 @@
def __init__(self, message: Optional[Union[str, tuple]] = None, **kwargs):
self.kwargs = kwargs
- self.kwargs['message'] = message
+ self.kwargs["message"] = message
- if 'code' not in self.kwargs:
+ if "code" not in self.kwargs:
try:
- self.kwargs['code'] = self.code
+ self.kwargs["code"] = self.code
except AttributeError:
pass
@@ -61,22 +62,21 @@
self.msg = message
super(StaffelnException, self).__init__(message)
- # Oslo.messaging use the argument 'message' to rebuild exception
+ # Oslo.messaging use the argument "message" to rebuild exception
# directly at the rpc client side, therefore we should not use it
# in our keyword arguments, otherwise, the rebuild process will fail
# with duplicate keyword exception.
- self.kwargs.pop('message', None)
+ self.kwargs.pop("message", None)
def _log_exception(self) -> None:
# kwargs doesn't match a variable in the message
# log the issue and the kwargs
- LOG.exception('Exception in string format operation:')
+ LOG.exception("Exception in string format operation:")
for name, value in self.kwargs.items():
- LOG.error("%(name)s: %(value)s",
- {'name': name, 'value': value})
+ LOG.error(f"{name}: {value}")
def _should_format(self) -> bool:
- return self.kwargs['message'] is None or '%(message)' in self.message
+ return self.kwargs["message"] is None or "%(message)" in self.message
class LockCreationFailed(StaffelnException):