Skip to content

Commit

Permalink
fix: fetch_core_users with ClusterShell
Browse files Browse the repository at this point in the history
  • Loading branch information
nicholasyang2022 committed Oct 23, 2023
1 parent c4c0153 commit 5057f87
Showing 1 changed file with 3 additions and 12 deletions.
15 changes: 3 additions & 12 deletions crmsh/bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 5057f87

Please sign in to comment.