- ssh.connect(node)
-
- remote_file_path = '{0}/{1}/{2}'.format(Constants.REMOTE_FW_DIR,
- Constants.RESOURCES_TPL_VAT,
- vat_name)
- # TODO this overwrites the output if the vat script has been used twice
- # remote_file_out = remote_file_path + ".out"
-
- cmd = "sudo -S {vat} {json} < {input}".format(
- vat=Constants.VAT_BIN_NAME,
- json="json" if json_out is True else "",
- input=remote_file_path)
- (ret_code, stdout, stderr) = ssh.exec_command(cmd, timeout)
+ try:
+ ssh.connect(node)
+ except:
+ raise SSHException(
+ f"Cannot open SSH connection to execute VAT command(s) "
+ f"from vat script {vat_name}"
+ )
+
+ if copy_on_execute:
+ ssh.scp(vat_name, vat_name)
+ remote_file_path = vat_name
+ if history:
+ with open(vat_name, "r") as vat_file:
+ for line in vat_file:
+ PapiHistory.add_to_papi_history(
+ node, line.replace(u"\n", u""), papi=False
+ )
+ else:
+ remote_file_path = f"{Constants.REMOTE_FW_DIR}/" \
+ f"{Constants.RESOURCES_TPL_VAT}/{vat_name}"
+
+ cmd = f"{Constants.VAT_BIN_NAME}" \
+ f"{u' json' if json_out is True else u''} " \
+ f"in {remote_file_path} script"
+ try:
+ ret_code, stdout, stderr = ssh.exec_command_sudo(
+ cmd=cmd, timeout=timeout
+ )
+ except SSHTimeout:
+ logger.error(f"VAT script execution timeout: {cmd}")
+ raise
+ except Exception:
+ raise RuntimeError(f"VAT script execution failed: {cmd}")
+