diff options
author | Chris St. Pierre <chris.a.st.pierre@gmail.com> | 2011-04-20 09:41:07 -0400 |
---|---|---|
committer | Chris St. Pierre <chris.a.st.pierre@gmail.com> | 2011-04-20 09:41:07 -0400 |
commit | b5810882e8c6b1e6b76a8239f70a129d415ecee6 (patch) | |
tree | 8c2df3610bebd92f52b70b7f37a7197c9ec2a3e9 /src/lib/Server/Lint/InfoXML.py | |
parent | 20974e1311168b75e621cad14894fe7b217b61a2 (diff) | |
download | bcfg2-b5810882e8c6b1e6b76a8239f70a129d415ecee6.tar.gz bcfg2-b5810882e8c6b1e6b76a8239f70a129d415ecee6.tar.bz2 bcfg2-b5810882e8c6b1e6b76a8239f70a129d415ecee6.zip |
Rewrote bcfg2-repo-validate as bcfg2-lint, which uses a plugin
interface to be lots more flexible and extensible. Added several more
tests. If bcfg2-lint is run as bcfg2-repo-validate, it roughly
emulates the functionality of that program.
TODO: Need to figure out correct way to symlink bcfg2-repo-validate to
bcfg2-lint on install.
Diffstat (limited to 'src/lib/Server/Lint/InfoXML.py')
-rw-r--r-- | src/lib/Server/Lint/InfoXML.py | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/src/lib/Server/Lint/InfoXML.py b/src/lib/Server/Lint/InfoXML.py new file mode 100644 index 000000000..097c2d6f9 --- /dev/null +++ b/src/lib/Server/Lint/InfoXML.py @@ -0,0 +1,38 @@ +import os.path +import Bcfg2.Options +import Bcfg2.Server.Lint + +class InfoXML(Bcfg2.Server.Lint.ServerPlugin): + """ ensure that all config files have an info.xml file""" + + @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 = ["owner", "group", "perms"] + if "required" in self.config: + required = self.config["required"].split(",") + + 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 + not Bcfg2.Options.MDATA_PARANOID.value and + 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) + |