74
74
"/etc/drbd.conf" , "/etc/drbd.d" , "/etc/ha.d/ldirectord.cf" , "/etc/lvm/lvm.conf" , "/etc/multipath.conf" ,
75
75
"/etc/samba/smb.conf" , SYSCONFIG_NFS , SYSCONFIG_PCMK , SYSCONFIG_SBD , PCMK_REMOTE_AUTH , WATCHDOG_CFG ,
76
76
PROFILES_FILE , CRM_CFG , SBD_SYSTEMD_DELAY_START_DIR )
77
- INIT_STAGES = ("ssh" , "csync2" , "csync2_remote" , "qnetd_remote" , "corosync" , "remote_auth" , "sbd" , "cluster" , "ocfs2" , "admin" , "qdevice" )
77
+
78
+ INIT_STAGES_EXTERNAL = ("ssh" , "csync2" , "corosync" , "sbd" , "cluster" , "ocfs2" , "admin" , "qdevice" )
79
+ INIT_STAGES_INTERNAL = ("csync2_remote" , "qnetd_remote" , "remote_auth" )
80
+ INIT_STAGES_ALL = INIT_STAGES_EXTERNAL + INIT_STAGES_INTERNAL
81
+ JOIN_STAGES_EXTERNAL = ("ssh" , "csync2" , "ssh_merge" , "cluster" )
78
82
79
83
80
84
class Context (object ):
@@ -247,15 +251,40 @@ def _validate_cluster_node(self):
247
251
"""
248
252
Validate cluster_node on join side
249
253
"""
250
- if self .cluster_node and self . type == ' join' :
254
+ if self .type == " join" and self . cluster_node :
251
255
user , node = _parse_user_at_host (self .cluster_node , None )
252
256
try :
253
257
# self.cluster_node might be hostname or IP address
254
258
ip_addr = socket .gethostbyname (node )
255
259
if utils .InterfacesInfo .ip_in_local (ip_addr ):
256
260
utils .fatal ("Please specify peer node's hostname or IP address" )
257
261
except socket .gaierror as err :
258
- utils .fatal ("\" {}\" : {}" .format (node , err ))
262
+ utils .fatal (f"\" { node } \" : { err } " )
263
+
264
+ def _validate_stage (self ):
265
+ """
266
+ Validate stage argument
267
+ """
268
+ if not self .stage :
269
+ if self .cluster_is_running :
270
+ utils .fatal ("Cluster is already running!" )
271
+ return
272
+
273
+ if self .type == "init" :
274
+ if self .stage not in INIT_STAGES_ALL :
275
+ utils .fatal (f"Invalid stage: { self .stage } (available stages: { ', ' .join (INIT_STAGES_EXTERNAL )} )" )
276
+ if self .stage in ("admin" , "qdevice" , "ocfs2" ) and not self .cluster_is_running :
277
+ utils .fatal (f"Cluster is inactive, can't run '{ self .stage } ' stage" )
278
+ if self .stage in ("corosync" , "cluster" ) and self .cluster_is_running :
279
+ utils .fatal (f"Cluster is active, can't run '{ self .stage } ' stage" )
280
+
281
+ elif self .type == "join" :
282
+ if self .stage not in JOIN_STAGES_EXTERNAL :
283
+ utils .fatal (f"Invalid stage: { self .stage } (available stages: { ', ' .join (JOIN_STAGES_EXTERNAL )} )" )
284
+ if self .stage and self .cluster_node is None :
285
+ utils .fatal (f"Can't use stage({ self .stage } ) without specifying cluster node" )
286
+ if self .stage in ("cluster" , ) and self .cluster_is_running :
287
+ utils .fatal (f"Cluster is active, can't run '{ self .stage } ' stage" )
259
288
260
289
def validate_option (self ):
261
290
"""
@@ -269,6 +298,7 @@ def validate_option(self):
269
298
self .skip_csync2 = utils .get_boolean (os .getenv ("SKIP_CSYNC2_SYNC" ))
270
299
if self .skip_csync2 and self .stage :
271
300
utils .fatal ("-x option or SKIP_CSYNC2_SYNC can't be used with any stage" )
301
+ self ._validate_stage ()
272
302
self ._validate_network_options ()
273
303
self ._validate_cluster_node ()
274
304
self ._validate_nodes_option ()
@@ -2112,23 +2142,10 @@ def bootstrap_init(context):
2112
2142
"""
2113
2143
global _context
2114
2144
_context = context
2145
+ stage = _context .stage
2115
2146
2116
2147
init ()
2117
2148
2118
- stage = _context .stage
2119
- if stage is None :
2120
- stage = ""
2121
-
2122
- if stage in ("admin" , "qdevice" , "ocfs2" ):
2123
- if not _context .cluster_is_running :
2124
- utils .fatal ("Cluster is inactive - can't run %s stage" % (stage ))
2125
- elif stage == "" :
2126
- if _context .cluster_is_running :
2127
- utils .fatal ("Cluster is currently active - can't run" )
2128
- elif stage not in ("ssh" , "csync2" , "csync2_remote" , "qnetd_remote" , "sbd" , "ocfs2" ):
2129
- if _context .cluster_is_running :
2130
- utils .fatal ("Cluster is currently active - can't run %s stage" % (stage ))
2131
-
2132
2149
_context .load_profiles ()
2133
2150
_context .init_sbd_manager ()
2134
2151
@@ -2228,10 +2245,6 @@ def bootstrap_join(context):
2228
2245
2229
2246
check_tty ()
2230
2247
2231
- corosync_active = ServiceManager (sh .ClusterShellAdaptorForLocalShell (sh .LocalShell ())).service_is_active ("corosync.service" )
2232
- if corosync_active and _context .stage != "ssh" :
2233
- utils .fatal ("Abort: Cluster is currently active. Run this command on a node joining the cluster." )
2234
-
2235
2248
if not check_prereqs ("join" ):
2236
2249
return
2237
2250
0 commit comments