|
|
@ -135,9 +135,15 @@ class ParamikoConnection(object):
|
|
|
|
|
|
|
|
|
|
|
|
def exec_command(self, cmd, tmp_path, sudoable=False): # pylint: disable-msg=W0613
|
|
|
|
def exec_command(self, cmd, tmp_path, sudoable=False): # pylint: disable-msg=W0613
|
|
|
|
''' run a command on the remote host '''
|
|
|
|
''' run a command on the remote host '''
|
|
|
|
|
|
|
|
bufsize = 4096 # Could make this a Runner param if needed
|
|
|
|
|
|
|
|
timeout_secs = self.runner.timeout # Reusing runner's TCP connect timeout as command progress timeout
|
|
|
|
|
|
|
|
chan = self.ssh.get_transport().open_session()
|
|
|
|
|
|
|
|
chan.settimeout(timeout_secs)
|
|
|
|
|
|
|
|
chan.get_pty() # Many sudo setups require a terminal; use in both cases for consistency
|
|
|
|
|
|
|
|
|
|
|
|
if not self.runner.sudo or not sudoable:
|
|
|
|
if not self.runner.sudo or not sudoable:
|
|
|
|
stdin, stdout, stderr = self.ssh.exec_command(cmd)
|
|
|
|
quoted_command = '"$SHELL" -c ' + pipes.quote(cmd)
|
|
|
|
return (stdin, stdout, stderr)
|
|
|
|
chan.exec_command(quoted_command)
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
# Rather than detect if sudo wants a password this time, -k makes
|
|
|
|
# Rather than detect if sudo wants a password this time, -k makes
|
|
|
|
# sudo always ask for a password if one is required. The "--"
|
|
|
|
# sudo always ask for a password if one is required. The "--"
|
|
|
@ -146,19 +152,11 @@ class ParamikoConnection(object):
|
|
|
|
# directly doesn't work, so we shellquote it with pipes.quote()
|
|
|
|
# directly doesn't work, so we shellquote it with pipes.quote()
|
|
|
|
# and pass the quoted string to the user's shell.
|
|
|
|
# and pass the quoted string to the user's shell.
|
|
|
|
sudocmd = 'sudo -k -- "$SHELL" -c ' + pipes.quote(cmd)
|
|
|
|
sudocmd = 'sudo -k -- "$SHELL" -c ' + pipes.quote(cmd)
|
|
|
|
bufsize = 4096 # Could make this a Runner param if needed
|
|
|
|
|
|
|
|
timeout_secs = self.runner.timeout # Reusing runner's TCP connect timeout as command progress timeout
|
|
|
|
|
|
|
|
chan = self.ssh.get_transport().open_session()
|
|
|
|
|
|
|
|
chan.settimeout(timeout_secs)
|
|
|
|
|
|
|
|
chan.get_pty() # Many sudo setups require a terminal
|
|
|
|
|
|
|
|
#print "exec_command: " + sudocmd
|
|
|
|
|
|
|
|
chan.exec_command(sudocmd)
|
|
|
|
chan.exec_command(sudocmd)
|
|
|
|
if self.runner.sudo_pass:
|
|
|
|
if self.runner.sudo_pass:
|
|
|
|
while not chan.recv_ready():
|
|
|
|
while not chan.recv_ready():
|
|
|
|
time.sleep(0.25)
|
|
|
|
time.sleep(0.25)
|
|
|
|
sudo_output = chan.recv(bufsize) # Pull prompt, catch errors, eat sudo output
|
|
|
|
sudo_output = chan.recv(bufsize) # Pull prompt, catch errors, eat sudo output
|
|
|
|
#print "exec_command: " + sudo_output
|
|
|
|
|
|
|
|
#print "exec_command: sending password"
|
|
|
|
|
|
|
|
chan.sendall(self.runner.sudo_pass + '\n')
|
|
|
|
chan.sendall(self.runner.sudo_pass + '\n')
|
|
|
|
|
|
|
|
|
|
|
|
stdin = chan.makefile('wb', bufsize)
|
|
|
|
stdin = chan.makefile('wb', bufsize)
|
|
|
|