VT now consumes all of it's data when looping using it's has_unread_data attribute

This commit is contained in:
Pedro Algarvio 2014-10-18 22:52:23 +01:00
parent ac9089e6f1
commit 84a791bfdc

View File

@ -6,6 +6,7 @@ Manage transport commands via ssh
# Import python libs # Import python libs
import re import re
import os import os
import json
import time import time
import logging import logging
import subprocess import subprocess
@ -313,52 +314,38 @@ class Shell(object):
sent_passwd = 0 sent_passwd = 0
ret_stdout = '' ret_stdout = ''
ret_stderr = '' ret_stderr = ''
while True:
stdout, stderr = term.recv() try:
if stdout: while term.has_unread_data:
ret_stdout += stdout stdout, stderr = term.recv()
if stderr: if stdout:
ret_stderr += stderr ret_stdout += stdout
if stdout and SSH_PASSWORD_PROMPT_RE.search(stdout): if stderr:
if len(stdout) > 256: ret_stderr += stderr
pass if stdout and SSH_PASSWORD_PROMPT_RE.search(stdout):
elif not self.passwd: if not self.passwd:
try: return '', 'Permission denied, no authentication information', 254
term.close(terminate=True, kill=True) if sent_passwd < passwd_retries:
except salt.utils.vt.TerminalException: term.sendline(self.passwd)
pass sent_passwd += 1
return '', 'Permission denied, no authentication information', 254 continue
if sent_passwd < passwd_retries: else:
term.sendline(self.passwd) # asking for a password, and we can't seem to send it
sent_passwd += 1 return '', 'Password authentication failed', 254
continue elif stdout and KEY_VALID_RE.search(stdout):
else: if key_accept:
# asking for a password, and we can't seem to send it term.sendline('yes')
try: continue
term.close(terminate=True, kill=True) else:
except salt.utils.vt.TerminalException: term.sendline('no')
pass ret_stdout = ('The host key needs to be accepted, to '
return '', 'Password authentication failed', 254 'auto accept run salt-ssh with the -i '
elif stdout and KEY_VALID_RE.search(stdout): 'flag:\n{0}').format(stdout)
if key_accept: return ret_stdout, '', 254
term.sendline('yes') elif stdout and stdout.endswith('_||ext_mods||_'):
continue mods_raw = json.dumps(self.mods, separators=(',', ':')) + '|_E|0|'
else: term.sendline(mods_raw)
term.sendline('no') time.sleep(0.5)
ret_stdout = ('The host key needs to be accepted, to ' return ret_stdout, ret_stderr, term.exitstatus
'auto accept run salt-ssh with the -i ' finally:
'flag:\n{0}').format(stdout) term.close(terminate=True, kill=True)
return ret_stdout, '', 254
if not term.isalive():
while True:
stdout, stderr = term.recv()
if stdout:
ret_stdout += stdout
if stderr:
ret_stderr += stderr
if stdout is None and stderr is None:
break
term.close(terminate=True, kill=True)
break
time.sleep(0.5)
return ret_stdout, ret_stderr, term.exitstatus