diff --git a/CHANGELOG.md b/CHANGELOG.md index 16f16dd..5d6d49e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ This file is used to list changes made in each version of the openstack-metering h_algorithms to be configurable * Remove old nosql check for running dbsync * Bump Chef gem to 11.16 +* Allow rabbit_hosts and rabbit_ha_queues to be configurable ## 10.0.0 * Upgrading to Juno diff --git a/recipes/common.rb b/recipes/common.rb index 5a4678b..8b6d588 100644 --- a/recipes/common.rb +++ b/recipes/common.rb @@ -47,6 +47,7 @@ end mq_service_type = node['openstack']['mq']['telemetry']['service_type'] if mq_service_type == 'rabbitmq' + node['openstack']['mq']['telemetry']['rabbit']['ha'] && (rabbit_hosts = rabbit_servers) mq_password = get_password 'user', node['openstack']['mq']['telemetry']['rabbit']['userid'] elsif mq_service_type == 'qpid' mq_password = get_password 'user', node['openstack']['mq']['telemetry']['qpid']['username'] @@ -99,6 +100,7 @@ template node['openstack']['telemetry']['conf'] do identity_admin_endpoint: identity_admin_endpoint, mq_service_type: mq_service_type, mq_password: mq_password, + rabbit_hosts: rabbit_hosts, service_pass: service_pass, service_tenant_name: service_tenant, service_user: service_user, diff --git a/spec/common_spec.rb b/spec/common_spec.rb index 65541ec..7b247ba 100644 --- a/spec/common_spec.rb +++ b/spec/common_spec.rb @@ -84,20 +84,63 @@ describe 'openstack-telemetry::common' do node.set['openstack']['mq']['telemetry']['service_type'] = 'rabbitmq' end - it 'has default rabbit_* options set' do - [ - /^rabbit_userid = guest$/, - /^rabbit_password = mq-pass$/, - /^rabbit_port = 5672$/, - /^rabbit_host = 127.0.0.1$/, - /^rabbit_virtual_host = \/$/, - /^rabbit_use_ssl = false$/, - %r{^auth_uri = http://127.0.0.1:5000/v2.0$}, - /^auth_host = 127.0.0.1$/, - /^auth_port = 35357$/, - /^auth_protocol = http$/ - ].each do |line| - expect(chef_run).to render_file(file.name).with_content(line) + describe 'ha rabbit disabled' do + before do + node.override['openstack']['mq']['telemetry']['rabbit']['ha'] = false + end + + it 'has default rabbit_* options set' do + [ + /^rabbit_userid = guest$/, + /^rabbit_password = mq-pass$/, + /^rabbit_port = 5672$/, + /^rabbit_host = 127.0.0.1$/, + /^rabbit_virtual_host = \/$/, + /^rabbit_use_ssl = false$/, + %r{^auth_uri = http://127.0.0.1:5000/v2.0$}, + /^auth_host = 127.0.0.1$/, + /^auth_port = 35357$/, + /^auth_protocol = http$/ + ].each do |line| + expect(chef_run).to render_file(file.name).with_content(line) + end + end + + it 'does not have ha rabbit options set' do + [/^rabbit_hosts = /, + /^rabbit_ha_queues = /].each do |line| + expect(chef_run).not_to render_file(file.name).with_content(line) + end + end + end + + describe 'ha rabbit enabled' do + before do + node.override['openstack']['mq']['telemetry']['rabbit']['ha'] = true + end + + it 'sets ha rabbit options correctly' do + [ + /^rabbit_userid = guest$/, + /^rabbit_password = mq-pass$/, + /^rabbit_hosts = 1.1.1.1:5672,2.2.2.2:5672$/, + /^rabbit_ha_queues = True$/, + /^rabbit_virtual_host = \/$/, + /^rabbit_use_ssl = false$/, + %r{^auth_uri = http://127.0.0.1:5000/v2.0$}, + /^auth_host = 127.0.0.1$/, + /^auth_port = 35357$/, + /^auth_protocol = http$/ + ].each do |line| + expect(chef_run).to render_file(file.name).with_content(line) + end + end + + it 'does not have non-ha rabbit options set' do + [/^rabbit_host = /, + /^rabbit_port = /].each do |line| + expect(chef_run).not_to render_file(file.name).with_content(line) + end end end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 3328895..a9fb88f 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -25,6 +25,8 @@ UBUNTU_OPTS = { shared_context 'telemetry-stubs' do before do + allow_any_instance_of(Chef::Recipe).to receive(:rabbit_servers) + .and_return '1.1.1.1:5672,2.2.2.2:5672' allow_any_instance_of(Chef::Recipe).to receive(:memcached_servers).and_return([]) allow_any_instance_of(Chef::Recipe).to receive(:get_password) .with('db', anything) diff --git a/templates/default/ceilometer.conf.erb b/templates/default/ceilometer.conf.erb index 420f134..8fd440f 100644 --- a/templates/default/ceilometer.conf.erb +++ b/templates/default/ceilometer.conf.erb @@ -23,8 +23,13 @@ amqp_auto_delete=<%= node["openstack"]["mq"]["telemetry"]["auto_delete"] %> ##### RABBITMQ ##### rabbit_userid = <%= node["openstack"]["mq"]["telemetry"]["rabbit"]["userid"] %> rabbit_password = <%= @mq_password %> +<% if node["openstack"]["mq"]["telemetry"]["rabbit"]["ha"] %> +rabbit_hosts = <%= @rabbit_hosts %> +rabbit_ha_queues = True +<% else %> rabbit_port = <%= node["openstack"]["mq"]["telemetry"]["rabbit"]["port"] %> rabbit_host = <%= node["openstack"]["mq"]["telemetry"]["rabbit"]["host"] %> +<% end %> rabbit_virtual_host = <%= node["openstack"]["mq"]["telemetry"]["rabbit"]["vhost"] %> rabbit_use_ssl = <%= node["openstack"]["mq"]["telemetry"]["rabbit"]["use_ssl"] %> rpc_backend = ceilometer.openstack.common.rpc.impl_kombu