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

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