Skip to content

Commit

Permalink
fixup: detect ssh availability when joining
Browse files Browse the repository at this point in the history
  • Loading branch information
nicholasyang2022 committed Oct 23, 2023
1 parent d0e0866 commit 462d1b8
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion crmsh/bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -1789,7 +1789,14 @@ def join_ssh_with_ssh_agent(
):
# As ssh-agent is used, the local_user does not have any effects
shell = sh.SSHShell(local_shell, 'root')
# FIXME: detect the availability of ssh session
if not shell.can_run_as(seed_host, seed_user):
raise ValueError(f'Failed to login to {seed_user}@{seed_host}')
if seed_user != 'root' and 0 != shell.subprocess_run_without_input(
seed_host, seed_user, 'sudo true',
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL,
).returncode:
raise ValueError(f'Failed to sudo on {seed_user}@{seed_host}')
authorized_key_manager = ssh_key.AuthorizedKeyManager(shell)
for key in ssh_public_keys:
authorized_key_manager.add(None, local_user, key)
Expand Down

0 comments on commit 462d1b8

Please sign in to comment.