diff options
author | Sol Jerome <sol.jerome@gmail.com> | 2013-03-29 10:47:53 -0500 |
---|---|---|
committer | Sol Jerome <sol.jerome@gmail.com> | 2013-03-29 10:47:53 -0500 |
commit | 20d1a9597bb039d693978c2b02e62e65826a5436 (patch) | |
tree | 6c2e58a63aba7c1a51ccab98f7340fd908238743 /src/lib/Bcfg2/Server/Plugins/Probes.py | |
parent | 644da402180bfccfa3c033c88dabed6d8dfff6dd (diff) | |
download | bcfg2-20d1a9597bb039d693978c2b02e62e65826a5436.tar.gz bcfg2-20d1a9597bb039d693978c2b02e62e65826a5436.tar.bz2 bcfg2-20d1a9597bb039d693978c2b02e62e65826a5436.zip |
Probes: Handle unicode probes
There is no good way of sending unicode probes to older clients which do
not have support for them. This change will cause unicode probes to be
skipped for unsupported clients and handled properly for new clients.
Signed-off-by: Sol Jerome <sol.jerome@gmail.com>
Diffstat (limited to 'src/lib/Bcfg2/Server/Plugins/Probes.py')
-rw-r--r-- | src/lib/Bcfg2/Server/Plugins/Probes.py | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/src/lib/Bcfg2/Server/Plugins/Probes.py b/src/lib/Bcfg2/Server/Plugins/Probes.py index a8001d9af..09e648750 100644 --- a/src/lib/Bcfg2/Server/Plugins/Probes.py +++ b/src/lib/Bcfg2/Server/Plugins/Probes.py @@ -63,7 +63,7 @@ class ProbeData(str): # pylint: disable=E0012,R0924 .json, and .yaml properties to provide convenient ways to use ProbeData objects as XML, JSON, or YAML data """ def __new__(cls, data): - return str.__new__(cls, data) + return str.__new__(cls, data.encode('utf-8')) def __init__(self, data): # pylint: disable=W0613 str.__init__(self) @@ -153,7 +153,17 @@ class ProbeSet(Bcfg2.Server.Plugin.EntrySet): probe = lxml.etree.Element('probe') probe.set('name', os.path.basename(name)) probe.set('source', self.plugin_name) - probe.text = entry.data + if metadata.version_info and metadata.version_info > (1, 3, 1, '', 0): + probe.text = entry.data.decode('utf-8') + else: + # msg = "Client unable to handle unicode probes." + # raise Bcfg2.Server.Plugin.PluginExecutionError(msg) + try: + probe.text = entry.data + except: + self.logger.error("Client unable to handle unicode probes. " + "Skipping %s" % probe.get('name')) + continue match = self.bangline.match(entry.data.split('\n')[0]) if match: probe.set('interpreter', match.group('interpreter')) @@ -210,7 +220,7 @@ class Probes(Bcfg2.Server.Plugin.Probing, timestamp=str(int(probedata.timestamp))) for probe in sorted(probedata): lxml.etree.SubElement(ctag, 'Probe', name=probe, - value=str(self.probedata[client][probe])) + value=str(self.probedata[client][probe]).decode('utf-8')) for group in sorted(self.cgroups[client]): lxml.etree.SubElement(ctag, "Group", name=group) try: |