From b5c08f8b33a85fe9b14ed6da090f0801bc5eb63a Mon Sep 17 00:00:00 2001 From: Alexander Sulfrian Date: Wed, 29 Oct 2014 23:11:33 +0100 Subject: Lint/Validate: fix default schema path --- src/lib/Bcfg2/Server/Lint/Validate.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/lib/Bcfg2/Server') diff --git a/src/lib/Bcfg2/Server/Lint/Validate.py b/src/lib/Bcfg2/Server/Lint/Validate.py index 0b3f1e24d..cab5d248d 100644 --- a/src/lib/Bcfg2/Server/Lint/Validate.py +++ b/src/lib/Bcfg2/Server/Lint/Validate.py @@ -18,7 +18,7 @@ class Validate(Bcfg2.Server.Lint.ServerlessPlugin): options = Bcfg2.Server.Lint.ServerlessPlugin.options + [ Bcfg2.Options.PathOption( "--schema", cf=("Validate", "schema"), - default="/usr/share/bcfg2/schema", + default="/usr/share/bcfg2/schemas", help="The full path to the XML schema files")] def __init__(self, *args, **kwargs): -- cgit v1.2.3-1-g7c22 From 9290e0f1e91cd6588a85c3e7a127174b6afd49ae Mon Sep 17 00:00:00 2001 From: Alexander Sulfrian Date: Wed, 29 Oct 2014 23:34:17 +0100 Subject: Lint/TemplateAbuse: fix access to FileInfo xml data --- src/lib/Bcfg2/Server/Lint/Comments.py | 2 +- src/lib/Bcfg2/Server/Lint/TemplateAbuse.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'src/lib/Bcfg2/Server') diff --git a/src/lib/Bcfg2/Server/Lint/Comments.py b/src/lib/Bcfg2/Server/Lint/Comments.py index fc4506c12..e96fac1dd 100644 --- a/src/lib/Bcfg2/Server/Lint/Comments.py +++ b/src/lib/Bcfg2/Server/Lint/Comments.py @@ -248,7 +248,7 @@ class Comments(Bcfg2.Server.Lint.ServerPlugin): rtype = "jinja2" elif isinstance(entry, CfgInfoXML): self.check_xml(entry.infoxml.name, - entry.infoxml.pnode.data, + entry.infoxml.xdata, "infoxml") continue if rtype: diff --git a/src/lib/Bcfg2/Server/Lint/TemplateAbuse.py b/src/lib/Bcfg2/Server/Lint/TemplateAbuse.py index 5a80a5884..eaa20b3b6 100644 --- a/src/lib/Bcfg2/Server/Lint/TemplateAbuse.py +++ b/src/lib/Bcfg2/Server/Lint/TemplateAbuse.py @@ -62,7 +62,7 @@ class TemplateAbuse(Bcfg2.Server.Lint.ServerPlugin): # finally, check for executable permissions in info.xml for entry in entryset.entries.values(): if isinstance(entry, CfgInfoXML): - for pinfo in entry.infoxml.pnode.data.xpath("//FileInfo"): + for pinfo in entry.infoxml.xdata.xpath("//FileInfo"): try: mode = int( pinfo.get("mode", -- cgit v1.2.3-1-g7c22 From 2ededa78c46293b4512ef9d9a0b82ce2609c518c Mon Sep 17 00:00:00 2001 From: Alexander Sulfrian Date: Wed, 29 Oct 2014 23:45:59 +0100 Subject: Lint/TemplateAbuse: we need the element --- src/lib/Bcfg2/Server/Lint/TemplateAbuse.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/lib/Bcfg2/Server') diff --git a/src/lib/Bcfg2/Server/Lint/TemplateAbuse.py b/src/lib/Bcfg2/Server/Lint/TemplateAbuse.py index eaa20b3b6..a437c1318 100644 --- a/src/lib/Bcfg2/Server/Lint/TemplateAbuse.py +++ b/src/lib/Bcfg2/Server/Lint/TemplateAbuse.py @@ -62,7 +62,7 @@ class TemplateAbuse(Bcfg2.Server.Lint.ServerPlugin): # finally, check for executable permissions in info.xml for entry in entryset.entries.values(): if isinstance(entry, CfgInfoXML): - for pinfo in entry.infoxml.xdata.xpath("//FileInfo"): + for pinfo in entry.infoxml.xdata.xpath("//FileInfo/Info"): try: mode = int( pinfo.get("mode", -- cgit v1.2.3-1-g7c22 From e7b805887e7c8ebf28c1ec3ad416bbc3b0687788 Mon Sep 17 00:00:00 2001 From: Alexander Sulfrian Date: Wed, 29 Oct 2014 23:54:13 +0100 Subject: Lint: remove executable bit from source files --- src/lib/Bcfg2/Server/Lint/Genshi.py | 0 src/lib/Bcfg2/Server/Lint/Jinja2.py | 0 2 files changed, 0 insertions(+), 0 deletions(-) mode change 100755 => 100644 src/lib/Bcfg2/Server/Lint/Genshi.py mode change 100755 => 100644 src/lib/Bcfg2/Server/Lint/Jinja2.py (limited to 'src/lib/Bcfg2/Server') diff --git a/src/lib/Bcfg2/Server/Lint/Genshi.py b/src/lib/Bcfg2/Server/Lint/Genshi.py old mode 100755 new mode 100644 diff --git a/src/lib/Bcfg2/Server/Lint/Jinja2.py b/src/lib/Bcfg2/Server/Lint/Jinja2.py old mode 100755 new mode 100644 -- cgit v1.2.3-1-g7c22 From b882e08e9842f5e3950531070eba5c71642e0fe6 Mon Sep 17 00:00:00 2001 From: Alexander Sulfrian Date: Thu, 30 Oct 2014 01:44:42 +0100 Subject: Lint/Comments: fix typo in options --- src/lib/Bcfg2/Server/Lint/Comments.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/lib/Bcfg2/Server') diff --git a/src/lib/Bcfg2/Server/Lint/Comments.py b/src/lib/Bcfg2/Server/Lint/Comments.py index e96fac1dd..120b1a064 100644 --- a/src/lib/Bcfg2/Server/Lint/Comments.py +++ b/src/lib/Bcfg2/Server/Lint/Comments.py @@ -93,11 +93,11 @@ class Comments(Bcfg2.Server.Lint.ServerPlugin): type=Bcfg2.Options.Types.comma_list, default=[], help="Required comments for info.xml files"), Bcfg2.Options.Option( - cf=("Comments", "probe_keywords"), + cf=("Comments", "probes_keywords"), type=Bcfg2.Options.Types.comma_list, default=[], help="Required keywords for probes"), Bcfg2.Options.Option( - cf=("Comments", "probe_comments"), + cf=("Comments", "probes_comments"), type=Bcfg2.Options.Types.comma_list, default=[], help="Required comments for probes")] -- cgit v1.2.3-1-g7c22 From 31217590131874945ac52cab6256c332ab6571a4 Mon Sep 17 00:00:00 2001 From: Alexander Sulfrian Date: Thu, 30 Oct 2014 01:45:06 +0100 Subject: Lint/Comments: add missing options --- src/lib/Bcfg2/Server/Lint/Comments.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'src/lib/Bcfg2/Server') diff --git a/src/lib/Bcfg2/Server/Lint/Comments.py b/src/lib/Bcfg2/Server/Lint/Comments.py index 120b1a064..fbe84de87 100644 --- a/src/lib/Bcfg2/Server/Lint/Comments.py +++ b/src/lib/Bcfg2/Server/Lint/Comments.py @@ -99,7 +99,15 @@ class Comments(Bcfg2.Server.Lint.ServerPlugin): Bcfg2.Options.Option( cf=("Comments", "probes_comments"), type=Bcfg2.Options.Types.comma_list, default=[], - help="Required comments for probes")] + help="Required comments for probes"), + Bcfg2.Options.Option( + cf=("Comments", "metadata_keywords"), + type=Bcfg2.Options.Types.comma_list, default=[], + help="Required keywords for metadata files"), + Bcfg2.Options.Option( + cf=("Comments", "metadata_comments"), + type=Bcfg2.Options.Types.comma_list, default=[], + help="Required comments for metadata files")] def __init__(self, *args, **kwargs): Bcfg2.Server.Lint.ServerPlugin.__init__(self, *args, **kwargs) -- cgit v1.2.3-1-g7c22 From e2bdcfa904b7858f369e95cced1a6b2e93fa5a10 Mon Sep 17 00:00:00 2001 From: Alexander Sulfrian Date: Thu, 30 Oct 2014 01:58:38 +0100 Subject: Lint: handle KeyboardInterupt during fam events If a KeyboardInterupt occurs during block_for_fam_events core.shutdown() has to be called. block_For_fam_events will start the fam thread and if shutdown is not called the main thread will stop on an exception and python will wait until the fam thread stops (never). --- src/lib/Bcfg2/Server/Lint/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/lib/Bcfg2/Server') diff --git a/src/lib/Bcfg2/Server/Lint/__init__.py b/src/lib/Bcfg2/Server/Lint/__init__.py index 9b3e6ece2..1358a46fb 100644 --- a/src/lib/Bcfg2/Server/Lint/__init__.py +++ b/src/lib/Bcfg2/Server/Lint/__init__.py @@ -428,9 +428,9 @@ class CLI(object): def run_server_plugins(self): """ run plugins that require a running server to run """ core = Bcfg2.Server.Core.Core() - core.load_plugins() - core.block_for_fam_events(handle_events=True) try: + core.load_plugins() + core.block_for_fam_events(handle_events=True) self.logger.debug("Running server plugins: %s" % [p.__name__ for p in self.serverplugins]) for plugin in self.serverplugins: -- cgit v1.2.3-1-g7c22 From a57d26e10aac0b8d539243f9919a18b2fb929f69 Mon Sep 17 00:00:00 2001 From: Alexander Sulfrian Date: Thu, 30 Oct 2014 03:30:07 +0100 Subject: Lint: fix default value for lint_plugins This is a bit tricky because we need the enabled server plugins for the default value. To have these available before parsing lint_plugins the server plugins needs to be parsed during early parsing mode. Additional there are lint plugins that has no matching server plugin. To identify them, this adds a reference from the lint plutins to the name of the matching server plugins in the member variable __serverplugin__. If this variable is None the plugin is always used. If a lint plugin could not be imported (maybe because of a missing dependency) the plugin is ignored and not considered as a default value. --- src/lib/Bcfg2/Server/Lint/AWSTags.py | 1 + src/lib/Bcfg2/Server/Lint/Bundler.py | 1 + src/lib/Bcfg2/Server/Lint/Cfg.py | 1 + src/lib/Bcfg2/Server/Lint/GroupPatterns.py | 1 + src/lib/Bcfg2/Server/Lint/InfoXML.py | 1 + src/lib/Bcfg2/Server/Lint/Metadata.py | 1 + src/lib/Bcfg2/Server/Lint/Pkgmgr.py | 1 + src/lib/Bcfg2/Server/Lint/TemplateHelper.py | 1 + src/lib/Bcfg2/Server/Lint/__init__.py | 71 +++++++++++++++++------------ 9 files changed, 49 insertions(+), 30 deletions(-) (limited to 'src/lib/Bcfg2/Server') diff --git a/src/lib/Bcfg2/Server/Lint/AWSTags.py b/src/lib/Bcfg2/Server/Lint/AWSTags.py index 25ad4ef61..c6d7a3a30 100644 --- a/src/lib/Bcfg2/Server/Lint/AWSTags.py +++ b/src/lib/Bcfg2/Server/Lint/AWSTags.py @@ -9,6 +9,7 @@ import Bcfg2.Server.Lint class AWSTags(Bcfg2.Server.Lint.ServerPlugin): """ ``bcfg2-lint`` plugin to check all given :ref:`AWSTags ` patterns for validity. """ + __serverplugin__ = 'AWSTags' def Run(self): cfg = self.core.plugins['AWSTags'].config diff --git a/src/lib/Bcfg2/Server/Lint/Bundler.py b/src/lib/Bcfg2/Server/Lint/Bundler.py index aee15cb5d..576e157ad 100644 --- a/src/lib/Bcfg2/Server/Lint/Bundler.py +++ b/src/lib/Bcfg2/Server/Lint/Bundler.py @@ -7,6 +7,7 @@ from Bcfg2.Server.Lint import ServerPlugin class Bundler(ServerPlugin): """ Perform various :ref:`Bundler ` checks. """ + __serverplugin__ = 'Bundler' def Run(self): self.missing_bundles() diff --git a/src/lib/Bcfg2/Server/Lint/Cfg.py b/src/lib/Bcfg2/Server/Lint/Cfg.py index 7716cd5c7..13b04a6b8 100644 --- a/src/lib/Bcfg2/Server/Lint/Cfg.py +++ b/src/lib/Bcfg2/Server/Lint/Cfg.py @@ -10,6 +10,7 @@ from Bcfg2.Server.Plugins.Cfg import CfgGenerator class Cfg(ServerPlugin): """ warn about Cfg issues """ + __serverplugin__ = 'Cfg' def Run(self): for basename, entry in list(self.core.plugins['Cfg'].entries.items()): diff --git a/src/lib/Bcfg2/Server/Lint/GroupPatterns.py b/src/lib/Bcfg2/Server/Lint/GroupPatterns.py index d8142cab9..8ddb9e796 100644 --- a/src/lib/Bcfg2/Server/Lint/GroupPatterns.py +++ b/src/lib/Bcfg2/Server/Lint/GroupPatterns.py @@ -13,6 +13,7 @@ class GroupPatterns(ServerPlugin): :class:`Bcfg2.Server.Plugins.GroupPatterns.PatternMap` object for each pattern, and catching exceptions and presenting them as ``bcfg2-lint`` errors.""" + __serverplugin__ = 'GroupPatterns' def Run(self): cfg = self.core.plugins['GroupPatterns'].config diff --git a/src/lib/Bcfg2/Server/Lint/InfoXML.py b/src/lib/Bcfg2/Server/Lint/InfoXML.py index 4b1513a11..950a86f01 100644 --- a/src/lib/Bcfg2/Server/Lint/InfoXML.py +++ b/src/lib/Bcfg2/Server/Lint/InfoXML.py @@ -15,6 +15,7 @@ class InfoXML(Bcfg2.Server.Lint.ServerPlugin): * Paranoid mode disabled in an ``info.xml`` file; * Required attributes missing from ``info.xml`` """ + __serverplugin__ = 'Cfg' options = Bcfg2.Server.Lint.ServerPlugin.options + [ Bcfg2.Options.Common.default_paranoid, diff --git a/src/lib/Bcfg2/Server/Lint/Metadata.py b/src/lib/Bcfg2/Server/Lint/Metadata.py index 248b1610c..e445892d1 100644 --- a/src/lib/Bcfg2/Server/Lint/Metadata.py +++ b/src/lib/Bcfg2/Server/Lint/Metadata.py @@ -15,6 +15,7 @@ class Metadata(ServerPlugin): * Multiple default groups or a default group that isn't a profile group. """ + __serverplugin__ = 'Metadata' def Run(self): self.nested_clients() diff --git a/src/lib/Bcfg2/Server/Lint/Pkgmgr.py b/src/lib/Bcfg2/Server/Lint/Pkgmgr.py index 3f0b9477c..eed6d4c19 100644 --- a/src/lib/Bcfg2/Server/Lint/Pkgmgr.py +++ b/src/lib/Bcfg2/Server/Lint/Pkgmgr.py @@ -12,6 +12,7 @@ class Pkgmgr(ServerlessPlugin): """ Find duplicate :ref:`Pkgmgr ` entries with the same priority. """ + __serverplugin__ = 'Pkgmgr' def Run(self): pset = set() diff --git a/src/lib/Bcfg2/Server/Lint/TemplateHelper.py b/src/lib/Bcfg2/Server/Lint/TemplateHelper.py index a952da724..9d05516f1 100644 --- a/src/lib/Bcfg2/Server/Lint/TemplateHelper.py +++ b/src/lib/Bcfg2/Server/Lint/TemplateHelper.py @@ -20,6 +20,7 @@ class TemplateHelper(ServerPlugin): * Bogus symbols listed in ``__export__``, including symbols that don't exist, that are reserved, or that start with underscores. """ + __serverplugin__ = 'TemplateHelper' def __init__(self, *args, **kwargs): ServerPlugin.__init__(self, *args, **kwargs) diff --git a/src/lib/Bcfg2/Server/Lint/__init__.py b/src/lib/Bcfg2/Server/Lint/__init__.py index 1358a46fb..526bdf159 100644 --- a/src/lib/Bcfg2/Server/Lint/__init__.py +++ b/src/lib/Bcfg2/Server/Lint/__init__.py @@ -14,6 +14,7 @@ import Bcfg2.Options import Bcfg2.Server.Core import Bcfg2.Server.Plugins from Bcfg2.Compat import walk_packages +from Bcfg2.Options import _debug def _ioctl_GWINSZ(fd): # pylint: disable=C0103 @@ -48,6 +49,11 @@ def get_termsize(): class Plugin(object): """ Base class for all bcfg2-lint plugins """ + #: Name of the matching server plugin or None if there is no + #: matching one. If this is None the lint plugin will only loaded + #: by default if the matching server plugin is enabled, too. + __serverplugin__ = None + options = [Bcfg2.Options.Common.repository] def __init__(self, errorhandler=None, files=None): @@ -291,19 +297,41 @@ class ServerPlugin(Plugin): # pylint: disable=W0223 class LintPluginAction(Bcfg2.Options.ComponentAction): - """ We want to load all lint plugins that pertain to server - plugins. In order to do this, we hijack the __call__() method of - this action and add all of the server plugins on the fly """ - + """ Option parser action to load lint plugins """ bases = ['Bcfg2.Server.Lint'] - def __call__(self, parser, namespace, values, option_string=None): - plugins = getattr(Bcfg2.Options.setup, "plugins", []) - for lint_plugin in walk_packages(path=__path__): - if lint_plugin[1] in plugins: - values.append(lint_plugin[1]) - Bcfg2.Options.ComponentAction.__call__(self, parser, namespace, values, - option_string) + +class LintPluginOption(Bcfg2.Options.Option): + """ Option class for the lint_plugins """ + + def early_parsing_hook(self, namespace): + """ + We want a usefull default for the enabled lint plugins. + Therfore we use all importable plugins, that either pertain + with enabled server plugins or that has no matching plugin. + """ + + plugins = [p.__name__ for p in namespace.plugins] + for loader, name, _is_pkg in walk_packages(path=__path__): + try: + module = loader.find_module(name).load_module(name) + plugin = getattr(module, name) + if plugin.__serverplugin__ is None or \ + plugin.__serverplugin__ in plugins: + _debug("Automatically adding lint plugin %s" % + plugin.__name__) + self.default.append(plugin.__name__) + except ImportError: + pass + + +class _EarlyOptions(object): + """ We need the server.plugins options in an early parsing hook + for determining the default value for the lint_plugins. So we + create a component that is parsed before the other options. """ + + parse_first = True + options = [Bcfg2.Options.Common.plugins] class CLI(object): @@ -313,7 +341,7 @@ class CLI(object): '--lint-config', default='/etc/bcfg2-lint.conf', action=Bcfg2.Options.ConfigFileAction, help='Specify bcfg2-lint configuration file'), - Bcfg2.Options.Option( + LintPluginOption( "--lint-plugins", cf=('lint', 'plugins'), default=[], type=Bcfg2.Options.Types.comma_list, action=LintPluginAction, help='bcfg2-lint plugin list'), @@ -328,28 +356,11 @@ class CLI(object): def __init__(self): parser = Bcfg2.Options.get_parser( description="Manage a running Bcfg2 server", - components=[self]) + components=[self, _EarlyOptions]) parser.parse() self.logger = logging.getLogger(parser.prog) - # automatically add Lint plugins for loaded server plugins - for plugin in Bcfg2.Options.setup.plugins: - try: - Bcfg2.Options.setup.lint_plugins.append( - getattr( - __import__("Bcfg2.Server.Lint.%s" % plugin.__name__, - fromlist=[plugin.__name__]), - plugin.__name__)) - self.logger.debug("Automatically adding lint plugin %s" % - plugin.__name__) - except ImportError: - # no lint plugin for this server plugin - self.logger.debug("No lint plugin for %s" % plugin.__name__) - except AttributeError: - self.logger.error("Failed to load plugin %s: %s" % - (plugin.__name__, sys.exc_info()[1])) - self.logger.debug("Running lint with plugins: %s" % [p.__name__ for p in Bcfg2.Options.setup.lint_plugins]) -- cgit v1.2.3-1-g7c22