Skip to content

Commit

Permalink
Selectively import RPC backend retry config
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Eoghan Glynn committed Nov 21, 2013
1 parent e116bff commit a8e12c0
Showing 1 changed file with 33 additions and 4 deletions.
37 changes: 33 additions & 4 deletions ceilometer/publisher/rpc.py
Expand Up @@ -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):
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit a8e12c0

Please sign in to comment.