diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/lib/Bcfg2/Client/Tools/__init__.py | 2 | ||||
-rw-r--r-- | src/lib/Bcfg2/Client/__init__.py | 10 | ||||
-rw-r--r-- | src/lib/Bcfg2/Options/Parser.py | 11 | ||||
-rw-r--r-- | src/lib/Bcfg2/Server/Admin.py | 4 | ||||
-rw-r--r-- | src/lib/Bcfg2/Server/Core.py | 19 | ||||
-rw-r--r-- | src/lib/Bcfg2/Server/Plugin/helpers.py | 36 | ||||
-rw-r--r-- | src/lib/Bcfg2/Server/Plugins/Metadata.py | 2 | ||||
-rw-r--r-- | src/lib/Bcfg2/Server/Plugins/NagiosGen.py | 9 | ||||
-rw-r--r-- | src/lib/Bcfg2/Server/Plugins/Packages/Yum.py | 2 | ||||
-rw-r--r-- | src/lib/Bcfg2/Server/SSLServer.py | 4 |
10 files changed, 47 insertions, 52 deletions
diff --git a/src/lib/Bcfg2/Client/Tools/__init__.py b/src/lib/Bcfg2/Client/Tools/__init__.py index ae7fa3aed..67cdd4d6d 100644 --- a/src/lib/Bcfg2/Client/Tools/__init__.py +++ b/src/lib/Bcfg2/Client/Tools/__init__.py @@ -205,6 +205,8 @@ class Tool(object): continue try: states[entry] = func(entry, mods) + except KeyboardInterrupt: + raise except: # pylint: disable=W0702 self.logger.error("%s: Unexpected failure verifying %s" % (self.name, diff --git a/src/lib/Bcfg2/Client/__init__.py b/src/lib/Bcfg2/Client/__init__.py index d834576c9..359d7ac73 100644 --- a/src/lib/Bcfg2/Client/__init__.py +++ b/src/lib/Bcfg2/Client/__init__.py @@ -617,6 +617,8 @@ class Client(object): for tool in self.tools: try: self.states.update(tool.Inventory()) + except KeyboardInterrupt: + raise except: # pylint: disable=W0702 self.logger.error("%s.Inventory() call failed:" % tool.name, exc_info=1) @@ -734,6 +736,8 @@ class Client(object): continue try: self.states.update(tool.Install(handled)) + except KeyboardInterrupt: + raise except: # pylint: disable=W0702 self.logger.error("%s.Install() call failed:" % tool.name, exc_info=1) @@ -754,6 +758,8 @@ class Client(object): for tool, bundle in tbm: try: self.states.update(tool.Inventory(structures=[bundle])) + except KeyboardInterrupt: + raise except: # pylint: disable=W0702 self.logger.error("%s.Inventory() call failed:" % tool.name, @@ -785,6 +791,8 @@ class Client(object): for tool in self.tools: try: self.states.update(tool.BundleNotUpdated(bundle)) + except KeyboardInterrupt: + raise except: # pylint: disable=W0702 self.logger.error('%s.BundleNotUpdated(%s:%s) call failed:' % (tool.name, bundle.tag, @@ -794,6 +802,8 @@ class Client(object): for tool in self.tools: try: self.states.update(tool.BundleNotUpdated(indep)) + except KeyboardInterrupt: + raise except: # pylint: disable=W0702 self.logger.error("%s.BundleNotUpdated(%s:%s) call failed:" % (tool.name, indep.tag, diff --git a/src/lib/Bcfg2/Options/Parser.py b/src/lib/Bcfg2/Options/Parser.py index c846e8093..d146e3aa2 100644 --- a/src/lib/Bcfg2/Options/Parser.py +++ b/src/lib/Bcfg2/Options/Parser.py @@ -6,7 +6,7 @@ import sys from Bcfg2.version import __version__ from Bcfg2.Compat import ConfigParser -from Bcfg2.Options import Option, PathOption, BooleanOption, _debug +from Bcfg2.Options import Option, PathOption, _debug __all__ = ["setup", "OptionParserException", "Parser", "get_parser", "new_parser"] @@ -43,9 +43,16 @@ class Parser(argparse.ArgumentParser): help="Path to configuration file", default="/etc/bcfg2.conf") + #: Verbose version string that is printed if executed with --version + _version_string = "%s %s on Python %s" % ( + os.path.basename(sys.argv[0]), + __version__, + ".".join(str(v) for v in sys.version_info[0:3])) + #: Builtin options that apply to all commands options = [configfile, - BooleanOption('--version', help="Print the version and exit"), + Option('--version', help="Print the version and exit", + action="version", version=_version_string), Option('-E', '--encoding', metavar='<encoding>', default='UTF-8', help="Encoding of config files", cf=('components', 'encoding'))] diff --git a/src/lib/Bcfg2/Server/Admin.py b/src/lib/Bcfg2/Server/Admin.py index ef7741880..c294e6be5 100644 --- a/src/lib/Bcfg2/Server/Admin.py +++ b/src/lib/Bcfg2/Server/Admin.py @@ -1198,7 +1198,9 @@ class CLI(Bcfg2.Options.CommandRegistry): def run(self): """ Run bcfg2-admin """ try: - self.commands[Bcfg2.Options.setup.subcommand].setup() + cmd = self.commands[Bcfg2.Options.setup.subcommand] + if hasattr(cmd, 'setup'): + cmd.setup() return self.runcommand() finally: self.shutdown() diff --git a/src/lib/Bcfg2/Server/Core.py b/src/lib/Bcfg2/Server/Core.py index bc305e47a..03ab40343 100644 --- a/src/lib/Bcfg2/Server/Core.py +++ b/src/lib/Bcfg2/Server/Core.py @@ -22,7 +22,7 @@ from Bcfg2.Server.Cache import Cache from Bcfg2.Compat import xmlrpclib, wraps # pylint: disable=W0622 from Bcfg2.Server.Plugin.exceptions import * # pylint: disable=W0401,W0614 from Bcfg2.Server.Plugin.interfaces import * # pylint: disable=W0401,W0614 -from Bcfg2.Server.Plugin import track_statistics +from Bcfg2.Server.Statistics import track_statistics try: from django.core.exceptions import ImproperlyConfigured @@ -495,7 +495,7 @@ class Core(object): (self.__class__.__name__, hook), time.time() - start) - @Bcfg2.Server.Statistics.track_statistics() + @track_statistics() def validate_structures(self, metadata, data): """ Checks the data structures by calling the :func:`Bcfg2.Server.Plugin.interfaces.StructureValidator.validate_structures` @@ -522,7 +522,7 @@ class Core(object): self.logger.error("Plugin %s: unexpected structure validation " "failure" % plugin.name, exc_info=1) - @Bcfg2.Server.Statistics.track_statistics() + @track_statistics() def validate_goals(self, metadata, data): """ Checks that the config matches the goals enforced by :class:`Bcfg2.Server.Plugin.interfaces.GoalValidator` plugins @@ -548,7 +548,7 @@ class Core(object): self.logger.error("Plugin %s: unexpected goal validation " "failure" % plugin.name, exc_info=1) - @Bcfg2.Server.Statistics.track_statistics() + @track_statistics() def GetStructures(self, metadata): """ Get all structures (i.e., bundles) for the given client @@ -560,14 +560,15 @@ class Core(object): structures = list( chain(*[struct.BuildStructures(metadata) for struct in self.plugins_by_type(Structure)])) - sbundles = [b.get('name') for b in structures if b.tag == 'Bundle'] + sbundles = [b.get('name') for b in structures + if b.tag == 'Bundle' or b.tag == 'Independent'] missing = [b for b in metadata.bundles if b not in sbundles] if missing: self.logger.error("Client %s configuration missing bundles: %s" % (metadata.hostname, ':'.join(missing))) return structures - @Bcfg2.Server.Statistics.track_statistics() + @track_statistics() def BindStructures(self, structures, metadata, config): """ Given a list of structures (i.e. bundles), bind all the entries in them and add the structures to the config. @@ -588,7 +589,7 @@ class Core(object): except: self.logger.error("error in BindStructure", exc_info=1) - @Bcfg2.Server.Statistics.track_statistics() + @track_statistics() def BindStructure(self, structure, metadata): """ Bind all elements in a single structure (i.e., bundle). @@ -821,7 +822,7 @@ class Core(object): % plugin.name, exc_info=1) return result - @Bcfg2.Server.Statistics.track_statistics() + @track_statistics() def check_acls(self, address, rmi): """ Check client IP address and metadata object against all :class:`Bcfg2.Server.Plugin.interfaces.ClientACLs` plugins. @@ -876,7 +877,7 @@ class Core(object): "%s" % (client, rmi, sys.exc_info()[1])) return False # failsafe - @Bcfg2.Server.Statistics.track_statistics() + @track_statistics() def build_metadata(self, client_name): """ Build initial client metadata for a client diff --git a/src/lib/Bcfg2/Server/Plugin/helpers.py b/src/lib/Bcfg2/Server/Plugin/helpers.py index 559612d1e..2aab231c6 100644 --- a/src/lib/Bcfg2/Server/Plugin/helpers.py +++ b/src/lib/Bcfg2/Server/Plugin/helpers.py @@ -3,7 +3,6 @@ import os import re import sys -import time import copy import glob import logging @@ -35,41 +34,6 @@ except ImportError: LOGGER = logging.getLogger(__name__) -class track_statistics(object): # pylint: disable=C0103 - """ Decorator that tracks execution time for the given - :class:`Plugin` method with :mod:`Bcfg2.Statistics` for reporting - via ``bcfg2-admin perf`` """ - - def __init__(self, name=None): - """ - :param name: The name under which statistics for this function - will be tracked. By default, the name will be - the name of the function concatenated with the - name of the class the function is a member of. - :type name: string - """ - # if this is None, it will be set later during __call_ - self.name = name - - def __call__(self, func): - if self.name is None: - self.name = func.__name__ - - @wraps(func) - def inner(obj, *args, **kwargs): - """ The decorated function """ - name = "%s:%s" % (obj.__class__.__name__, self.name) - - start = time.time() - try: - return func(obj, *args, **kwargs) - finally: - Bcfg2.Server.Statistics.stats.add_value(name, - time.time() - start) - - return inner - - def removecomment(stream): """ A Genshi filter that removes comments from the stream. This function is a generator. diff --git a/src/lib/Bcfg2/Server/Plugins/Metadata.py b/src/lib/Bcfg2/Server/Plugins/Metadata.py index 1d15656af..26f39e50d 100644 --- a/src/lib/Bcfg2/Server/Plugins/Metadata.py +++ b/src/lib/Bcfg2/Server/Plugins/Metadata.py @@ -502,6 +502,8 @@ class Metadata(Bcfg2.Server.Plugin.Metadata, """This class contains data for bcfg2 server metadata.""" __author__ = 'bcfg-dev@mcs.anl.gov' sort_order = 500 + __rmi__ = Bcfg2.Server.Plugin.DatabaseBacked.__rmi__ + ['list_clients', + 'remove_client'] options = Bcfg2.Server.Plugin.DatabaseBacked.options + [ Bcfg2.Options.Common.password, diff --git a/src/lib/Bcfg2/Server/Plugins/NagiosGen.py b/src/lib/Bcfg2/Server/Plugins/NagiosGen.py index 045e46350..d3c38ef19 100644 --- a/src/lib/Bcfg2/Server/Plugins/NagiosGen.py +++ b/src/lib/Bcfg2/Server/Plugins/NagiosGen.py @@ -45,7 +45,11 @@ class NagiosGen(Plugin, Generator): raise PluginExecutionError("Failed to find IP address for %s" % metadata.hostname) host_groups = [grp for grp in metadata.groups - if os.path.isfile('%s/%s-group.cfg' % (self.data, grp))] + if os.path.isfile('%s/%s-group.cfg' % + (self.data, grp))] + \ + [bundle for bundle in metadata.bundles + if os.path.isfile('%s/%s-bundle.cfg' % + (self.data, bundle))] host_config = ['define host {', self.line_fmt % ('host_name', metadata.hostname), self.line_fmt % ('alias', metadata.hostname), @@ -81,7 +85,8 @@ class NagiosGen(Plugin, Generator): def createserverconfig(self, entry, _): """Build monolithic server configuration file.""" host_configs = glob.glob(os.path.join(self.data, '*-host.cfg')) - group_configs = glob.glob(os.path.join(self.data, '*-group.cfg')) + group_configs = glob.glob(os.path.join(self.data, '*-group.cfg')) + \ + glob.glob(os.path.join(self.data, '*-bundle.cfg')) host_data = [] group_data = [] for host in host_configs: diff --git a/src/lib/Bcfg2/Server/Plugins/Packages/Yum.py b/src/lib/Bcfg2/Server/Plugins/Packages/Yum.py index f26ded4c5..b6e9f13eb 100644 --- a/src/lib/Bcfg2/Server/Plugins/Packages/Yum.py +++ b/src/lib/Bcfg2/Server/Plugins/Packages/Yum.py @@ -1231,7 +1231,7 @@ class YumSource(Source): self.provides[arch][prov] = list() self.provides[arch][prov].append(pkgname) - @Bcfg2.Server.Plugin.track_statistics() + @track_statistics() def parse_group(self, data): """ parse comps.xml.gz data """ for group in data.getchildren(): diff --git a/src/lib/Bcfg2/Server/SSLServer.py b/src/lib/Bcfg2/Server/SSLServer.py index 6ad5b5635..1f8febd0e 100644 --- a/src/lib/Bcfg2/Server/SSLServer.py +++ b/src/lib/Bcfg2/Server/SSLServer.py @@ -43,8 +43,10 @@ class XMLRPCDispatcher(SimpleXMLRPCServer.SimpleXMLRPCDispatcher): params = (address, ) + params response = self.instance._dispatch(method, params, self.funcs) # py3k compatibility - if type(response) not in [bool, str, list, dict]: + if type(response) not in [bool, str, list, dict, set, type(None)]: response = (response.decode('utf-8'), ) + elif type(response) == set: + response = (list(response), ) else: response = (response, ) raw_response = xmlrpclib.dumps(response, methodresponse=True, |