From 6d4d8df68717780239fad273dd722359db10e64b Mon Sep 17 00:00:00 2001 From: "Chris St. Pierre" Date: Mon, 24 Sep 2012 13:07:15 -0400 Subject: expanded pylint tests --- src/lib/Bcfg2/Server/Lint/GroupNames.py | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) (limited to 'src/lib/Bcfg2/Server/Lint/GroupNames.py') diff --git a/src/lib/Bcfg2/Server/Lint/GroupNames.py b/src/lib/Bcfg2/Server/Lint/GroupNames.py index 5df98a30e..52e42aa7b 100644 --- a/src/lib/Bcfg2/Server/Lint/GroupNames.py +++ b/src/lib/Bcfg2/Server/Lint/GroupNames.py @@ -1,11 +1,14 @@ +""" ensure that all named groups are valid group names """ + import os import re import Bcfg2.Server.Lint try: from Bcfg2.Server.Plugins.Bundler import BundleTemplateFile - has_genshi = True + HAS_GENSHI = True except ImportError: - has_genshi = False + HAS_GENSHI = False + class GroupNames(Bcfg2.Server.Lint.ServerPlugin): """ ensure that all named groups are valid group names """ @@ -28,6 +31,7 @@ class GroupNames(Bcfg2.Server.Lint.ServerPlugin): return {"invalid-group-name": "error"} def check_rules(self): + """ Check groups used in the Rules plugin for validity """ for rules in self.core.plugins['Rules'].entries.values(): if not self.HandlesFile(rules.name): continue @@ -36,20 +40,23 @@ class GroupNames(Bcfg2.Server.Lint.ServerPlugin): os.path.join(self.config['repo'], rules.name)) def check_bundles(self): - """ check bundles for BoundPath entries with missing attrs """ + """ Check groups used in the Bundler plugin for validity """ for bundle in self.core.plugins['Bundler'].entries.values(): if (self.HandlesFile(bundle.name) and - (not has_genshi or + (not HAS_GENSHI or not isinstance(bundle, BundleTemplateFile))): self.check_entries(bundle.xdata.xpath("//Group"), bundle.name) def check_metadata(self): + """ Check groups used or declared in the Metadata plugin for + validity """ self.check_entries(self.metadata.groups_xml.xdata.xpath("//Group"), os.path.join(self.config['repo'], self.metadata.groups_xml.name)) def check_grouppatterns(self): + """ Check groups used in the GroupPatterns plugin for validity """ cfg = self.core.plugins['GroupPatterns'].config if not self.HandlesFile(cfg.name): return @@ -60,7 +67,9 @@ class GroupNames(Bcfg2.Server.Lint.ServerPlugin): (cfg.name, self.RenderXML(grp, keep_text=True))) def check_cfg(self): - for root, dirs, files in os.walk(self.core.plugins['Cfg'].data): + """ Check groups used in group-specific files in the Cfg + plugin for validity """ + for root, _, files in os.walk(self.core.plugins['Cfg'].data): for fname in files: basename = os.path.basename(root) if (re.search(r'^%s\.G\d\d_' % basename, fname) and @@ -71,6 +80,8 @@ class GroupNames(Bcfg2.Server.Lint.ServerPlugin): os.path.join(root, fname)) def check_entries(self, entries, fname): + """ Check a generic list of XML entries for tags with + invalid name attributes """ for grp in entries: if not self.valid.search(grp.get("name")): self.LintError("invalid-group-name", -- cgit v1.2.3-1-g7c22