This is a partial fix for:
Ticket: CSIT-1434
and should fix one pylint violation.
Many files to remove SSH() from remain.
+ Use -E (together with previous -S) in ssh.py when sudo=True.
Needed in some cases, no downsides expected.
Change-Id: Ie2ad03b3c656a4d3965a61a1e5435276f99a28c0
Signed-off-by: Vratko Polak <vrpolak@cisco.com>
from .DropRateSearch import DropRateSearch
from .Constants import Constants
from .DropRateSearch import DropRateSearch
from .Constants import Constants
-from .ssh import SSH, exec_cmd_no_error
+from .ssh import exec_cmd_no_error, exec_cmd
from .topology import NodeType
from .topology import NodeSubTypeTG
from .topology import Topology
from .topology import NodeType
from .topology import NodeSubTypeTG
from .topology import Topology
if subtype == NodeSubTypeTG.TREX:
self._node = tg_node
if subtype == NodeSubTypeTG.TREX:
self._node = tg_node
- ssh = SSH()
- ssh.connect(self._node)
-
- (ret, _, _) = ssh.exec_command(
- "sudo -E sh -c '{0}/resources/tools/trex/"
+ exec_cmd_no_error(
+ self._node,
+ "sh -c '{0}/resources/tools/trex/"
"trex_installer.sh {1}'".format(Constants.REMOTE_FW_DIR,
Constants.TREX_INSTALL_VERSION),
"trex_installer.sh {1}'".format(Constants.REMOTE_FW_DIR,
Constants.TREX_INSTALL_VERSION),
- timeout=1800)
- if int(ret) != 0:
- raise RuntimeError('TRex installation failed.')
+ sudo=True, timeout=1800, message='TRex installation failed.')
if1_pci = Topology().get_interface_pci_addr(self._node, tg_if1)
if2_pci = Topology().get_interface_pci_addr(self._node, tg_if2)
if1_pci = Topology().get_interface_pci_addr(self._node, tg_if1)
if2_pci = Topology().get_interface_pci_addr(self._node, tg_if2)
self._ifaces_reordered = True
if osi_layer == 'L2' or osi_layer == 'L3':
self._ifaces_reordered = True
if osi_layer == 'L2' or osi_layer == 'L3':
- (ret, _, _) = ssh.exec_command(
- "sudo sh -c 'cat << EOF > /etc/trex_cfg.yaml\n"
+ exec_cmd_no_error(
+ self._node,
+ "sh -c 'cat << EOF > /etc/trex_cfg.yaml\n"
"- version: 2\n"
" interfaces: [\"{0}\",\"{1}\"]\n"
" port_info:\n"
"- version: 2\n"
" interfaces: [\"{0}\",\"{1}\"]\n"
" port_info:\n"
"0x"+if1_adj_addr.replace(":", ",0x"),
"0x"+if1_addr.replace(":", ",0x"),
"0x"+if2_adj_addr.replace(":", ",0x"),
"0x"+if1_adj_addr.replace(":", ",0x"),
"0x"+if1_addr.replace(":", ",0x"),
"0x"+if2_adj_addr.replace(":", ",0x"),
- "0x"+if2_addr.replace(":", ",0x")))
+ "0x"+if2_addr.replace(":", ",0x")),
+ sudo=True, message='TRex config generation error')
- (ret, _, _) = ssh.exec_command(
- "sudo sh -c 'cat << EOF > /etc/trex_cfg.yaml\n"
+ exec_cmd_no_error(
+ self._node,
+ "sh -c 'cat << EOF > /etc/trex_cfg.yaml\n"
"- version: 2\n"
" interfaces: [\"{0}\",\"{1}\"]\n"
" port_info:\n"
"- version: 2\n"
" interfaces: [\"{0}\",\"{1}\"]\n"
" port_info:\n"
"EOF'"\
.format(if1_pci, if2_pci,
if1_addr, if1_adj_addr,
"EOF'"\
.format(if1_pci, if2_pci,
if1_addr, if1_adj_addr,
- if2_addr, if2_adj_addr))
+ if2_addr, if2_adj_addr),
+ sudo=True, message='TRex config generation error')
else:
raise ValueError("Unknown Test Type")
else:
raise ValueError("Unknown Test Type")
- if int(ret) != 0:
- raise RuntimeError('TRex config generation error')
self._startup_trex(osi_layer)
self._startup_trex(osi_layer)
exec_cmd_no_error(self._node, cmd, sudo=True)
except RuntimeError:
cmd = "sh -c 'cat /tmp/trex.log'"
exec_cmd_no_error(self._node, cmd, sudo=True)
except RuntimeError:
cmd = "sh -c 'cat /tmp/trex.log'"
- exec_cmd_no_error(self._node, cmd, sudo=True,
- message='Get TRex logs failed!')
+ exec_cmd_no_error(
+ self._node, cmd, sudo=True, message='Get TRex logs failed!')
raise RuntimeError('Start TRex failed!')
# Test if TRex starts successfuly.
raise RuntimeError('Start TRex failed!')
# Test if TRex starts successfuly.
"""
# No need to check subtype, we know it is TREX.
"""
# No need to check subtype, we know it is TREX.
- ssh = SSH()
- ssh.connect(node)
- ret, _, _ = ssh.exec_command_sudo("pidof t-rex")
+ ret, _, _ = exec_cmd(node, "pidof t-rex", sudo=True)
return bool(int(ret) == 0)
@staticmethod
return bool(int(ret) == 0)
@staticmethod
"""
subtype = check_subtype(node)
if subtype == NodeSubTypeTG.TREX:
"""
subtype = check_subtype(node)
if subtype == NodeSubTypeTG.TREX:
- ssh = SSH()
- ssh.connect(node)
- (ret, _, _) = ssh.exec_command(
- "sh -c 'sudo pkill t-rex && sleep 3'")
- if int(ret) != 0:
- raise RuntimeError('pkill t-rex failed')
+ exec_cmd_no_error(
+ node, "sh -c 'sudo pkill t-rex && sleep 3'",
+ sudo=False, message='pkill t-rex failed')
def _parse_traffic_results(self, stdout):
"""Parse stdout of scripts into fieds of self.
def _parse_traffic_results(self, stdout):
"""Parse stdout of scripts into fieds of self.
:raises RuntimeError: If stop traffic script fails.
"""
# No need to check subtype, we know it is TREX.
:raises RuntimeError: If stop traffic script fails.
"""
# No need to check subtype, we know it is TREX.
- ssh = SSH()
- ssh.connect(node)
-
- (ret, stdout, _) = ssh.exec_command(
+ stdout, _ = exec_cmd_no_error(
+ node,
"sh -c '{}/resources/tools/trex/"
"sh -c '{}/resources/tools/trex/"
- "trex_stateless_stop.py'".format(Constants.REMOTE_FW_DIR))
-
- if int(ret) != 0:
- raise RuntimeError('TRex stateless runtime error')
-
+ "trex_stateless_stop.py'".format(Constants.REMOTE_FW_DIR),
+ message='TRex stateless runtime error')
self._parse_traffic_results(stdout)
def trex_stl_start_remote_exec(
self._parse_traffic_results(stdout)
def trex_stl_start_remote_exec(
:raises RuntimeError: In case of TG driver issue.
"""
# No need to check subtype, we know it is TREX.
:raises RuntimeError: In case of TG driver issue.
"""
# No need to check subtype, we know it is TREX.
- ssh = SSH()
- ssh.connect(self._node)
reorder = self._ifaces_reordered # Just to make the next line fit.
p_0, p_1 = (rx_port, tx_port) if reorder else (tx_port, rx_port)
# Values from Robot can introduce type unicode,
reorder = self._ifaces_reordered # Just to make the next line fit.
p_0, p_1 = (rx_port, tx_port) if reorder else (tx_port, rx_port)
# Values from Robot can introduce type unicode,
command += " --unidirection"
command += "'"
command += " --unidirection"
command += "'"
- (ret, stdout, _) = ssh.exec_command(
- command, timeout=float(duration) + 60)
+ stdout, _ = exec_cmd_no_error(
+ self._node, command, timeout=float(duration) + 60,
+ message='TRex stateless runtime error')
- if int(ret) != 0:
- raise RuntimeError('TRex stateless runtime error')
- elif async_call:
#no result
self._start_time = time.time()
self._rate = float(rate[:-3]) if "pps" in rate else rate
#no result
self._start_time = time.time()
self._rate = float(rate[:-3]) if "pps" in rate else rate
if isinstance(cmd, (list, tuple)):
cmd = OptionString(cmd)
if cmd_input is None:
if isinstance(cmd, (list, tuple)):
cmd = OptionString(cmd)
if cmd_input is None:
- command = 'sudo -S {c}'.format(c=cmd)
+ command = 'sudo -E -S {c}'.format(c=cmd)
- command = 'sudo -S {c} <<< "{i}"'.format(c=cmd, i=cmd_input)
+ command = 'sudo -E -S {c} <<< "{i}"'.format(c=cmd, i=cmd_input)
return self.exec_command(command, timeout,
log_stdout_err=log_stdout_err)
return self.exec_command(command, timeout,
log_stdout_err=log_stdout_err)
.format(p=lxc_params, n=lxc_name, c=lxc_cmd)
if sudo:
.format(p=lxc_params, n=lxc_name, c=lxc_cmd)
if sudo:
- command = 'sudo -S {c}'.format(c=command)
+ command = 'sudo -E -S {c}'.format(c=command)
return self.exec_command(command, timeout)
def interactive_terminal_open(self, time_out=45):
return self.exec_command(command, timeout)
def interactive_terminal_open(self, time_out=45):
if not sudo:
(ret_code, stdout, stderr) = ssh.exec_command(cmd, timeout=timeout)
else:
if not sudo:
(ret_code, stdout, stderr) = ssh.exec_command(cmd, timeout=timeout)
else:
- (ret_code, stdout, stderr) = ssh.exec_command_sudo(cmd,
- timeout=timeout)
+ (ret_code, stdout, stderr) = ssh.exec_command_sudo(
+ cmd, timeout=timeout)
except SSHException as err:
logger.error(repr(err))
return None, None, None
except SSHException as err:
logger.error(repr(err))
return None, None, None