Skip to content
This repository was archived by the owner on Dec 16, 2025. It is now read-only.

Commit bff688c

Browse files
committed
fix: add status command through load modules, probably should add an own status-mode?
Signed-off-by: Boekhorst <[email protected]>
1 parent b33cd08 commit bff688c

File tree

6 files changed

+64
-31
lines changed

6 files changed

+64
-31
lines changed

src/rookify/__main__.py

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,9 @@ def read_pickle_file(
116116
)
117117

118118

119-
def show_progress_from_pickle_file(
119+
def show_progress_from_state(
120120
args: argparse.Namespace, pickle_file_name: str, log: BindableLogger
121-
) -> None:
121+
) -> bool:
122122
# states_data = load_pickler(pickle_file_name)
123123
modules = get_all_modules()
124124

@@ -127,9 +127,12 @@ def show_progress_from_pickle_file(
127127
module = args.show_progress
128128
if args.show_progress not in modules:
129129
log.error(f"The module {module} does not exist")
130+
return False
130131
log.info("Show progress of the {0} module".format(args.show_progress))
132+
return True
131133
else:
132134
log.info("Show progress of {0} modules".format(args.show_progress))
135+
return True
133136

134137

135138
def main() -> None:
@@ -182,24 +185,18 @@ def main() -> None:
182185
)
183186
return
184187

185-
# If show_progress is run and there is a picklefile, show progress status based on picklefile contents
186-
# NOTE: this is always run in preflight-mode (migration shoudl not be executed)
187-
if args.show_progress is not None and pickle_file_name is not None:
188-
show_progress_from_pickle_file(args, pickle_file_name, log)
189-
return
190-
191-
# TODO: should progress be checkable if no pickle file is present? Should rookify check the status by analyzing the source and traget machines state?
192-
elif args.show_progress is not None and pickle_file_name is None:
193-
log.info(
194-
"Currently rookify can only check the state of progress by analyzing the pickle file states."
195-
)
196-
return
197-
198-
# Else run the rook migration
199188
else:
200-
log.debug("Executing Rookify")
201-
202189
machine = Machine(config["general"].get("machine_pickle_file"))
203-
load_modules(machine, config)
204190

205-
machine.execute(dry_run_mode=args.dry_run_mode)
191+
if args.show_progress is not None:
192+
if show_progress_from_state(args, pickle_file_name, log) is True:
193+
load_modules(machine, config, show_progress=True)
194+
# NOTE: this is always run in preflight-mode (migration should not be executed)
195+
machine.execute(dry_run_mode=True)
196+
return
197+
else:
198+
return
199+
else:
200+
load_modules(machine, config)
201+
log.debug("Executing Rookify")
202+
machine.execute(dry_run_mode=args.dry_run_mode)

src/rookify/modules/__init__.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# -*- coding: utf-8 -*-
22

33
import importlib
4-
from typing import Any, Dict
4+
from typing import Any, Dict, Optional
55
from ..logger import get_logger
66
from .machine import Machine
77

@@ -22,7 +22,12 @@ def __init__(self, module_name: str, message: str):
2222
self.message = message
2323

2424

25-
def _load_module(machine: Machine, config: Dict[str, Any], module_name: str) -> None:
25+
def _load_module(
26+
machine: Machine,
27+
config: Dict[str, Any],
28+
module_name: str,
29+
show_progress: Optional[bool] = False,
30+
) -> None:
2631
"""
2732
Dynamically loads a module from the 'rookify.modules' package.
2833
@@ -43,12 +48,14 @@ def _load_module(machine: Machine, config: Dict[str, Any], module_name: str) ->
4348
additional_modules = module.ModuleHandler.REQUIRES
4449

4550
for module_name in additional_modules:
46-
_load_module(machine, config, module_name)
51+
_load_module(machine, config, module_name, show_progress)
4752

48-
module.ModuleHandler.register_states(machine, config)
53+
module.ModuleHandler.register_states(machine, config, show_progress)
4954

5055

51-
def load_modules(machine: Machine, config: Dict[str, Any]) -> None:
56+
def load_modules(
57+
machine: Machine, config: Dict[str, Any], show_progress: Optional[bool] = False
58+
) -> None:
5259
"""
5360
Dynamically loads modules from the 'modules' package.
5461
@@ -61,7 +68,7 @@ def load_modules(machine: Machine, config: Dict[str, Any]) -> None:
6168
for entry in importlib.resources.files("rookify.modules").iterdir():
6269
if entry.is_dir() and entry.name in config["migration_modules"]:
6370
migration_modules.remove(entry.name)
64-
_load_module(machine, config, entry.name)
71+
_load_module(machine, config, entry.name, show_progress)
6572

