diff options
author | Chris St. Pierre <chris.a.st.pierre@gmail.com> | 2012-10-09 08:18:12 -0400 |
---|---|---|
committer | Chris St. Pierre <chris.a.st.pierre@gmail.com> | 2012-10-09 08:18:12 -0400 |
commit | 591dcc5f9206581a5a5c997b5574d8f36c56e0be (patch) | |
tree | 7d6174f7d363390442349ae40a95229265765d61 | |
parent | 3ff97b55da290df736e51a85b0abdd14101efeab (diff) | |
download | bcfg2-591dcc5f9206581a5a5c997b5574d8f36c56e0be.tar.gz bcfg2-591dcc5f9206581a5a5c997b5574d8f36c56e0be.tar.bz2 bcfg2-591dcc5f9206581a5a5c997b5574d8f36c56e0be.zip |
fixed more pylint checks
-rw-r--r-- | src/lib/Bcfg2/Server/Plugins/Reporting.py | 44 | ||||
-rwxr-xr-x | src/sbin/bcfg2-report-collector | 16 |
2 files changed, 33 insertions, 27 deletions
diff --git a/src/lib/Bcfg2/Server/Plugins/Reporting.py b/src/lib/Bcfg2/Server/Plugins/Reporting.py index a49003ea4..f275bcc9d 100644 --- a/src/lib/Bcfg2/Server/Plugins/Reporting.py +++ b/src/lib/Bcfg2/Server/Plugins/Reporting.py @@ -1,24 +1,22 @@ +""" Unified statistics and reporting plugin """ + import time import platform import traceback from lxml import etree - from Bcfg2.Reporting.Transport import load_transport_from_config, \ - TransportError, TransportImportError - -try: - import cPickle as pickle -except: - import pickle - + TransportError +from Bcfg2.Compat import cPickle from Bcfg2.Options import REPORTING_COMMON_OPTIONS from Bcfg2.Server.Plugin import Statistics, PullSource, PluginInitError, \ PluginExecutionError + def _rpc_call(method): + """ Given the name of a Reporting Transport method, get a function + that defers an XML-RPC call to that method """ def _real_rpc_call(self, *args, **kwargs): """Wrapper for calls to the reporting collector""" - try: return self.transport.rpc(method, *args, **kwargs) except TransportError: @@ -26,12 +24,13 @@ def _rpc_call(method): raise PluginExecutionError return _real_rpc_call -class Reporting(Statistics, PullSource): +class Reporting(Statistics, PullSource): # pylint: disable=W0223 + """ Unified statistics and reporting plugin """ __rmi__ = ['Ping', 'GetExtra', 'GetCurrentEntry'] CLIENT_METADATA_FILEDS = ('profile', 'bundles', 'aliases', 'addresses', - 'groups', 'categories', 'uuid', 'version') + 'groups', 'categories', 'uuid', 'version') def __init__(self, core, datastore): Statistics.__init__(self, core, datastore) @@ -52,12 +51,11 @@ class Reporting(Statistics, PullSource): (self.name, traceback.format_exc().splitlines()[-1])) raise PluginInitError - def process_statistics(self, client, xdata): stats = xdata.find("Statistics") stats.set('time', time.asctime(time.localtime())) - cdata = { 'server': self.whoami } + cdata = {'server': self.whoami} for field in self.CLIENT_METADATA_FILEDS: try: value = getattr(client, field) @@ -69,13 +67,16 @@ class Reporting(Statistics, PullSource): cdata[field] = value try: - interaction_data = pickle.dumps({ 'hostname': client.hostname, - 'metadata': cdata, 'stats': - etree.tostring(stats, xml_declaration=False).decode('UTF-8') }) - except: + interaction_data = cPickle.dumps(dict( + hostname=client.hostname, + metadata=cdata, + stats=etree.tostring( + stats, + xml_declaration=False).decode('UTF-8'))) + except: # pylint: disable=W0702 self.logger.error("%s: Failed to build interaction object: %s" % (self.__class__.__name__, - traceback.format_exc().splitlines()[-1])) + traceback.format_exc().splitlines()[-1])) # try 3 times to store the data for i in [1, 2, 3]: @@ -87,9 +88,9 @@ class Reporting(Statistics, PullSource): except TransportError: continue except: - self.logger.error("%s: Attempt %s: Failed to add statistic %s" % - (self.__class__.__name__, i, - traceback.format_exc().splitlines()[-1])) + self.logger.error("%s: Attempt %s: Failed to add statistic %s" + % (self.__class__.__name__, i, + traceback.format_exc().splitlines()[-1])) self.logger.error("%s: Retry limit reached for %s" % (self.__class__.__name__, client.hostname)) @@ -101,4 +102,3 @@ class Reporting(Statistics, PullSource): Ping = _rpc_call('Ping') GetExtra = _rpc_call('GetExtra') GetCurrentEntry = _rpc_call('GetCurrentEntry') - diff --git a/src/sbin/bcfg2-report-collector b/src/sbin/bcfg2-report-collector index cba5be2b3..bc941ff6f 100755 --- a/src/sbin/bcfg2-report-collector +++ b/src/sbin/bcfg2-report-collector @@ -1,4 +1,7 @@ #!/usr/bin/env python +""" Daemon that runs to collect logs from the LocalFilesystem +Reporting transport object and add them to the Reporting storage +backend """ import sys import logging @@ -6,9 +9,9 @@ import Bcfg2.Logger import Bcfg2.Options from Bcfg2.Reporting.Collector import ReportingCollector, ReportingError -logger = logging.getLogger('bcfg2-report-collector') -if __name__ == '__main__': +def main(): + logger = logging.getLogger('bcfg2-report-collector') optinfo = dict( daemon=Bcfg2.Options.DAEMON, repo=Bcfg2.Options.SERVER_REPOSITORY, @@ -27,7 +30,10 @@ if __name__ == '__main__': except ReportingError: msg = sys.exc_info()[1] logger.error(msg) - sys.exit(1) + raise SystemError(1) except KeyboardInterrupt: - sys.exit(1) - sys.exit(0) + raise SystemError(1) + + +if __name__ == '__main__': + sys.exit(main()) |