diff --git a/lib/rapi/baserlib.py b/lib/rapi/baserlib.py
index b44d454d2f967ff636eeaa2cf787b46c20673fd2..1f97a3705081aad9d1b589b71300d2df4a14eb04 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 f960381b5af6cfa75dea9d819096db511ca00025..2de5a3c60a854b7f33459f13b541bccdfe169f7b 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 cde68cedca02198e35d778b93cc14c0159d82be7..c16a8413badf0281feb285f98064e2d65ece9b24 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):