summaryrefslogtreecommitdiffstats
path: root/src/lib/Bcfg2/Server/Plugins/Reporting.py
diff options
context:
space:
mode:
authorChris St. Pierre <chris.a.st.pierre@gmail.com>2012-10-09 08:18:12 -0400
committerChris St. Pierre <chris.a.st.pierre@gmail.com>2012-10-09 08:18:12 -0400
commit591dcc5f9206581a5a5c997b5574d8f36c56e0be (patch)
tree7d6174f7d363390442349ae40a95229265765d61 /src/lib/Bcfg2/Server/Plugins/Reporting.py
parent3ff97b55da290df736e51a85b0abdd14101efeab (diff)
downloadbcfg2-591dcc5f9206581a5a5c997b5574d8f36c56e0be.tar.gz
bcfg2-591dcc5f9206581a5a5c997b5574d8f36c56e0be.tar.bz2
bcfg2-591dcc5f9206581a5a5c997b5574d8f36c56e0be.zip
fixed more pylint checks
Diffstat (limited to 'src/lib/Bcfg2/Server/Plugins/Reporting.py')
-rw-r--r--src/lib/Bcfg2/Server/Plugins/Reporting.py44
1 files changed, 22 insertions, 22 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')
-