Repository: RedHatInsights/insights-core

Issue:
The default value of strip from function context_wrap should not be True
When executing insights-run, the parser `OdCpuDmaLatency` fails to parse the following output:

~~~
     100000
~~~

The reason is `if content and content[0].isdigit():` is false as `content[0] is "     100000"`. 
However, py.test works well. The reason is that `context_wrap` applies strip before parsing logic.
To avoid such issue, the default strip from function context_wrap should not be True

Discussion:
@xiangce: After a further discussion with @wushiqinlou, we both agree with that:

1. Do not modify the default value of the kwarg `strip=True` to the `context_wrap` method, as it will impact too many existing unit tests.
2. For the cases, e.g. the OdCpuDmaLatency, to keep its original content value which includes a staring whitespace, we'd use `context_wrap(CONTENT, strip=False)` explicitly in the test.

Closing this issue per this agreement.

Solution patch:
diff --git a/insights/parsers/od_cpu_dma_latency.py b/insights/parsers/od_cpu_dma_latency.py
index 75161828cc..f9c4f241f3 100644
--- a/insights/parsers/od_cpu_dma_latency.py
+++ b/insights/parsers/od_cpu_dma_latency.py
@@ -31,7 +31,7 @@ class OdCpuDmaLatency(CommandParser):
     """
 
     def parse_content(self, content):
-        if content and content[0].isdigit():
-            self.force_latency = int(content[0])
+        if content and content[0].strip().isdigit():
+            self.force_latency = int(content[0].strip())
         else:
             raise SkipComponent('Nothing to parse.')


Test patch:
diff --git a/insights/tests/parsers/test_od_cpu_dma_latency.py b/insights/tests/parsers/test_od_cpu_dma_latency.py
index 28aaccf913..d7dd812168 100644
--- a/insights/tests/parsers/test_od_cpu_dma_latency.py
+++ b/insights/tests/parsers/test_od_cpu_dma_latency.py
@@ -6,22 +6,20 @@
 from insights.parsers.od_cpu_dma_latency import OdCpuDmaLatency
 from insights.tests import context_wrap
 
-CONTENT_OD_CPU_DMA_LATENCY = """
-  2000000000
-"""
+CONTENT_OD_CPU_DMA_LATENCY = """  2000000000"""
 
 CONTENT_OD_CPU_DMA_LATENCY_EMPTY = ""
 
 
 def test_doc_examples():
-    env = {'cpu_dma_latency': OdCpuDmaLatency(context_wrap(CONTENT_OD_CPU_DMA_LATENCY))}
+    env = {'cpu_dma_latency': OdCpuDmaLatency(context_wrap(CONTENT_OD_CPU_DMA_LATENCY, strip=False))}
     failed, total = doctest.testmod(od_cpu_dma_latency, globs=env)
     assert failed == 0
 
 
 def test_OdCpuDmaLatency():
-    d = OdCpuDmaLatency(context_wrap(CONTENT_OD_CPU_DMA_LATENCY))
+    d = OdCpuDmaLatency(context_wrap(CONTENT_OD_CPU_DMA_LATENCY, strip=False))
     assert d.force_latency == 2000000000
 
     with pytest.raises(SkipComponent):
-        OdCpuDmaLatency(context_wrap(CONTENT_OD_CPU_DMA_LATENCY_EMPTY))
+        OdCpuDmaLatency(context_wrap(CONTENT_OD_CPU_DMA_LATENCY_EMPTY, strip=False))