diff options
Diffstat (limited to 'src/sbin')
-rwxr-xr-x | src/sbin/bcfg2-lint | 3 | ||||
-rwxr-xr-x | src/sbin/bcfg2-test | 59 |
2 files changed, 50 insertions, 12 deletions
diff --git a/src/sbin/bcfg2-lint b/src/sbin/bcfg2-lint index 557a03405..4f81df89c 100755 --- a/src/sbin/bcfg2-lint +++ b/src/sbin/bcfg2-lint @@ -50,7 +50,8 @@ def run_plugin(plugin, plugin_name, errorhandler=None, args=None, files=None): else: args.append(setup) - return plugin(*args, files=files, errorhandler=errorhandler).Run() + # python 2.5 doesn't support mixing *magic and keyword arguments + return plugin(*args, **dict(files=files, errorhandler=errorhandler)).Run() def get_errorhandler(): diff --git a/src/sbin/bcfg2-test b/src/sbin/bcfg2-test index 28023a0f2..75079ec3f 100755 --- a/src/sbin/bcfg2-test +++ b/src/sbin/bcfg2-test @@ -3,7 +3,9 @@ """This tool verifies that all clients known to the server build without failures""" +import os import sys +import signal import fnmatch import logging import Bcfg2.Logger @@ -12,6 +14,7 @@ from nose.core import TestProgram from nose.suite import LazySuite from unittest import TestCase + class ClientTest(TestCase): """ A test case representing the build of all of the configuration for @@ -20,7 +23,7 @@ class ClientTest(TestCase): files that we know will cause errors (because they are private files we don't have access to, for instance) """ - __test__ = False # Do not collect + __test__ = False # Do not collect def __init__(self, bcfg2_core, client, ignore=None): TestCase.__init__(self) @@ -44,10 +47,16 @@ class ClientTest(TestCase): return True return False + def shortDescription(self): + return "Building configuration for %s" % self.client + def runTest(self): """ run this individual test """ config = self.bcfg2_core.BuildConfiguration(self.client) + assert len(config.findall("Bundle")) > 0, \ + "%s has no content" % self.client + failures = [] msg = ["Failures:"] for failure in config.xpath('//*[@failure]'): @@ -63,6 +72,20 @@ class ClientTest(TestCase): id = __str__ + +def get_sigint_handler(core): + """ Get a function that handles SIGINT/Ctrl-C by shutting down the + core and exiting properly.""" + + def hdlr(sig, frame): # pylint: disable=W0613 + """ Handle SIGINT/Ctrl-C by shutting down the core and exiting + properly. """ + core.shutdown() + os._exit(1) # pylint: disable=W0212 + + return hdlr + + def main(): optinfo = dict(noseopts=Bcfg2.Options.TEST_NOSEOPTS, test_ignore=Bcfg2.Options.TEST_IGNORE, @@ -75,10 +98,22 @@ def main(): setup.buildHelpMessage() setup.parse(sys.argv[1:]) - if setup['verbose']: - Bcfg2.Logger.setup_logging("bcfg2-test", to_syslog=setup['syslog']) + if setup['debug']: + level = logging.DEBUG + elif setup['verbose']: + level = logging.INFO + else: + level = logging.WARNING + Bcfg2.Logger.setup_logging("bcfg2-test", + to_console=setup['verbose'] or setup['debug'], + to_syslog=False, + to_file=setup['logging'], + level=level) + if (setup['debug'] or setup['verbose']) and "-v" not in setup['noseopts']: + setup['noseopts'].append("-v") core = Bcfg2.Server.Core.BaseCore() + signal.signal(signal.SIGINT, get_sigint_handler(core)) ignore = dict() for entry in setup['test_ignore']: @@ -88,21 +123,23 @@ def main(): except KeyError: ignore[tag] = [name] - def run_tests(): - """ Run the test suite """ - core.fam.handle_events_in_interval(0.1) + core.fam.handle_events_in_interval(0.1) - if setup['args']: - clients = setup['args'] - else: - clients = core.metadata.clients + if setup['args']: + clients = setup['args'] + else: + clients = core.metadata.clients + def run_tests(): + """ Run the test suite """ for client in clients: - logging.info("Building %s" % client) yield ClientTest(core, client, ignore) TestProgram(argv=sys.argv[0:1] + setup['noseopts'], suite=LazySuite(run_tests)) + core.shutdown() + os._exit(0) # pylint: disable=W0212 + if __name__ == "__main__": sys.exit(main()) |