Skip to content

Commit 7fed1b8

Browse files
authored
Merge pull request #1377 from liangxin1300/20240402_revert_list_cluster_nodes_return_ip
Fix: ui_node: When `utils.list_cluster_nodes` return None, try to get…
2 parents ed9189d + 8618f74 commit 7fed1b8

File tree

5 files changed

+15
-25
lines changed

5 files changed

+15
-25
lines changed

crmsh/ui_node.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -246,9 +246,12 @@ def parse_option_for_nodes(context, *args):
246246
# return local node
247247
if (not options.all and not args) or (len(args) == 1 and args[0] == utils.this_node()):
248248
return [utils.this_node()]
249-
member_list = utils.list_cluster_nodes()
249+
member_list = utils.list_cluster_nodes() or utils.get_address_list_from_corosync_conf()
250250
if not member_list:
251251
context.fatal_error("Cannot get the node list from cluster")
252+
for node in args:
253+
if node not in member_list:
254+
context.fatal_error(f"Node '{node}' is not a member of the cluster")
252255

253256
node_list = member_list if options.all else args
254257
for node in node_list:

crmsh/utils.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1775,10 +1775,10 @@ def list_cluster_nodes(no_reg=False):
17751775
else:
17761776
cib_path = os.getenv('CIB_file', constants.CIB_RAW_FILE)
17771777
if not os.path.isfile(cib_path):
1778-
return get_address_list_from_corosync_conf()
1778+
return None
17791779
cib = xmlutil.file2cib_elem(cib_path)
17801780
if cib is None:
1781-
return get_address_list_from_corosync_conf()
1781+
return None
17821782

17831783
node_list = []
17841784
for node in cib.xpath(constants.XML_NODE_PATH):

test/features/bootstrap_bugs.feature

+3
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,9 @@ Feature: Regression test for bootstrap bugs
152152
Then Cluster service is "started" on "hanode1"
153153
Then Cluster service is "started" on "hanode2"
154154

155+
When Try "crm cluster start xxx"
156+
Then Except "ERROR: cluster.start: Node 'xxx' is not a member of the cluster"
157+
155158
@clean
156159
Scenario: Can't stop all nodes' cluster service when local node's service is down(bsc#1213889)
157160
Given Cluster service is "stopped" on "hanode1"

test/features/crm_report_normal.feature

+2-1
Original file line numberDiff line numberDiff line change
@@ -105,4 +105,5 @@ Feature: crm report functional test for common cases
105105
When Run "crm cluster stop --all" on "hanode1"
106106
When Run "rm -f /var/lib/pacemaker/cib/cib*" on "hanode1"
107107
When Run "rm -f /var/lib/pacemaker/cib/cib*" on "hanode2"
108-
When Run "crm report" OK
108+
When Try "crm report" on "hanode1"
109+
Then Expected "Could not figure out a list of nodes; is this a cluster node" in stderr

test/unittests/test_utils.py

+4-21
Original file line numberDiff line numberDiff line change
@@ -1079,43 +1079,26 @@ def test_is_quorate(mock_run):
10791079
mock_run_inst.get_stdout_or_raise_error.assert_called_once_with("corosync-quorumtool -s", None, success_exit_status={0, 2})
10801080

10811081

1082-
@mock.patch('crmsh.utils.get_address_list_from_corosync_conf')
10831082
@mock.patch('crmsh.utils.etree.fromstring')
10841083
@mock.patch('crmsh.sh.ShellUtils.get_stdout_stderr')
1085-
def test_list_cluster_nodes_none(mock_run, mock_etree, mock_corosync):
1084+
def test_list_cluster_nodes_none(mock_run, mock_etree):
10861085
mock_run.return_value = (0, "data", None)
10871086
mock_etree.return_value = None
1088-
mock_corosync.return_value = ["node1", "node2"]
10891087
res = utils.list_cluster_nodes()
1090-
assert res == ["node1", "node2"]
1088+
assert res is None
10911089
mock_run.assert_called_once_with(constants.CIB_QUERY, no_reg=False)
10921090
mock_etree.assert_called_once_with("data")
10931091

10941092

1095-
@mock.patch('crmsh.utils.get_address_list_from_corosync_conf')
1096-
@mock.patch('crmsh.utils.etree.fromstring')
1097-
@mock.patch('crmsh.sh.ShellUtils.get_stdout_stderr')
1098-
def test_list_cluster_nodes_none_no_reg(mock_run, mock_etree, mock_corosync):
1099-
mock_run.return_value = (0, "data", None)
1100-
mock_etree.return_value = None
1101-
mock_corosync.return_value = ["node1", "node2"]
1102-
res = utils.list_cluster_nodes(no_reg=True)
1103-
assert res == ["node1", "node2"]
1104-
mock_run.assert_called_once_with(constants.CIB_QUERY, no_reg=True)
1105-
mock_etree.assert_called_once_with("data")
1106-
1107-
1108-
@mock.patch('crmsh.utils.get_address_list_from_corosync_conf')
11091093
@mock.patch('os.path.isfile')
11101094
@mock.patch('os.getenv')
11111095
@mock.patch('crmsh.sh.ShellUtils.get_stdout_stderr')
1112-
def test_list_cluster_nodes_cib_not_exist(mock_run, mock_env, mock_isfile, mock_corosync):
1096+
def test_list_cluster_nodes_cib_not_exist(mock_run, mock_env, mock_isfile):
11131097
mock_run.return_value = (1, None, None)
11141098
mock_env.return_value = constants.CIB_RAW_FILE
11151099
mock_isfile.return_value = False
1116-
mock_corosync.return_value = ["node1", "node2"]
11171100
res = utils.list_cluster_nodes()
1118-
assert res == ["node1", "node2"]
1101+
assert res is None
11191102
mock_run.assert_called_once_with(constants.CIB_QUERY, no_reg=False)
11201103
mock_env.assert_called_once_with("CIB_file", constants.CIB_RAW_FILE)
11211104
mock_isfile.assert_called_once_with(constants.CIB_RAW_FILE)

0 commit comments

Comments
 (0)