Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle access to undefined states gracefully #85

Merged
merged 4 commits into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading