@@ -2136,6 +2136,70 @@ def remove_node_from_cluster(node):
2136
2136
invoke ("corosync-cfgtool -R" )
2137
2137
2138
2138
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
+
2139
2203
def bootstrap_init (context ):
2140
2204
"""
2141
2205
Init cluster process
@@ -2163,6 +2227,7 @@ def bootstrap_init(context):
2163
2227
_context .node_list_in_cluster = [utils .this_node ()]
2164
2228
2165
2229
if stage != "" :
2230
+ check_stage_dependency (stage )
2166
2231
globals ()["init_" + stage ]()
2167
2232
else :
2168
2233
init_ssh ()
0 commit comments