From a0b33a46598499c47ac90eba26f27bff4eab991c Mon Sep 17 00:00:00 2001
From: Doug Hellmann <doug@doughellmann.com>
Date: Wed, 3 Jun 2015 19:53:27 +0000
Subject: [PATCH] replace rpc_response_timeout use in rabbit driver

The rabbit driver was using the rpc_response_timeout configuration
option as a reconnect timeout value, even though the option was defined
only in oslo_messaging.client and was not always being registered before
being accessed. An earlier patch fixed this by registering the option
here in the driver, too, but that breaks several levels of
abstraction. This changes the driver to define a new option with the
same default value, so that the driver is only using options it defines
itself. It also removes the old hacky fix.

Closes-bug: #1461182

Change-Id: Ia96c815d157219e12a10d94b87b0156503369a6b
---
 oslo_messaging/_drivers/impl_rabbit.py | 25 ++++++++++++++++---------
 1 file changed, 16 insertions(+), 9 deletions(-)

diff --git a/oslo_messaging/_drivers/impl_rabbit.py b/oslo_messaging/_drivers/impl_rabbit.py
index 73902bf61..e5538e5e9 100644
--- a/oslo_messaging/_drivers/impl_rabbit.py
+++ b/oslo_messaging/_drivers/impl_rabbit.py
@@ -41,7 +41,6 @@ from oslo_messaging._i18n import _LE
 from oslo_messaging._i18n import _LI
 from oslo_messaging._i18n import _LW
 from oslo_messaging import exceptions
-from oslo_messaging.rpc import client as rpc_client
 
 
 rabbit_opts = [
@@ -71,6 +70,18 @@ rabbit_opts = [
                  deprecated_group='DEFAULT',
                  help='How long to wait before reconnecting in response to an '
                       'AMQP consumer cancel notification.'),
+    cfg.IntOpt('kombu_reconnect_timeout',
+               # NOTE(dhellmann): We want this to be similar to
+               # rpc_response_timeout, but we can't use
+               # "$rpc_response_timeout" as a default because that
+               # option may not have been defined by the time this
+               # option is accessed. Instead, document the intent in
+               # the help text for this option and provide a separate
+               # literal default value.
+               default=60,
+               help='How long to wait before considering a reconnect '
+                    'attempt to have failed. This value should not be '
+                    'longer than rpc_response_timeout.'),
     cfg.StrOpt('rabbit_host',
                default='localhost',
                deprecated_group='DEFAULT',
@@ -1003,17 +1014,13 @@ class Connection(object):
             RuntimeError("_publish_and_retry_on_missing_exchange() must be "
                          "called with an passive exchange.")
 
-        # FIXME(dhellmann): This is a hack to make sure the option
-        # we're about to use is registered. Since we're not going
-        # through a Client object here, it won't be registered by
-        # Client.__init__. We should do this more cleanly.
-        self.conf.register_opts(rpc_client._client_opts)
-
         # TODO(sileht): use @retrying
         # NOTE(sileht): no need to wait the application expect a response
         # before timeout is exshauted
-        duration = (timeout if timeout is not None
-                    else self.conf.rpc_response_timeout)
+        duration = (
+            timeout if timeout is not None
+            else self.conf.oslo_messaging_rabbit.kombu_reconnect_timeout
+        )
 
         timer = rpc_common.DecayingTimer(duration=duration)
         timer.start()