Skip to content
Snippets Groups Projects
Commit da04c447 authored by Michael Hanselmann's avatar Michael Hanselmann
Browse files

RemoteApiHandler: Add support for mocked LUXI client


This will be used for providing a type-checking RAPI client for tests.

Signed-off-by: default avatarMichael Hanselmann <hansmi@google.com>
Reviewed-by: default avatarIustin Pop <iustin@google.com>
parent f5e6a62c
No related branches found
No related tags found
No related merge requests found
...@@ -289,7 +289,7 @@ class ResourceBase(object): ...@@ -289,7 +289,7 @@ class ResourceBase(object):
POST_ACCESS = [rapi.RAPI_ACCESS_WRITE] POST_ACCESS = [rapi.RAPI_ACCESS_WRITE]
DELETE_ACCESS = [rapi.RAPI_ACCESS_WRITE] DELETE_ACCESS = [rapi.RAPI_ACCESS_WRITE]
def __init__(self, items, queryargs, req, _client_cls=luxi.Client): def __init__(self, items, queryargs, req, _client_cls=None):
"""Generic resource constructor. """Generic resource constructor.
@param items: a list with variables encoded in the URL @param items: a list with variables encoded in the URL
...@@ -301,6 +301,10 @@ class ResourceBase(object): ...@@ -301,6 +301,10 @@ class ResourceBase(object):
self.items = items self.items = items
self.queryargs = queryargs self.queryargs = queryargs
self._req = req self._req = req
if _client_cls is None:
_client_cls = luxi.Client
self._client_cls = _client_cls self._client_cls = _client_cls
def _GetRequestBody(self): def _GetRequestBody(self):
......
...@@ -71,11 +71,12 @@ class RemoteApiHandler(http.auth.HttpServerRequestAuthentication, ...@@ -71,11 +71,12 @@ class RemoteApiHandler(http.auth.HttpServerRequestAuthentication,
""" """
AUTH_REALM = "Ganeti Remote API" AUTH_REALM = "Ganeti Remote API"
def __init__(self): def __init__(self, _client_cls=None):
# pylint: disable=W0233 # pylint: disable=W0233
# it seems pylint doesn't see the second parent class there # it seems pylint doesn't see the second parent class there
http.server.HttpServerHandler.__init__(self) http.server.HttpServerHandler.__init__(self)
http.auth.HttpServerRequestAuthentication.__init__(self) http.auth.HttpServerRequestAuthentication.__init__(self)
self._client_cls = _client_cls
self._resmap = connector.Mapper() self._resmap = connector.Mapper()
self._users = None self._users = None
...@@ -132,7 +133,7 @@ class RemoteApiHandler(http.auth.HttpServerRequestAuthentication, ...@@ -132,7 +133,7 @@ class RemoteApiHandler(http.auth.HttpServerRequestAuthentication,
self._resmap.getController(req.request_path) self._resmap.getController(req.request_path)
ctx = RemoteApiRequestContext() ctx = RemoteApiRequestContext()
ctx.handler = HandlerClass(items, args, req) ctx.handler = HandlerClass(items, args, req, _client_cls=self._client_cls)
method = req.request_method.upper() method = req.request_method.upper()
try: try:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment