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

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