On Tue, Aug 21, 2012 at 3:05 PM, Iustin Pop <[email protected]> wrote: > > This implements the same query=True|False functionality as in > GetClient for cli.py, however since the RAPI code is much more > unit-tested (and the unit-test clients are mocked, for the most part, > without support for addresses) we have to do many adaptations in the > tests. > > Signed-off-by: Iustin Pop <[email protected]> > --- > lib/rapi/baserlib.py | 14 ++++++++++++-- > lib/rapi/testutils.py | 5 +++-- > test/ganeti.rapi.rlib2_unittest.py | 15 +++++++++------ > 3 files changed, 24 insertions(+), 10 deletions(-) > > diff --git a/lib/rapi/baserlib.py b/lib/rapi/baserlib.py > index b44d454..1f97a37 100644 > --- a/lib/rapi/baserlib.py > +++ b/lib/rapi/baserlib.py > @@ -34,6 +34,7 @@ from ganeti import rapi > from ganeti import http > from ganeti import errors > from ganeti import compat > +from ganeti import constants > > > # Dummy value to detect unchanged parameters > @@ -382,13 +383,22 @@ class ResourceBase(object): > """ > return bool(self._checkIntVariable("dry-run")) > > - def GetClient(self): > + def GetClient(self, query=False): > """Wrapper for L{luxi.Client} with HTTP-specific error handling. > > + @param query: this signifies that the client will only be used for > + queries; if the build-time parameter enable-split-queries is > + enabled, then the client will be connected to the query socket > + instead of the masterd socket > + > """ > + if query and constants.ENABLE_SPLIT_QUERY: > + address = constants.QUERY_SOCKET > + else: > + address = None > # Could be a function, pylint: disable=R0201 > try: > - return self._client_cls() > + return self._client_cls(address=address) > except luxi.NoMasterError, err: > raise http.HttpBadGateway("Can't connect to master daemon: %s" % err) > except luxi.PermissionError: > diff --git a/lib/rapi/testutils.py b/lib/rapi/testutils.py > index f960381..2de5a3c 100644 > --- a/lib/rapi/testutils.py > +++ b/lib/rapi/testutils.py > @@ -294,7 +294,7 @@ class _LuxiCallRecorder: > """ > return self._called > > - def __call__(self): > + def __call__(self, address=None): > """Creates an instrumented LUXI client. > > The LUXI client will record all method calls (use L{CalledNames} to > @@ -302,7 +302,8 @@ class _LuxiCallRecorder: > > """ > return luxi.Client(transport=compat.partial(_TestLuxiTransport, > - self.Record)) > + self.Record), > + address=address) > > > def _TestWrapper(fn, *args, **kwargs): > diff --git a/test/ganeti.rapi.rlib2_unittest.py > b/test/ganeti.rapi.rlib2_unittest.py > index cde68ce..c16a841 100755 > --- a/test/ganeti.rapi.rlib2_unittest.py > +++ b/test/ganeti.rapi.rlib2_unittest.py > @@ -1,7 +1,7 @@ > #!/usr/bin/python > # > > -# Copyright (C) 2010 Google Inc. > +# Copyright (C) 2010, 2012 Google Inc. > # > # This program is free software; you can redistribute it and/or modify > # it under the terms of the GNU General Public License as published by > @@ -57,7 +57,7 @@ def _CreateHandler(cls, items, queryargs, body_data, > client_cls): > > > class _FakeClient: > - def __init__(self): > + def __init__(self, address=None): > self._jobs = [] > > def GetNextSubmittedJob(self): > @@ -77,8 +77,8 @@ class _FakeClientFactory: > def GetNextClient(self): > return self._clients.pop(0) > > - def __call__(self): > - cl = self._client_cls() > + def __call__(self, address=None): > + cl = self._client_cls(address=address) > self._clients.append(cl) > return cl > > @@ -103,7 +103,7 @@ class TestConstants(unittest.TestCase): > > class TestClientConnectError(unittest.TestCase): > @staticmethod > - def _FailingClient(): > + def _FailingClient(address=None): > raise luxi.NoMasterError("test") > > def test(self): > @@ -119,6 +119,9 @@ class TestClientConnectError(unittest.TestCase): > > class TestJobSubmitError(unittest.TestCase): > class _SubmitErrorClient: > + def __init__(self, address=None): > + pass > + > @staticmethod > def SubmitJob(ops): > raise errors.JobQueueFull("test") > @@ -1714,7 +1717,7 @@ class TestSimpleResources(unittest.TestCase): > > class TestClusterInfo(unittest.TestCase): > class _ClusterInfoClient: > - def __init__(self): > + def __init__(self, address=None): > self.cluster_info = None > > def QueryClusterInfo(self): > -- > 1.7.7.3 >
LGTM
