aboutsummaryrefslogtreecommitdiffstats
path: root/resources/libraries/python
diff options
context:
space:
mode:
authorMiroslav Miklus <mmiklus@cisco.com>2016-09-29 17:03:17 +0200
committerPeter Mikus <pmikus@cisco.com>2016-10-04 05:53:06 +0000
commit5dc98f39c227fb09ce59caa38d28f0dba8558e4b (patch)
tree104fd1e792a84d7fe059a27e2c310f119d18d87d /resources/libraries/python
parent7a518f56201e7fb3a1e096d40248866330656fab (diff)
Interactive terminal fixes
- remember if execution timed out and do not try to send "quit" on close - increase timeout of vat command execution from 10s to 60s Change-Id: I2b96a6dce1220eff45002276d1fe8a771fca2205 Signed-off-by: Miroslav Miklus <mmiklus@cisco.com>
Diffstat (limited to 'resources/libraries/python')
-rw-r--r--resources/libraries/python/VatExecutor.py18
-rw-r--r--resources/libraries/python/ssh.py2
2 files changed, 14 insertions, 6 deletions
diff --git a/resources/libraries/python/VatExecutor.py b/resources/libraries/python/VatExecutor.py
index f0e28a1ae1..a0f9634d8c 100644
--- a/resources/libraries/python/VatExecutor.py
+++ b/resources/libraries/python/VatExecutor.py
@@ -150,6 +150,7 @@ class VatTerminal(object):
self._tty,
'sudo -S {}{}'.format(Constants.VAT_BIN_NAME, json_text),
self.__VAT_PROMPT)
+ self._exec_failure = False
def __enter__(self):
return self
@@ -166,9 +167,14 @@ class VatTerminal(object):
None if not in JSON mode.
"""
logger.debug("Executing command in VAT terminal: {}".format(cmd))
- out = self._ssh.interactive_terminal_exec_command(self._tty,
+ try:
+ out = self._ssh.interactive_terminal_exec_command(self._tty,
cmd,
self.__VAT_PROMPT)
+ except:
+ self._exec_failure = True
+ raise
+
logger.debug("VAT output: {}".format(out))
if self.json:
obj_start = out.find('{')
@@ -177,7 +183,7 @@ class VatTerminal(object):
array_end = out.rfind(']')
if -1 == obj_start and -1 == array_start:
- raise RuntimeError("No JSON data.")
+ raise RuntimeError("VAT: no JSON data.")
if obj_start < array_start or -1 == array_start:
start = obj_start
@@ -193,9 +199,11 @@ class VatTerminal(object):
def vat_terminal_close(self):
"""Close VAT terminal."""
- self._ssh.interactive_terminal_exec_command(self._tty,
- 'quit',
- self.__LINUX_PROMPT)
+ #interactive terminal is dead, we only need to close session
+ if not self._exec_failure:
+ self._ssh.interactive_terminal_exec_command(self._tty,
+ 'quit',
+ self.__LINUX_PROMPT)
self._ssh.interactive_terminal_close(self._tty)
def vat_terminal_exec_cmd_from_template(self, vat_template_file, **args):
diff --git a/resources/libraries/python/ssh.py b/resources/libraries/python/ssh.py
index 298c93ee8e..b470e86ccc 100644
--- a/resources/libraries/python/ssh.py
+++ b/resources/libraries/python/ssh.py
@@ -213,7 +213,7 @@ class SSH(object):
@staticmethod
def interactive_terminal_exec_command(chan, cmd, prompt,
- time_out=10):
+ time_out=30):
"""Execute command on interactive terminal.
interactive_terminal_open() method has to be called first!
self.parent) def resolve_ndp(self): super(VppSubInterface, self).resolve_ndp(self.parent) @abstractmethod def add_dot1_layer(self, pkt): pass def remove_vpp_config(self): self.test.vapi.delete_subif(self._sw_if_index) class VppDot1QSubint(VppSubInterface): @property def vlan(self): """VLAN tag""" return self._vlan def __init__(self, test, parent, sub_id, vlan=None): if vlan is None: vlan = sub_id self._vlan = vlan r = test.vapi.create_vlan_subif(parent.sw_if_index, vlan) self._sw_if_index = r.sw_if_index super(VppDot1QSubint, self).__init__(test, parent, sub_id) def create_arp_req(self): packet = VppPGInterface.create_arp_req(self) return self.add_dot1_layer(packet) def create_ndp_req(self): packet = VppPGInterface.create_ndp_req(self) return self.add_dot1_layer(packet) def add_dot1_layer(self, packet): payload = packet.payload packet.remove_payload() packet.add_payload(Dot1Q(vlan=self.sub_id) / payload) return packet def remove_dot1_layer(self, packet): payload = packet.payload self.test.instance().assertEqual(type(payload), Dot1Q) self.test.instance().assertEqual(payload.vlan, self.vlan) payload = payload.payload packet.remove_payload() packet.add_payload(payload) return packet class VppDot1ADSubint(VppSubInterface): @property def outer_vlan(self): """Outer VLAN tag""" return self._outer_vlan @property def inner_vlan(self): """Inner VLAN tag""" return self._inner_vlan def __init__(self, test, parent, sub_id, outer_vlan, inner_vlan): r = test.vapi.create_subif(parent.sw_if_index, sub_id, outer_vlan, inner_vlan, dot1ad=1, two_tags=1, exact_match=1) self._sw_if_index = r.sw_if_index super(VppDot1ADSubint, self).__init__(test, parent, sub_id) self.DOT1AD_TYPE = 0x88A8 self.DOT1Q_TYPE = 0x8100 self._outer_vlan = outer_vlan self._inner_vlan = inner_vlan def create_arp_req(self): packet = VppPGInterface.create_arp_req(self) return self.add_dot1_layer(packet) def create_ndp_req(self): packet = VppPGInterface.create_ndp_req(self) return self.add_dot1_layer(packet) def add_dot1_layer(self, packet): payload = packet.payload packet.remove_payload() packet.add_payload(Dot1Q(vlan=self.outer_vlan) / Dot1Q(vlan=self.inner_vlan) / payload) packet.type = self.DOT1AD_TYPE return packet def remove_dot1_layer(self, packet): self.test.instance().assertEqual(type(packet), Ether) self.test.instance().assertEqual(packet.type, self.DOT1AD_TYPE) packet.type = self.DOT1Q_TYPE packet = Ether(str(packet)) payload = packet.payload self.test.instance().assertEqual(type(payload), Dot1Q) self.test.instance().assertEqual(payload.vlan, self.outer_vlan) payload = payload.payload self.test.instance().assertEqual(type(payload), Dot1Q) self.test.instance().assertEqual(payload.vlan, self.inner_vlan) payload = payload.payload packet.remove_payload() packet.add_payload(payload) return packet