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

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