From cc6484c475c12dadfb0310c5d7ad74befde74aa1 Mon Sep 17 00:00:00 2001
From: Iustin Pop <iustin@google.com>
Date: Thu, 8 Apr 2010 18:08:51 +0200
Subject: [PATCH] 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: Iustin Pop <iustin@google.com>
Reviewed-by: Guido Trotter <ultrotter@google.com>
---
 lib/confd/client.py                  | 12 +++++++++---
 test/ganeti.confd_client_unittest.py |  4 ++++
 2 files changed, 13 insertions(+), 3 deletions(-)

diff --git a/lib/confd/client.py b/lib/confd/client.py
index e08141b0c..9bd9ef7fc 100644
--- a/lib/confd/client.py
+++ b/lib/confd/client.py
@@ -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"
diff --git a/test/ganeti.confd_client_unittest.py b/test/ganeti.confd_client_unittest.py
index d116483fe..e501c1d2e 100755
--- a/test/ganeti.confd_client_unittest.py
+++ b/test/ganeti.confd_client_unittest.py
@@ -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)
 
 
-- 
GitLab