Skip to content

Commit cbb6a8b

Browse files
authored
Dev: ui_cluster: Improve 'rename' subcommand (ClusterLabs#2079)
Changes: - To compare the input new name with the current cluster name, get the value from corosync.conf, instead of cluster property - Improve the log to increase clarity - Hint the user to use `crm cluster rename` command when detecting cluster name conflict
2 parents 89daedf + 6b7ec7f commit cbb6a8b

3 files changed

Lines changed: 14 additions & 14 deletions

File tree

crmsh/qdevice.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,11 @@ def validate_and_start_qnetd(self):
271271
cmd = f"corosync-qnetd-tool -l -c {self.cluster_name}"
272272
if shell.get_stdout_or_raise_error(cmd, self.qnetd_addr):
273273
exception_msg = f"This cluster's name \"{self.cluster_name}\" already exists on qnetd server!"
274-
suggestion_msg = "Please consider to use the different cluster-name property"
274+
if self.is_stage:
275+
suggestion_msg = "Please consider to use `crm cluster rename` to change a different cluster name."
276+
else:
277+
suggestion_msg = "Please consider to use -n option to specify a different cluster name."
278+
suggestion_msg += "\nOr, run `crm cluster remove --qdevice` on the existing cluster beforehand."
275279
else:
276280
exception_msg = f"Package \"corosync-qnetd\" not installed on {self.qnetd_addr}!"
277281
suggestion_msg = f"Please install \"corosync-qnetd\" on {self.qnetd_addr}"

crmsh/ui_cluster.py

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -611,23 +611,19 @@ def do_rename(self, context, new_name):
611611
logger.info(suggestion)
612612
return
613613

614-
cib_factory = cibconfig.cib_factory_instance()
615-
old_name = cib_factory.get_property('cluster-name')
614+
old_name = corosync.get_value('totem.cluster_name')
616615
if old_name and new_name == old_name:
617-
context.fatal_error("Expected a different name")
618-
619-
# Update config file with the new name on all nodes
620-
nodes = utils.list_cluster_nodes()
616+
context.fatal_error("Expected a different cluster name")
617+
logger.info("Setting totem.cluster_name to %s in corosync.conf", new_name)
621618
corosync.set_value('totem.cluster_name', new_name)
619+
620+
nodes = utils.list_cluster_nodes_except_me()
622621
if len(nodes) > 1:
623-
nodes.remove(utils.this_node())
624-
context.info("Copy cluster config file to \"{}\"".format(' '.join(nodes)))
622+
logger.info("Syncing corosync.conf to other nodes in the cluster")
625623
corosync.push_configuration(nodes)
626624

627-
# Change the cluster-name property in the CIB
628-
cib_factory.create_object("property", "cluster-name={}".format(new_name))
629-
if not cib_factory.commit():
630-
context.fatal_error("Change property cluster-name failed!")
625+
logger.info("Setting cluster-name property to %s in CIB", new_name)
626+
utils.set_property("cluster-name", new_name)
631627

632628
if xmlutil.CrmMonXmlParser().is_non_stonith_resource_running():
633629
context.info("To apply the change, restart the cluster service at convenient time")

test/unittests/test_qdevice.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ def test_validate_and_start_qnetd_duplicated_cluster_name(
295295
mock_cluster_shell.return_value = mock_cluster_inst
296296
mock_cluster_inst.get_stdout_or_raise_error.return_value = "data"
297297
mock_installed.return_value = True
298-
excepted_err_string = "This cluster's name \"cluster1\" already exists on qnetd server!\nPlease consider to use the different cluster-name property"
298+
excepted_err_string = "This cluster's name \"cluster1\" already exists on qnetd server!\nPlease consider to use `crm cluster rename` to change a different cluster name.\nOr, run `crm cluster remove --qdevice` on the existing cluster beforehand."
299299

300300
with self.assertRaises(ValueError) as err:
301301
self.qdevice_with_stage_cluster_name.validate_and_start_qnetd()

0 commit comments

Comments
 (0)