Blame SOURCES/sos-collector-race-condition-cluster-loading.patch

52984c
From 79a29ec5111e65013020bf6fd34e962e923d8698 Mon Sep 17 00:00:00 2001
52984c
From: Jake Hunsaker <jhunsake@redhat.com>
52984c
Date: Tue, 6 Nov 2018 12:17:07 -0500
52984c
Subject: [PATCH] [soscollector] Fix race condition in loading cluster profiles
52984c
52984c
Fixes a race condition where a layered cluster profile would not be
52984c
properly loaded because the base profile would be checked first.
52984c
52984c
Now, once a profile is matched, we check to see if there are any layered
52984c
profiles built on top of it. If there are, those are checked and if
52984c
their enablement check returns True, the layered profile is used instead
52984c
of the base profile. If the layered profile's check returns False, or if
52984c
no layered profiles are found, the base profile is still used.
52984c
52984c
Resolves: #12
52984c
52984c
Signed-off-by: Jake Hunsaker <jhunsake@redhat.com>
52984c
---
52984c
 soscollector/sos_collector.py | 31 +++++++++++++++++++++++++------
52984c
 1 file changed, 25 insertions(+), 6 deletions(-)
52984c
52984c
diff --git a/soscollector/sos_collector.py b/soscollector/sos_collector.py
52984c
index 60daa2e..e7f3ea7 100644
52984c
--- a/soscollector/sos_collector.py
52984c
+++ b/soscollector/sos_collector.py
52984c
@@ -409,12 +409,31 @@ this utility or remote systems that it connects to.
52984c
         If a list of nodes is given, this is not run, however the cluster
52984c
         can still be run if the user sets a --cluster-type manually
52984c
         '''
52984c
-
52984c
-        for clus in self.clusters:
52984c
-            self.clusters[clus].master = self.master
52984c
-            if self.clusters[clus].check_enabled():
52984c
-                self.config['cluster'] = self.clusters[clus]
52984c
-                name = str(self.clusters[clus].__class__.__name__).lower()
52984c
+        checks = list(self.clusters.values())
52984c
+        for cluster in checks:
52984c
+            checks.remove(cluster)
52984c
+            cluster.master = self.master
52984c
+            if cluster.check_enabled():
52984c
+                cname = cluster.__class__.__name__
52984c
+                self.log_debug("Installation matches %s, checking for layered "
52984c
+                               "profiles" % cname)
52984c
+                for remaining in checks:
52984c
+                    if issubclass(remaining.__class__, cluster.__class__):
52984c
+                        rname = remaining.__class__.__name__
52984c
+                        self.log_debug("Layered profile %s found. "
52984c
+                                       "Checking installation"
52984c
+                                       % rname)
52984c
+                        remaining.master = self.master
52984c
+                        if remaining.check_enabled():
52984c
+                            self.log_debug("Installation matches both layered "
52984c
+                                           "profile %s and base profile %s, "
52984c
+                                           "setting cluster type to layered "
52984c
+                                           "profile" % (rname, cname))
52984c
+                            cluster = remaining
52984c
+                            break
52984c
+
52984c
+                self.config['cluster'] = cluster
52984c
+                name = str(cluster.__class__.__name__).lower()
52984c
                 self.config['cluster_type'] = name
52984c
                 self.log_info(
52984c
                     'Cluster type set to %s' % self.config['cluster_type'])
52984c
-- 
52984c
2.17.2
52984c