summaryrefslogtreecommitdiffstats
path: root/src/sbin/bcfg2-test
diff options
context:
space:
mode:
authorCalen Pennington <cpennington@wgen.net>2011-12-07 23:49:00 -0500
committerCalen Pennington <cpennington@wgen.net>2011-12-07 23:49:00 -0500
commitf2d4bed4de0b1b7a245b89bedac97dee235c78b4 (patch)
tree98059d9989e4c24e12e6e1c2b65f6c71c3f9a3e7 /src/sbin/bcfg2-test
parent0dad8cbb8fe8ff6287fb193a1a66bb5e536e20de (diff)
downloadbcfg2-f2d4bed4de0b1b7a245b89bedac97dee235c78b4.tar.gz
bcfg2-f2d4bed4de0b1b7a245b89bedac97dee235c78b4.tar.bz2
bcfg2-f2d4bed4de0b1b7a245b89bedac97dee235c78b4.zip
Add a tool to build all the client configurations and verify that they contain no failures
Diffstat (limited to 'src/sbin/bcfg2-test')
-rw-r--r--src/sbin/bcfg2-test67
1 files changed, 67 insertions, 0 deletions
diff --git a/src/sbin/bcfg2-test b/src/sbin/bcfg2-test
new file mode 100644
index 000000000..a0257ca52
--- /dev/null
+++ b/src/sbin/bcfg2-test
@@ -0,0 +1,67 @@
+#!/usr/bin/env python
+
+"""This tool verifies that all clients known to the server build without failures"""
+
+import sys
+import Bcfg2.Server.Core
+from nose.core import TestProgram
+from unittest import TestCase
+
+class ClientTest(TestCase):
+ """
+ A test case representing the build of all of the configuration for a single host.
+ Checks that none of the build config entities has had a failure when it is building.
+ Optionally ignores some config 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
+
+ def __init__(self, bcfg2_core, client):
+ TestCase.__init__(self)
+ self.bcfg2_core = bcfg2_core
+ self.client = client
+
+ def runTest(self):
+ config = self.bcfg2_core.BuildConfiguration(self.client)
+ failures = config.xpath('//*[@failure]')
+
+ def format_failure(failure):
+ return "%s(%s): %s" % (
+ failure.tag,
+ failure.attrib.get('name'),
+ failure.attrib.get('failure')
+ )
+
+ assert len(failures) == 0, "Failures:\n%s" % "\n".join(
+ [format_failure(failure) for failure in failures]
+ )
+
+ def __str__(self):
+ return "ClientTest(%s)" % self.client
+
+ id = __str__
+
+def main():
+ optinfo = {
+ 'configfile': Bcfg2.Options.CFILE,
+ 'help': Bcfg2.Options.HELP,
+ 'encoding': Bcfg2.Options.ENCODING,
+ 'repo': Bcfg2.Options.SERVER_REPOSITORY,
+ 'plugins': Bcfg2.Options.SERVER_PLUGINS,
+ 'password': Bcfg2.Options.SERVER_PASSWORD,
+ }
+ setup = Bcfg2.Options.OptionParser(optinfo)
+ setup.parse(sys.argv[1:])
+ core = Bcfg2.Server.Core.Core(
+ setup['repo'],
+ setup['plugins'],
+ setup['password'],
+ setup['encoding']
+ )
+ core.fam.handle_events_in_interval(4)
+ suite = [ClientTest(core, client) for client in core.metadata.clients]
+
+ TestProgram(argv=sys.argv[0:1], suite = suite)
+
+if __name__ == "__main__":
+ sys.exit(main())