Skip to content

Commit 2b5310b

Browse files
authored
Merge pull request #1137 from liangxin1300/20230302_sudo_crm_node
Dev: bootstrap: Add sudo before crm_node under non-root user on remote node
2 parents fc28249 + e2961b8 commit 2b5310b

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

crmsh/bootstrap.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1927,7 +1927,7 @@ def setup_passwordless_with_other_nodes(init_node):
19271927
# Fetch cluster nodes list
19281928
remote_user = _context.user_list[0]
19291929
local_user = _context.current_user
1930-
cmd = 'ssh {} {}@{} PATH=\\"\\$PATH\\":/usr/sbin:/sbin crm_node -l'.format(SSH_OPTION, remote_user, init_node)
1930+
cmd = f'ssh {SSH_OPTION} {remote_user}@{init_node} sudo crm_node -l'
19311931
rc, out, err = utils.su_get_stdout_stderr(local_user, cmd)
19321932
if rc != 0:
19331933
utils.fatal("Can't fetch cluster nodes list from {}: {}".format(init_node, err))

test/unittests/test_bootstrap.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -561,7 +561,7 @@ def test_setup_passwordless_with_other_nodes_failed_fetch_nodelist(self, mock_ru
561561
with self.assertRaises(SystemExit):
562562
bootstrap.setup_passwordless_with_other_nodes("node1")
563563

564-
mock_run.assert_called_once_with('carol', 'ssh {} alice@node1 PATH=\\"\\$PATH\\":/usr/sbin:/sbin crm_node -l'.format(constants.SSH_OPTION))
564+
mock_run.assert_called_once_with('carol', 'ssh {} alice@node1 sudo crm_node -l'.format(constants.SSH_OPTION))
565565
mock_error.assert_called_once_with("Can't fetch cluster nodes list from node1: None")
566566

567567
@mock.patch('crmsh.utils.fatal')
@@ -589,7 +589,7 @@ def test_setup_passwordless_with_other_nodes_failed_fetch_hostname(
589589
bootstrap.setup_passwordless_with_other_nodes("node1")
590590

591591
mock_run.assert_has_calls([
592-
mock.call('carol', 'ssh {} alice@node1 PATH=\\"\\$PATH\\":/usr/sbin:/sbin crm_node -l'.format(constants.SSH_OPTION)),
592+
mock.call('carol', 'ssh {} alice@node1 sudo crm_node -l'.format(constants.SSH_OPTION)),
593593
mock.call('carol', 'ssh {} alice@node1 hostname'.format(constants.SSH_OPTION))
594594
])
595595
mock_error.assert_called_once_with("Can't fetch hostname of node1: None")
@@ -623,7 +623,7 @@ def test_setup_passwordless_with_other_nodes(
623623
bootstrap.setup_passwordless_with_other_nodes("node1")
624624

625625
mock_run.assert_has_calls([
626-
mock.call('carol', 'ssh {} alice@node1 PATH=\\"\\$PATH\\":/usr/sbin:/sbin crm_node -l'.format(constants.SSH_OPTION)),
626+
mock.call('carol', 'ssh {} alice@node1 sudo crm_node -l'.format(constants.SSH_OPTION)),
627627
mock.call('carol', 'ssh {} alice@node1 hostname'.format(constants.SSH_OPTION))
628628
])
629629
mock_userof.assert_called_once_with("node2")

0 commit comments

Comments
 (0)