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