Skip to content

Commit e7b023a

Browse files
committed
ft-orchestration jq.py replace lbr_testsuite ssh execution with manual ssh command + redirect
1 parent 6a71c7d commit e7b023a

1 file changed

Lines changed: 17 additions & 15 deletions

File tree

  • tools/ft-orchestration/src/collector

tools/ft-orchestration/src/collector/jq.py

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import time
66
import xml.etree.ElementTree as ET
77

8+
import fabric
89
import numpy as np
910
from src.collector.interface import (
1011
CollectorOutputReaderException,
@@ -290,28 +291,29 @@ def save_csv(self, csv_file: str):
290291
Path to CSV file. Local file, CSV will be downloaded when collector running on remote.
291292
"""
292293
header = CSV_HEADER_TO_ANALYZER_HEADER.values()
293-
294-
batch_size = 100_000
295-
buffer = []
294+
conn: fabric.Connection = self._executor._connection
295+
user = conn.user
296+
host = conn.host
297+
kwargs = conn.connect_kwargs
298+
299+
if "key_filename" in kwargs:
300+
key_filename = kwargs["key_filename"]
301+
ssh_cmd = (
302+
f"ssh -i {key_filename} {user}@{host} '{self._cmd_csv}' >> {csv_file}"
303+
)
304+
else:
305+
password = kwargs["password"]
306+
ssh_cmd = f"sshpass -p {password} ssh {user}@{host} '{self._cmd_csv}' >> {csv_file}"
296307

297308
logging.getLogger().info(
298309
"Preparing CSV output by calling ipfixcol2 + jq command..."
299310
)
300311
start = time.time()
301312
# write csv
302-
process = AsyncTool(self._cmd_csv, executor=self._executor)
303-
process.run()
304-
305-
with open(csv_file, mode="w", buffering=1024**2) as f:
313+
with open(csv_file, mode="w") as f:
306314
f.write(",".join(header) + "\n")
307-
for line in process.stdout:
308-
buffer.append(line + "\n")
309-
if len(buffer) >= batch_size:
310-
f.writelines(buffer)
311-
buffer = []
312-
313-
if buffer:
314-
f.writelines(buffer)
315+
316+
Tool(ssh_cmd).run()
315317

316318
end = time.time()
317319
logging.getLogger().info("CSV output saved in %.2f seconds.", (end - start))

0 commit comments

Comments
 (0)