diff options
author | Sol Jerome <sol.jerome@gmail.com> | 2012-04-24 14:51:03 -0500 |
---|---|---|
committer | Sol Jerome <sol.jerome@gmail.com> | 2012-05-05 17:41:45 -0500 |
commit | 2d77ed68e7f0f200618da34f1bd51b82b3ab8955 (patch) | |
tree | 2021129d5a3b4b9019fb22fc3c364c156d3d62eb /src | |
parent | 07b5f654364ca236aa08b80df6d54c1b37bed4b6 (diff) | |
download | bcfg2-2d77ed68e7f0f200618da34f1bd51b82b3ab8955.tar.gz bcfg2-2d77ed68e7f0f200618da34f1bd51b82b3ab8955.tar.bz2 bcfg2-2d77ed68e7f0f200618da34f1bd51b82b3ab8955.zip |
PY3K: Get server code working again
Signed-off-by: Sol Jerome <sol.jerome@gmail.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/lib/Bcfg2/Logger.py | 6 | ||||
-rw-r--r-- | src/lib/Bcfg2/SSLServer.py | 3 | ||||
-rw-r--r-- | src/lib/Bcfg2/Server/Core.py | 11 | ||||
-rw-r--r-- | src/lib/Bcfg2/Server/Plugin.py | 2 | ||||
-rw-r--r-- | src/lib/Bcfg2/Server/Plugins/SSHbase.py | 15 |
5 files changed, 24 insertions, 13 deletions
diff --git a/src/lib/Bcfg2/Logger.py b/src/lib/Bcfg2/Logger.py index 06aae615e..81b45550f 100644 --- a/src/lib/Bcfg2/Logger.py +++ b/src/lib/Bcfg2/Logger.py @@ -95,9 +95,9 @@ class FragmentingSysLogHandler(logging.handlers.SysLogHandler): else: msgs = [record] for newrec in msgs: - msg = self.log_format_string % (self.encodePriority(self.facility, - newrec.levelname.lower()), - self.format(newrec)) + msg = '<%d>%s\000' % (self.encodePriority(self.facility, + newrec.levelname.lower()), + self.format(newrec)) try: self.socket.send(msg.encode('ascii')) except socket.error: diff --git a/src/lib/Bcfg2/SSLServer.py b/src/lib/Bcfg2/SSLServer.py index 418e259cc..6aa46ea58 100644 --- a/src/lib/Bcfg2/SSLServer.py +++ b/src/lib/Bcfg2/SSLServer.py @@ -14,7 +14,6 @@ import logging import ssl import threading import time -import types # Compatibility imports from Bcfg2.Bcfg2Py3k import xmlrpclib, SimpleXMLRPCServer, SocketServer @@ -46,7 +45,7 @@ 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, types.NoneType]: + if type(response) not in [bool, str, list, dict] or response is None: response = (response.decode('utf-8'), ) else: response = (response, ) diff --git a/src/lib/Bcfg2/Server/Core.py b/src/lib/Bcfg2/Server/Core.py index 4321c060b..0be28ee46 100644 --- a/src/lib/Bcfg2/Server/Core.py +++ b/src/lib/Bcfg2/Server/Core.py @@ -42,7 +42,10 @@ def sort_xml(node, key=None): for child in node: sort_xml(child, key) - sorted_children = sorted(node, key=key) + try: + sorted_children = sorted(node, key=key) + except TypeError: + sorted_children = node node[:] = sorted_children @@ -239,12 +242,14 @@ class Core(Component): continue try: self.Bind(entry, metadata) - except PluginExecutionError, exc: + except PluginExecutionError: + exc = sys.exc_info()[1] if 'failure' not in entry.attrib: entry.set('failure', 'bind error: %s' % format_exc()) logger.error("Failed to bind entry: %s %s" % \ (entry.tag, entry.get('name'))) - except Exception, exc: + except Exception: + exc = sys.exc_info()[1] if 'failure' not in entry.attrib: entry.set('failure', 'bind error: %s' % format_exc()) logger.error("Unexpected failure in BindStructure: %s %s" \ diff --git a/src/lib/Bcfg2/Server/Plugin.py b/src/lib/Bcfg2/Server/Plugin.py index 41314bbea..dc70a630f 100644 --- a/src/lib/Bcfg2/Server/Plugin.py +++ b/src/lib/Bcfg2/Server/Plugin.py @@ -945,6 +945,8 @@ class SpecificData(object): return try: self.data = open(self.name).read() + except UnicodeDecodeError: + self.data = open(self.name, mode='rb').read() except: logger.error("Failed to read file %s" % self.name) diff --git a/src/lib/Bcfg2/Server/Plugins/SSHbase.py b/src/lib/Bcfg2/Server/Plugins/SSHbase.py index ac281ad1a..a1a29727f 100644 --- a/src/lib/Bcfg2/Server/Plugins/SSHbase.py +++ b/src/lib/Bcfg2/Server/Plugins/SSHbase.py @@ -1,4 +1,4 @@ -'''This module manages ssh key files for bcfg2''' +"""This module manages ssh key files for bcfg2""" import binascii import re @@ -19,10 +19,15 @@ logger = logging.getLogger(__name__) class KeyData(Bcfg2.Server.Plugin.SpecificData): def __init__(self, name, specific, encoding): - Bcfg2.Server.Plugin.SpecificData.__init__(self, name, specific, + Bcfg2.Server.Plugin.SpecificData.__init__(self, + name, + specific, encoding) self.encoding = encoding + def __lt__(self, other): + return self.name < other.name + def bind_entry(self, entry, metadata): entry.set('type', 'file') if entry.get('encoding') == 'base64': @@ -212,7 +217,7 @@ class SSHbase(Bcfg2.Server.Plugin.Plugin, continue skn.append("%s %s" % (','.join(hostnames), - entry.data.decode().rstrip())) + entry.data.rstrip())) self.__skn = "\n".join(skn) + "\n" return self.__skn @@ -323,8 +328,8 @@ class SSHbase(Bcfg2.Server.Plugin.Plugin, pass hostkeys.sort() for hostkey in hostkeys: - entry.text += "localhost,localhost.localdomain,127.0.0.1 %s" % ( - hostkey.data.decode()) + entry.text += "localhost,localhost.localdomain,127.0.0.1 %s" % \ + (hostkey.data) self.entries[entry.get('name')].bind_info_to_entry(entry, metadata) def build_hk(self, entry, metadata): |