@@ -61,7 +61,7 @@ def _ellide_log_lines(log):
61
61
return "\n {}" .format ("\n " .join (reduced_message ))
62
62
63
63
def _ssh (hostname_or_ip , cmd , check , simple_output , suppress_fingerprint_warnings ,
64
- background , target_os , decode , options ):
64
+ background , decode , options ):
65
65
opts = list (options )
66
66
opts .append ('-o "BatchMode yes"' )
67
67
if suppress_fingerprint_warnings :
@@ -76,17 +76,11 @@ def _ssh(hostname_or_ip, cmd, check, simple_output, suppress_fingerprint_warning
76
76
command = cmd
77
77
else :
78
78
command = " " .join (cmd )
79
- if background and target_os != "windows" :
80
- # https://stackoverflow.com/questions/29142/getting-ssh-to-execute-a-command-in-the-background-on-target-machine
81
- # ... and run the command through a bash shell so that output redirection both works on Linux and FreeBSD.
82
- # Bash being available on VMs is a documented requirement.
83
- command = "nohup bash -c \" %s &>/dev/null &\" " % command
84
79
85
80
ssh_cmd = f"ssh root@{ hostname_or_ip } { ' ' .join (opts )} { shlex .quote (command )} "
86
81
87
- windows_background = background and target_os == "windows"
88
82
# Fetch banner and remove it to avoid stdout/stderr pollution.
89
- if config .ignore_ssh_banner and not windows_background :
83
+ if config .ignore_ssh_banner :
90
84
banner_res = subprocess .run (
91
85
"ssh root@%s %s '%s'" % (hostname_or_ip , ' ' .join (opts ), '\n ' ),
92
86
shell = True ,
@@ -95,15 +89,15 @@ def _ssh(hostname_or_ip, cmd, check, simple_output, suppress_fingerprint_warning
95
89
check = False
96
90
)
97
91
92
+ logging .debug (f"[{ hostname_or_ip } ] { command } " )
98
93
process = subprocess .Popen (
99
94
ssh_cmd ,
100
95
shell = True ,
101
96
stdout = subprocess .PIPE ,
102
97
stderr = subprocess .STDOUT
103
98
)
104
- logging .debug (f"[{ hostname_or_ip } ] { command } " )
105
- if windows_background :
106
- return True , process
99
+ if background :
100
+ return True , None
107
101
108
102
stdout = []
109
103
for line in iter (process .stdout .readline , b'' ):
@@ -140,9 +134,9 @@ def _ssh(hostname_or_ip, cmd, check, simple_output, suppress_fingerprint_warning
140
134
# This function is kept short for shorter pytest traces upon SSH failures, which are common,
141
135
# as pytest prints the whole function definition that raised the SSHCommandFailed exception
142
136
def ssh (hostname_or_ip , cmd , check = True , simple_output = True , suppress_fingerprint_warnings = True ,
143
- background = False , target_os = 'linux' , decode = True , options = []):
137
+ background = False , decode = True , options = []):
144
138
success , result_or_exc = _ssh (hostname_or_ip , cmd , check , simple_output , suppress_fingerprint_warnings ,
145
- background , target_os , decode , options )
139
+ background , decode , options )
146
140
if not success :
147
141
raise result_or_exc
148
142
return result_or_exc
0 commit comments