Ported xmlserver to subclass from Executioner

This commit is contained in:
Jason Gerard DeRose
2009-01-23 16:16:00 -07:00
committed by Rob Crittenden
parent 0cfb0e191a
commit 0a3ae60038
4 changed files with 12 additions and 53 deletions

View File

@@ -226,7 +226,7 @@ class xmlclient(Backend):
) )
) )
conn = ServerProxy(self.env.xmlrpc_uri, conn = ServerProxy(self.env.xmlrpc_uri,
transport=KerbTransport(), #transport=KerbTransport(),
allow_none=True, allow_none=True,
encoding='UTF-8', encoding='UTF-8',
) )

View File

@@ -24,7 +24,7 @@ Also see the `ipalib.rpc` module.
""" """
from xmlrpclib import Fault from xmlrpclib import Fault
from ipalib import Backend from ipalib.backend import Executioner
from ipalib.errors2 import PublicError, InternalError, CommandError from ipalib.errors2 import PublicError, InternalError, CommandError
from ipalib.rpc import xml_dumps, xml_loads from ipalib.rpc import xml_dumps, xml_loads
from ipalib.util import make_repr from ipalib.util import make_repr
@@ -39,36 +39,22 @@ def params_2_args_options(params):
return (params, dict()) return (params, dict())
class xmlserver(Backend): class xmlserver(Executioner):
""" """
Execution backend plugin for XML-RPC server. Execution backend plugin for XML-RPC server.
Also see the `ipalib.rpc.xmlclient` plugin. Also see the `ipalib.rpc.xmlclient` plugin.
""" """
def dispatch(self, method, params): def marshaled_dispatch(self, data):
self.debug('Received RPC call to %r', method)
if method not in self.Command:
raise CommandError(name=method)
(args, options) = params_2_args_options(params)
result = self.Command[method](*args, **options)
return (result,) # Must wrap XML-RPC response in a tuple singleton
def execute(self, data):
""" """
Execute the XML-RPC request in contained in ``data``. Execute the XML-RPC request in contained in ``data``.
""" """
try: try:
(params, method) = xml_loads(data) (params, name) = xml_loads(data)
response = self.dispatch(method, params) (args, options) = params_2_args_options(params)
print 'okay' response = (self.execute(name, *args, **options),)
except Exception, e: except PublicError, e:
if not isinstance(e, PublicError): self.info('response: %s: %s', e.__class__.__name__, str(e))
self.exception(
'%s: %s', e.__class__.__name__, str(e)
)
e = InternalError()
assert isinstance(e, PublicError)
self.info('%s: %s', e.__class__.__name__, str(e))
response = Fault(e.errno, e.strerror) response = Fault(e.errno, e.strerror)
return xml_dumps(response, methodresponse=True) return xml_dumps(response, methodresponse=True)

View File

@@ -50,9 +50,9 @@ class Server(SimpleXMLRPCServer):
def _marshaled_dispatch(self, data, dispatch_method=None): def _marshaled_dispatch(self, data, dispatch_method=None):
""" """
Use `ipaserver.rpcserver.xmlserver.execute()` to do the real work. Use `ipaserver.rpcserver.xmlserver.marshaled_dispatch()`.
""" """
return api.Backend.xmlserver.execute(data) return api.Backend.xmlserver.marshaled_dispatch(data)
kw = dict(logRequests=False) kw = dict(logRequests=False)

View File

@@ -48,32 +48,5 @@ class test_xmlserver(PluginTester):
_plugin = rpcserver.xmlserver _plugin = rpcserver.xmlserver
def test_dispatch(self): def test_marshaled_dispatch(self):
"""
Test the `ipaserver.rpcserver.xmlserver.dispatch` method.
"""
(o, api, home) = self.instance('Backend', in_server=True)
e = raises(errors2.CommandError, o.dispatch, 'echo', tuple())
assert e.name == 'echo'
class echo(Command):
takes_args = ['arg1', 'arg2+']
takes_options = ['option1?', 'option2?']
def execute(self, *args, **options):
assert type(args[1]) is tuple
return args + (options,)
(o, api, home) = self.instance('Backend', echo, in_server=True)
def call(params):
response = o.dispatch('echo', params)
assert type(response) is tuple and len(response) == 1
return response[0]
arg1 = unicode_str
arg2 = (u'Hello', unicode_str, u'world!')
options = dict(option1=u'How are you?', option2=unicode_str)
assert call((arg1, arg2, options)) == (arg1, arg2, options)
assert call((arg1,) + arg2 + (options,)) == (arg1, arg2, options)
def test_execute(self):
(o, api, home) = self.instance('Backend', in_server=True) (o, api, home) = self.instance('Backend', in_server=True)