From 99b0fdf5e409d36df83a538e1c2a28fb9e5b78f2 Mon Sep 17 00:00:00 2001 From: Ilya Dryomov Date: Thu, 24 Nov 2022 13:37:44 +0100 Subject: [PATCH] mgr/rbd_support: clean up and enable flake8 Signed-off-by: Ilya Dryomov --- src/pybind/mgr/rbd_support/__init__.py | 1 + src/pybind/mgr/rbd_support/common.py | 4 ++-- .../mgr/rbd_support/mirror_snapshot_schedule.py | 14 +++++++------- src/pybind/mgr/rbd_support/module.py | 1 - src/pybind/mgr/rbd_support/schedule.py | 5 ++--- src/pybind/mgr/rbd_support/task.py | 1 + src/pybind/mgr/rbd_support/trash_purge_schedule.py | 14 ++++++-------- src/pybind/mgr/tox.ini | 1 + 8 files changed, 20 insertions(+), 21 deletions(-) diff --git a/src/pybind/mgr/rbd_support/__init__.py b/src/pybind/mgr/rbd_support/__init__.py index 8f210ac9247..ee85dc9d376 100644 --- a/src/pybind/mgr/rbd_support/__init__.py +++ b/src/pybind/mgr/rbd_support/__init__.py @@ -1 +1,2 @@ +# flake8: noqa from .module import Module diff --git a/src/pybind/mgr/rbd_support/common.py b/src/pybind/mgr/rbd_support/common.py index 9c9c9248fb5..a6c041bf729 100644 --- a/src/pybind/mgr/rbd_support/common.py +++ b/src/pybind/mgr/rbd_support/common.py @@ -1,10 +1,11 @@ import re -from typing import Any, Dict, Optional, Tuple, TYPE_CHECKING, Union +from typing import Dict, Optional, Tuple, TYPE_CHECKING, Union GLOBAL_POOL_KEY = (None, None) + class NotAuthorizedError(Exception): pass @@ -45,4 +46,3 @@ def get_rbd_pools(module: 'Module') -> Dict[int, str]: osd_map = module.get('osd_map') return {pool['pool']: pool['pool_name'] for pool in osd_map['pools'] if 'rbd' in pool.get('application_metadata', {})} - diff --git a/src/pybind/mgr/rbd_support/mirror_snapshot_schedule.py b/src/pybind/mgr/rbd_support/mirror_snapshot_schedule.py index c8cf4e4ee7e..47efa57e82c 100644 --- a/src/pybind/mgr/rbd_support/mirror_snapshot_schedule.py +++ b/src/pybind/mgr/rbd_support/mirror_snapshot_schedule.py @@ -2,15 +2,15 @@ import errno import json import rados import rbd -import re import traceback from datetime import datetime from threading import Condition, Lock, Thread -from typing import Any, Dict, List, NamedTuple, Optional, Sequence, Set, Tuple, Union +from typing import Any, Dict, List, NamedTuple, Optional, Set, Tuple, Union from .common import get_rbd_pools -from .schedule import LevelSpec, Interval, StartTime, Schedule, Schedules +from .schedule import LevelSpec, Schedules + def namespace_validator(ioctx: rados.Ioctx) -> None: mode = rbd.RBD().mirror_mode_get(ioctx) @@ -18,6 +18,7 @@ def namespace_validator(ioctx: rados.Ioctx) -> None: raise ValueError("namespace {} is not in mirror image mode".format( ioctx.get_namespace())) + def image_validator(image: rbd.Image) -> None: mode = image.mirror_image_get_mode() if mode != rbd.RBD_MIRROR_IMAGE_MODE_SNAPSHOT: @@ -224,7 +225,6 @@ class CreateSnapshotRequests: pool_id, namespace, image_id, e)) self.close_image(image_spec, image) - def handle_create_snapshot(self, image_spec: ImageSpec, image: rbd.Image, @@ -601,8 +601,8 @@ class MirrorSnapshotScheduleHandler: continue image_name = self.images[pool_id][namespace][image_id] scheduled_images.append({ - 'schedule_time' : schedule_time, - 'image' : image_name + 'schedule_time': schedule_time, + 'image': image_name }) - return 0, json.dumps({'scheduled_images' : scheduled_images}, + return 0, json.dumps({'scheduled_images': scheduled_images}, indent=4, sort_keys=True), "" diff --git a/src/pybind/mgr/rbd_support/module.py b/src/pybind/mgr/rbd_support/module.py index 7a3f4d62609..86bb3858830 100644 --- a/src/pybind/mgr/rbd_support/module.py +++ b/src/pybind/mgr/rbd_support/module.py @@ -8,7 +8,6 @@ import functools import inspect import rados import rbd -import traceback from typing import cast, Any, Callable, Optional, Tuple, TypeVar from mgr_module import CLIReadCommand, CLIWriteCommand, MgrModule, Option diff --git a/src/pybind/mgr/rbd_support/schedule.py b/src/pybind/mgr/rbd_support/schedule.py index b8507a1b8fe..a91309c98c9 100644 --- a/src/pybind/mgr/rbd_support/schedule.py +++ b/src/pybind/mgr/rbd_support/schedule.py @@ -424,7 +424,6 @@ class Schedules: ioctx: rados.Ioctx, namespace_validator: Optional[Callable], image_validator: Optional[Callable]) -> None: - pool_id = ioctx.get_pool_id() pool_name = ioctx.get_pool_name() stale_keys = [] start_after = '' @@ -569,7 +568,7 @@ class Schedules: ls = self.level_specs[level_spec_id] if ls == parent or ls == level_spec or ls.is_child_of(level_spec): result[level_spec_id] = { - 'name' : schedule.name, - 'schedule' : schedule.to_list(), + 'name': schedule.name, + 'schedule': schedule.to_list(), } return result diff --git a/src/pybind/mgr/rbd_support/task.py b/src/pybind/mgr/rbd_support/task.py index d283962a365..3c89acbb8cb 100644 --- a/src/pybind/mgr/rbd_support/task.py +++ b/src/pybind/mgr/rbd_support/task.py @@ -149,6 +149,7 @@ ImageSpecT = Tuple[str, str, str] PoolSpecT = Tuple[str, str] MigrationStatusT = Dict[str, str] + class TaskHandler: lock = Lock() condition = Condition(lock) diff --git a/src/pybind/mgr/rbd_support/trash_purge_schedule.py b/src/pybind/mgr/rbd_support/trash_purge_schedule.py index 5f817bd8038..e12fec45732 100644 --- a/src/pybind/mgr/rbd_support/trash_purge_schedule.py +++ b/src/pybind/mgr/rbd_support/trash_purge_schedule.py @@ -1,8 +1,6 @@ -import errno import json import rados import rbd -import re import traceback from datetime import datetime @@ -10,7 +8,7 @@ from threading import Condition, Lock, Thread from typing import Any, Dict, List, Optional, Tuple from .common import get_rbd_pools -from .schedule import LevelSpec, Interval, StartTime, Schedule, Schedules +from .schedule import LevelSpec, Schedules class TrashPurgeScheduleHandler: @@ -262,10 +260,10 @@ class TrashPurgeScheduleHandler: continue pool_name = self.pools[pool_id][namespace] scheduled.append({ - 'schedule_time' : schedule_time, - 'pool_id' : pool_id, - 'pool_name' : pool_name, - 'namespace' : namespace + 'schedule_time': schedule_time, + 'pool_id': pool_id, + 'pool_name': pool_name, + 'namespace': namespace }) - return 0, json.dumps({'scheduled' : scheduled}, indent=4, + return 0, json.dumps({'scheduled': scheduled}, indent=4, sort_keys=True), "" diff --git a/src/pybind/mgr/tox.ini b/src/pybind/mgr/tox.ini index bf184915756..d078d8c097d 100644 --- a/src/pybind/mgr/tox.ini +++ b/src/pybind/mgr/tox.ini @@ -179,6 +179,7 @@ modules = nfs orchestrator prometheus + rbd_support selftest commands = flake8 --config=tox.ini {posargs} \ -- 2.39.5