Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reorganize Iperf error reporting #349

Merged
merged 2 commits into from
Jan 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lnst/Agent/Job.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def _run(self):

os.setpgrp()
signal.signal(signal.SIGHUP, signal.SIG_DFL)
signal.signal(signal.SIGINT, signal.SIG_DFL)
signal.signal(signal.SIGINT, signal.default_int_handler)
signal.signal(signal.SIGTERM, signal.SIG_DFL)

self._log_ctl.disable_logging()
Expand Down
72 changes: 34 additions & 38 deletions lnst/Tests/Iperf.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import logging
import signal
import subprocess
import json
from json.decoder import JSONDecodeError
Expand Down Expand Up @@ -34,57 +35,52 @@ def run(self):

try:
stdout, stderr = server.communicate()
stdout = stdout.decode()
stderr = stderr.decode()
except KeyboardInterrupt:
Kuba314 marked this conversation as resolved.
Show resolved Hide resolved
pass
server.send_signal(signal.SIGINT)
olichtne marked this conversation as resolved.
Show resolved Hide resolved
finally:
stdout, stderr = server.communicate()
stdout = stdout.decode().strip()
stderr = stderr.decode().strip()

try:
self._res_data["data"] = json.loads(stdout)
except JSONDecodeError:
self._res_data["msg"] = "Error while parsing the iperf json output"
self._res_data["data"] = stdout
if server.returncode > 0:
msg = f"iperf {self._role} returncode = {server.returncode}"
logging.error(msg)
logging.error(f"iperf stderr: {stderr}")
logging.debug(f"iperf stdout: {stdout}")
self._res_data["msg"] = msg
self._res_data["stderr"] = stderr
jtluka marked this conversation as resolved.
Show resolved Hide resolved
logging.error(self._res_data["msg"])
return False

try:
self._check_json_sanity()
except:
self._res_data["msg"] = "Iperf provided incomplete json data"
self._res_data["data"] = stdout
self._res_data["data"] = json.loads(stdout)
except JSONDecodeError:
msg = "Error while parsing the iperf json output"
logging.error(msg)
logging.error(f"iperf stderr: {stderr}")
logging.debug(f"iperf stdout: {stdout}")
self._res_data["msg"] = msg
self._res_data["stderr"] = stderr
logging.error(self._res_data["msg"])
return False

self._res_data["stderr"] = stderr

if stderr != "":
self._res_data["msg"] = "errors reported by iperf"
logging.error(self._res_data["msg"])
logging.error(self._res_data["stderr"])

if server.returncode > 0:
self._res_data["msg"] = "{} returncode = {}".format(
self._role, server.returncode)
logging.error(self._res_data["msg"])
if not self._is_json_complete(self._res_data["data"]):
msg = "Iperf provided incomplete json data"
logging.error(msg)
logging.error(f"iperf stderr: {stderr}")
logging.debug(f"iperf stdout: {stdout}")
self._res_data["msg"] = msg
self._res_data["stderr"] = stderr
return False

return True

def _check_json_sanity(self):
data = self._res_data["data"]
if "start" not in data:
raise Exception()

if "end" not in data:
raise Exception()

if len(data["intervals"]) == 0:
raise Exception()

if "streams" not in data["end"]:
raise Exception
@staticmethod
def _is_json_complete(data: dict) -> bool:
return (
"start" in data
and "end" in data
and len(data["intervals"]) > 0
and "streams" in data["end"]
)


class IperfServer(IperfBase):
Expand Down
Loading