Skip to content

Commit

Permalink
fix typing
Browse files Browse the repository at this point in the history
Signed-off-by: Jan-Marten Brüggemann <[email protected]>
  • Loading branch information
brueggemann committed Mar 13, 2024
1 parent fbef497 commit f19d027
Show file tree
Hide file tree
Showing 10 changed files with 29 additions and 18 deletions.
9 changes: 5 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,15 @@
limitations under the License.
"""

from typing import Dict, Any

try:
from setuptools import find_packages, setup
except ImportError:
from distutils import find_packages, setup
#
from distutils import find_packages, setup # type: ignore


def get_version():
def get_version() -> str:
"""
Returns the version currently in development.
Expand All @@ -36,7 +37,7 @@ def get_version():

#

_setup = {
_setup: Dict[str, Any] = {
"version": get_version()[1:],
"data_files": [("docs", ["LICENSE", "README.md"])],
"test_suite": "tests",
Expand Down
10 changes: 6 additions & 4 deletions src/rookify/modules/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def check_module_sanity(module_name: str, module: types.ModuleType):
)

# Load the modules in the given list and recursivley load required modules
required_modules = OrderedDict()
required_modules: OrderedDict[str, types.ModuleType] = OrderedDict()

def load_required_modules(modules_out: OrderedDict, module_names: list) -> None:
for module_name in module_names:
Expand All @@ -70,7 +70,7 @@ def load_required_modules(modules_out: OrderedDict, module_names: list) -> None:
load_required_modules(required_modules, module_names)

# Recursively load the modules in the PREFLIGHT_REQUIRES attribute of the given modules
preflight_modules = OrderedDict()
preflight_modules: OrderedDict[str, types.ModuleType] = OrderedDict()

def load_preflight_modules(
modules_in: OrderedDict, modules_out: OrderedDict, module_names: list
Expand All @@ -94,10 +94,12 @@ def load_preflight_modules(
if module_name not in modules_in:
modules_out[module_name] = module

load_preflight_modules(required_modules, preflight_modules, required_modules.keys())
load_preflight_modules(
required_modules, preflight_modules, list(required_modules.keys())
)

# Sort the modules by the AFTER keyword
modules = OrderedDict()
modules: OrderedDict[str, types.ModuleType] = OrderedDict()

def sort_modules(
modules_in: OrderedDict, modules_out: OrderedDict, module_names: list
Expand Down
1 change: 1 addition & 0 deletions src/rookify/modules/analyze_ceph/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-
# type: ignore

from .main import AnalyzeCephHandler

Expand Down
4 changes: 2 additions & 2 deletions src/rookify/modules/analyze_ceph/main.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# -*- coding: utf-8 -*-


from typing import Dict
from ..module import ModuleHandler


class AnalyzeCephHandler(ModuleHandler):
def run(self) -> dict:
commands = ["mon dump", "osd dump", "device ls", "fs dump", "node ls"]

results = dict()
results: Dict[str, dict] = dict()
for command in commands:
parts = command.split(" ")
leaf = results
Expand Down
1 change: 1 addition & 0 deletions src/rookify/modules/example/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-
# type: ignore

from .main import ExampleHandler

Expand Down
2 changes: 1 addition & 1 deletion src/rookify/modules/example/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ def preflight_check(self):

def run(self) -> dict:
# Run the migration tasks
pass
return {}
1 change: 1 addition & 0 deletions src/rookify/modules/migrate_monitors/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-
# type: ignore

from .main import MigrateMonitorsHandler

Expand Down
1 change: 1 addition & 0 deletions src/rookify/modules/migrate_osds/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-
# type: ignore

from .main import MigrateOSDsHandler

Expand Down
5 changes: 4 additions & 1 deletion src/rookify/modules/migrate_osds/main.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# -*- coding: utf-8 -*-

from typing import Dict

from ..module import ModuleHandler


Expand All @@ -10,7 +12,7 @@ def preflight_check(self):
# raise ModuleException('test error')

def run(self) -> dict:
osd_config = dict()
osd_config: Dict[str, dict] = dict()
for node, osds in self._data["analyze_ceph"]["node"]["ls"]["osd"].items():
osd_config[node] = {"osds": {}}
for osd in osds:
Expand All @@ -33,3 +35,4 @@ def run(self) -> dict:
break

print(osd_config)
return {}
13 changes: 7 additions & 6 deletions src/rookify/modules/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import rados
import kubernetes
import fabric
from typing import Any


class ModuleException(Exception):
Expand All @@ -17,7 +18,7 @@ class ModuleHandler:
"""

class __Ceph:
def __init__(self, config: dict):
def __init__(self, config: dict[str, Any]):
try:
self.__ceph = rados.Rados(
conffile=config["conf_file"], conf={"keyring": config["keyring"]}
Expand All @@ -26,9 +27,9 @@ def __init__(self, config: dict):
except rados.ObjectNotFound as err:
raise ModuleException(f"Could not connect to ceph: {err}")

def mon_command(self, command: str, **kwargs) -> dict:
def mon_command(self, command: str, **kwargs: dict[str, str]) -> dict[str, Any]:
cmd = {"prefix": command, "format": "json"}
cmd.update(kwargs)
cmd.update(**kwargs)
result = self.__ceph.mon_command(json.dumps(cmd), b"")
if result[0] != 0:
raise ModuleException(f"Ceph did return an error: {result}")
Expand Down Expand Up @@ -86,9 +87,9 @@ def __init__(self, config: dict, data: dict):
"""
self._config = config
self._data = data
self.__ceph = None
self.__k8s = None
self.__ssh = None
self.__ceph: self.__Ceph = None # type: ignore
self.__k8s: self.__K8s = None # type: ignore
self.__ssh: self.__SSH = None # type: ignore

@abc.abstractmethod
def preflight_check(self) -> None:
Expand Down

0 comments on commit f19d027

Please sign in to comment.