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