Blame SOURCES/0004-result-names-are-not-translated-when-reading-input-f.patch

e6a568
From 5efeafa16a893cb6277ece4d573184bb64ee2744 Mon Sep 17 00:00:00 2001
e6a568
From: Rob Crittenden <rcritten@redhat.com>
e6a568
Date: Mon, 30 Nov 2020 15:06:03 -0500
e6a568
Subject: [PATCH] result names are not translated when reading input from json
e6a568
 file
e6a568
e6a568
The strings were being retained so when processing the results to
e6a568
determine the return code it was always a 1 because none of
e6a568
the values were being translated. It was always comparing
e6a568
the string like 'SUCCESS' to constants.SUCCESS which is 0.
e6a568
e6a568
https://bugzilla.redhat.com/show_bug.cgi?id=1866558
e6a568
---
e6a568
 src/ipahealthcheck/core/constants.py | 20 +++++++++++++++++++-
e6a568
 src/ipahealthcheck/core/plugin.py    |  4 ++--
e6a568
 tests/test_results.py                |  8 ++++++++
e6a568
 3 files changed, 29 insertions(+), 3 deletions(-)
e6a568
e6a568
diff --git a/src/ipahealthcheck/core/constants.py b/src/ipahealthcheck/core/constants.py
e6a568
index a55469c..b6ee029 100644
e6a568
--- a/src/ipahealthcheck/core/constants.py
e6a568
+++ b/src/ipahealthcheck/core/constants.py
e6a568
@@ -36,7 +36,25 @@ def getLevelName(level):
e6a568
     is passed in instead the corresponding string representation is
e6a568
     returned.
e6a568
     """
e6a568
-    return _levelToName.get(level) or _nameToLevel.get(level) or level
e6a568
+    name = _levelToName.get(level) or _nameToLevel.get(level)
e6a568
+    if name is not None:
e6a568
+        return name
e6a568
+
e6a568
+    return level
e6a568
+
e6a568
+
e6a568
+def getLevel(name):
e6a568
+    """
e6a568
+    Translate between level text and their numeric constants
e6a568
+
e6a568
+    If the level is one of the predefined levels then returns the
e6a568
+    corresponding number.
e6a568
+    """
e6a568
+    level = _nameToLevel.get(name)
e6a568
+    if level is not None:
e6a568
+        return level
e6a568
+
e6a568
+    return name
e6a568
 
e6a568
 
e6a568
 CONFIG_FILE = '/etc/ipahealthcheck/ipahealthcheck.conf'
e6a568
diff --git a/src/ipahealthcheck/core/plugin.py b/src/ipahealthcheck/core/plugin.py
e6a568
index 7ac923a..26dddd4 100644
e6a568
--- a/src/ipahealthcheck/core/plugin.py
e6a568
+++ b/src/ipahealthcheck/core/plugin.py
e6a568
@@ -6,7 +6,7 @@ import uuid
e6a568
 from datetime import datetime
e6a568
 from functools import wraps
e6a568
 
e6a568
-from ipahealthcheck.core.constants import getLevelName
e6a568
+from ipahealthcheck.core.constants import getLevelName, getLevel
e6a568
 
e6a568
 
e6a568
 def duration(f):
e6a568
@@ -204,7 +204,7 @@ def json_to_results(data):
e6a568
     results = Results()
e6a568
 
e6a568
     for line in data:
e6a568
-        result = line.pop('result')
e6a568
+        result = getLevel(line.pop('result'))
e6a568
         source = line.pop('source')
e6a568
         check = line.pop('check')
e6a568
         duration = line.pop('duration')
e6a568
diff --git a/tests/test_results.py b/tests/test_results.py
e6a568
index dd6e8fd..99c18d7 100644
e6a568
--- a/tests/test_results.py
e6a568
+++ b/tests/test_results.py
e6a568
@@ -69,3 +69,11 @@ def test_Result():
e6a568
         assert x['result'] in (constants.getLevelName(constants.SUCCESS),
e6a568
                                constants.getLevelName(constants.CRITICAL))
e6a568
         assert len(x['kw']) == 0
e6a568
+
e6a568
+
e6a568
+def test_getLevel():
e6a568
+    assert constants.getLevel('SUCCESS') == constants.SUCCESS
e6a568
+    assert constants.getLevel('WARNING') == constants.WARNING
e6a568
+    assert constants.getLevel('ERROR') == constants.ERROR
e6a568
+    assert constants.getLevel('CRITICAL') == constants.CRITICAL
e6a568
+    assert constants.getLevel('FOO') == 'FOO'
e6a568
-- 
e6a568
2.25.4
e6a568