Blame SOURCES/0013-Add-service-check-dependencies.patch

863b3c
From 235198b41a0932a7a190124fff5f8c1afa5d6679 Mon Sep 17 00:00:00 2001
863b3c
From: Rob Crittenden <rcritten@redhat.com>
863b3c
Date: Wed, 5 May 2021 15:35:19 -0400
863b3c
Subject: [PATCH] Add service check dependencies
863b3c
863b3c
Since 389-ds is the heart of IPA there may not be a point in checking
863b3c
all dependent services. ipa-dnskeysyncd in particular doesn't like
863b3c
when it can't connect and tries to restart itself multiple times.
863b3c
863b3c
Note that this currently works because the services are sorted
863b3c
alphabetically and dirsrv appears near the top. Re-ordering may be
863b3c
necessary in the future.
863b3c
863b3c
I'm choosing not to add dirsrv to the other services because they
863b3c
return cleanly if it is not available.
863b3c
863b3c
https://bugzilla.redhat.com/show_bug.cgi?id=1776687
863b3c
863b3c
Signed-off-by: Rob Crittenden <rcritten@redhat.com>
863b3c
---
863b3c
 src/ipahealthcheck/core/core.py     | 20 ++++++++++++++++++++
863b3c
 src/ipahealthcheck/meta/services.py |  2 ++
863b3c
 2 files changed, 22 insertions(+)
863b3c
863b3c
diff --git a/src/ipahealthcheck/core/core.py b/src/ipahealthcheck/core/core.py
863b3c
index a4af690..eaa2d9c 100644
863b3c
--- a/src/ipahealthcheck/core/core.py
863b3c
+++ b/src/ipahealthcheck/core/core.py
863b3c
@@ -81,6 +81,26 @@ def run_service_plugins(plugins, source, check):
863b3c
         if not isinstance(plugin, ServiceCheck):
863b3c
             continue
863b3c
 
863b3c
+        # Try to save some time to not check dependent services if the
863b3c
+        # parent is down.
863b3c
+        if not set(plugin.requires).issubset(available):
863b3c
+            # A required service is not available. Either it hasn't been
863b3c
+            # checked yet or it isn't running. If not running break.
863b3c
+            running = True
863b3c
+            for result in results.results:
863b3c
+                if result.check in plugin.requires:
863b3c
+                    # if not in available but in results the service failed
863b3c
+                    running = False
863b3c
+                    break
863b3c
+            if not running:
863b3c
+                logger.debug(
863b3c
+                    'Skipping %s:%s because %s service(s) not running',
863b3c
+                    plugin.__class__.__module__,
863b3c
+                    plugin.__class__.__name__,
863b3c
+                    ', '.join(set(plugin.requires) - set(available))
863b3c
+                )
863b3c
+                continue
863b3c
+
863b3c
         logger.debug('Calling check %s', plugin)
863b3c
         for result in plugin.check():
863b3c
             # always run the service checks so dependencies work
863b3c
diff --git a/src/ipahealthcheck/meta/services.py b/src/ipahealthcheck/meta/services.py
863b3c
index a987108..5d80728 100644
863b3c
--- a/src/ipahealthcheck/meta/services.py
863b3c
+++ b/src/ipahealthcheck/meta/services.py
863b3c
@@ -92,6 +92,8 @@ class ipa_dnskeysyncd(IPAServiceCheck):
863b3c
     def check(self):
863b3c
         self.service_name = 'ipa-dnskeysyncd'
863b3c
 
863b3c
+        requires = ('dirsrv',)
863b3c
+
863b3c
         if not bindinstance.named_conf_exists():
863b3c
             return ()
863b3c
 
863b3c
-- 
863b3c
2.31.1
863b3c