Untitled
unknown
python
3 years ago
2.0 kB
8
Indexable
import os
import subprocess
import time
IPERF_VER = os.environ.get('IPERF_VER', '2')
PROTOCOL = os.environ.get('PROTOCOL', 'TCP')
SERVER_POD_PORT = int(os.environ.get('SERVER_POD_PORT', '5201'))
SERVER_CORE_LIST = os.environ.get('SERVER_CORE_LIST', '2-5,6-9')
SERVER_OPTIONS = os.environ.get('SERVER_OPTIONS', '')
SERVER_POD_IP = os.environ.get('SERVER_POD_IP', 'iperf-server-service')
PARALLEL_NUM = int(os.environ.get('PARALLEL_NUM', '8'))
# iperf command line on server side
if IPERF_VER == "2":
SERVER_CMD = f"taskset -c {SERVER_CORE_LIST} iperf -s -m -p {SERVER_POD_PORT} -e -o output.logs"
else:
SERVER_CPU_NUM = SERVER_CORE_LIST.count(',') + 1
SERVER_CMD = f"taskset -c {SERVER_CORE_LIST} iperf3 -s -p {SERVER_POD_PORT} -A {SERVER_CPU_NUM} -V"
if PROTOCOL == "UDP" and IPERF_VER == "2":
SERVER_CMD += " -u"
SERVER_CMD += f" {SERVER_OPTIONS}"
print(f"SERVER_CMD: {SERVER_CMD}")
subprocess.Popen(SERVER_CMD, shell=True, stdout=subprocess.DEVNULL, stderr=subprocess.STDOUT)
time.sleep(5)
with open("/tmp/statuscheck", "w") as f:
f.write("1")
# wait for the ending of test
COUNT = 0
if PARALLEL_NUM == 1:
KEY_WORD = "Interval"
else:
KEY_WORD = "SUM"
while True:
with open("output.logs", "r") as f:
lines = f.readlines()
test_finished = False
for line in lines:
if KEY_WORD in line:
test_finished = True
break
if test_finished or COUNT == 50:
break
time.sleep(10)
COUNT += 1
if not test_finished:
print("Timeout while testing. No summary in log on server side.")
exit(3)
subprocess.run(["killall", "iperf"])
# parse and modify the output when no summary in the log
if PARALLEL_NUM == 1:
with open("output.logs", "r+") as f:
lines = f.readlines()
for i, line in enumerate(lines):
if "pkts" in line:
lines[i] = line.replace("[ 1]", "[SUM]")
f.seek(0)
f.writelines(lines)
f.truncate()
Editor is loading...