]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
pybind/mgr: clean up various flake8 issues in mgr_util.py
authorJohn Mulligan <jmulligan@redhat.com>
Tue, 7 May 2024 17:49:16 +0000 (13:49 -0400)
committerJohn Mulligan <jmulligan@redhat.com>
Thu, 13 Jun 2024 14:14:29 +0000 (10:14 -0400)
Clean up many obvious to fix issues detected by flake8 in mgr_util.py.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
src/pybind/mgr/mgr_util.py

index 05ec6496682f4dd7a9f24826100c4cd46df9b2ba..7c0b2b082813264cd71a5bcaf71b2c82965e9372 100644 (file)
@@ -13,7 +13,7 @@ import time
 import logging
 import sys
 from ipaddress import ip_address
-from threading import Lock, Condition, Event
+from threading import Lock, Condition
 from typing import no_type_check, NewType
 import urllib
 from functools import wraps
@@ -70,6 +70,7 @@ class CephfsConnectionException(Exception):
     def __str__(self) -> str:
         return "{0} ({1})".format(self.errno, self.error_str)
 
+
 class RTimer(Timer):
     """
     recurring timer variant of Timer
@@ -85,6 +86,7 @@ class RTimer(Timer):
             logger.error("task exception: %s", e)
             raise
 
+
 @contextlib.contextmanager
 def lock_timeout_log(lock: Lock, timeout: int = 5) -> Iterator[None]:
     start = time.time()
@@ -333,7 +335,6 @@ class CephfsClient(Generic[Module_T]):
         return fs_list
 
 
-
 @contextlib.contextmanager
 def open_filesystem(fsc: CephfsClient, fs_name: str) -> Generator["cephfs.LibCephFS", None, None]:
     """
@@ -516,7 +517,7 @@ def create_self_signed_cert(organisation: str = 'Ceph',
 
     :param organisation: String representing the Organisation(O) RDN (default='Ceph')
     :param common_name: String representing the Common Name(CN) RDN (default='mgr')
-    :param dname: Optional dictionary containing RDNs to use for crt/key generation 
+    :param dname: Optional dictionary containing RDNs to use for crt/key generation
 
     :return: ssl crt and key in utf-8 format
 
@@ -600,7 +601,8 @@ def verify_cacrt(cert_fname):
         raise ServerConfigException(
             'Invalid certificate {}: {}'.format(cert_fname, str(e)))
 
-def get_cert_issuer_info(crt: str) -> Tuple[Optional[str],Optional[str]]:
+
+def get_cert_issuer_info(crt: str) -> Tuple[Optional[str], Optional[str]]:
     """Basic validation of a ca cert"""
 
     from OpenSSL import crypto, SSL
@@ -618,6 +620,7 @@ def get_cert_issuer_info(crt: str) -> Tuple[Optional[str],Optional[str]]:
     except (ValueError, crypto.Error) as e:
         raise ServerConfigException(f'Invalid certificate key: {e}')
 
+
 def verify_tls(crt, key):
     # type: (str, str) -> None
     verify_cacrt_content(crt)
@@ -648,7 +651,6 @@ def verify_tls(crt, key):
         raise ServerConfigException(f'Invalid cert/key pair: {e}')
 
 
-
 def verify_tls_files(cert_fname, pkey_fname):
     # type: (str, str) -> None
     """Basic checks for TLS certificate and key files
@@ -716,6 +718,7 @@ def get_most_recent_rate(rates: Optional[List[Tuple[float, float]]]) -> float:
         return 0.0
     return rates[-1][1]
 
+
 def get_time_series_rates(data: List[Tuple[float, float]]) -> List[Tuple[float, float]]:
     """ Rates from time series data
 
@@ -744,6 +747,7 @@ def get_time_series_rates(data: List[Tuple[float, float]]) -> List[Tuple[float,
     return [(data2[0], _derivative(data1, data2) if data1 is not None else 0.0) for data1, data2 in
             _pairwise(data)]
 
+
 def name_to_config_section(name: str) -> ConfEntity:
     """
     Map from daemon names to ceph entity names (as seen in config)
@@ -840,12 +844,12 @@ def to_pretty_timedelta(n: datetime.timedelta) -> str:
     if n < datetime.timedelta(hours=48):
         return str(int(n.total_seconds()) // 3600) + 'h'
     if n < datetime.timedelta(days=14):
-        return str(int(n.total_seconds()) // (3600*24)) + 'd'
-    if n < datetime.timedelta(days=7*12):
-        return str(int(n.total_seconds()) // (3600*24*7)) + 'w'
-    if n < datetime.timedelta(days=365*2):
-        return str(int(n.total_seconds()) // (3600*24*30)) + 'M'
-    return str(int(n.total_seconds()) // (3600*24*365)) + 'y'
+        return str(int(n.total_seconds()) // (3600 * 24)) + 'd'
+    if n < datetime.timedelta(days=7 * 12):
+        return str(int(n.total_seconds()) // (3600 * 24 * 7)) + 'w'
+    if n < datetime.timedelta(days=365 * 2):
+        return str(int(n.total_seconds()) // (3600 * 24 * 30)) + 'M'
+    return str(int(n.total_seconds()) // (3600 * 24 * 365)) + 'y'
 
 
 def profile_method(skip_attribute: bool = False) -> Callable[[Callable[..., T]], Callable[..., T]]: