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

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