Skip to content

Commit

Permalink
Merge branch 'main' into prs/enhance-analyze-ceph
Browse files Browse the repository at this point in the history
  • Loading branch information
NotTheEvilOne authored Oct 21, 2024
2 parents a6a0df8 + b745bcd commit f6770e3
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 28 deletions.
34 changes: 27 additions & 7 deletions src/rookify/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,33 @@ def parse_args(args: list[str]) -> argparse.Namespace:
# Putting args-parser in seperate function to make this testable
arg_parser = ArgumentParser("Rookify")

# --dry-run option
arg_parser.add_argument("--dry-run", action="store_true", dest="dry_run_mode")
arg_parser.add_argument(
"-d",
"--dry-run",
action="store_true",
dest="dry_run_mode",
help="Preflight data analysis and migration validation.",
)

arg_parser.add_argument(
"-m",
"--migrate",
action="store_true",
dest="execution_mode",
help="Run the migration.",
)

arg_parser.add_argument(
"-s",
"--show-states",
action="store_true",
dest="show_states",
help="Show states of the modules.",
)

if len(args) < 1:
args = ["--dry-run"]

return arg_parser.parse_args(args)


Expand All @@ -39,7 +56,7 @@ def main() -> None:

# Configure logging
try:
if args.show_states is True:
if args.show_states:
configure_logging(
{"level": "ERROR", "format": {"renderer": "console", "time": "iso"}}
)
Expand All @@ -51,16 +68,19 @@ def main() -> None:
# Get Logger
log = get_logger()

log.info("Executing Rookify ...")

machine = Machine(config["general"].get("machine_pickle_file"))

load_modules(machine, config)

if args.show_states is True:
if args.show_states:
log.debug("Showing Rookify state ...")
ModuleHandler.show_states(machine, config)
else:
elif args.dry_run_mode:
log.info("Running Rookify in dry-run mode ...")
machine.execute(dry_run_mode=args.dry_run_mode)
else:
log.info("Executing Rookify ...")
machine.execute()


if __name__ == "__main__":
Expand Down
18 changes: 8 additions & 10 deletions src/rookify/modules/create_rook_cluster/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@ class CreateRookClusterHandler(ModuleHandler):
]

def preflight(self) -> None:
if self.machine.get_execution_state_data(
"CreateRookClusterHandler", "generated", default_value=False
):
cluster_definition = self.machine.get_preflight_state_data(
"CreateRookClusterHandler", "cluster_definition"
)

if cluster_definition is not None:
return

state_data = self.machine.get_preflight_state("AnalyzeCephHandler").data
Expand Down Expand Up @@ -64,13 +66,9 @@ def preflight(self) -> None:
if mgr_count > 5:
mgr_count = rook_config["cluster"].get("max_mgr_count", 5)

self.machine.get_execution_state(
"CreateRookClusterHandler"
).mgr_count = mgr_count

self.machine.get_execution_state(
"CreateRookClusterHandler"
).mon_count = mon_count
state = self.machine.get_preflight_state("CreateRookClusterHandler")
state.mgr_count = mgr_count
state.mon_count = mon_count

cluster_definition_values = {
"cluster_name": rook_config["cluster"]["name"],
Expand Down
14 changes: 12 additions & 2 deletions src/rookify/modules/machine.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,25 @@ def _get_state_tags_data(self, name: str) -> Dict[str, Any]:
return data

def get_execution_state(self, name: str) -> Any:
return self.get_state(self.__class__.STATE_NAME_EXECUTION_PREFIX + name)
state_name = self.__class__.STATE_NAME_EXECUTION_PREFIX + name

if state_name not in self.states:
return None

return self.get_state(state_name)

def get_execution_state_data(
self, name: str, tag: str, default_value: Any = None
) -> Any:
return getattr(self.get_execution_state(name), tag, default_value)

def get_preflight_state(self, name: str) -> Any:
return self.get_state(self.__class__.STATE_NAME_PREFLIGHT_PREFIX + name)
state_name = self.__class__.STATE_NAME_PREFLIGHT_PREFIX + name

if state_name not in self.states:
return None

return self.get_state(state_name)

def get_preflight_state_data(
self, name: str, tag: str, default_value: Any = None
Expand Down
6 changes: 3 additions & 3 deletions src/rookify/modules/migrate_mds_pools/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ def preflight(self) -> None:
if pool_data_osd_name not in migrated_pools:
migrated_pools.append(pool_data_osd_name)

self.machine.get_execution_state(
"MigrateMdsPoolsHandler"
).migrated_pools = migrated_pools
state = self.machine.get_execution_state("MigrateMdsPoolsHandler")
if state is not None:
state.migrated_pools = migrated_pools

continue

Expand Down
2 changes: 1 addition & 1 deletion src/rookify/modules/migrate_mgrs/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def _migrate_mgr(self, mgr_host: str) -> None:
"MigrateMgrsHandler"
).migrated_mgrs = migrated_mgrs

mgr_count_expected = self.machine.get_execution_state_data(
mgr_count_expected = self.machine.get_preflight_state_data(
"CreateRookClusterHandler", "mgr_count", default_value=3
)

Expand Down
2 changes: 1 addition & 1 deletion src/rookify/modules/migrate_mons/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def _migrate_mon(self, mon: Dict[str, Any]) -> None:
"MigrateMonsHandler",
).migrated_mons = migrated_mons

mon_count_expected = self.machine.get_execution_state_data(
mon_count_expected = self.machine.get_preflight_state_data(
"CreateRookClusterHandler", "mon_count", default_value=3
)

Expand Down
10 changes: 6 additions & 4 deletions tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@

# fmt: off
test_cases: List[TestCase] = [
(["--dry-run"], argparse.Namespace(dry_run_mode=True, show_states=False)),
(["--show-states"], argparse.Namespace(dry_run_mode=False, show_states=True)),
(["--dry-run", "--show-states"], argparse.Namespace(dry_run_mode=True, show_states=True)),
([], argparse.Namespace(dry_run_mode=False, show_states=False)),
(["--migrate"], argparse.Namespace(dry_run_mode=False, show_states=False, execution_mode=True)),
(["--migrate", "--dry-run"], argparse.Namespace(dry_run_mode=True, show_states=False, execution_mode=True)),
(["--dry-run"], argparse.Namespace(dry_run_mode=True, show_states=False, execution_mode=False)),
(["--show-states"], argparse.Namespace(dry_run_mode=False, show_states=True, execution_mode=False)),
(["--dry-run", "--show-states"], argparse.Namespace(dry_run_mode=True, show_states=True, execution_mode=False)),
([], argparse.Namespace(dry_run_mode=True, show_states=False, execution_mode=False)),
]
# fmt: on

Expand Down

0 comments on commit f6770e3

Please sign in to comment.