summaryrefslogtreecommitdiffstats
path: root/src/sbin/bcfg2-lint
diff options
context:
space:
mode:
Diffstat (limited to 'src/sbin/bcfg2-lint')
-rwxr-xr-xsrc/sbin/bcfg2-lint95
1 files changed, 40 insertions, 55 deletions
diff --git a/src/sbin/bcfg2-lint b/src/sbin/bcfg2-lint
index 78b833f02..1038beca8 100755
--- a/src/sbin/bcfg2-lint
+++ b/src/sbin/bcfg2-lint
@@ -61,51 +61,32 @@ def get_errorhandler(config):
def load_server(setup):
""" load server """
- core = Bcfg2.Server.Core.Core(setup['repo'], setup['plugins'],
- setup['password'], setup['encoding'],
- filemonitor=setup['filemonitor'],
- setup=setup)
- if setup['event debug']:
- core.fam.debug = True
+ core = Bcfg2.Server.Core.BaseCore(setup)
core.fam.handle_events_in_interval(4)
return core
+def load_plugin(module, obj_name=None):
+ parts = module.split(".")
+ if obj_name is None:
+ obj_name = parts[-1]
+
+ mod = __import__(module)
+ for p in parts[1:]:
+ mod = getattr(mod, p)
+ return getattr(mod, obj_name)
+
if __name__ == '__main__':
- optinfo = {
- 'configfile': Bcfg2.Options.CFILE,
- 'help': Bcfg2.Options.HELP,
- 'verbose': Bcfg2.Options.VERBOSE,
- 'event debug': Bcfg2.Options.DEBUG,
- 'encoding': Bcfg2.Options.ENCODING,
- # Server options
- 'repo': Bcfg2.Options.SERVER_REPOSITORY,
- 'plugins': Bcfg2.Options.SERVER_PLUGINS,
- 'mconnect': Bcfg2.Options.SERVER_MCONNECT,
- 'filemonitor': Bcfg2.Options.SERVER_FILEMONITOR,
- 'location': Bcfg2.Options.SERVER_LOCATION,
- 'static': Bcfg2.Options.SERVER_STATIC,
- 'key': Bcfg2.Options.SERVER_KEY,
- 'cert': Bcfg2.Options.SERVER_CERT,
- 'ca': Bcfg2.Options.SERVER_CA,
- 'password': Bcfg2.Options.SERVER_PASSWORD,
- 'protocol': Bcfg2.Options.SERVER_PROTOCOL,
- # More options
- 'logging': Bcfg2.Options.LOGGING_FILE_PATH,
- 'stdin': Bcfg2.Options.FILES_ON_STDIN,
- 'schema': Bcfg2.Options.SCHEMA_PATH,
- 'config': Bcfg2.Options.Option('Specify bcfg2-lint configuration file',
- '/etc/bcfg2-lint.conf',
- cmd='--lint-config',
- odesc='<conffile>',
- long_arg=True),
- 'showerrors': Bcfg2.Options.Option('Show error handling', False,
- cmd='--list-errors',
- long_arg=True),
- }
+ optinfo = dict(config=Bcfg2.Options.LINT_CONFIG,
+ showerrors=Bcfg2.Options.LINT_SHOW_ERRORS,
+ stdin=Bcfg2.Options.LINT_FILES_ON_STDIN,
+ schema=Bcfg2.Options.SCHEMA_PATH,
+ plugins=Bcfg2.Options.SERVER_PLUGINS)
+ optinfo.update(Bcfg2.Options.CLI_COMMON_OPTIONS)
+ optinfo.update(Bcfg2.Options.SERVER_COMMON_OPTIONS)
setup = Bcfg2.Options.OptionParser(optinfo)
setup.parse(sys.argv[1:])
- log_args = dict(to_syslog=False, to_console=logging.WARNING)
+ log_args = dict(to_syslog=setup['syslog'], to_console=logging.WARNING)
if setup['verbose']:
log_args['to_console'] = logging.DEBUG
Bcfg2.Logger.setup_logging('bcfg2-info', **log_args)
@@ -116,36 +97,40 @@ if __name__ == '__main__':
# get list of plugins to run
if setup['args']:
- allplugins = setup['args']
+ plugin_list = setup['args']
elif "bcfg2-repo-validate" in sys.argv[0]:
- allplugins = 'Duplicates,RequiredAttrs,Validate'.split(',')
+ plugin_list = 'Duplicates,RequiredAttrs,Validate'.split(',')
else:
try:
- allplugins = config.get('lint', 'plugins').split(',')
+ plugin_list = config.get('lint', 'plugins').split(',')
except (ConfigParser.NoOptionError, ConfigParser.NoSectionError):
- allplugins = Bcfg2.Server.Lint.__all__
+ plugin_list = Bcfg2.Server.Lint.__all__
if setup['stdin']:
files = [s.strip() for s in sys.stdin.readlines()]
else:
files = None
- # load plugins
- serverplugins = {}
- serverlessplugins = {}
- for plugin_name in allplugins:
+ allplugins = dict()
+ for plugin in plugin_list:
try:
- mod = getattr(__import__("Bcfg2.Server.Lint.%s" %
- (plugin_name)).Server.Lint, plugin_name)
+ allplugins[plugin] = load_plugin("Bcfg2.Server.Lint." + plugin)
except ImportError:
try:
- mod = __import__(plugin_name)
- except Exception:
- err = sys.exc_info()[1]
- logger.error("Failed to load plugin %s: %s" % (plugin_name,
- err))
- raise SystemExit(1)
- plugin = getattr(mod, plugin_name)
+ allplugins[plugin] = \
+ load_plugin("Bcfg2.Server.Plugins." + plugin,
+ obj_name=plugin + "Lint")
+ except (ImportError, AttributeError):
+ err = sys.exc_info()[1]
+ logger.error("Failed to load plugin %s: %s" % (plugin + "Lint",
+ err))
+ except AttributeError:
+ err = sys.exc_info()[1]
+ logger.error("Failed to load plugin %s: %s" % (obj_name, err))
+
+ serverplugins = dict()
+ serverlessplugins = dict()
+ for plugin_name, plugin in allplugins.items():
if [c for c in inspect.getmro(plugin)
if c == Bcfg2.Server.Lint.ServerPlugin]:
serverplugins[plugin_name] = plugin