From 24f6403f1ba483b813e30ea15446a59090d90d90 Mon Sep 17 00:00:00 2001 From: "Chris St. Pierre" Date: Thu, 21 Apr 2011 14:43:39 -0400 Subject: Misc. bcfg2-lint fixes and tweaks: * fixed bcfg2-lint bug with older pythons * made bcfg2-lint silent by default on success * adjusted bcfg2-lint defaults and alerting levels to work better out-of-the-box --- src/lib/Server/Lint/Bundles.py | 2 +- src/lib/Server/Lint/Comments.py | 6 ++---- src/lib/Server/Lint/InfoXML.py | 2 +- src/sbin/bcfg2-lint | 15 +++++++++++---- 4 files changed, 15 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/lib/Server/Lint/Bundles.py b/src/lib/Server/Lint/Bundles.py index a1ce631c9..b242239ae 100644 --- a/src/lib/Server/Lint/Bundles.py +++ b/src/lib/Server/Lint/Bundles.py @@ -52,5 +52,5 @@ class Bundles(Bcfg2.Server.Lint.ServerPlugin): groups = [self.RenderXML(g) for g in xdata.getroottree().findall("//Group")] if groups: - self.LintError(" tag is not allowed in SGenshi Bundle:\n%s" % + self.LintWarning(" 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 0b50df373..1b75bb25e 100644 --- a/src/lib/Server/Lint/Comments.py +++ b/src/lib/Server/Lint/Comments.py @@ -20,14 +20,14 @@ class Comments(Bcfg2.Server.Lint.ServerPlugin): def required_keywords(self, rtype): """ given a file type, fetch the list of required VCS keywords from the bcfg2-lint config """ - return self.required_items(rtype, "keyword", default=["Id"]) + return self.required_items(rtype, "keyword") def required_comments(self, rtype): """ given a file type, fetch the list of required comments from the bcfg2-lint config """ return self.required_items(rtype, "comment") - def required_items(self, rtype, itype, default=None): + def required_items(self, rtype, itype): """ given a file type and item type (comment or keyword), fetch the list of required items from the bcfg2-lint config """ if itype not in self.config_cache: @@ -38,8 +38,6 @@ class Comments(Bcfg2.Server.Lint.ServerPlugin): global_item = "global_%ss" % itype if global_item in self.config: rv.extend(self.config[global_item].split(",")) - elif default is not None: - rv.extend(default) item = "%s_%ss" % (rtype.lower(), itype) if item in self.config: diff --git a/src/lib/Server/Lint/InfoXML.py b/src/lib/Server/Lint/InfoXML.py index 42679109a..798d8c208 100644 --- a/src/lib/Server/Lint/InfoXML.py +++ b/src/lib/Server/Lint/InfoXML.py @@ -14,7 +14,7 @@ class InfoXML(Bcfg2.Server.Lint.ServerPlugin): entryset.infoxml is not None): xdata = entryset.infoxml.pnode.data for info in xdata.getroottree().findall("//Info"): - required = ["owner", "group", "perms"] + required = [] if "required_attrs" in self.config: required = self.config["required_attrs"].split(",") diff --git a/src/sbin/bcfg2-lint b/src/sbin/bcfg2-lint index 91869617f..cfb37a206 100755 --- a/src/sbin/bcfg2-lint +++ b/src/sbin/bcfg2-lint @@ -57,9 +57,14 @@ def run_plugin(plugin, plugin_name, setup=None, args=None, config=None, args.append(dict(config.items(plugin_name), **setup)) else: args.append(setup) - + + # older versions of python do not support mixing *-magic and + # non-*-magic (e.g., "plugin(*args, files=files)", so we do this + # all with *-magic + kwargs = dict(files=files) + try: - return plugin(*args, files=files).Run() + return plugin(*args, **kwargs).Run() except Exception, err: logger.error("Failed to run plugin %s: %s" % (plugin, err)) raise SystemExit(1) @@ -158,8 +163,10 @@ if __name__ == '__main__': perrors = run_server_plugins(serverplugins, config=config, setup=setup) errors = [errors[n] + perrors[n] for n in range(0, len(errors))] - print "%d errors" % errors[0] - print "%d warnings" % errors[1] + if errors[0] or errors[1] or setup['verbose']: + print "%d errors" % errors[0] + print "%d warnings" % errors[1] + if errors[0]: raise SystemExit(2) elif errors[1]: -- cgit v1.2.3-1-g7c22