summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorChris St. Pierre <chris.a.st.pierre@gmail.com>2012-09-04 08:37:58 -0400
committerChris St. Pierre <chris.a.st.pierre@gmail.com>2012-09-04 08:42:53 -0400
commit6697481f7bed646b4c66c54c9a46d11aa075af4a (patch)
tree9eb5ea833d9727950dac9ba71e729aa536b9f9be /src
parent7b67855c6a34d092bcfc92786ccb99e08ffcc252 (diff)
downloadbcfg2-6697481f7bed646b4c66c54c9a46d11aa075af4a.tar.gz
bcfg2-6697481f7bed646b4c66c54c9a46d11aa075af4a.tar.bz2
bcfg2-6697481f7bed646b4c66c54c9a46d11aa075af4a.zip
Metadata: fixed category suppression, warnings about category suppression
Diffstat (limited to 'src')
-rw-r--r--src/lib/Bcfg2/Server/Plugins/Metadata.py48
1 files changed, 25 insertions, 23 deletions
diff --git a/src/lib/Bcfg2/Server/Plugins/Metadata.py b/src/lib/Bcfg2/Server/Plugins/Metadata.py
index fad9d7e38..774c6b1ef 100644
--- a/src/lib/Bcfg2/Server/Plugins/Metadata.py
+++ b/src/lib/Bcfg2/Server/Plugins/Metadata.py
@@ -314,6 +314,8 @@ class MetadataGroup(tuple):
self.is_profile = is_profile
self.is_public = is_public
self.is_private = is_private
+ # record which clients we've warned about category suppression
+ self.warned = []
def __str__(self):
return repr(self)
@@ -326,6 +328,7 @@ class MetadataGroup(tuple):
def __hash__(self):
return hash(self.name)
+
class Metadata(Bcfg2.Server.Plugin.Metadata,
Bcfg2.Server.Plugin.Statistics,
Bcfg2.Server.Plugin.DatabaseBacked):
@@ -631,9 +634,8 @@ class Metadata(Bcfg2.Server.Plugin.Metadata,
def _handle_groups_xml_event(self, event):
self.groups = {}
- # get_condition and aggregate_conditions must be separate
- # functions in order to ensure that the scope is right for the
- # closures they return
+ # these three functions must be separate functions in order to
+ # ensure that the scope is right for the closures they return
def get_condition(element):
negate = element.get('negate', 'false').lower() == 'true'
pname = element.get("name")
@@ -642,6 +644,22 @@ class Metadata(Bcfg2.Server.Plugin.Metadata,
elif element.tag == 'Client':
return lambda c, g, _: negate != (pname == c)
+ def get_category_condition(category, gname):
+ def in_cat(client, groups, categories):
+ if category in categories:
+ if (gname not in self.groups or
+ client not in self.groups[gname].warned):
+ self.logger.warning("%s: Group %s suppressed by "
+ "category %s; %s already a member "
+ "of %s" %
+ (self.name, gname, category, client,
+ categories[category]))
+ if gname in self.groups:
+ self.groups[gname].warned.append(client)
+ return False
+ return True
+ return in_cat
+
def aggregate_conditions(conditions):
return lambda client, groups, cats: \
all(cond(client, groups, cats) for cond in conditions)
@@ -697,26 +715,10 @@ class Metadata(Bcfg2.Server.Plugin.Metadata,
self.negated_groups[aggregate_conditions(conditions)] = \
self.groups[gname]
else:
- if self.groups[gname].category and gname in self.groups:
- category = self.groups[gname].category
-
- def in_cat(client, groups, categories):
- if category in categories:
- # this is debug, not warning, because it
- # gets called a _lot_ -- every time a
- # group in a category is processed for
- # every creation of client metadata. this
- # message is produced in two other places,
- # so the user should get warned by one of
- # those.
- self.logger.debug("%s: Group %s suppressed by "
- "category %s; %s already a "
- "member of %s" %
- (self.name, gname, category,
- client, categories[category]))
- return False
- return True
- conditions.append(in_cat)
+ if self.groups[gname].category:
+ conditions.append(
+ get_category_condition(self.groups[gname].category,
+ gname))
self.group_membership[aggregate_conditions(conditions)] = \
self.groups[gname]