Repository: RedHatInsights/insights-core

Issue:
PsEo parser is raising ValueError exception
`insights.parsers.ps.PsEo` parser is raising `ValueError` exception when attempting to parser content. The exception occurs when `insights.parsers.parse_delimited_table()` is called. The exception traceback:
```
  File "/home/remote/vdymna/repos/insights-core/insights/core/dr.py", line 962, in run
    result = DELEGATES[component].process(broker)
  File "/home/remote/vdymna/repos/insights-core/insights/core/dr.py", line 681, in process
    return self.invoke(broker)
  File "/home/remote/vdymna/repos/insights-core/insights/core/plugins.py", line 130, in invoke
    return self.component(dep_value)
  File "/home/remote/vdymna/repos/insights-core/insights/parsers/ps.py", line 59, in __init__
    super(Ps, self).__init__(*args, **kwargs)
  File "/home/remote/vdymna/repos/insights-core/insights/core/__init__.py", line 569, in __init__
    super(CommandParser, self).__init__(context)
  File "/home/remote/vdymna/repos/insights-core/insights/core/__init__.py", line 92, in __init__
    self._handle_content(context)
  File "/home/remote/vdymna/repos/insights-core/insights/core/__init__.py", line 95, in _handle_content
    self.parse_content(context.content)
  File "/home/remote/vdymna/repos/insights-core/insights/parsers/ps.py", line 376, in parse_content
    super(PsEo, self).parse_content(content)
  File "/home/remote/vdymna/repos/insights-core/insights/parsers/ps.py", line 71, in parse_content
    raw_line_key=raw_line_key
  File "/home/remote/vdymna/repos/insights-core/insights/parsers/__init__.py", line 423, in parse_delimited_table
    first_line = calc_offset(table_lines, heading_ignore)
  File "/home/remote/vdymna/repos/insights-core/insights/parsers/__init__.py", line 275, in calc_offset
    raise ValueError("Line containing '{}' was not found in table".format(','.join(target)))
ValueError: Line containing '    PID    PPID COMMAND' was not found in table
```
This can be easily reproduces by calling `insights inspect insights.parsers.ps.PsEo` command.


Discussion:

Resolving patch:
diff --git a/insights/parsers/__init__.py b/insights/parsers/__init__.py
--- a/insights/parsers/__init__.py
+++ b/insights/parsers/__init__.py
@@ -265,7 +265,8 @@ def calc_offset(lines, target, invert_search=False):
     """
     if target and target[0] is not None:
         for offset, line in enumerate(l.strip() for l in lines):
-            found_any = any([line.startswith(t) for t in target])
+            # strip `target` string along with `line` value
+            found_any = any([line.startswith(t.strip()) for t in target])
             if not invert_search and found_any:
                 return offset
             elif invert_search and not(line == '' or found_any):


Test patch:
diff --git a/insights/parsers/tests/test_ps.py b/insights/parsers/tests/test_ps.py
--- a/insights/parsers/tests/test_ps.py
+++ b/insights/parsers/tests/test_ps.py
@@ -66,7 +66,7 @@ def test_doc_examples():
         'ps': ps.PsAuxww(context_wrap(PsAuxww_TEST_DOC)),
         'ps_auxww': ps.PsAuxww(context_wrap(PsAuxww_TEST_DOC)),
         'ps_ef': ps.PsEf(context_wrap(PsEf_TEST_DOC)),
-        'ps_eo': ps.PsEo(context_wrap(PsEo_TEST_DOC)),
+        'ps_eo': ps.PsEo(context_wrap(PsEo_TEST_DOC, strip=False)),
         'ps_alxwww': ps.PsAlxwww(context_wrap(PsAlxwww_TEST_DOC))
     }
     failed, total = doctest.testmod(ps, globs=env)
@@ -373,7 +373,7 @@ def test_ps_auxww_with_bad_input():
 
 
 def test_ps_eo():
-    p = ps.PsEo(context_wrap(PS_EO_NORMAL))
+    p = ps.PsEo(context_wrap(PS_EO_NORMAL, strip=False))
     assert p is not None
     assert len(p.pid_info) == 23
     assert '15663' in p.pid_info
@@ -389,6 +389,12 @@ def test_ps_eo():
     assert len(p.children('2')) == 6
 
 
+def test_ps_eo_stripped():
+    p = ps.PsEo(context_wrap(PS_EO_NORMAL, strip=True))
+    assert p is not None
+    assert len(p.pid_info) == 23
+
+
 PS_ALXWWW_DATA = """
 F   UID   PID  PPID PRI  NI    VSZ   RSS WCHAN  STAT TTY        TIME COMMAND
 4     0     1     0  20   0 128292  6944 ep_pol Ss   ?          0:02 /usr/lib/systemd/systemd --switched-root --system --deserialize 22