Skip to content

Commit

Permalink
Merge pull request #1223 from nicholasyang2022/upgradeutil_timeout_4.4
Browse files Browse the repository at this point in the history
[crmsh-4.4] Fix: upgradeutil: reduce ConnectTimeout when checking the availability of ssh access (bsc#1213797)
  • Loading branch information
liangxin1300 authored Aug 2, 2023
2 parents eb94f41 + 2ec3067 commit 50accdf
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
5 changes: 4 additions & 1 deletion crmsh/upgradeutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
# touch this file to force a upgrade process
FORCE_UPGRADE_FILE_PATH = DATA_DIR + '/upgrade_forced'

TIMEOUT_CHECK_SSH_AVAILABLE = 3


VERSION_FEATURES = {
(1, 0): [crmsh.healthcheck.PasswordlessHaclusterAuthenticationFeature]
Expand Down Expand Up @@ -140,7 +142,8 @@ def upgrade_if_needed():
if not crmsh.utils.can_ask(background_wait=False):
return
nodes = crmsh.utils.list_cluster_nodes(no_reg=True)
if nodes and _is_upgrade_needed(nodes) and not crmsh.utils.check_passwordless_between_nodes(nodes):
if nodes and _is_upgrade_needed(nodes) \
and not crmsh.utils.check_passwordless_between_nodes(nodes, timeout_seconds=TIMEOUT_CHECK_SSH_AVAILABLE):
logger.debug("upgradeutil: configuration fix needed")
try:
if not _is_cluster_target_seq_consistent(nodes):
Expand Down
12 changes: 6 additions & 6 deletions crmsh/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2104,18 +2104,18 @@ def get_iplist_corosync_using():
return re.findall(r'id\s*=\s*(.*)', out)


def check_ssh_passwd_need(host, user="root"):
def check_ssh_passwd_need(host, user="root", timeout_seconds=15):
"""
Check whether access to host need password
"""
ssh_options = "-o StrictHostKeyChecking=no -o EscapeChar=none -o ConnectTimeout=15"
ssh_options = f"-o StrictHostKeyChecking=no -o EscapeChar=none -o ConnectTimeout={timeout_seconds}"
ssh_cmd = "ssh {} -T -o Batchmode=yes {} true".format(ssh_options, host)
ssh_cmd = add_su(ssh_cmd, user)
rc, _, _ = get_stdout_stderr(ssh_cmd)
return rc != 0


def check_passwordless_between_nodes(node_list, user='root'):
def check_passwordless_between_nodes(node_list, user='root', timeout_seconds=15):
"""
Check passwordless between cluster nodes
Suppose each node has the same user
Expand All @@ -2127,7 +2127,7 @@ def check_passwordless_between_nodes(node_list, user='root'):
for node in node_list:
if node == me:
continue
if check_ssh_passwd_need(node, user):
if check_ssh_passwd_need(node, user, timeout_seconds=timeout_seconds):
need_pw_pair_list.append((me, node))

if not need_pw_pair_list:
Expand All @@ -2136,9 +2136,9 @@ def check_passwordless_between_nodes(node_list, user='root'):
if node == n or node == me:
continue
if user == 'root':
cmd = f"ssh {node} \"ssh {SSH_OPTION} -T -o Batchmode=yes {user}@{n} true\""
cmd = f"ssh {node} \"ssh {SSH_OPTION} -o ConnectTimeout={timeout_seconds} -T -o Batchmode=yes {user}@{n} true\""
else:
cmd = f"ssh {node} \"su - {user} -c 'ssh {SSH_OPTION} -T -o Batchmode=yes {user}@{n} true'\""
cmd = f"ssh {node} \"su - {user} -c 'ssh {SSH_OPTION} -o ConnectTimeout={timeout_seconds} -T -o Batchmode=yes {user}@{n} true'\""
rc, _, _ = get_stdout_stderr(cmd)
if rc != 0:
need_pw_pair_list.append((node, n))
Expand Down

0 comments on commit 50accdf

Please sign in to comment.