]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Update rpc from openstack-common.
authorRussell Bryant <rbryant@redhat.com>
Wed, 12 Sep 2012 16:30:04 +0000 (12:30 -0400)
committerRussell Bryant <rbryant@redhat.com>
Wed, 12 Sep 2012 16:35:45 +0000 (12:35 -0400)
Fix bug 1049843.

This commit syncs the following commit from openstack-common:

    commit 7e9f72bb28456c912aa80945dbdb8d200f81b462
    Make projects define 'control_exchange'.

This change allows cinder to set a project-specific default of 'cinder'
for the 'control_exchange' option.  The option is now defined in
cinder.flags.

Change-Id: Ia91c172ca0665798d616f9faf5880770074235c8

cinder/flags.py
cinder/openstack/common/rpc/__init__.py
cinder/openstack/common/rpc/amqp.py
cinder/openstack/common/rpc/impl_kombu.py
cinder/openstack/common/rpc/impl_qpid.py
etc/cinder/cinder.conf.sample

index c3dc34e38f5ea43c552edad23a51456b11622601..f69015cad2705b207dfc5361b93759ead6df149e 100644 (file)
@@ -213,6 +213,9 @@ global_opts = [
                default='noauth',
                help='The strategy to use for auth. Supports noauth, keystone, '
                     'and deprecated.'),
+    cfg.StrOpt('control_exchange',
+               default='cinder',
+               help='AMQP exchange to connect to if using RabbitMQ or Qpid'),
 ]
 
 FLAGS.register_opts(global_opts)
index d34aae6983efd8cbfd46136c587943401e69fddf..acc2daafcd46f1fdc1b3eb1676a48ad51508d622 100644 (file)
@@ -49,15 +49,21 @@ rpc_opts = [
     cfg.ListOpt('allowed_rpc_exception_modules',
                 default=['cinder.openstack.common.exception',
                          'nova.exception',
+                         'cinder.exception',
                          ],
                 help='Modules of exceptions that are permitted to be recreated'
                      'upon receiving exception data from an rpc call.'),
-    cfg.StrOpt('control_exchange',
-               default='nova',
-               help='AMQP exchange to connect to if using RabbitMQ or Qpid'),
     cfg.BoolOpt('fake_rabbit',
                 default=False,
                 help='If passed, use a fake RabbitMQ provider'),
+    #
+    # The following options are not registered here, but are expected to be
+    # present. The project using this library must register these options with
+    # the configuration so that project-specific defaults may be defined.
+    #
+    #cfg.StrOpt('control_exchange',
+    #           default='nova',
+    #           help='AMQP exchange to connect to if using RabbitMQ or Qpid'),
 ]
 
 cfg.CONF.register_opts(rpc_opts)
index 1f226971e512575a8b20e0a64696e850c746da6b..f31ab939faf886863059893acbb457dccc465c59 100644 (file)
@@ -34,6 +34,7 @@ from eventlet import greenpool
 from eventlet import pools
 from eventlet import semaphore
 
+from cinder.openstack.common import cfg
 from cinder.openstack.common import excutils
 from cinder.openstack.common.gettextutils import _
 from cinder.openstack.common import local
@@ -416,3 +417,10 @@ def notify(conf, context, topic, msg, connection_pool):
 def cleanup(connection_pool):
     if connection_pool:
         connection_pool.empty()
+
+
+def get_control_exchange(conf):
+    try:
+        return conf.control_exchange
+    except cfg.NoSuchOptError:
+        return 'openstack'
index 9483f3b2460e1c93c8cd41e1be7e3236cd9932b4..faf6c138423d0aaa5fb41741d13bb000a6be760a 100644 (file)
@@ -210,10 +210,10 @@ class TopicConsumer(ConsumerBase):
                    'auto_delete': False,
                    'exclusive': False}
         options.update(kwargs)
-        exchange = kombu.entity.Exchange(name=conf.control_exchange,
-                                         type='topic',
-                                         durable=options['durable'],
-                                         auto_delete=options['auto_delete'])
+        exchange = kombu.entity.Exchange(
+                name=rpc_amqp.get_control_exchange(conf),
+                type='topic', durable=options['durable'],
+                auto_delete=options['auto_delete'])
         super(TopicConsumer, self).__init__(channel,
                                             callback,
                                             tag,
@@ -307,8 +307,9 @@ class TopicPublisher(Publisher):
                    'auto_delete': False,
                    'exclusive': False}
         options.update(kwargs)
-        super(TopicPublisher, self).__init__(channel, conf.control_exchange,
-                                             topic, type='topic', **options)
+        super(TopicPublisher, self).__init__(channel,
+                rpc_amqp.get_control_exchange(conf), topic,
+                type='topic', **options)
 
 
 class FanoutPublisher(Publisher):
index 382a2f2864a81fa649ce899b6cb1b79bcf940010..bf8b26d457d0ecb60aef9e80fd1104b8dbfbfa7d 100644 (file)
@@ -181,9 +181,8 @@ class TopicConsumer(ConsumerBase):
         """
 
         super(TopicConsumer, self).__init__(session, callback,
-                                            "%s/%s" % (conf.control_exchange,
-                                                       topic),
-                                            {}, name or topic, {})
+                "%s/%s" % (rpc_amqp.get_control_exchange(conf), topic),
+                {}, name or topic, {})
 
 
 class FanoutConsumer(ConsumerBase):
@@ -256,9 +255,8 @@ class TopicPublisher(Publisher):
     def __init__(self, conf, session, topic):
         """init a 'topic' publisher.
         """
-        super(TopicPublisher, self).__init__(
-            session,
-            "%s/%s" % (conf.control_exchange, topic))
+        super(TopicPublisher, self).__init__(session,
+                "%s/%s" % (rpc_amqp.get_control_exchange(conf), topic))
 
 
 class FanoutPublisher(Publisher):
@@ -276,10 +274,9 @@ class NotifyPublisher(Publisher):
     def __init__(self, conf, session, topic):
         """init a 'topic' publisher.
         """
-        super(NotifyPublisher, self).__init__(
-            session,
-            "%s/%s" % (conf.control_exchange, topic),
-            {"durable": True})
+        super(NotifyPublisher, self).__init__(session,
+                "%s/%s" % (rpc_amqp.get_control_exchange(conf), topic),
+                {"durable": True})
 
 
 class Connection(object):
index 809bf8c3fbac5a14d431223046cca55183ca3b03..785525937d86f135ea7820243c7970f90ab57b79 100644 (file)
 #### (StrOpt) The strategy to use for auth. Supports noauth, keystone, and
 ####          deprecated.
 
+# control_exchange=cinder
+#### (StrOpt) AMQP exchange to connect to if using RabbitMQ or Qpid
+
 
 ######## defined in cinder.policy ########
 
 #### (IntOpt) Seconds to wait before a cast expires (TTL). Only supported
 ####          by impl_zmq.
 
-# allowed_rpc_exception_modules=cinder.openstack.common.exception,nova.exception
+# allowed_rpc_exception_modules=cinder.openstack.common.exception,nova.exception,cinder.exception
 #### (ListOpt) Modules of exceptions that are permitted to be recreatedupon
 ####           receiving exception data from an rpc call.
 
-# control_exchange=nova
-#### (StrOpt) AMQP exchange to connect to if using RabbitMQ or Qpid
-
 # fake_rabbit=false
 #### (BoolOpt) If passed, use a fake RabbitMQ provider