summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--examples/bcfg2-lint.conf2
-rw-r--r--src/lib/Server/Lint/Bundles.py81
-rw-r--r--src/lib/Server/Lint/Comments.py63
-rw-r--r--src/lib/Server/Lint/InfoXML.py61
-rw-r--r--src/lib/Server/Lint/RequiredAttrs.py15
5 files changed, 116 insertions, 106 deletions
diff --git a/examples/bcfg2-lint.conf b/examples/bcfg2-lint.conf
index dbb69dbb2..96b86af3b 100644
--- a/examples/bcfg2-lint.conf
+++ b/examples/bcfg2-lint.conf
@@ -1,5 +1,5 @@
[lint]
-plugins=Duplicates,InfoXML,Bundles,Headers,RequiredAttrs,Validate
+plugins=Duplicates,InfoXML,Bundles,Comments,RequiredAttrs,Validate
[InfoXML]
required_attrs = owner,group,perms,paranoid
diff --git a/src/lib/Server/Lint/Bundles.py b/src/lib/Server/Lint/Bundles.py
index b242239ae..417f76c2d 100644
--- a/src/lib/Server/Lint/Bundles.py
+++ b/src/lib/Server/Lint/Bundles.py
@@ -1,56 +1,61 @@
import lxml.etree
import Bcfg2.Server.Lint
-
+
class Bundles(Bcfg2.Server.Lint.ServerPlugin):
""" Perform various bundle checks """
@Bcfg2.Server.Lint.returnErrors
def Run(self):
""" run plugin """
- self.missing_bundles()
- self.bundle_names()
- self.sgenshi_groups()
+ if 'Bundler' in self.core.plugins:
+ self.missing_bundles()
+ for bundle in self.core.plugins['Bundler'].entries.values():
+ if self.HandlesFile(bundle.name):
+ if (Bcfg2.Server.Plugins.Bundler.have_genshi and
+ type(bundle) is
+ Bcfg2.Server.Plugins.SGenshi.SGenshiTemplateFile):
+ self.sgenshi_groups(bundle)
+ else:
+ self.bundle_names(bundle)
def missing_bundles(self):
""" find bundles listed in Metadata but not implemented in Bundler """
- groupdata = self.metadata.groups_xml.xdata
- ref_bundles = set([b.get("name")
- for b in groupdata.findall("//Bundle")])
+ 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 %s referenced, but does not exist" %
- 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 %s referenced, but does not exist" %
+ bundle)
- def bundle_names(self):
+ def bundle_names(self, bundle):
""" verify bundle name attribute matches filename """
- for bundle in self.core.plugins['Bundler'].entries.values():
- if self.HandlesFile(bundle.name):
- try:
- xdata = lxml.etree.XML(bundle.data)
- except AttributeError:
- # genshi template
- xdata = lxml.etree.parse(bundle.template.filepath).getroot()
+ 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.LintWarning("Inconsistent bundle name: filename is %s, bundle name is %s" %
- (fname, bname))
+ fname = bundle.name.split('Bundler/')[1].split('.')[0]
+ bname = xdata.get('name')
+ if fname != bname:
+ self.LintWarning("Inconsistent bundle name: filename is %s, bundle name is %s" %
+ (fname, bname))
- def sgenshi_groups(self):
+ def sgenshi_groups(self, bundle):
""" ensure that Genshi Bundles do not include <Group> tags,
which are not supported """
- for bundle in self.core.plugins['Bundler'].entries.values():
- if self.HandlesFile(bundle.name):
- if (type(bundle) is
- Bcfg2.Server.Plugins.SGenshi.SGenshiTemplateFile):
- xdata = lxml.etree.parse(bundle.name)
- groups = [self.RenderXML(g)
- for g in xdata.getroottree().findall("//Group")]
- if groups:
- self.LintWarning("<Group> tag is not allowed in SGenshi Bundle:\n%s" %
- "\n".join(groups))
+ xdata = lxml.etree.parse(bundle.name)
+ groups = [self.RenderXML(g)
+ for g in xdata.getroottree().findall("//Group")]
+ if groups:
+ self.LintWarning("<Group> tag is not allowed in SGenshi Bundle:\n%s" %
+ "\n".join(groups))
diff --git a/src/lib/Server/Lint/Comments.py b/src/lib/Server/Lint/Comments.py
index 1b75bb25e..587f20603 100644
--- a/src/lib/Server/Lint/Comments.py
+++ b/src/lib/Server/Lint/Comments.py
@@ -51,17 +51,18 @@ class Comments(Bcfg2.Server.Lint.ServerPlugin):
def check_bundles(self):
""" check bundle files for required headers """
- for bundle in self.core.plugins['Bundler'].entries.values():
- xdata = None
- rtype = ""
- try:
- xdata = lxml.etree.XML(bundle.data)
- rtype = "bundler"
- except AttributeError:
- xdata = lxml.etree.parse(bundle.template.filepath).getroot()
- rtype = "sgenshi"
-
- self.check_xml(bundle.name, xdata, rtype)
+ if 'Bundler' in self.core.plugins:
+ for bundle in self.core.plugins['Bundler'].entries.values():
+ xdata = None
+ rtype = ""
+ try:
+ xdata = lxml.etree.XML(bundle.data)
+ rtype = "bundler"
+ except AttributeError:
+ xdata = lxml.etree.parse(bundle.template.filepath).getroot()
+ rtype = "sgenshi"
+
+ self.check_xml(bundle.name, xdata, rtype)
def check_properties(self):
""" check properties files for required headers """
@@ -73,33 +74,35 @@ class Comments(Bcfg2.Server.Lint.ServerPlugin):
def check_metadata(self):
""" check metadata files for required headers """
- metadata = self.core.plugins['Metadata']
if self.has_all_xincludes("groups.xml"):
- self.check_xml(os.path.join(metadata.data, "groups.xml"),
- metadata.groups_xml.data,
+ self.check_xml(os.path.join(self.metadata.data, "groups.xml"),
+ self.metadata.groups_xml.data,
"metadata")
if self.has_all_xincludes("clients.xml"):
- self.check_xml(os.path.join(metadata.data, "clients.xml"),
- metadata.clients_xml.data,
+ self.check_xml(os.path.join(self.metadata.data, "clients.xml"),
+ self.metadata.clients_xml.data,
"metadata")
def check_cfg(self):
""" check Cfg files for required headers """
- for entryset in self.core.plugins['Cfg'].entries.values():
- for entry in entryset.entries.values():
- if entry.name.endswith(".genshi"):
- rtype = "tgenshi"
- else:
- rtype = "cfg"
- self.check_plaintext(entry.name, entry.data, rtype)
+ if 'Cfg' in self.core.plugins:
+ for entryset in self.core.plugins['Cfg'].entries.values():
+ for entry in entryset.entries.values():
+ if entry.name.endswith(".genshi"):
+ rtype = "tgenshi"
+ else:
+ rtype = "cfg"
+ self.check_plaintext(entry.name, entry.data, rtype)
def check_infoxml(self):
""" check info.xml files for required headers """
- for entryset in self.core.plugins['Cfg'].entries.items():
- if hasattr(entryset, "infoxml") and entryset.infoxml is not None:
- self.check_xml(entryset.infoxml.name,
- entryset.infoxml.pnode.data,
- "infoxml")
+ if 'Cfg' in self.core.plugins:
+ for entryset in self.core.plugins['Cfg'].entries.items():
+ if (hasattr(entryset, "infoxml") and
+ entryset.infoxml is not None):
+ self.check_xml(entryset.infoxml.name,
+ entryset.infoxml.pnode.data,
+ "infoxml")
def check_probes(self):
""" check probes for required headers """
@@ -145,8 +148,8 @@ class Comments(Bcfg2.Server.Lint.ServerPlugin):
missing = [keyword for (keyword, status) in found.items()
if status is False]
if missing:
- self.LintError("%s: Required keywords(s) not found: %s" %
- (filename, ", ".join(missing)))
+ self.LintError("%s: Required keywords(s) not found: $%s$" %
+ (filename, "$, $".join(missing)))
# next, check for required comments. found is just
# boolean
diff --git a/src/lib/Server/Lint/InfoXML.py b/src/lib/Server/Lint/InfoXML.py
index 798d8c208..25f609902 100644
--- a/src/lib/Server/Lint/InfoXML.py
+++ b/src/lib/Server/Lint/InfoXML.py
@@ -7,36 +7,37 @@ class InfoXML(Bcfg2.Server.Lint.ServerPlugin):
@Bcfg2.Server.Lint.returnErrors
def Run(self):
- for filename, entryset in self.core.plugins['Cfg'].entries.items():
- infoxml_fname = os.path.join(entryset.path, "info.xml")
- if self.HandlesFile(infoxml_fname):
- if (hasattr(entryset, "infoxml") and
- entryset.infoxml is not None):
- xdata = entryset.infoxml.pnode.data
- for info in xdata.getroottree().findall("//Info"):
- required = []
- if "required_attrs" in self.config:
- required = self.config["required_attrs"].split(",")
+ if 'Cfg' in self.core.plugins:
+ for filename, entryset in self.core.plugins['Cfg'].entries.items():
+ infoxml_fname = os.path.join(entryset.path, "info.xml")
+ if self.HandlesFile(infoxml_fname):
+ if (hasattr(entryset, "infoxml") and
+ entryset.infoxml is not None):
+ self.check_infoxml(entryset.infoxml.pnode.data)
+ elif ("require" in self.config and
+ self.config["require"].lower != "false"):
+ self.LintError("No info.xml found for %s" % filename)
- missing = [attr for attr in required
- if info.get(attr) is None]
- if missing:
- self.LintError("Required attribute(s) %s not found in %s:%s" %
- (",".join(missing), infoxml_fname,
- self.RenderXML(info)))
+ def check_infoxml(self, xdata):
+ for info in xdata.getroottree().findall("//Info"):
+ required = []
+ if "required_attrs" in self.config:
+ required = self.config["required_attrs"].split(",")
- if ("require_paranoid" in self.config and
- self.config["require_paranoid"].lower() == "true" and
- (Bcfg2.Options.MDATA_PARANOID.value and
- info.get("paranoid") is not None and
- info.get("paranoid").lower() == "false") or
- (not Bcfg2.Options.MDATA_PARANOID.value and
- (info.get("paranoid") is None or
- info.get("paranoid").lower() != "true"))):
- self.LintError("Paranoid must be true in %s:%s" %
- (infoxml_fname,
- self.RenderXML(info)))
- elif ("require" in self.config and
- self.config["require"].lower != "false"):
- self.LintError("No info.xml found for %s" % filename)
+ missing = [attr for attr in required if info.get(attr) is None]
+ if missing:
+ self.LintError("Required attribute(s) %s not found in %s:%s" %
+ (",".join(missing), infoxml_fname,
+ self.RenderXML(info)))
+
+ if ("require_paranoid" in self.config and
+ self.config["require_paranoid"].lower() == "true" and
+ (Bcfg2.Options.MDATA_PARANOID.value and
+ info.get("paranoid") is not None and
+ info.get("paranoid").lower() == "false") or
+ (not Bcfg2.Options.MDATA_PARANOID.value and
+ (info.get("paranoid") is None or
+ info.get("paranoid").lower() != "true"))):
+ self.LintError("Paranoid must be true in %s:%s" %
+ (infoxml_fname, self.RenderXML(info)))
diff --git a/src/lib/Server/Lint/RequiredAttrs.py b/src/lib/Server/Lint/RequiredAttrs.py
index 7215fe163..70ce4fe0a 100644
--- a/src/lib/Server/Lint/RequiredAttrs.py
+++ b/src/lib/Server/Lint/RequiredAttrs.py
@@ -34,14 +34,15 @@ class RequiredAttrs(Bcfg2.Server.Lint.ServerPlugin):
def check_bundles(self):
""" check bundles for BoundPath entries with missing attrs """
- for bundle in self.core.plugins['Bundler'].entries.values():
- try:
- xdata = lxml.etree.XML(bundle.data)
- except AttributeError:
- xdata = lxml.etree.parse(bundle.template.filepath).getroot()
+ if 'Bundler' in self.core.plugins:
+ for bundle in self.core.plugins['Bundler'].entries.values():
+ try:
+ xdata = lxml.etree.XML(bundle.data)
+ except AttributeError:
+ xdata = lxml.etree.parse(bundle.template.filepath).getroot()
- for path in xdata.xpath("//BoundPath"):
- self.check_entry(path, bundle.name)
+ for path in xdata.xpath("//BoundPath"):
+ self.check_entry(path, bundle.name)
def check_entry(self, entry, filename):
""" generic entry check """