From 5057f873de434a8fbacda125cc1ede622d5bd5ed Mon Sep 17 00:00:00 2001 From: nicholasyang Date: Mon, 23 Oct 2023 16:30:49 +0800 Subject: [PATCH] fix: fetch_core_users with ClusterShell --- crmsh/bootstrap.py | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/crmsh/bootstrap.py b/crmsh/bootstrap.py index 86a2344f3e..aba7708293 100644 --- a/crmsh/bootstrap.py +++ b/crmsh/bootstrap.py @@ -957,18 +957,9 @@ def _merge_authorized_keys(keys: typing.List[str]) -> bytes: return buf -def _fetch_core_hosts(local_user, remote_user, remote_host) -> typing.Tuple[typing.List[str], typing.List[str]]: +def _fetch_core_hosts(shell: sh.ClusterShell, remote_host) -> typing.Tuple[typing.List[str], typing.List[str]]: cmd = 'crm options show core.hosts' - result = sh.LocalShell().su_subprocess_run( - local_user, - f'ssh {SSH_OPTION} {remote_user}@{remote_host} sudo /bin/sh', - input=cmd.encode('utf-8'), - stdout=subprocess.PIPE, - stderr=subprocess.PIPE, - ) - if result.returncode != 0: - utils.fatal('Failed to run command "{}" on host {}: {}'.format(cmd, remote_host, result.stderr.decode('utf-8'))) - text = result.stdout.decode('utf-8') + text = shell.get_stdout_or_raise_error(cmd, remote_host) match = re.match('core\\.hosts\\s*=\\s*(.*)\\s*', text) if match is None: utils.fatal('Malformed core.hosts from host {}: {}'.format(remote_host, text)) @@ -2048,7 +2039,7 @@ def setup_passwordless_with_other_nodes(init_node, remote_user): user_by_host = utils.HostUserConfig() user_by_host.add(local_user, utils.this_node()) try: - user_list, host_list = _fetch_core_hosts(local_user, remote_user, init_node) + user_list, host_list = _fetch_core_hosts(shell, init_node) for user, host in zip(user_list, host_list): user_by_host.add(user, host) except ValueError: