From a8e12c0429516d477b40eb7106c3b160a29c965a Mon Sep 17 00:00:00 2001 From: Eoghan Glynn Date: Fri, 25 Oct 2013 16:25:41 +0100 Subject: [PATCH] Selectively import RPC backend retry config Fixes bug 1244698 When setting the RPC publisher policies, selectively import the retry config native to the configured RPC backend. This avoid ImportErrors when all the dependencies of an unused RPC backend are not installed locally. Change-Id: If05a5a389a1b417875e0426fd83fb6d73d570487 --- ceilometer/publisher/rpc.py | 37 +++++++++++++++++++++++++++++++++---- 1 file changed, 33 insertions(+), 4 deletions(-) diff --git a/ceilometer/publisher/rpc.py b/ceilometer/publisher/rpc.py index 892eca46a7..f3ab83fdbb 100644 --- a/ceilometer/publisher/rpc.py +++ b/ceilometer/publisher/rpc.py @@ -57,8 +57,37 @@ def register_opts(config): register_opts(cfg.CONF) -cfg.CONF.import_opt('rabbit_max_retries', - 'ceilometer.openstack.common.rpc.impl_kombu') + +def import_backend_retry_config(): + """Import the retry config option native to the configured + rpc backend (if such a native config option exists). + """ + cfg.CONF.import_opt('rpc_backend', + 'ceilometer.openstack.common.rpc') + kombu = 'ceilometer.openstack.common.rpc.impl_kombu' + if cfg.CONF.rpc_backend == kombu: + try: + cfg.CONF.import_opt('rabbit_max_retries', kombu) + except ImportError: + pass + + +import_backend_retry_config() + + +def override_backend_retry_config(value): + """Override the retry config option native to the configured + rpc backend (if such a native config option exists). + + :param value: the value to override + """ + # TODO(eglynn): ultimately we should add to olso a more generic concept + # of retry config (i.e. not specific to an individual AMQP provider) + # see: https://bugs.launchpad.net/ceilometer/+bug/1244698 + kombu = 'ceilometer.openstack.common.rpc.impl_kombu' + if cfg.CONF.rpc_backend == kombu: + if 'rabbit_max_retries' in cfg.CONF: + cfg.CONF.set_override('rabbit_max_retries', value) def compute_signature(message, secret): @@ -126,8 +155,8 @@ def __init__(self, parsed_url): if self.policy in ['queue', 'drop']: LOG.info('Publishing policy set to %s, \ - override rabbit_max_retries to 1' % self.policy) - cfg.CONF.set_override("rabbit_max_retries", 1) + override backend retry config to 1' % self.policy) + override_backend_retry_config(1) elif self.policy == 'default': LOG.info('Publishing policy set to %s' % self.policy)