Skip to content

Commit 284d481

Browse files
committed
Dev: bootstrap: Setup the stage dependency on init and join side
1 parent 931acda commit 284d481

File tree

1 file changed

+65
-0
lines changed

1 file changed

+65
-0
lines changed

crmsh/bootstrap.py

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2136,6 +2136,70 @@ def remove_node_from_cluster(node):
21362136
invoke("corosync-cfgtool -R")
21372137

21382138

2139+
def ssh_stage_finished():
2140+
"""
2141+
Dectect if the ssh stage is finished
2142+
"""
2143+
key_file_manager = ssh_key.KeyFileManager(sh.cluster_shell())
2144+
keys = key_file_manager.list_public_key_for_user(None, 'hacluster')
2145+
return bool(keys)
2146+
2147+
2148+
def csync2_stage_finished():
2149+
"""
2150+
Dectect if the csync2 stage is finished
2151+
"""
2152+
return ServiceManager().service_is_active(CSYNC2_SERVICE)
2153+
2154+
2155+
def corosync_stage_finished():
2156+
"""
2157+
Dectect if the corosync stage is finished
2158+
"""
2159+
try:
2160+
conf_parser.ConfParser.verify_config_file()
2161+
except ValueError as e:
2162+
logger.error(e)
2163+
return False
2164+
return True
2165+
2166+
2167+
INIT_STAGES_DEPENDENCY_MAP = {
2168+
# stage: (function, is_internal)
2169+
"ssh": (ssh_stage_finished, False),
2170+
"csync2": (csync2_stage_finished, False),
2171+
"corosync": (corosync_stage_finished, False),
2172+
"remote_auth": (init_remote_auth, True),
2173+
"sbd": (lambda: True, False),
2174+
"upgradeutil": (init_upgradeutil, True),
2175+
"cluster": (is_online, False)
2176+
}
2177+
2178+
2179+
JOIN_STAGES_DEPENDENCY_MAP = {
2180+
# stage: (function, is_internal)
2181+
"ssh": (ssh_stage_finished, False),
2182+
"csync2": (csync2_stage_finished, False),
2183+
"ssh_merge": (lambda: True, False),
2184+
"cluster": (is_online, False)
2185+
}
2186+
2187+
2188+
def check_stage_dependency(stage):
2189+
"""
2190+
"""
2191+
dependency_map = INIT_STAGES_DEPENDENCY_MAP if _context.type == "init" else JOIN_STAGES_DEPENDENCY_MAP
2192+
if stage not in dependency_map:
2193+
return
2194+
for stage_name, (func, is_internal) in dependency_map.items():
2195+
if stage_name == stage:
2196+
break
2197+
if is_internal:
2198+
func()
2199+
elif not func():
2200+
utils.fatal(f"Please run '{stage_name}' stage first")
2201+
2202+
21392203
def bootstrap_init(context):
21402204
"""
21412205
Init cluster process
@@ -2163,6 +2227,7 @@ def bootstrap_init(context):
21632227
_context.node_list_in_cluster = [utils.this_node()]
21642228

21652229
if stage != "":
2230+
check_stage_dependency(stage)
21662231
globals()["init_" + stage]()
21672232
else:
21682233
init_ssh()

0 commit comments

Comments
 (0)