diff options
author | Chris St. Pierre <chris.a.st.pierre@gmail.com> | 2012-06-14 20:08:47 -0400 |
---|---|---|
committer | Chris St. Pierre <chris.a.st.pierre@gmail.com> | 2012-06-14 20:08:47 -0400 |
commit | e43040b084d66702efe1887a9d953b9154732512 (patch) | |
tree | 4240ab12cd944a752daf78d24d7081c4e9a0787b /src/lib/Bcfg2/Server/Plugins/Bundler.py | |
parent | 5dba50f1db4b9807a137a2f40b338010eaf297ea (diff) | |
download | bcfg2-e43040b084d66702efe1887a9d953b9154732512.tar.gz bcfg2-e43040b084d66702efe1887a9d953b9154732512.tar.bz2 bcfg2-e43040b084d66702efe1887a9d953b9154732512.zip |
made bcfg2-lint load lint plugins from server plugins where appropriate
Diffstat (limited to 'src/lib/Bcfg2/Server/Plugins/Bundler.py')
-rw-r--r-- | src/lib/Bcfg2/Server/Plugins/Bundler.py | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/src/lib/Bcfg2/Server/Plugins/Bundler.py b/src/lib/Bcfg2/Server/Plugins/Bundler.py index cbaa85089..6289439c6 100644 --- a/src/lib/Bcfg2/Server/Plugins/Bundler.py +++ b/src/lib/Bcfg2/Server/Plugins/Bundler.py @@ -8,6 +8,7 @@ import re import sys import Bcfg2.Server import Bcfg2.Server.Plugin +import Bcfg2.Server.Lint try: import genshi.template.base @@ -91,3 +92,52 @@ class Bundler(Bcfg2.Server.Plugin.Plugin, self.logger.error("Bundler: Unexpected bundler error for %s" % bundlename, exc_info=1) return bundleset + +class BundlerLint(Bcfg2.Server.Lint.ServerPlugin): + """ Perform various bundle checks """ + def Run(self): + """ run plugin """ + self.missing_bundles() + for bundle in self.core.plugins['Bundler'].entries.values(): + if (self.HandlesFile(bundle.name) and + (not have_genshi or type(bundle) is not SGenshiTemplateFile)): + self.bundle_names(bundle) + + @classmethod + def Errors(cls): + return {"bundle-not-found":"error", + "inconsistent-bundle-name":"warning"} + + def missing_bundles(self): + """ find bundles listed in Metadata but not implemented in Bundler """ + if self.files is None: + # when given a list of files on stdin, this check is + # useless, so skip it + groupdata = self.metadata.groups_xml.xdata + ref_bundles = set([b.get("name") + for b in groupdata.findall("//Bundle")]) + + allbundles = self.core.plugins['Bundler'].entries.keys() + for bundle in ref_bundles: + xmlbundle = "%s.xml" % bundle + genshibundle = "%s.genshi" % bundle + if (xmlbundle not in allbundles and + genshibundle not in allbundles): + self.LintError("bundle-not-found", + "Bundle %s referenced, but does not exist" % + bundle) + + def bundle_names(self, bundle): + """ verify bundle name attribute matches filename """ + try: + xdata = lxml.etree.XML(bundle.data) + except AttributeError: + # genshi template + xdata = lxml.etree.parse(bundle.template.filepath).getroot() + + fname = bundle.name.split('Bundler/')[1].split('.')[0] + bname = xdata.get('name') + if fname != bname: + self.LintError("inconsistent-bundle-name", + "Inconsistent bundle name: filename is %s, " + "bundle name is %s" % (fname, bname)) |