From 591dcc5f9206581a5a5c997b5574d8f36c56e0be Mon Sep 17 00:00:00 2001 From: "Chris St. Pierre" Date: Tue, 9 Oct 2012 08:18:12 -0400 Subject: fixed more pylint checks --- src/lib/Bcfg2/Server/Plugins/Reporting.py | 44 +++++++++++++++---------------- 1 file changed, 22 insertions(+), 22 deletions(-) (limited to 'src/lib/Bcfg2') 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') - -- cgit v1.2.3-1-g7c22