6673
if len(migration_modules) > 0 or len(config["migration_modules"]) < 1:
6774
logger = get_logger()

src/rookify/modules/analyze_ceph/main.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,9 @@ def status(self) -> Any:
5555
self.logger.info("AnalyzeCephHandler has already been run.")
5656
self.logger.info("Current state data: %s", state.data)
5757
else:
58-
self.logger.info("Progress: Not all commands have been run yet.")
58+
self.logger.info(
59+
"AnalyzeCephHandler Progress: Not all commands have been run yet."
60+
)
5961

6062
@staticmethod
6163
def register_preflight_state(

src/rookify/modules/machine.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ def add_execution_state(self, name: str, **kwargs: Dict[str, Any]) -> None:
2626
def add_preflight_state(self, name: str, **kwargs: Dict[str, Any]) -> None:
2727
self._preflight_states.append(self.__class__.state_cls(name, **kwargs))
2828

29-
def execute(self, dry_run_mode: bool = False) -> None:
29+
def execute(
30+
self, dry_run_mode: bool = False, show_progress: Optional[bool] = False
31+
) -> None:
3032
states = self._preflight_states
3133
if not dry_run_mode:
3234
states = states + self._execution_states

src/rookify/modules/module.py

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,13 @@ def ssh(self) -> SSH:
5959
self.__ssh = SSH(self._config["ssh"])
6060
return self.__ssh
6161

62+
@abc.abstractmethod
63+
def status(self) -> None:
64+
"""
65+
Run the modules status check
66+
"""
67+
pass
68+
6269
@abc.abstractmethod
6370
def preflight(self) -> None:
6471
"""
@@ -87,7 +94,12 @@ def load_template(self, filename: str, **variables: Any) -> Template:
8794
return template
8895

8996
@classmethod
90-
def register_states(cls, machine: Machine, config: Dict[str, Any]) -> None:
97+
def register_states(
98+
cls,
99+
machine: Machine,
100+
config: Dict[str, Any],
101+
show_progress: Optional[bool] = False,
102+
) -> None:
91103
"""
92104
Register states for transitions
93105
"""
@@ -116,7 +128,10 @@ def register_states(cls, machine: Machine, config: Dict[str, Any]) -> None:
116128
)
117129
else:
118130
if preflight_state_name is not None:
119-
cls.register_preflight_state(machine, preflight_state_name, handler)
131+
if show_progress is True:
132+
cls.register_status_state(machine, preflight_state_name, handler)
133+
else:
134+
cls.register_preflight_state(machine, preflight_state_name, handler)
120135

121136
if execution_state_name is not None:
122137
cls.register_execution_state(machine, execution_state_name, handler)
@@ -131,6 +146,16 @@ def register_preflight_state(
131146

132147
machine.add_preflight_state(state_name, on_enter=handler.preflight, **kwargs)
133148

149+
@staticmethod
150+
def register_status_state(
151+
machine: Machine, state_name: str, handler: Any, **kwargs: Any
152+
) -> None:
153+
"""
154+
Register state for transitions
155+
"""
156+
157+
machine.add_preflight_state(state_name, on_enter=handler.status, **kwargs)
158+
134159
@staticmethod
135160
def register_execution_state(
136161
machine: Machine, state_name: str, handler: Any, **kwargs: Any

tests/test_main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ def getUnsortedData() -> Any:
210210
(["--dry-run", "--show-progress", "analyze_ceph"], "Show progress of the analyze_ceph module", "info"),
211211
(["--show-progress"], "Show progress of all modules", "info"),
212212
(["--dry-run", "--show-progress"], "Show progress of all modules", "info"),
213-
(["--show-progress"], "Analyze ceph has been run", "info")
213+
(["--show-progress"], "AnalyzeCephHandler Progress: Not all commands have been run yet.", "info")
214214
]
215215
# fmt: on
216216

0 commit comments

Comments
 (0)