On Fri, 5 Jun 2015 at 18:05 'Petr Pudlak' via ganeti-devel <
[email protected]> wrote:

> 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 <[email protected]>
> ---
>  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..3729c06 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
>

typo: actually


> -        # 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 acutally on the master node before trying
>

typo: actually again :)


> +          # 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)
> --
> 2.2.0.rc0.207.ga3a616c
>
>
Rest LGTM, thanks

Reply via email to