From d1715e2fa400d80d401fc590825e0c9c713a63a9 Mon Sep 17 00:00:00 2001 From: "Chris St. Pierre" Date: Mon, 28 Jan 2013 17:10:52 -0500 Subject: bcfg2-test: various improvements - avoided hang on Ctrl-C - better output formatting and verbosity --- src/sbin/bcfg2-test | 51 ++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 40 insertions(+), 11 deletions(-) (limited to 'src/sbin/bcfg2-test') diff --git a/src/sbin/bcfg2-test b/src/sbin/bcfg2-test index 815d2740c..4123effe4 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,6 +47,9 @@ 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) @@ -63,6 +69,15 @@ class ClientTest(TestCase): id = __str__ + +def get_sigint_handler(core): + def hdlr(sig, frame): + core.shutdown() + os._exit(1) + + return hdlr + + def main(): optinfo = dict(noseopts=Bcfg2.Options.TEST_NOSEOPTS, test_ignore=Bcfg2.Options.TEST_IGNORE, @@ -75,10 +90,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(setup) + signal.signal(signal.SIGINT, get_sigint_handler(core)) ignore = dict() for entry in setup['test_ignore']: @@ -88,21 +115,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()) -- cgit v1.2.3-1-g7c22 From e74a45e719cbb5445720a32c8a3ec41b306e2667 Mon Sep 17 00:00:00 2001 From: "Chris St. Pierre" Date: Tue, 29 Jan 2013 08:39:11 -0500 Subject: fixed unit tests --- src/sbin/bcfg2-test | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'src/sbin/bcfg2-test') diff --git a/src/sbin/bcfg2-test b/src/sbin/bcfg2-test index 4123effe4..25476c7b4 100755 --- a/src/sbin/bcfg2-test +++ b/src/sbin/bcfg2-test @@ -71,9 +71,14 @@ class ClientTest(TestCase): def get_sigint_handler(core): - def hdlr(sig, frame): + """ 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) + os._exit(1) # pylint: disable=W0212 return hdlr -- cgit v1.2.3-1-g7c22 From bd44478c06f65b7cb2a7f87ab8de862033dd80dc Mon Sep 17 00:00:00 2001 From: "Chris St. Pierre" Date: Fri, 8 Feb 2013 08:13:20 -0500 Subject: bcfg2-test: test for clients with no entries --- src/sbin/bcfg2-test | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/sbin/bcfg2-test') diff --git a/src/sbin/bcfg2-test b/src/sbin/bcfg2-test index 25476c7b4..f77e98269 100755 --- a/src/sbin/bcfg2-test +++ b/src/sbin/bcfg2-test @@ -54,6 +54,9 @@ class ClientTest(TestCase): """ 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]'): -- cgit v1.2.3-1-g7c22