URL: https://github.com/freeipa/freeipa/pull/5169
Author: menonsudhir
 Title: #5169: ipa-healthcheck test fixes running on RHEL
Action: opened

PR body:
"""
ipatests: ipa-healthcheck test fixes running on RHEL
Added function in tasks.py to get healthcheck version.
Added if else condition to certain tests to check healthcheck version and then 
assert the expected test output

"""

To pull the PR as Git branch:
git remote add ghfreeipa https://github.com/freeipa/freeipa
git fetch ghfreeipa pull/5169/head:pr5169
git checkout pr5169
From 7a1267062df30b3c7ddec4b4e3e65e4a41a8fa11 Mon Sep 17 00:00:00 2001
From: Sudhir Menon <sume...@redhat.com>
Date: Wed, 23 Sep 2020 13:28:44 +0530
Subject: [PATCH 1/2] ipatests: ipa-healthcheck test fixes running on RHEL

1. Added function in tasks.py to get healthcheck version.
2. Added if else condition to certain tests to
check healthcheck version and then assert the expected test output

Signed-off-by: Sudhir Menon <sume...@redhat.com>
---
 ipatests/pytest_ipa/integration/tasks.py      |  22 ++++
 .../test_integration/test_ipahealthcheck.py   | 104 ++++++++++++++----
 2 files changed, 107 insertions(+), 19 deletions(-)

diff --git a/ipatests/pytest_ipa/integration/tasks.py b/ipatests/pytest_ipa/integration/tasks.py
index fceac1b628..0690e7f6cb 100755
--- a/ipatests/pytest_ipa/integration/tasks.py
+++ b/ipatests/pytest_ipa/integration/tasks.py
@@ -2345,6 +2345,28 @@ def get_sssd_version(host):
     return parse_version(version)
 
 
+def get_healthcheck_version(host):
+    """
+    Function to get healthcheck version on fedora and rhel
+    """
+    platform = get_platform(host)
+    if platform in ("rhel", "fedora"):
+        cmd = host.run_command(
+            ["rpm", "-qa", "--qf", "%{VERSION}", "*ipa-healthcheck"]
+        )
+        healthcheck_version = cmd.stdout_text
+        if not healthcheck_version:
+            raise ValueError(
+                "get_healthcheck_version: "
+                "ipa-healthcheck package is not installed"
+            )
+    else:
+        raise ValueError(
+            "get_healthcheck_version: unknown platform %s" % platform
+        )
+    return healthcheck_version
+
+
 def run_ssh_cmd(
     from_host=None, to_host=None, username=None, cmd=None,
     auth_method=None, password=None, private_key_path=None,
diff --git a/ipatests/test_integration/test_ipahealthcheck.py b/ipatests/test_integration/test_ipahealthcheck.py
index 987d791130..9ce07b8b67 100644
--- a/ipatests/test_integration/test_ipahealthcheck.py
+++ b/ipatests/test_integration/test_ipahealthcheck.py
@@ -23,6 +23,7 @@
 from ipaplatform.paths import paths
 from ipaplatform.osinfo import osinfo
 from ipatests.test_integration.base import IntegrationTest
+from pkg_resources import parse_version
 from ipatests.test_integration.test_cert import get_certmonger_fs_id
 from ipatests.test_integration.test_external_ca import (
     install_server_external_ca_step1,
@@ -54,7 +55,26 @@
     "ipahealthcheck.ipa.roles",
     "ipahealthcheck.ipa.topology",
     "ipahealthcheck.ipa.trust",
+    "ipahealthcheck.ipa.meta",
+    "ipahealthcheck.meta.core",
     "ipahealthcheck.meta.services",
+    "ipahealthcheck.system.filesystemspace",
+]
+
+sources_0_4 = [
+    "ipahealthcheck.dogtag.ca",
+    "ipahealthcheck.ds.replication",
+    "ipahealthcheck.dogtag.ca",
+    "ipahealthcheck.ipa.certs",
+    "ipahealthcheck.ipa.dna",
+    "ipahealthcheck.ipa.idns",
+    "ipahealthcheck.ipa.files",
+    "ipahealthcheck.ipa.host",
+    "ipahealthcheck.ipa.roles",
+    "ipahealthcheck.ipa.topology",
+    "ipahealthcheck.ipa.trust",
+    "ipahealthcheck.meta.services",
+    "ipahealthcheck.system.filesystemspace",
 ]
 
 ipa_cert_checks = [
@@ -103,6 +123,7 @@
 dogtag_checks = ["DogtagCertsConfigCheck", "DogtagCertsConnectivityCheck"]
 iparoles_checks = ["IPACRLManagerCheck", "IPARenewalMasterCheck"]
 replication_checks = ["ReplicationCheck"]
+replication_checks_0_4 = ["ReplicationConflictCheck"]
 ruv_checks = ["RUVCheck"]
 dna_checks = ["IPADNARangeCheck"]
 idns_checks = ["IPADNSSystemRecordsCheck"]
@@ -235,8 +256,13 @@ def test_run_ipahealthcheck_list_source(self):
         """
         Testcase to verify sources available in healthcheck tool.
         """
+        version = tasks.get_healthcheck_version(self.master)
         result = self.master.run_command(["ipa-healthcheck", "--list-sources"])
-        for source in sources:
+        if parse_version(version) > parse_version("0.4"):
+            sources_avail = sources
+        else:
+            sources_avail = sources_0_4
+        for source in sources_avail:
             assert source in result.stdout_text
 
     def test_human_output(self, restart_service):
@@ -275,10 +301,16 @@ def test_replication_check_exists(self):
         Testcase to verify checks available in
         ipahealthcheck.ds.replication source
         """
+        version = tasks.get_healthcheck_version(self.master)
         result = self.master.run_command(
             ["ipa-healthcheck", "--source", "ipahealthcheck.ds.replication"]
         )
         for check in replication_checks:
+            if parse_version(version) > parse_version("0.4"):
+                checks = replication_checks
+            else:
+                checks = replication_checks_0_4
+        for check in checks:
             assert check in result.stdout_text
 
     def test_ipa_cert_check_exists(self):
@@ -667,6 +699,9 @@ def test_ipa_healthcheck_revocation(self):
         error_msg = (
             "Certificate tracked by {key} is revoked {revocation_reason}"
         )
+        error_msg_0_4 = (
+            "Certificate is revoked, unspecified"
+        )
 
         result = self.master.run_command(
             ["getcert", "list", "-f", paths.HTTPD_CERT_FILE]
@@ -689,11 +724,18 @@ def test_ipa_healthcheck_revocation(self):
         assert returncode == 1
         assert len(data) == 12
 
+        version = tasks.get_healthcheck_version(self.master)
         for check in data:
             if check["kw"]["key"] == request_id:
                 assert check["result"] == "ERROR"
                 assert check["kw"]["revocation_reason"] == "unspecified"
-                assert check["kw"]["msg"] == error_msg
+                if (parse_version(version) > parse_version('0.4')):
+                    assert check["kw"]["msg"] == error_msg
+                else:
+                    assert (
+                        check["kw"]["msg"]
+                        == error_msg_0_4
+                    )
             else:
                 assert check["result"] == "SUCCESS"
 
@@ -739,14 +781,24 @@ def test_run_with_stopped_master(self, ipactl):
         contains only errors regarding master being stopped and no other false
         positives.
         """
-        returncode, output = run_healthcheck(
-            self.master,
-            "ipahealthcheck.meta",
-            output_type="human",
-            failures_only=True)
+        version = tasks.get_healthcheck_version(self.master)
+        if (parse_version(version) > parse_version('0.4')):
+            returncode, output = run_healthcheck(
+                self.master,
+                "ipahealthcheck.meta",
+                output_type="human",
+                failures_only=True,
+            )
+        else:
+            returncode, output = run_healthcheck(
+                self.master,
+                "ipahealthcheck.meta.services",
+                output_type="human",
+                failures_only=True,
+            )
         assert returncode == 1
         errors = re.findall("ERROR: .*: not running", output)
-        assert len(errors) == len(output.split('\n'))
+        assert len(errors) == len(output.split("\n"))
 
     @pytest.fixture
     def move_ipa_ca_crt(self):
@@ -1387,6 +1439,7 @@ def test_tomcat_filecheck_too_restrictive(self, modify_permissions):
             )
 
     def test_tomcat_filecheck_too_permissive(self, modify_permissions):
+        version = tasks.get_healthcheck_version(self.master)
         modify_permissions(self.master, path=paths.CA_CS_CFG_PATH,
                            mode="0666")
         returncode, data = run_healthcheck(
@@ -1403,13 +1456,20 @@ def test_tomcat_filecheck_too_permissive(self, modify_permissions):
             assert check["kw"]["type"] == 'mode'
             assert check["kw"]["expected"] == '0660'
             assert check["kw"]["got"] == '0666'
-            assert (
-                check["kw"]["msg"]
-                == "Permissions of %s are too permissive: "
-                   "0666 and should be 0660"
-                % check["kw"]["path"]
-            )
-
+            if (parse_version(version) > parse_version('0.4')):
+                assert (
+                    check["kw"]["msg"]
+                    == "Permissions of %s are too permissive: "
+                       "0666 and should be 0660"
+                    % check["kw"]["path"]
+                )
+            else:
+                assert (
+                    check["kw"]["msg"]
+                    == "Permissions of %s are 0666 and should "
+                       "be 0660"
+                    % check["kw"]["path"]
+                )
 
 class TestIpaHealthCheckFilesystemSpace(IntegrationTest):
     """
@@ -1697,13 +1757,19 @@ def test_ipahealthcheck_certmongerca(self, getcert_ca):
             self.master, "ipahealthcheck.ipa.certs", "IPACertmongerCA",
         )
         assert returncode == 1
+        version = tasks.get_healthcheck_version(self.master)
         for check in data:
             if check["kw"]["key"] == "dogtag-ipa-ca-renew-agent":
                 assert check["result"] == "ERROR"
-                assert (
-                    check["kw"]["msg"]
-                    == "Certmonger CA '{key}' missing"
-                )
+                if (parse_version(version) > parse_version('0.4')):
+                    assert (
+                        check["kw"]["msg"] == "Certmonger CA '{key}' missing"
+                    )
+                else:
+                    assert (
+                        check["kw"]["msg"]
+                        == "Certmonger CA 'dogtag-ipa-ca-renew-agent' missing"
+                    )
 
     @pytest.fixture()
     def rename_httpd_cert(self):

From baf6431155d7fd4d6cc36d6ff571ff7a9efc1670 Mon Sep 17 00:00:00 2001
From: Sudhir Menon <sume...@redhat.com>
Date: Wed, 23 Sep 2020 13:29:53 +0530
Subject: [PATCH 2/2] Temp Commit

Signed-off-by: Sudhir Menon <sume...@redhat.com>
---
 .freeipa-pr-ci.yaml                        | 2 +-
 ipatests/prci_definitions/temp_commit.yaml | 6 +++---
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/.freeipa-pr-ci.yaml b/.freeipa-pr-ci.yaml
index abcf8c5b63..8065669008 120000
--- a/.freeipa-pr-ci.yaml
+++ b/.freeipa-pr-ci.yaml
@@ -1 +1 @@
-ipatests/prci_definitions/gating.yaml
\ No newline at end of file
+ipatests/prci_definitions/temp_commit.yaml
\ No newline at end of file
diff --git a/ipatests/prci_definitions/temp_commit.yaml b/ipatests/prci_definitions/temp_commit.yaml
index ef2e4bfa90..995e6e6893 100644
--- a/ipatests/prci_definitions/temp_commit.yaml
+++ b/ipatests/prci_definitions/temp_commit.yaml
@@ -68,7 +68,7 @@ jobs:
       class: RunPytest
       args:
         build_url: '{fedora-latest/build_url}'
-        test_suite: test_integration/test_REPLACEME.py
+        test_suite: test_integration/test_ipahealthcheck.py::TestIpaHealthCheckWithExternalCA test_integration/test_ipahealthcheck.py::TestIpaHealthCheck
         template: *ci-master-latest
-        timeout: 3600
-        topology: *master_1repl_1client
+        timeout: 7200
+        topology: *master_1repl
_______________________________________________
FreeIPA-devel mailing list -- freeipa-devel@lists.fedorahosted.org
To unsubscribe send an email to freeipa-devel-le...@lists.fedorahosted.org
Fedora Code of Conduct: 
https://docs.fedoraproject.org/en-US/project/code-of-conduct/
List Guidelines: https://fedoraproject.org/wiki/Mailing_list_guidelines
List Archives: 
https://lists.fedorahosted.org/archives/list/freeipa-devel@lists.fedorahosted.org

Reply via email to