error: [Errno 9] Bad file descriptor
Change-Id: I4c5278d41e979f6af43054e3b5890fb154555494
Signed-off-by: Peter Mikus <pmikus@cisco.com>
__LINUX_PROMPT = (":~$ ", "~]$ ", "~]# ")
def __init__(self, node, json_param=True):
__LINUX_PROMPT = (":~$ ", "~]$ ", "~]# ")
def __init__(self, node, json_param=True):
- """TODO: Should we document this constructor can raise RuntimeError?"""
json_text = ' json' if json_param else ''
self.json = json_param
self._node = node
json_text = ' json' if json_param else ''
self.json = json_param
self._node = node
self._ssh.connect(self._node)
try:
self._tty = self._ssh.interactive_terminal_open()
self._ssh.connect(self._node)
try:
self._tty = self._ssh.interactive_terminal_open()
raise RuntimeError("Cannot open interactive terminal on node {0}".
format(self._node))
raise RuntimeError("Cannot open interactive terminal on node {0}".
format(self._node))
self._tty,
'sudo -S {0}{1}'.format(Constants.VAT_BIN_NAME, json_text),
self.__VAT_PROMPT)
self._tty,
'sudo -S {0}{1}'.format(Constants.VAT_BIN_NAME, json_text),
self.__VAT_PROMPT)
"""Execute command on the opened VAT terminal.
:param cmd: Command to be executed.
"""Execute command on the opened VAT terminal.
:param cmd: Command to be executed.
:returns: Command output in python representation of JSON format or
None if not in JSON mode.
:returns: Command output in python representation of JSON format or
None if not in JSON mode.
- :raise RuntimeError: If VAT command execution fails.
"""
VatHistory.add_to_vat_history(self._node, cmd)
logger.debug("Executing command in VAT terminal: {0}".format(cmd))
"""
VatHistory.add_to_vat_history(self._node, cmd)
logger.debug("Executing command in VAT terminal: {0}".format(cmd))
out = self._ssh.interactive_terminal_exec_command(self._tty, cmd,
self.__VAT_PROMPT)
self.vat_stdout = out
out = self._ssh.interactive_terminal_exec_command(self._tty, cmd,
self.__VAT_PROMPT)
self.vat_stdout = out
self._exec_failure = True
vpp_pid = get_vpp_pid(self._node)
if vpp_pid:
self._exec_failure = True
vpp_pid = get_vpp_pid(self._node)
if vpp_pid:
for line_tmpl in cmd_template:
vat_cmd = line_tmpl.format(**args)
ret.append(self.vat_terminal_exec_cmd(vat_cmd.replace('\n', '')))
for line_tmpl in cmd_template:
vat_cmd = line_tmpl.format(**args)
ret.append(self.vat_terminal_exec_cmd(vat_cmd.replace('\n', '')))
+ return ret
\ No newline at end of file
format(self._ssh.get_transport().getpeername()))
logger.debug('Connections: {0}'.
format(str(SSH.__existing_connections)))
format(self._ssh.get_transport().getpeername()))
logger.debug('Connections: {0}'.
format(str(SSH.__existing_connections)))
- except RuntimeError as exc:
if attempts > 0:
self._reconnect(attempts-1)
else:
if attempts > 0:
self._reconnect(attempts-1)
else:
def disconnect(self, node):
"""Close SSH connection to the node.
def disconnect(self, node):
"""Close SSH connection to the node.
def interactive_terminal_open(self, time_out=30):
"""Open interactive terminal on a new channel on the connected Node.
def interactive_terminal_open(self, time_out=30):
"""Open interactive terminal on a new channel on the connected Node.
- FIXME: Convert or document other possible exceptions, such as
- socket.error or SSHException.
+ :param time_out: Timeout in seconds.
+ :returns: SSH channel with opened terminal.
.. warning:: Interruptingcow is used here, and it uses
signal(SIGALRM) to let the operating system interrupt program
.. warning:: Interruptingcow is used here, and it uses
signal(SIGALRM) to let the operating system interrupt program
handlers only apply to the main thread, so you cannot use this
from other threads. You must not use this in a program that
uses SIGALRM itself (this includes certain profilers)
handlers only apply to the main thread, so you cannot use this
from other threads. You must not use this in a program that
uses SIGALRM itself (this includes certain profilers)
-
- :param time_out: Timeout in seconds.
- :returns: SSH channel with opened terminal.
- :raise IOError: If receive attempt results in socket.timeout.
"""
chan = self._ssh.get_transport().open_session()
chan.get_pty()
"""
chan = self._ssh.get_transport().open_session()
chan.get_pty()
break
except socket.timeout:
logger.error('Socket timeout: {0}'.format(buf))
break
except socket.timeout:
logger.error('Socket timeout: {0}'.format(buf))
- # TODO: Find out which exception would callers appreciate here.
- raise IOError('Socket timeout: {0}'.format(buf))
+ raise Exception('Socket timeout: {0}'.format(buf))
return chan
def interactive_terminal_exec_command(self, chan, cmd, prompt):
return chan
def interactive_terminal_exec_command(self, chan, cmd, prompt):
interactive_terminal_open() method has to be called first!
interactive_terminal_open() method has to be called first!
+ :param chan: SSH channel with opened terminal.
+ :param cmd: Command to be executed.
+ :param prompt: Command prompt, sequence of characters used to
+ indicate readiness to accept commands.
+ :returns: Command output.
+
.. warning:: Interruptingcow is used here, and it uses
signal(SIGALRM) to let the operating system interrupt program
execution. This has the following limitations: Python signal
handlers only apply to the main thread, so you cannot use this
from other threads. You must not use this in a program that
uses SIGALRM itself (this includes certain profilers)
.. warning:: Interruptingcow is used here, and it uses
signal(SIGALRM) to let the operating system interrupt program
execution. This has the following limitations: Python signal
handlers only apply to the main thread, so you cannot use this
from other threads. You must not use this in a program that
uses SIGALRM itself (this includes certain profilers)
-
- :param chan: SSH channel with opened terminal.
- :param cmd: Command to be executed.
- :param prompt: Command prompt, sequence of characters used to
- indicate readiness to accept commands.
- :returns: Command output.
- :raise IOError: If receive attempt results in socket.timeout.
"""
chan.sendall('{c}\n'.format(c=cmd))
buf = ''
"""
chan.sendall('{c}\n'.format(c=cmd))
buf = ''
except socket.timeout:
logger.error('Socket timeout during execution of command: '
'{0}\nBuffer content:\n{1}'.format(cmd, buf))
except socket.timeout:
logger.error('Socket timeout during execution of command: '
'{0}\nBuffer content:\n{1}'.format(cmd, buf))
- # TODO: Find out which exception would callers appreciate here.
- raise IOError('Socket timeout during execution of command: '
- '{0}\nBuffer content:\n{1}'.format(cmd, buf))
+ raise Exception('Socket timeout during execution of command: '
+ '{0}\nBuffer content:\n{1}'.format(cmd, buf))
tmp = buf.replace(cmd.replace('\n', ''), '')
for item in prompt:
tmp.replace(item, '')
tmp = buf.replace(cmd.replace('\n', ''), '')
for item in prompt:
tmp.replace(item, '')
def exec_cmd(node, cmd, timeout=600, sudo=False):
"""Convenience function to ssh/exec/return rc, out & err.
def exec_cmd(node, cmd, timeout=600, sudo=False):
"""Convenience function to ssh/exec/return rc, out & err.
- FIXME: Document :param, :type, :raise and similar.
Returns (rc, stdout, stderr).
"""
if node is None:
Returns (rc, stdout, stderr).
"""
if node is None:
(ret_code, stdout, stderr) = exec_cmd(node, cmd, timeout=timeout, sudo=sudo)
assert_equal(ret_code, 0, 'Command execution failed: "{}"\n{}'.
format(cmd, stderr))
(ret_code, stdout, stderr) = exec_cmd(node, cmd, timeout=timeout, sudo=sudo)
assert_equal(ret_code, 0, 'Command execution failed: "{}"\n{}'.
format(cmd, stderr))
+ return stdout, stderr
\ No newline at end of file