bcfg2-lint, like most parts of Bcfg2, has a pluggable backend that lets you easily write your own plugins to verify various parts of your Bcfg2 specification.
Plugins are included in a module of the same name as the plugin class in Bcfg2.Server.Lint, e.g., Bcfg2.Server.Lint.Validate.
Note
It is no longer possible to include lint plugins directly in a Bcfg2 server plugin, e.g., Bcfg2.Server.Plugins.Metadata.MetadataLint.
There are two types of bcfg2-lint plugins:
Serverless plugins are run before bcfg2-lint starts up a local Bcfg2 server, so the amount of introspection they can do is fairly limited. They can directly examine the Bcfg2 specification, of course, but they can’t examine the entries handled by a given plugin or anything that requires a running server.
If a serverless plugin raises a lint error, however, the server will not be started and no Server plugins will be run. This makes them useful to check for the sorts of errors that might prevent the Bcfg2 server from starting properly.
Serverless plugins must subclass Bcfg2.Server.Lint.ServerlessPlugin.
Bcfg2.Server.Lint.Validate is an example of a serverless plugin.
Server plugins are run after a local Bcfg2 server has been started, and have full access to all of the parsed data and so on. Because of this, they tend to be easier to use than Serverless plugins, and thus are more common.
Server plugins are only run if all Serverless plugins run successfully (i.e., raise no errors).
Server plugins must subclass Bcfg2.Server.Lint.ServerPlugin.
Bcfg2.Server.Lint.Genshi is an example of a server plugin.
The job of a bcfg2-lint plugin is to find errors. Each error that a plugin may produce must have a name, a short string that briefly describes the error and will be used to configure error levels in bcfg2.conf. It must also have a default reporting level. Possible reporting levels are “error”, “warning”, or “silent”. All of the errors that may be produced by a plugin must be returned as a dict by Bcfg2.Server.Lint.Plugin.Errors(). For instance, consider Bcfg2.Server.Lint.InfoXML.InfoXML.Errors():
@classmethod
def Errors(cls):
return {"no-infoxml": "warning",
"deprecated-info-file": "warning",
"paranoid-false": "warning",
"required-infoxml-attrs-missing": "error"}
This means that the Bcfg2.Server.Lint.InfoXML.InfoXML lint plugin can produce five lint errors, although four of them are just warnings by default.
The errors returned by each plugin’s Errors() method will be passed to Bcfg2.Server.Lint.ErrorHandler.RegisterErrors(), which will use that information and the information in the config file to determine how to display (or not display) each error to the end user.
Errors are produced in a plugin with Bcfg2.Server.Lint.Plugin.LintError(), which takes two arguments: the name of the error, which must correspond to a key in the dict returned by Bcfg2.Server.Lint.Plugin.Errors(), and a freeform string that will be displayed to the end user. Note that the error name and its display are thus only tied together when the error is produced; that is, a single error (by name) can have two completely different outputs.
Base classes for Lint plugins and error handling
Bases: object
A class to handle errors for bcfg2-lint plugins
Parameters: | errors (dict) – An initial dict of errors to register |
---|
Register a dict of errors that a plugin may raise. The keys of the dict are short strings that describe each error; the values are the default error handling for that error (“error”, “warning”, or “silent”).
Parameters: | errors (dict) – The error dict |
---|
Log a silent/debug condition.
Parameters: | msg (string) – The freeform message to display to the end user. |
---|
Dispatch an error to the correct handler.
Parameters: |
|
---|
Log an error condition.
Parameters: | msg (string) – The freeform message to display to the end user. |
---|
The number of errors passed to this error handler
A dict of registered errors
Log a warning condition.
Parameters: | msg (string) – The freeform message to display to the end user. |
---|
The number of warnings passed to this error handler
Bases: Bcfg2.Options.Actions.ComponentAction
Option parser action to load lint plugins
Bases: Bcfg2.Options.Options.Option
Option class for the lint_plugins
See argparse.ArgumentParser.add_argument() for a full list of accepted parameters.
In addition to supporting all arguments and keyword arguments from argparse.ArgumentParser.add_argument(), several additional keyword arguments are allowed.
Parameters: |
|
---|
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.
Bases: object
Base class for all bcfg2-lint plugins
Parameters: |
|
---|
Returns a dict of errors the plugin supplies, in a format suitable for passing to Bcfg2.Server.Lint.ErrorHandler.RegisterErrors().
Must be overloaded by child classes.
Returns: | dict |
---|
Returns True if the given file should be handled by the plugin according to Bcfg2.Server.Lint.Plugin.files, False otherwise.
Raise an error from the lint process.
Parameters: |
|
---|
Render an XML element for error output. This prefixes the line number and removes children for nicer display.
Parameters: |
|
---|
The error handler
The list of files that bcfg2-lint should be run against
list all files matching the path in self.files or the bcfg2 repo.
Bases: Bcfg2.Server.Lint.Plugin
Base class for bcfg2-lint plugins that check things that require the running Bcfg2 server.
Parameters: |
|
---|
The server core
The metadata plugin
Bases: Bcfg2.Server.Lint.Plugin
Base class for bcfg2-lint plugins that are run before the server starts up (i.e., plugins that check things that may prevent the server from starting up).
Parameters: |
|
---|
bcfg2-lint plugin to check all given AWSTags patterns for validity.
Bases: Bcfg2.Server.Lint.ServerPlugin
bcfg2-lint plugin to check all given AWSTags patterns for validity.
Parameters: |
|
---|
bcfg2-lint plugin for Bundler
Bases: Bcfg2.Server.Lint.ServerPlugin
Perform various Bundler checks.
Parameters: |
|
---|
Check files for various required comments.
Bases: Bcfg2.Server.Lint.ServerPlugin
The Comments lint plugin checks files for header comments that give information about the files. For instance, you can require SVN keywords in a comment, or require the name of the maintainer of a Genshi template, and so on.
Generic check to check a plain text file for required comments.
Parameters: |
---|
Generic check to check an XML file for required comments.
Parameters: |
---|
Return True if Bcfg2.Server.Lint.Plugin.files includes all XIncludes listed in the specified metadata type, false otherwise. In other words, this returns True if bcfg2-lint is dealing with complete metadata.
Parameters: | mfile (string) – The metadata file (“clients.xml” or “groups.xml”) to check for XIncludes |
---|---|
Returns: | bool |
Given a file type, fetch the list of required comments from the bcfg2-lint config. Valid file types are documented in bcfg2-lint.conf(5).
Parameters: | rtype (string) – The file type |
---|---|
Returns: | list - the required items |
Check Genshi templates for syntax errors.
Bases: Bcfg2.Server.Lint.ServerPlugin
Check Genshi templates for syntax errors.
Parameters: |
|
---|
Ensure that all named groups are valid group names.
Bases: Bcfg2.Server.Lint.ServerPlugin
Ensure that all named groups are valid group names.
Parameters: |
|
---|
Check a generic list of XML entries for <Group> tags with invalid name attributes.
Parameters: |
|
---|
A string regex that matches only valid group names. Currently, a group name is considered valid if it contains only non-whitespace characters.
A compiled regex for Bcfg2.Server.Lint.GroupNames.GroupNames.pattern
bcfg2-lint plugin for GroupPatterns
Bases: Bcfg2.Server.Lint.ServerPlugin
bcfg2-lint plugin to check all given GroupPatterns patterns for validity. This is simply done by trying to create a Bcfg2.Server.Plugins.GroupPatterns.PatternMap object for each pattern, and catching exceptions and presenting them as bcfg2-lint errors.
Parameters: |
|
---|
Ensure that all config files have a valid info.xml file.
Bases: Bcfg2.Server.Lint.ServerPlugin
Ensure that all config files have a valid info.xml file. This plugin can check for:
Parameters: |
|
---|
find Probes or Cfg files with multiple similar files that might be merged into one
Bases: Bcfg2.Server.Lint.ServerPlugin
find Probes or Cfg files with multiple similar files that might be merged into one
Parameters: |
|
---|
bcfg2-lint plugin for Metadata
Bases: Bcfg2.Server.Lint.ServerPlugin
bcfg2-lint plugin for Metadata. This checks for several things:
Parameters: |
|
---|
Check for clients that have profiles that are either not flagged as profile groups in groups.xml, or don’t exist.
Check for the location='floating' option, which has been deprecated in favor of floating='true'.
Generic duplicate entry finder.
Parameters: |
|
---|
Check for groups that are defined more than once. There are two ways this can happen:
In this context, ‘first’ refers to the order in which groups are parsed; see the loop condition below and _handle_groups_xml_event above for details.
bcfg2-lint plugin for Pkgmgr
Bases: Bcfg2.Server.Lint.ServerlessPlugin
Find duplicate Pkgmgr entries with the same priority.
Parameters: |
|
---|
Verify attributes for configuration entries that cannot be verified with an XML schema alone.
Bases: Bcfg2.Server.Lint.ServerPlugin
Verify attributes for configuration entries that cannot be verified with an XML schema alone.
Check that a default ACL contains either no entries or minimum required entries
Return True if val is a string describing a positive integer
Return True if val is a string describing a valid full path
Return True if val is a string describing a valid octal permissions mode
Return True if val is a string describing a valid (although not necessarily existent) SELinux type
bcfg2-lint plugin for TemplateHelper
Bases: Bcfg2.Server.Lint.ServerPlugin
bcfg2-lint plugin to ensure that all TemplateHelper modules are valid. This can check for:
Validate XML files.
Ensure that all XML files in the Bcfg2 repository validate according to their respective schemas.
Bases: Bcfg2.Server.Lint.ServerlessPlugin
Ensure that all XML files in the Bcfg2 repository validate according to their respective schemas.
A dict of <file glob>: <schema file> that maps files in the Bcfg2 specification to their schemas. The globs are extended fnmatch globs that also support **, which matches any number of any characters, including forward slashes. The schema files are relative to the schema directory, which can be controlled by the bcfg2-lint --schema option.
Get lists of different kinds of files to validate. This doesn’t return anything, but it sets Bcfg2.Server.Lint.Validate.Validate.filelists to a dict whose keys are path globs given in Bcfg2.Server.Lint.Validate.Validate.filesets and whose values are lists of the full paths to all files in the Bcfg2 repository (or given with bcfg2-lint --stdin) that match the glob.
Parse an XML file, raising the appropriate LintErrors if it can’t be parsed or read. Return the lxml.etree._ElementTree parsed from the file.
Parameters: | filename (string) – The full path to the file to parse |
---|---|
Returns: | lxml.etree._ElementTree - the parsed data |
Validate a file against the given schema.
Parameters: |
|
---|---|
Returns: | bool - True if the file validates, false otherwise |