From: Russell Bryant Date: Fri, 1 Jun 2012 18:42:32 +0000 (-0400) Subject: Use openstack.common.cfg.CONF. X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=0f362edeb03177c12a65b9587d13df7aac76a2f7;p=openstack-build%2Fcinder-build.git Use openstack.common.cfg.CONF. Part of blueprint common-rpc. This patch makes the rpc code use the global config object from openstack-common. Based on some recent discussions on the mailing list, this may not be the final way configuration handling is done here, but it is certainly better than the register_opts() hack that is removed by this patch. Change-Id: Id128126e0bc064a2a1c710c6bd32fb3d137dc7f6 --- diff --git a/bin/cinder-manage b/bin/cinder-manage index 1fc33dc80..93f3f862a 100755 --- a/bin/cinder-manage +++ b/bin/cinder-manage @@ -528,7 +528,6 @@ def methods_of(obj): def main(): """Parse options and call the appropriate class/method.""" - rpc.register_opts(FLAGS) try: argv = flags.parse_args(sys.argv) diff --git a/bin/clear_rabbit_queues b/bin/clear_rabbit_queues index 1baa31c6f..d1b0b4a01 100755 --- a/bin/clear_rabbit_queues +++ b/bin/clear_rabbit_queues @@ -72,7 +72,6 @@ def delete_queues(queues): if __name__ == '__main__': args = flags.parse_args(sys.argv) logging.setup() - rpc.register_opts(flags.FLAGS) delete_queues(args[1:]) if FLAGS.delete_exchange: delete_exchange(FLAGS.control_exchange) diff --git a/cinder/rpc/__init__.py b/cinder/rpc/__init__.py index 266e89b4f..07e4364b0 100644 --- a/cinder/rpc/__init__.py +++ b/cinder/rpc/__init__.py @@ -54,14 +54,7 @@ rpc_opts = [ help='If passed, use a fake RabbitMQ provider'), ] -_CONF = None - - -def register_opts(conf): - global _CONF - _CONF = conf - _CONF.register_opts(rpc_opts) - _get_impl().register_opts(_CONF) +cfg.CONF.register_opts(rpc_opts) def create_connection(new=True): @@ -77,7 +70,7 @@ def create_connection(new=True): :returns: An instance of cinder.rpc.common.Connection """ - return _get_impl().create_connection(_CONF, new=new) + return _get_impl().create_connection(cfg.CONF, new=new) def call(context, topic, msg, timeout=None): @@ -100,7 +93,7 @@ def call(context, topic, msg, timeout=None): :raises: cinder.rpc.common.Timeout if a complete response is not received before the timeout is reached. """ - return _get_impl().call(_CONF, context, topic, msg, timeout) + return _get_impl().call(cfg.CONF, context, topic, msg, timeout) def cast(context, topic, msg): @@ -118,7 +111,7 @@ def cast(context, topic, msg): :returns: None """ - return _get_impl().cast(_CONF, context, topic, msg) + return _get_impl().cast(cfg.CONF, context, topic, msg) def fanout_cast(context, topic, msg): @@ -139,7 +132,7 @@ def fanout_cast(context, topic, msg): :returns: None """ - return _get_impl().fanout_cast(_CONF, context, topic, msg) + return _get_impl().fanout_cast(cfg.CONF, context, topic, msg) def multicall(context, topic, msg, timeout=None): @@ -169,7 +162,7 @@ def multicall(context, topic, msg, timeout=None): :raises: cinder.rpc.common.Timeout if a complete response is not received before the timeout is reached. """ - return _get_impl().multicall(_CONF, context, topic, msg, timeout) + return _get_impl().multicall(cfg.CONF, context, topic, msg, timeout) def notify(context, topic, msg): @@ -182,7 +175,7 @@ def notify(context, topic, msg): :returns: None """ - return _get_impl().notify(_CONF, context, topic, msg) + return _get_impl().notify(cfg.CONF, context, topic, msg) def cleanup(): @@ -210,7 +203,7 @@ def cast_to_server(context, server_params, topic, msg): :returns: None """ - return _get_impl().cast_to_server(_CONF, context, server_params, topic, + return _get_impl().cast_to_server(cfg.CONF, context, server_params, topic, msg) @@ -226,7 +219,7 @@ def fanout_cast_to_server(context, server_params, topic, msg): :returns: None """ - return _get_impl().fanout_cast_to_server(_CONF, context, server_params, + return _get_impl().fanout_cast_to_server(cfg.CONF, context, server_params, topic, msg) @@ -242,5 +235,5 @@ def _get_impl(): """Delay import of rpc_backend until configuration is loaded.""" global _RPCIMPL if _RPCIMPL is None: - _RPCIMPL = importutils.import_module(_CONF.rpc_backend) + _RPCIMPL = importutils.import_module(cfg.CONF.rpc_backend) return _RPCIMPL diff --git a/cinder/rpc/impl_fake.py b/cinder/rpc/impl_fake.py index a1ca192b0..d8de6f749 100644 --- a/cinder/rpc/impl_fake.py +++ b/cinder/rpc/impl_fake.py @@ -177,7 +177,3 @@ def fanout_cast(conf, context, topic, msg): consumer.call(context, method, args, None) except Exception: pass - - -def register_opts(conf): - pass diff --git a/cinder/rpc/impl_kombu.py b/cinder/rpc/impl_kombu.py index ca24cde50..71dfc12f4 100644 --- a/cinder/rpc/impl_kombu.py +++ b/cinder/rpc/impl_kombu.py @@ -81,6 +81,8 @@ kombu_opts = [ ] +cfg.CONF.register_opts(kombu_opts) + LOG = rpc_common.LOG @@ -740,7 +742,3 @@ def notify(conf, context, topic, msg): def cleanup(): return rpc_amqp.cleanup(Connection.pool) - - -def register_opts(conf): - conf.register_opts(kombu_opts) diff --git a/cinder/rpc/impl_qpid.py b/cinder/rpc/impl_qpid.py index e4db9d99e..878ab9dd3 100644 --- a/cinder/rpc/impl_qpid.py +++ b/cinder/rpc/impl_qpid.py @@ -77,6 +77,8 @@ qpid_opts = [ help='Disable Nagle algorithm'), ] +cfg.CONF.register_opts(qpid_opts) + class ConsumerBase(object): """Consumer base class.""" @@ -562,7 +564,3 @@ def notify(conf, context, topic, msg): def cleanup(): return rpc_amqp.cleanup(Connection.pool) - - -def register_opts(conf): - conf.register_opts(qpid_opts) diff --git a/cinder/service.py b/cinder/service.py index 4f6cd54b3..ded8bdc2c 100644 --- a/cinder/service.py +++ b/cinder/service.py @@ -156,7 +156,6 @@ class Service(object): vcs_string = version.version_string_with_vcs() LOG.audit(_('Starting %(topic)s node (version %(vcs_string)s)'), {'topic': self.topic, 'vcs_string': vcs_string}) - rpc.register_opts(FLAGS) self.manager.init_host() self.model_disconnected = False ctxt = context.get_admin_context() @@ -375,7 +374,6 @@ class WSGIService(object): :returns: None """ - rpc.register_opts(FLAGS) if self.manager: self.manager.init_host() self.server.start() diff --git a/cinder/tests/__init__.py b/cinder/tests/__init__.py index 3b5e43e05..3b95e052e 100644 --- a/cinder/tests/__init__.py +++ b/cinder/tests/__init__.py @@ -59,9 +59,6 @@ def reset_db(): def setup(): import mox # Fail fast if you don't have mox. Workaround for bug 810424 - from cinder import rpc # Register rpc_backend before fake_flags sets it - FLAGS.register_opts(rpc.rpc_opts) - from cinder.db import migration from cinder.tests import fake_flags fake_flags.set_defaults(FLAGS) diff --git a/cinder/tests/rpc/test_kombu.py b/cinder/tests/rpc/test_kombu.py index b9c5ea354..2001be01e 100644 --- a/cinder/tests/rpc/test_kombu.py +++ b/cinder/tests/rpc/test_kombu.py @@ -61,7 +61,6 @@ class RpcKombuTestCase(common.BaseRpcAMQPTestCase): def setUp(self): if kombu: self.rpc = impl_kombu - impl_kombu.register_opts(FLAGS) else: self.rpc = None super(RpcKombuTestCase, self).setUp() diff --git a/cinder/tests/rpc/test_kombu_ssl.py b/cinder/tests/rpc/test_kombu_ssl.py index cc4ff03c1..8f7329ae7 100644 --- a/cinder/tests/rpc/test_kombu_ssl.py +++ b/cinder/tests/rpc/test_kombu_ssl.py @@ -44,7 +44,6 @@ class RpcKombuSslTestCase(test.TestCase): def setUp(self): super(RpcKombuSslTestCase, self).setUp() if kombu: - impl_kombu.register_opts(FLAGS) self.flags(kombu_ssl_keyfile=SSL_KEYFILE, kombu_ssl_ca_certs=SSL_CA_CERT, kombu_ssl_certfile=SSL_CERT, diff --git a/cinder/tests/rpc/test_qpid.py b/cinder/tests/rpc/test_qpid.py index 9b33b578c..4f28a76a3 100644 --- a/cinder/tests/rpc/test_qpid.py +++ b/cinder/tests/rpc/test_qpid.py @@ -66,7 +66,6 @@ class RpcQpidTestCase(test.TestCase): self.mock_receiver = None if qpid: - impl_qpid.register_opts(FLAGS) self.orig_connection = qpid.messaging.Connection self.orig_session = qpid.messaging.Session self.orig_sender = qpid.messaging.Sender