From 4a3b7baed785f7492e8404dac3eee8a8ce9fd937 Mon Sep 17 00:00:00 2001 From: Rob Crittenden Date: Fri, 6 Mar 2020 17:19:18 -0500 Subject: [PATCH] Test that ipa-healthcheck human output translates error strings The code rather than the string was being displayed in human output for non-SUCCESS messages. Verify that in case of an error the right output will be present. https://bugzilla.redhat.com/show_bug.cgi?id=1752849 Reviewed-By: Mohammad Rizwan Yusuf Reviewed-By: Sumedh Sidhaye Reviewed-By: Stanislav Levin Reviewed-By: Christian Heimes --- .../test_integration/test_ipahealthcheck.py | 38 +++++++++++++++++-- 1 file changed, 35 insertions(+), 3 deletions(-) diff --git a/ipatests/test_integration/test_ipahealthcheck.py b/ipatests/test_integration/test_ipahealthcheck.py index d0483459a..6a62c202d 100644 --- a/ipatests/test_integration/test_ipahealthcheck.py +++ b/ipatests/test_integration/test_ipahealthcheck.py @@ -109,11 +109,15 @@ DEFAULT_PKI_KRA_CERTS = [ ] -def run_healthcheck(host, source=None, check=None): +def run_healthcheck(host, source=None, check=None, output_type="json"): """ Run ipa-healthcheck on the remote host and return the result - Returns: the tuple returncode, json (if any) + Returns: the tuple returncode, output + + output is: + json data if output_type == "json" + stdout if output_type == "human" """ data = None cmd = ["ipa-healthcheck"] @@ -125,10 +129,16 @@ def run_healthcheck(host, source=None, check=None): cmd.append("--check") cmd.append(check) + cmd.append("--output-type") + cmd.append(output_type) + result = host.run_command(cmd, raiseonerr=False) if result.stdout_text: - data = json.loads(result.stdout_text) + if output_type == "json": + data = json.loads(result.stdout_text) + else: + data = result.stdout_text.strip() return result.returncode, data @@ -168,6 +178,28 @@ class TestIpaHealthCheck(IntegrationTest): for source in sources: assert source in result.stdout_text + def test_human_output(self): + """ + Test that in human output the severity value is correct + + Only the SUCCESS (0) value was being translated, otherwise + the numeric value was being shown (BZ 1752849) + """ + self.master.run_command(["systemctl", "stop", "sssd"]) + try: + returncode, output = run_healthcheck( + self.master, + "ipahealthcheck.meta.services", + "sssd", + "human", + ) + finally: + self.master.run_command(["systemctl", "start", "sssd"]) + + assert returncode == 1 + assert output == \ + "ERROR: ipahealthcheck.meta.services.sssd: sssd: not running" + def test_dogtag_ca_check_exists(self): """ Testcase to verify checks available in