summaryrefslogtreecommitdiffstats
path: root/src/lib/Bcfg2/Server/Lint
diff options
context:
space:
mode:
authorChris St. Pierre <chris.a.st.pierre@gmail.com>2012-10-11 16:20:49 -0400
committerChris St. Pierre <chris.a.st.pierre@gmail.com>2012-10-15 09:10:21 -0400
commit48f64b1086b5ce8b42367fbeeb5c46a8fdaba05a (patch)
treeb305a99e5d9686dcf8de0e852b428305886b431f /src/lib/Bcfg2/Server/Lint
parent4548a6df055a19d7dfbb2d44aec522bf26d670ca (diff)
downloadbcfg2-48f64b1086b5ce8b42367fbeeb5c46a8fdaba05a.tar.gz
bcfg2-48f64b1086b5ce8b42367fbeeb5c46a8fdaba05a.tar.bz2
bcfg2-48f64b1086b5ce8b42367fbeeb5c46a8fdaba05a.zip
bcfg2-lint: rolled Duplicates plugin into MetadataLint
Diffstat (limited to 'src/lib/Bcfg2/Server/Lint')
-rw-r--r--src/lib/Bcfg2/Server/Lint/Duplicates.py73
1 files changed, 0 insertions, 73 deletions
diff --git a/src/lib/Bcfg2/Server/Lint/Duplicates.py b/src/lib/Bcfg2/Server/Lint/Duplicates.py
deleted file mode 100644
index 9b36f054b..000000000
--- a/src/lib/Bcfg2/Server/Lint/Duplicates.py
+++ /dev/null
@@ -1,73 +0,0 @@
-""" Find duplicate clients, groups, etc. """
-
-import Bcfg2.Server.Lint
-
-
-class Duplicates(Bcfg2.Server.Lint.ServerPlugin):
- """ Find duplicate clients, groups, etc. """
-
- def __init__(self, *args, **kwargs):
- Bcfg2.Server.Lint.ServerPlugin.__init__(self, *args, **kwargs)
- self.groups_xdata = None
- self.clients_xdata = None
- self.load_xdata()
-
- def Run(self):
- """ run plugin """
- # only run this plugin if we were not given a list of files.
- # not only is it marginally silly to run this plugin with a
- # partial list of files, it turns out to be really freaking
- # hard to get only a fragment of group or client metadata
- if self.groups_xdata is not None:
- self.duplicate_groups()
- self.duplicate_defaults()
- if self.clients_xdata is not None:
- self.duplicate_clients()
-
- @classmethod
- def Errors(cls):
- return {"duplicate-client": "error",
- "duplicate-group": "error",
- "duplicate-package": "error",
- "multiple-default-groups": "error"}
-
- def load_xdata(self):
- """ attempt to load XML data for groups and clients. only
- actually load data if all documents reference in XIncludes can
- be found in self.files"""
- if self.has_all_xincludes("groups.xml"):
- self.groups_xdata = self.metadata.clients_xml.xdata
- if self.has_all_xincludes("clients.xml"):
- self.clients_xdata = self.metadata.clients_xml.xdata
-
- def duplicate_groups(self):
- """ find duplicate groups """
- self.duplicate_entries(self.clients_xdata.xpath('//Groups/Group'),
- 'group')
-
- def duplicate_clients(self):
- """ find duplicate clients """
- self.duplicate_entries(self.clients_xdata.xpath('//Clients/Client'),
- 'client')
-
- def duplicate_entries(self, data, etype):
- """ generic duplicate entry finder """
- seen = {}
- for el in data:
- if el.get('name') not in seen:
- seen[el.get('name')] = el
- else:
- self.LintError("duplicate-%s" % etype,
- "Duplicate %s '%s':\n%s\n%s" %
- (etype, el.get('name'),
- self.RenderXML(seen[el.get('name')]),
- self.RenderXML(el)))
-
- def duplicate_defaults(self):
- """ check for multiple default group definitions """
- default_groups = [g for g in self.groups_xdata.findall('.//Group')
- if g.get('default') == 'true']
- if len(default_groups) > 1:
- self.LintError("multiple-default-groups",
- "Multiple default groups defined: %s" %
- ",".join(default_groups))