Skip to content

Commit

Permalink
Fix: forward ssh-agent for crm report __slave
Browse files Browse the repository at this point in the history
  • Loading branch information
nicholasyang2022 committed Nov 20, 2023
1 parent e331b44 commit 544abcd
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
10 changes: 9 additions & 1 deletion crmsh/report/collect.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import pwd
import datetime

import crmsh.user_of_host
from crmsh import log, sh
from crmsh import utils as crmutils
from crmsh.report import constants, utillib
Expand Down Expand Up @@ -56,7 +57,14 @@ def collect_ratraces():
"""
# since the "trace_dir" attribute been removed from cib after untrace
# need to parse crmsh log file to extract custom trace ra log directory on each node
shell = sh.cluster_shell()
if crmsh.user_of_host.instance().use_ssh_agent():
shell = sh.ClusterShell(
sh.LocalShell(additional_environ={'SSH_AUTH_SOCK': os.environ.get('SSH_AUTH_SOCK', '')}),
crmsh.user_of_host.instance(),
forward_ssh_agent=True,
)
else:
shell = sh.cluster_shell()
log_contents = ""
cmd = "grep 'INFO: Trace for .* is written to ' {}*|grep -v 'collect'".format(log.CRMSH_LOG_FILE)
for node in crmutils.list_cluster_nodes():
Expand Down
2 changes: 1 addition & 1 deletion crmsh/report/utillib.py
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ def get_distro_info():
res = re.search("PRETTY_NAME=\"(.*)\"", read_from_file(constants.OSRELEASE))
elif which("lsb_release"):
logger.debug("Using lsb_release to get distribution info")
out = sh.cluster_shell().get_stdout_or_raise_error("lsb_release -d")
out = sh.LocalShell().get_stdout_or_raise_error("lsb_release -d")
res = re.search("Description:\s+(.*)", out)
return res.group(1) if res else "Unknown"

Expand Down
3 changes: 3 additions & 0 deletions test/features/ssh_agent.feature
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,6 @@ Feature: ssh-agent support
Then Show cluster status on "hanode1"
When Run "crm resource start g-booth" on "hanode2"
Then Show cluster status on "hanode2"

Scenario: crm report
Then Run "SSH_AUTH_SOCK=/tmp/ssh-auth-sock crm report" OK

0 comments on commit 544abcd

Please sign in to comment.