- logger.debug("Executing command in VAT terminal: {}".format(cmd));
- out = self._ssh.interactive_terminal_exec_command(self._tty,
- cmd,
- self.__VAT_PROMPT)
- logger.debug("VAT output: {}".format(out));
- json_out = json.loads(out)
- return json_out
+ PapiHistory.add_to_papi_history(self._node, cmd, papi=False)
+ logger.debug(f"Executing command in VAT terminal: {cmd}")
+ try:
+ out = self._ssh.interactive_terminal_exec_command(
+ self._tty, cmd, self.__VAT_PROMPT
+ )
+ self.vat_stdout = out
+ except Exception:
+ self._exec_failure = True
+ vpp_pid = get_vpp_pid(self._node)
+ if vpp_pid:
+ if isinstance(vpp_pid, int):
+ msg = f"VPP running on node {self._node[u'host']} " \
+ f"but VAT command {cmd} execution failed."
+ else:
+ msg = f"More instances of VPP running on node " \
+ f"{self._node[u'host']}. VAT command {cmd} " \
+ f"execution failed."
+ else:
+ msg = f"VPP not running on node {self._node[u'host']}. " \
+ f"VAT command {cmd} execution failed."
+ raise RuntimeError(msg)
+
+ logger.debug(f"VAT output: {out}")
+ if self.json:
+ obj_start = out.find(u"{")
+ obj_end = out.rfind(u"}")
+ array_start = out.find(u"[")
+ array_end = out.rfind(u"]")
+
+ if obj_start == -1 and array_start == -1:
+ raise RuntimeError(f"VAT command {cmd}: no JSON data.")
+
+ if obj_start < array_start or array_start == -1:
+ start = obj_start
+ end = obj_end + 1
+ else:
+ start = array_start
+ end = array_end + 1
+ out = out[start:end]
+ json_out = json.loads(out)
+ return json_out
+
+ return None