From 18442571f2c037d65900d8f1ec8b8956be0e4db3 Mon Sep 17 00:00:00 2001 From: ZhongShengping Date: Thu, 5 May 2016 23:30:48 +0800 Subject: [PATCH] Use oslo module for messaging (rabbit) configuration Change-Id: I75dbd9bf37d812a560a401eee2a293cee876a036 --- manifests/init.pp | 49 ++++++++++++++++++-------------- spec/classes/magnum_init_spec.rb | 18 ++++++------ 2 files changed, 36 insertions(+), 31 deletions(-) diff --git a/manifests/init.pp b/manifests/init.pp index 5078b4c..2a4fb1a 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -12,6 +12,11 @@ # (Optional) Notification driver to use # Defaults to $::os_service_default # +# [*rpc_backend*] +# (optional) The rpc backend implementation to use, can be: +# rabbit (for rabbitmq) +# Defaults to 'rabbit' +# # [*rabbit_host*] # (Optional) Host for rabbit server # Defaults to $::os_service_default @@ -61,6 +66,7 @@ class magnum( $package_ensure = 'present', $notification_driver = $::os_service_default, + $rpc_backend = 'rabbit', $rabbit_host = $::os_service_default, $rabbit_hosts = $::os_service_default, $rabbit_port = $::os_service_default, @@ -85,32 +91,31 @@ class magnum( tag => ['openstack', 'magnum-package'], } - magnum_config { - 'DEFAULT/rpc_backend' : value => 'rabbit'; - 'oslo_messaging_rabbit/userid' : value => $rabbit_userid; - 'oslo_messaging_rabbit/rabbit_password' : value => $rabbit_password, secret => true; - 'oslo_messaging_rabbit/rabbit_virtual_host' : value => $rabbit_virtual_host; - 'oslo_messaging_rabbit/rabbit_use_ssl' : value => $rabbit_use_ssl; - 'oslo_messaging_rabbit/kombu_ssl_ca_certs' : value => $kombu_ssl_ca_certs; - 'oslo_messaging_rabbit/kombu_ssl_certfile' : value => $kombu_ssl_certfile; - 'oslo_messaging_rabbit/kombu_ssl_keyfile' : value => $kombu_ssl_keyfile; - 'oslo_messaging_rabbit/kombu_ssl_version' : value => $kombu_ssl_version; - } + if $rpc_backend == 'rabbit' { - if ! is_service_default($rabbit_hosts) and $rabbit_hosts { - magnum_config { 'oslo_messaging_rabbit/rabbit_hosts': value => join(any2array($rabbit_hosts), ',') } - } else { - magnum_config { 'oslo_messaging_rabbit/rabbit_host': value => $rabbit_host } - magnum_config { 'oslo_messaging_rabbit/rabbit_port': value => $rabbit_port } - magnum_config { 'oslo_messaging_rabbit/rabbit_hosts': ensure => absent } - } + if ! $rabbit_password { + fail('Please specify a rabbit_password parameter.') + } - if !is_service_default($notification_driver) and $notification_driver { - magnum_config { - 'DEFAULT/notification_driver': value => join(any2array($notification_driver), ','); + oslo::messaging::rabbit { 'magnum_config': + rabbit_userid => $rabbit_userid, + rabbit_password => $rabbit_password, + rabbit_virtual_host => $rabbit_virtual_host, + rabbit_host => $rabbit_host, + rabbit_port => $rabbit_port, + rabbit_hosts => $rabbit_hosts, + rabbit_use_ssl => $rabbit_use_ssl, + kombu_ssl_version => $kombu_ssl_version, + kombu_ssl_keyfile => $kombu_ssl_keyfile, + kombu_ssl_certfile => $kombu_ssl_certfile, + kombu_ssl_ca_certs => $kombu_ssl_ca_certs, } } else { - magnum_config { 'DEFAULT/notification_driver': ensure => absent; } + magnum_config { 'DEFAULT/rpc_backend': value => $rpc_backend } + } + + oslo::messaging::notifications { 'magnum_config': + driver => $notification_driver } } diff --git a/spec/classes/magnum_init_spec.rb b/spec/classes/magnum_init_spec.rb index 7f0fb58..c1c4a0a 100644 --- a/spec/classes/magnum_init_spec.rb +++ b/spec/classes/magnum_init_spec.rb @@ -44,12 +44,12 @@ describe 'magnum' do context 'with overridden parameters' do let :params do - { :package_ensure => 'latest', + { :package_ensure => 'latest', :notification_driver => 'messagingv1', - :rabbit_host => '53.210.103.65', - :rabbit_port => '1234', - :rabbit_userid => 'me', - :rabbit_password => 'secrete', + :rabbit_host => '53.210.103.65', + :rabbit_port => '1234', + :rabbit_userid => 'me', + :rabbit_password => 'secrete', :rabbit_virtual_host => 'vhost', } end @@ -101,12 +101,12 @@ describe 'magnum' do context 'with rabbit ssl enabled with kombu' do let :params do - { :rabbit_hosts => ['rabbit:5673'], - :rabbit_use_ssl => true, + { :rabbit_hosts => ['rabbit:5673'], + :rabbit_use_ssl => true, :kombu_ssl_ca_certs => '/etc/ca.crt', :kombu_ssl_certfile => '/etc/certfile', - :kombu_ssl_keyfile => '/etc/key', - :kombu_ssl_version => 'TLSv1', + :kombu_ssl_keyfile => '/etc/key', + :kombu_ssl_version => 'TLSv1', } end