[Pkg-ganeti-devel] [ganeti] 127/165: Allow the Transport class to be used for non-master nodes

Apollon Oikonomopoulos apoikos at moszumanska.debian.org
Tue Aug 11 13:53:20 UTC 2015


This is an automated email from the git hooks/post-receive script.

apoikos pushed a commit to branch master
in repository ganeti.

commit ade70feb258a57ae0565395ba48ac2b3ef02b1c0
Author: Petr Pudlak <pudlak at google.com>
Date:   Fri Jun 5 14:13:48 2015 +0200

    Allow the Transport class to be used for non-master nodes
    
    If a communication failure occurred and the caller was not running on
    the master node, Transport assumed that this itself was the cause of
    the error condition.
    
    However, for communication with the metadata daemon we need to support
    non-master nodes as well.
    
    Add a parameter that allows to use the class on non-master nodes.
    
    Signed-off-by: Petr Pudlak <pudlak at google.com>
    Reviewed-by: Helga Velroyen <helgav at google.com>
---
 lib/rpc/transport.py | 26 ++++++++++++++------------
 1 file changed, 14 insertions(+), 12 deletions(-)

diff --git a/lib/rpc/transport.py b/lib/rpc/transport.py
index 88f30a9..0a70b8e 100644
--- a/lib/rpc/transport.py
+++ b/lib/rpc/transport.py
@@ -64,7 +64,7 @@ class Transport:
 
   """
 
-  def __init__(self, address, timeouts=None):
+  def __init__(self, address, timeouts=None, allow_non_master=None):
     """Constructor for the Client class.
 
     Arguments:
@@ -98,7 +98,8 @@ class Transport:
       # Try to connect
       try:
         utils.Retry(self._Connect, 1.0, self._ctimeout,
-                    args=(self.socket, address, self._ctimeout))
+                    args=(self.socket, address, self._ctimeout,
+                          allow_non_master))
       except utils.RetryTimeout:
         raise errors.TimeoutError("Connect timed out")
 
@@ -110,7 +111,7 @@ class Transport:
       raise
 
   @staticmethod
-  def _Connect(sock, address, timeout):
+  def _Connect(sock, address, timeout, allow_non_master):
     sock.settimeout(timeout)
     try:
       sock.connect(address)
@@ -119,15 +120,16 @@ class Transport:
     except socket.error, err:
       error_code = err.args[0]
       if error_code in (errno.ENOENT, errno.ECONNREFUSED):
-        # Verify if we're acutally on the master node before trying
-        # again.
-        ss = ssconf.SimpleStore()
-        try:
-          master, myself = ssconf.GetMasterAndMyself(ss=ss)
-        except ganeti.errors.ConfigurationError:
-          raise errors.NoMasterError(address)
-        if master != myself:
-          raise errors.NoMasterError(address)
+        if not allow_non_master:
+          # Verify if we're actually on the master node before trying
+          # again.
+          ss = ssconf.SimpleStore()
+          try:
+            master, myself = ssconf.GetMasterAndMyself(ss=ss)
+          except ganeti.errors.ConfigurationError:
+            raise errors.NoMasterError(address)
+          if master != myself:
+            raise errors.NoMasterError(address)
         raise utils.RetryAgain()
       elif error_code in (errno.EPERM, errno.EACCES):
         raise errors.PermissionError(address)

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-ganeti/ganeti.git



More information about the Pkg-ganeti-devel mailing list