From 5a19134459fd9e88e05163a06a1c6887d7bbae9f Mon Sep 17 00:00:00 2001 From: Chris Dent Date: Mon, 12 Jan 2015 16:12:01 +0000 Subject: [PATCH] Update redis-sentinel support to handle multiple sentinels If there are multiple sentinels we would like to configure the coordination backend to use all of them. This change makes that possible by constructing a coordination url that lists all the sentinel hosts: one in the netloc portion of the url and the rest as sentinel_fallback parameters. If no sentinel hosts are provided, none are used. If only one is provided, only the first host is set, no fallbacks. This change also ensures that the configured sentinel port is respected in the generated sentinel configurations and in the ceilometer coordination url and that redis slaves bind to an appropriate host. This URL format will be present in the forthcoming tooz 0.11. Change-Id: I49edd2143b800ee1c3020fc04ed5ad817ddffe6c --- packstack/plugins/ceilometer_800.py | 15 +++++++++++++++ packstack/puppet/templates/ceilometer.pp | 8 +++++++- packstack/puppet/templates/redis_sentinel.pp | 11 +++++++---- packstack/puppet/templates/redis_slave.pp | 2 +- 4 files changed, 30 insertions(+), 6 deletions(-) diff --git a/packstack/plugins/ceilometer_800.py b/packstack/plugins/ceilometer_800.py index f35d6a87c..bf76dd43f 100644 --- a/packstack/plugins/ceilometer_800.py +++ b/packstack/plugins/ceilometer_800.py @@ -249,6 +249,21 @@ def create_manifest(config, messages): manifestdata = getManifestTemplate(get_mq(config, "ceilometer")) manifestdata += getManifestTemplate("ceilometer") + if config['CONFIG_CEILOMETER_COORDINATION_BACKEND'] == 'redis': + # Determine if we need to configure multiple sentinel hosts as + # fallbacks for use in coordination url. + sentinel_hosts = split_hosts(config['CONFIG_REDIS_SENTINEL_HOSTS']) + sentinel_port = config['CONFIG_REDIS_SENTINEL_PORT'] + sentinel_contact = config['CONFIG_REDIS_SENTINEL_CONTACT_HOST'] + if len(sentinel_hosts) > 1: + sentinel_fallbacks = '&'.join(['sentinel_fallback=%s:%s' % + (host, sentinel_port) + for host in sentinel_hosts + if host != sentinel_contact]) + else: + sentinel_fallbacks = '' + config['CONFIG_REDIS_SENTINEL_FALLBACKS'] = sentinel_fallbacks + fw_details = dict() key = "ceilometer_api" fw_details.setdefault(key, {}) diff --git a/packstack/puppet/templates/ceilometer.pp b/packstack/puppet/templates/ceilometer.pp index e6f05fcd9..9ab7ead5a 100644 --- a/packstack/puppet/templates/ceilometer.pp +++ b/packstack/puppet/templates/ceilometer.pp @@ -6,10 +6,16 @@ if $config_ceilometer_coordination_backend == 'redis' { $redis_host = hiera('CONFIG_REDIS_MASTER_HOST') $redis_port = hiera('CONFIG_REDIS_PORT') $sentinel_host = hiera('CONFIG_REDIS_SENTINEL_CONTACT_HOST') + $sentinel_fallbacks = hiera('CONFIG_REDIS_SENTINEL_FALLBACKS') if $sentinel_host != '' { $master_name = hiera('CONFIG_REDIS_MASTER_NAME') $sentinel_port = hiera('CONFIG_REDIS_SENTINEL_PORT') - $coordination_url = "redis://${sentinel_host}:${sentinel_port}?sentinel=${master_name}" + $base_coordination_url = "redis://${sentinel_host}:${sentinel_port}?sentinel=${master_name}" + if $sentinel_fallbacks != '' { + $coordination_url = "${base_coordination_url}&${sentinel_fallbacks}" + } else { + $coordination_url = $base_coordination_url + } } else { $coordination_url = "redis://${redis_host}:${redis_port}" } diff --git a/packstack/puppet/templates/redis_sentinel.pp b/packstack/puppet/templates/redis_sentinel.pp index b58406d5c..04512ef74 100644 --- a/packstack/puppet/templates/redis_sentinel.pp +++ b/packstack/puppet/templates/redis_sentinel.pp @@ -2,10 +2,13 @@ $redis_master_host = hiera('CONFIG_REDIS_MASTER_HOST') $redis_master_port = hiera('CONFIG_REDIS_PORT') $redis_master_name = hiera('CONFIG_REDIS_MASTER_NAME') $redis_sentinel_quorum = hiera('CONFIG_REDIS_SENTINEL_QUORUM') +$redis_sentinel_port = hiera('CONFIG_REDIS_SENTINEL_PORT') class { 'redis::sentinel': - master_name => "${redis_master_name}", - redis_host => $redis_master_host, - redis_port => $redis_master_port, - quorum => $redis_sentinel_quorum, + master_name => "${redis_master_name}", + redis_host => $redis_master_host, + redis_port => $redis_master_port, + quorum => $redis_sentinel_quorum, + sentinel_port => $redis_sentinel_port, + log_file => '/var/log/redis/sentinel.log', } diff --git a/packstack/puppet/templates/redis_slave.pp b/packstack/puppet/templates/redis_slave.pp index 7d26f3224..00be092e5 100644 --- a/packstack/puppet/templates/redis_slave.pp +++ b/packstack/puppet/templates/redis_slave.pp @@ -3,7 +3,7 @@ $redis_port = hiera('CONFIG_REDIS_PORT') $redis_master_host = hiera('CONFIG_REDIS_MASTER_HOST') class { 'redis': - bind => $redis_host, + bind => '0.0.0.0', port => $redis_port, appendonly => true, daemonize => false,