Blame SOURCES/0002-Move-main-to-run_healthcheck-for-abstraction-purpose.patch

ef63c6
From eb87d277442dd1a1076ba9ae74c18ace8cc7dda8 Mon Sep 17 00:00:00 2001
ef63c6
From: Rob Crittenden <rcritten@redhat.com>
ef63c6
Date: Mon, 11 Nov 2019 10:29:53 -0500
ef63c6
Subject: [PATCH 2/5] Move main to run_healthcheck for abstraction purposes
ef63c6
ef63c6
Take as arguments the entry point name and the configuration
ef63c6
file.
ef63c6
---
ef63c6
 src/ipahealthcheck/core/config.py |  4 ++--
ef63c6
 src/ipahealthcheck/core/main.py   | 37 +++++++++++++++++--------------
ef63c6
 2 files changed, 22 insertions(+), 19 deletions(-)
ef63c6
ef63c6
diff --git a/src/ipahealthcheck/core/config.py b/src/ipahealthcheck/core/config.py
ef63c6
index 46da507..0cb72b7 100644
ef63c6
--- a/src/ipahealthcheck/core/config.py
ef63c6
+++ b/src/ipahealthcheck/core/config.py
ef63c6
@@ -5,7 +5,7 @@
ef63c6
 import logging
ef63c6
 from configparser import ConfigParser, ParsingError
ef63c6
 
ef63c6
-from ipahealthcheck.core.constants import CONFIG_FILE, CONFIG_SECTION
ef63c6
+from ipahealthcheck.core.constants import CONFIG_SECTION
ef63c6
 from ipahealthcheck.core.constants import DEFAULT_CONFIG
ef63c6
 
ef63c6
 logger = logging.getLogger()
ef63c6
@@ -70,7 +70,7 @@ class Config:
ef63c6
             self.__d[key] = d[key]
ef63c6
 
ef63c6
 
ef63c6
-def read_config(config_file=CONFIG_FILE):
ef63c6
+def read_config(config_file):
ef63c6
     """
ef63c6
     Simple configuration file reader
ef63c6
 
ef63c6
diff --git a/src/ipahealthcheck/core/main.py b/src/ipahealthcheck/core/main.py
ef63c6
index b3fbe6a..f59a8a8 100644
ef63c6
--- a/src/ipahealthcheck/core/main.py
ef63c6
+++ b/src/ipahealthcheck/core/main.py
ef63c6
@@ -28,11 +28,14 @@ else:
ef63c6
     from ipahealthcheck.meta.services import ServiceCheck
ef63c6
 
ef63c6
 
ef63c6
-def find_registries():
ef63c6
-    return {
ef63c6
-        ep.name: ep.resolve()
ef63c6
-        for ep in pkg_resources.iter_entry_points('ipahealthcheck.registry')
ef63c6
-    }
ef63c6
+def find_registries(entry_points):
ef63c6
+    registries = {}
ef63c6
+    for entry_point in entry_points:
ef63c6
+        registries.update({
ef63c6
+            ep.name: ep.resolve()
ef63c6
+            for ep in pkg_resources.iter_entry_points(entry_point)
ef63c6
+        })
ef63c6
+    return registries
ef63c6
 
ef63c6
 
ef63c6
 def find_plugins(name, registry):
ef63c6
@@ -194,9 +197,7 @@ def limit_results(results, source, check):
ef63c6
     return new_results
ef63c6
 
ef63c6
 
ef63c6
-def main():
ef63c6
-    environ["KRB5_CLIENT_KTNAME"] = "/etc/krb5.keytab"
ef63c6
-    environ["KRB5CCNAME"] = "MEMORY:"
ef63c6
+def run_healthcheck(entry_points, configfile):
ef63c6
     framework = object()
ef63c6
     plugins = []
ef63c6
     output = constants.DEFAULT_OUTPUT
ef63c6
@@ -208,17 +209,11 @@ def main():
ef63c6
     if options.debug:
ef63c6
         logger.setLevel(logging.DEBUG)
ef63c6
 
ef63c6
-    config = read_config()
ef63c6
+    config = read_config(configfile)
ef63c6
     if config is None:
ef63c6
         sys.exit(1)
ef63c6
 
ef63c6
-    if not (
ef63c6
-        options.source or options.list_sources
ef63c6
-    ) and not is_ipa_configured():
ef63c6
-        logging.error("IPA is not configured on this system.")
ef63c6
-        sys.exit(1)
ef63c6
-
ef63c6
-    for name, registry in find_registries().items():
ef63c6
+    for name, registry in find_registries(entry_points).items():
ef63c6
         try:
ef63c6
             registry.initialize(framework)
ef63c6
         except Exception as e:
ef63c6
@@ -283,4 +278,12 @@ def main():
ef63c6
             return_value = 1
ef63c6
             break
ef63c6
 
ef63c6
-    sys.exit(return_value)
ef63c6
+    return return_value
ef63c6
+
ef63c6
+
ef63c6
+def main():
ef63c6
+    environ["KRB5_CLIENT_KTNAME"] = "/etc/krb5.keytab"
ef63c6
+    environ["KRB5CCNAME"] = "MEMORY:"
ef63c6
+
ef63c6
+    sys.exit(run_healthcheck(['ipahealthcheck.registry'],
ef63c6
+                             constants.CONFIG_FILE))
ef63c6
-- 
ef63c6
2.20.1
ef63c6