Skip to content
Snippets Groups Projects
Commit e655f672 authored by nimrod's avatar nimrod
Browse files

Parse output.

The tests aren't the greatest and binary is broken but I think the
parsing works.
parent 8f482983
No related branches found
No related tags found
No related merge requests found
Pipeline #1968 failed
...@@ -93,8 +93,7 @@ class Check: ...@@ -93,8 +93,7 @@ class Check:
ExitCode = None ExitCode = None
Output = None Output = None
PerfData = [] PerfData = []
LongOutput = None AdditionalOutput = []
AdditionalOutput = None
stderr = None stderr = None
_stdout = None _stdout = None
...@@ -107,11 +106,40 @@ class Check: ...@@ -107,11 +106,40 @@ class Check:
def _parse_output(self): def _parse_output(self):
"""Parses the plugin output to get the output, perf data and long """Parses the plugin output to get the output, perf data and long
output. Can be run after the plugin has run and finished output.
successfully."""
Can only be run after the plugin has run and finished successfully.
"""
if self.ExitCode is None: if self.ExitCode is None:
raise RuntimeError("Check hasn't run yet.") raise RuntimeError("Check hasn't run yet.")
lines = self._stdout.splitlines()
if not lines:
logging.info("Emptry stdout.")
return
if "|" in lines[0]:
p1, p2 = lines[0].split("|")
self.Output = p1.strip()
self.PerfData.append(PerfData(p2))
else:
self.Output = lines[0].strip()
if len(lines) == 1:
return
processing_perfdata = False
for line in lines[1:]:
if processing_perfdata:
self.PerfData.append(PerfData(line))
else:
if "|" in line:
self.AdditionalOutput.append(line.split("|")[0].strip())
processing_perfdata = True
self.PerfData.append(PerfData(line.split("|")[1]))
else:
self.AdditionalOutput.append(line)
def run(self, timeout=DEFAULT_TIMEOUT): def run(self, timeout=DEFAULT_TIMEOUT):
"""Run the check (if it's hasn't run yet).""" """Run the check (if it's hasn't run yet)."""
if self.ExitCode is not None: if self.ExitCode is not None:
......
...@@ -107,7 +107,8 @@ def test_output_parsing(output): ...@@ -107,7 +107,8 @@ def test_output_parsing(output):
) )
with _mock_run(return_value=proc): with _mock_run(return_value=proc):
check.run() check.run()
# TODO: validate something. assert isinstance(check.Output, str)
assert len(check.Output.splitlines()) == 1
@pytest.mark.parametrize("line", PERF_DATA) @pytest.mark.parametrize("line", PERF_DATA)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment