URL: https://github.com/freeipa/freeipa/pull/4944 Author: rcritten Title: #4944: ipatests: verify that all services can be deteced by healthcheck Action: opened
PR body: """ Add fixture to handle restarting services so that if something goes wrong in the test the service(s) will all be restarted so that subsequent tests can pass. Services are restarted in reverse order. """ To pull the PR as Git branch: git remote add ghfreeipa https://github.com/freeipa/freeipa git fetch ghfreeipa pull/4944/head:pr4944 git checkout pr4944
From b66de6105c3d417f3f54282a75bffe36f06f65b7 Mon Sep 17 00:00:00 2001 From: Rob Crittenden <rcrit...@redhat.com> Date: Wed, 22 Jul 2020 11:47:23 -0400 Subject: [PATCH 1/4] ipatests: lib389 is now providing healthchecks, update naming --- ipatests/test_integration/test_ipahealthcheck.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ipatests/test_integration/test_ipahealthcheck.py b/ipatests/test_integration/test_ipahealthcheck.py index 729a685284..246fec859a 100644 --- a/ipatests/test_integration/test_ipahealthcheck.py +++ b/ipatests/test_integration/test_ipahealthcheck.py @@ -89,7 +89,7 @@ ipafiles_checks = ["IPAFileNSSDBCheck", "IPAFileCheck", "TomcatFileCheck"] dogtag_checks = ["DogtagCertsConfigCheck", "DogtagCertsConnectivityCheck"] iparoles_checks = ["IPACRLManagerCheck", "IPARenewalMasterCheck"] -replication_checks = ["ReplicationConflictCheck"] +replication_checks = ["ReplicationCheck"] ruv_checks = ["RUVCheck"] dna_checks = ["IPADNARangeCheck"] idns_checks = ["IPADNSSystemRecordsCheck"] From e95abca48d14c7838cf9e358e3a2e4ccdb1109ab Mon Sep 17 00:00:00 2001 From: Rob Crittenden <rcrit...@redhat.com> Date: Fri, 24 Jul 2020 10:09:35 -0400 Subject: [PATCH 2/4] ipatests: Use healthcheck namespacing in stopped server test The test_run_with_stopped_master() test runs ipactl stop and then verifies that all the errors relate to the services not being available. The newly integrated PKI tests also report errors in this case. Use the namespacing introduced in freeipa-healthcheck-0.6 to limit the execution to the ipahealthcheck.meta checks to avoid the spurious PKI errors. Signed-off-by: Rob Crittenden <rcrit...@redhat.com> --- ipatests/test_integration/test_ipahealthcheck.py | 1 + 1 file changed, 1 insertion(+) diff --git a/ipatests/test_integration/test_ipahealthcheck.py b/ipatests/test_integration/test_ipahealthcheck.py index 246fec859a..7a3efd5851 100644 --- a/ipatests/test_integration/test_ipahealthcheck.py +++ b/ipatests/test_integration/test_ipahealthcheck.py @@ -717,6 +717,7 @@ def test_run_with_stopped_master(self, ipactl): """ returncode, output = run_healthcheck( self.master, + "ipahealthcheck.meta", output_type="human", failures_only=True) assert returncode == 1 From 7f1073e6674872a10cf19b1e79d52fae658ccf28 Mon Sep 17 00:00:00 2001 From: Rob Crittenden <rcrit...@redhat.com> Date: Wed, 22 Jul 2020 11:45:05 -0400 Subject: [PATCH 3/4] ipatests: verify that all services can be deteced by healthcheck Add fixture to handle restarting services so that if something goes wrong in the test the service(s) will all be restarted so that subsequent tests can pass. Services are restarted in reverse order. --- .../test_integration/test_ipahealthcheck.py | 119 ++++++++++++------ 1 file changed, 79 insertions(+), 40 deletions(-) diff --git a/ipatests/test_integration/test_ipahealthcheck.py b/ipatests/test_integration/test_ipahealthcheck.py index 7a3efd5851..079e5e860f 100644 --- a/ipatests/test_integration/test_ipahealthcheck.py +++ b/ipatests/test_integration/test_ipahealthcheck.py @@ -157,6 +157,36 @@ def run_healthcheck(host, source=None, check=None, output_type="json", return result.returncode, data +@pytest.fixture +def restart_service(): + """Shut down and restart a service as a fixture""" + + service = dict() + + def _stop_service(host, service_name): + service_name = service_name.replace('_', '-') + if service_name == 'pki-tomcatd': + service_name = 'pki-tomcatd@pki-tomcat' + elif service_name == 'dirsrv': + serverid = (realm_to_serverid(host.domain.realm)).upper() + service_name = 'dirsrv@%s.service' % serverid + elif service_name == 'named': + service_name = 'named-pkcs11' + if 'host' not in service: + service['host'] = host + service['name'] = [service_name] + else: + service['name'].append(service_name) + host.run_command(["systemctl", "stop", service_name]) + + yield _stop_service + + if service.get('name'): + service.get('name', []).reverse() + for name in service.get('name', []): + service.get('host').run_command(["systemctl", "start", name]) + + class TestIpaHealthCheck(IntegrationTest): """ Tier-1 test for ipa-healthcheck tool with IPA Master setup with @@ -192,23 +222,21 @@ def test_run_ipahealthcheck_list_source(self): for source in sources: assert source in result.stdout_text - def test_human_output(self): + def test_human_output(self, restart_service): """ 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"]) + restart_service(self.master, "sssd") + + returncode, output = run_healthcheck( + self.master, + "ipahealthcheck.meta.services", + "sssd", + "human", + ) assert returncode == 1 assert output == \ @@ -258,33 +286,46 @@ def test_ipa_trust_check_exists(self): for check in ipatrust_checks: assert check in result.stdout_text - def test_source_ipahealthcheck_meta_services_check_sssd(self): + def test_source_ipahealthcheck_meta_services_check(self, restart_service): """ - Testcase checks behaviour of check sssd in + Testcase checks behaviour of check configured services in ipahealthcheck.meta.services when service is stopped and started respectively """ - self.master.run_command(["systemctl", "stop", "sssd"]) - returncode, data = run_healthcheck( - self.master, - "ipahealthcheck.meta.services", - "sssd", - ) - assert returncode == 1 - for check in data: - assert check["result"] == "ERROR" - assert check["kw"]["msg"] == "sssd: not running" - assert check["kw"]["status"] is False - self.master.run_command(["systemctl", "start", "sssd"]) - returncode, data = run_healthcheck( - self.master, - "ipahealthcheck.meta.services", - "sssd", - ) - assert returncode == 0 - assert data[0]["check"] == "sssd" - assert data[0]["result"] == "SUCCESS" - assert data[0]["kw"]["status"] is True + svc_list = ('certmonger', 'gssproxy', 'httpd', 'ipa_custodia', + 'ipa_dnskeysyncd', 'kadmin', 'krb5kdc', + 'named', 'pki_tomcatd', 'sssd', 'dirsrv') + + for service in svc_list: + returncode, data = run_healthcheck( + self.master, + "ipahealthcheck.meta.services", + service, + ) + assert returncode == 0 + assert data[0]["check"] == service + assert data[0]["result"] == "SUCCESS" + assert data[0]["kw"]["status"] is True + + for service in svc_list: + restart_service(self.master, service) + returncode, data = run_healthcheck( + self.master, + "ipahealthcheck.meta.services", + service, + ) + assert returncode == 1 + service_found = False + for check in data: + if check["check"] != service: + continue + if service != 'pki_tomcatd': + service = service.replace('_', '-') + assert check["result"] == "ERROR" + assert check["kw"]["msg"] == "%s: not running" % service + assert check["kw"]["status"] is False + service_found = True + assert service_found def test_source_ipahealthcheck_dogtag_ca_dogtagcertsconfigcheck(self): """ @@ -365,7 +406,9 @@ def test_source_ipahealthcheck_meta_core_metacheck(self): assert data[0]["kw"]["ipa_version"] in result.stdout_text assert data[0]["kw"]["ipa_api_version"] in result.stdout_text - def test_source_ipahealthcheck_ipa_host_check_ipahostkeytab(self): + def test_source_ipahealthcheck_ipa_host_check_ipahostkeytab( + self, restart_service + ): """ Testcase checks behaviour of check IPAHostKeytab in source ipahealthcheck.ipa.host when dirsrv service is stopped and @@ -377,11 +420,8 @@ def test_source_ipahealthcheck_ipa_host_check_ipahostkeytab(self): "Minor code may provide more information, " "Minor (2529638972): Generic error (see e-text)" ) + restart_service(self.master, "dirsrv") dirsrv_ipactl_status = 'Directory Service: STOPPED' - api.env.realm = self.master.domain.name - serverid = (realm_to_serverid(api.env.realm)).upper() - dirsrv_service = "dirsrv@%s.service" % serverid - self.master.run_command(["systemctl", "stop", dirsrv_service]) result = self.master.run_command( ["ipactl", "status"]) returncode, data = run_healthcheck( @@ -395,7 +435,6 @@ def test_source_ipahealthcheck_ipa_host_check_ipahostkeytab(self): assert data[0]["kw"]["msg"] == msg else: assert data[0]["result"] == "SUCCESS" - self.master.run_command(["systemctl", "start", dirsrv_service]) def test_source_ipahealthcheck_topology_IPATopologyDomainCheck(self): """ From 92992a33ef34423b05d8144f6aa56c0d5a15351d Mon Sep 17 00:00:00 2001 From: Rob Crittenden <rcrit...@redhat.com> Date: Fri, 24 Jul 2020 14:23:57 -0400 Subject: [PATCH 4/4] Temp commit --- .freeipa-pr-ci.yaml | 2 +- ipatests/prci_definitions/temp_commit.yaml | 4 ++-- 2 files changed, 3 insertions(+), 3 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 e337068145..787a117232 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::TestIpaHealthCheck::test_source_ipahealthcheck_meta_services_check template: *ci-master-latest timeout: 3600 - topology: *master_1repl_1client + 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