Commit cc6484c4 authored by Iustin Pop's avatar Iustin Pop
Browse files

ConfdClient.SendRequest: allow max coverage



This patch changes the coverage parameter to allow specification of max
coverage (via -1), versus auto-computation (default, 0) and manual
specification.

Unittests are updated for this case too.
Signed-off-by: default avatarIustin Pop <iustin@google.com>
Reviewed-by: default avatarGuido Trotter <ultrotter@google.com>
parent 6328fea3
......@@ -194,7 +194,7 @@ class ConfdClient:
)
self._callback(client_reply)
def SendRequest(self, request, args=None, coverage=None, async=True):
def SendRequest(self, request, args=None, coverage=0, async=True):
"""Send a confd request to some MCs
@type request: L{objects.ConfdRequest}
......@@ -202,13 +202,19 @@ class ConfdClient:
@type args: tuple
@param args: additional callback arguments
@type coverage: integer
@param coverage: number of remote nodes to contact
@param coverage: number of remote nodes to contact; if default
(0), it will use a reasonable default
(L{ganeti.constants.CONFD_DEFAULT_REQ_COVERAGE}), if -1 is
passed, it will use the maximum number of peers, otherwise the
number passed in will be used
@type async: boolean
@param async: handle the write asynchronously
"""
if coverage is None:
if coverage == 0:
coverage = min(len(self._peers), constants.CONFD_DEFAULT_REQ_COVERAGE)
elif coverage == -1:
coverage = len(self._peers)
if coverage > len(self._peers):
raise errors.ConfdClientError("Not enough MCs known to provide the"
......
......@@ -139,6 +139,10 @@ class TestClient(unittest.TestCase):
req2, coverage=15)
self.assertEquals(self.client._socket.send_count,
constants.CONFD_DEFAULT_REQ_COVERAGE)
# Send with max coverage
self.client.SendRequest(req2, coverage=-1)
self.assertEquals(self.client._socket.send_count,
constants.CONFD_DEFAULT_REQ_COVERAGE + len(self.mc_list))
self.assert_(self.client._socket.last_address in self.mc_list)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment