From fb8fd8a01c1239fff9280d1a1d2a06fc882156c7 Mon Sep 17 00:00:00 2001 From: Maksym Yatsenko Date: Fri, 15 Apr 2016 12:15:05 +0300 Subject: [PATCH] Switch mistral to use puppet-oslo module rabbit messaging, db, logging parameters were configured by puppet-oslo module: * switch messaging related parameters to $::os_service_default as they are used in oslo::messaging_rabbit define * update unit test Change-Id: Id9c820f446b040625611223cb0fd778a3f7a2203 --- manifests/db.pp | 48 ++------ manifests/init.pp | 113 +++++++----------- manifests/logging.pp | 42 +++---- manifests/params.pp | 2 - metadata.json | 3 +- ...ch_to_oslo_messaging-70e92a6709162b1e.yaml | 5 + spec/classes/mistral_db_spec.rb | 24 +++- spec/classes/mistral_init_spec.rb | 35 +++--- 8 files changed, 114 insertions(+), 158 deletions(-) create mode 100644 releasenotes/notes/switch_to_oslo_messaging-70e92a6709162b1e.yaml diff --git a/manifests/db.pp b/manifests/db.pp index ca13f75..495f773 100644 --- a/manifests/db.pp +++ b/manifests/db.pp @@ -43,8 +43,6 @@ class mistral::db ( $database_max_overflow = $::os_service_default, ) { - include ::mistral::params - # NOTE(spredzy): In order to keep backward compatibility we rely on the pick function # to use mistral:: if mistral::db:: isn't specified. $database_connection_real = pick($::mistral::database_connection,$database_connection) @@ -58,44 +56,14 @@ class mistral::db ( validate_re($database_connection_real, '^(sqlite|mysql(\+pymysql)?|postgresql):\/\/(\S+:\S+@\S+\/\S+)?') - case $database_connection_real { - /^mysql(\+pymysql)?:\/\//: { - require 'mysql::bindings' - require 'mysql::bindings::python' - if $database_connection_real =~ /^mysql\+pymysql/ { - $backend_package = $::mistral::params::pymysql_package_name - } else { - $backend_package = false - } - } - /^postgresql:\/\//: { - $backend_package = false - require 'postgresql::lib::python' - } - /^sqlite:\/\//: { - $backend_package = $::mistral::params::sqlite_package_name - } - default: { - fail('Unsupported backend configured') - } - } - - if $backend_package and !defined(Package[$backend_package]) { - package {'mistral-backend-package': - ensure => present, - name => $backend_package, - tag => 'openstack', - } - } - - mistral_config { - 'database/connection': value => $database_connection_real, secret => true; - 'database/idle_timeout': value => $database_idle_timeout_real; - 'database/min_pool_size': value => $database_min_pool_size_real; - 'database/max_retries': value => $database_max_retries_real; - 'database/retry_interval': value => $database_retry_interval_real; - 'database/max_pool_size': value => $database_max_pool_size_real; - 'database/max_overflow': value => $database_max_overflow_real; + oslo::db { 'mistral_config': + connection => $database_connection_real, + idle_timeout => $database_idle_timeout_real, + min_pool_size => $database_min_pool_size_real, + max_pool_size => $database_max_pool_size_real, + max_retries => $database_max_retries_real, + retry_interval => $database_retry_interval_real, + max_overflow => $database_max_overflow_real, } } diff --git a/manifests/init.pp b/manifests/init.pp index 1c2b138..12dd39f 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -87,33 +87,33 @@ # # [*rabbit_host*] # (Optional) IP or hostname of the rabbit server. -# Defaults to '127.0.0.1' +# Defaults to $::os_service_default # # [*rabbit_port*] # (Optional) Port of the rabbit server. -# Defaults to 5672. +# Defaults to $::os_service_default # # [*rabbit_hosts*] # (Optional) Array of host:port (used with HA queues). # If defined, will remove rabbit_host & rabbit_port parameters from config -# Defaults to undef. +# Defaults to $::os_service_default # # [*rabbit_userid*] # (Optional) User to connect to the rabbit server. -# Defaults to 'guest' +# Defaults to $::os_service_default # # [*rabbit_password*] # (Required) Password to connect to the rabbit_server. -# Defaults to empty. Required if using the Rabbit (kombu) -# backend. +# Required if using the Rabbit (kombu) backend. +# Default to $::os_service_default # # [*rabbit_virtual_host*] # (Optional) Virtual_host to use. -# Defaults to '/' +# Defaults to $::os_service_default # # [*rabbit_ha_queues*] # (optional) Use HA queues in RabbitMQ (x-ha-policy: all). -# Defaults to undef +# Defaults to $::os_service_default # # [*rabbit_heartbeat_timeout_threshold*] # (optional) Number of seconds after which the RabbitMQ broker is considered @@ -121,18 +121,18 @@ # Heartbeating helps to ensure the TCP connection to RabbitMQ isn't silently # closed, resulting in missed or lost messages from the queue. # (Requires kombu >= 3.0.7 and amqp >= 1.4.0) -# Defaults to 0 +# Defaults to $::os_service_default # # [*rabbit_heartbeat_rate*] # (optional) How often during the rabbit_heartbeat_timeout_threshold period to # check the heartbeat on RabbitMQ connection. (i.e. rabbit_heartbeat_rate=2 # when rabbit_heartbeat_timeout_threshold=60, the heartbeat will be checked # every 30 seconds. -# Defaults to 2 +# Defaults to $::os_service_default # # [*rabbit_use_ssl*] # (optional) Connect over SSL for RabbitMQ -# Defaults to false +# Defaults to $::os_service_default # # [*report_interval*] # (optional) Interval, in seconds, between nodes reporting state to @@ -168,8 +168,8 @@ # Defaults to $::os_service_default # # [*amqp_durable_queues*] -# Use durable queues in amqp. -# (Optional) Defaults to false. +# (optional)Use durable queues in amqp. +# Defaults to $::os_service_default # # [*control_exchange*] # (Optional) @@ -188,21 +188,21 @@ class mistral( $keystone_user = 'mistral', $keystone_tenant = 'services', $package_ensure = 'present', - $database_connection = undef, - $rpc_backend = 'rabbit', + $database_connection = $::os_service_default, + $rpc_backend = $::os_service_default, $auth_uri = 'http://localhost:5000/', $identity_uri = 'http://localhost:35357/', $control_exchange = 'openstack', - $rabbit_host = '127.0.0.1', - $rabbit_port = 5672, - $rabbit_hosts = undef, - $rabbit_virtual_host = '/', - $rabbit_ha_queues = undef, - $rabbit_heartbeat_timeout_threshold = 0, - $rabbit_heartbeat_rate = 2, - $rabbit_userid = 'guest', - $rabbit_password = false, - $rabbit_use_ssl = false, + $rabbit_host = $::os_service_default, + $rabbit_port = $::os_service_default, + $rabbit_hosts = $::os_service_default, + $rabbit_virtual_host = $::os_service_default, + $rabbit_ha_queues = $::os_service_default, + $rabbit_heartbeat_timeout_threshold = $::os_service_default, + $rabbit_heartbeat_rate = $::os_service_default, + $rabbit_userid = $::os_service_default, + $rabbit_password = $::os_service_default, + $rabbit_use_ssl = $::os_service_default, $service_down_time = $::os_service_default, $report_interval = $::os_service_default, $kombu_ssl_ca_certs = $::os_service_default, @@ -210,7 +210,7 @@ class mistral( $kombu_ssl_keyfile = $::os_service_default, $kombu_ssl_version = $::os_service_default, $kombu_reconnect_delay = $::os_service_default, - $amqp_durable_queues = false, + $amqp_durable_queues = $::os_service_default, $use_syslog = undef, $use_stderr = undef, $log_dir = '/var/log/mistral', @@ -234,7 +234,6 @@ class mistral( } mistral_config { - 'DEFAULT/rpc_backend': value => $rpc_backend; 'keystone_authtoken/auth_uri': value => $auth_uri; 'keystone_authtoken/identity_uri': value => $identity_uri; 'keystone_authtoken/admin_user': value => $keystone_user; @@ -247,47 +246,27 @@ class mistral( 'DEFAULT/service_down_time': value => $service_down_time; } - if $rpc_backend == 'rabbit' { + if $rpc_backend in [$::os_service_default, 'rabbit'] { - if ! $rabbit_password { - fail('Please specify a rabbit_password parameter.') + oslo::messaging::rabbit {'mistral_config': + rabbit_host => $rabbit_host, + rabbit_port => $rabbit_port, + rabbit_hosts => $rabbit_hosts, + rabbit_password => $rabbit_password, + rabbit_userid => $rabbit_userid, + rabbit_virtual_host => $rabbit_virtual_host, + rabbit_ha_queues => $rabbit_ha_queues, + rabbit_use_ssl => $rabbit_use_ssl, + kombu_ssl_version => $kombu_ssl_version, + kombu_ssl_ca_certs => $kombu_ssl_ca_certs, + kombu_ssl_certfile => $kombu_ssl_certfile, + kombu_ssl_keyfile => $kombu_ssl_keyfile, + kombu_reconnect_delay => $kombu_reconnect_delay, + heartbeat_timeout_threshold => $rabbit_heartbeat_timeout_threshold, + heartbeat_rate => $rabbit_heartbeat_rate, + amqp_durable_queues => $amqp_durable_queues, } - - mistral_config { - 'oslo_messaging_rabbit/rabbit_password': value => $rabbit_password, secret => true; - 'oslo_messaging_rabbit/rabbit_userid': value => $rabbit_userid; - '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_version': value => $kombu_ssl_version; - '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_reconnect_delay': value => $kombu_reconnect_delay; - 'oslo_messaging_rabbit/heartbeat_timeout_threshold': value => $rabbit_heartbeat_timeout_threshold; - 'oslo_messaging_rabbit/heartbeat_rate': value => $rabbit_heartbeat_rate; - 'oslo_messaging_rabbit/amqp_durable_queues': value => $amqp_durable_queues; - } - - if $rabbit_hosts { - mistral_config { 'oslo_messaging_rabbit/rabbit_hosts': value => join(any2array($rabbit_hosts), ',') } - mistral_config { 'oslo_messaging_rabbit/rabbit_host': ensure => absent } - mistral_config { 'oslo_messaging_rabbit/rabbit_port': ensure => absent } - } else { - mistral_config { 'oslo_messaging_rabbit/rabbit_host': value => $rabbit_host } - mistral_config { 'oslo_messaging_rabbit/rabbit_port': value => $rabbit_port } - mistral_config { 'oslo_messaging_rabbit/rabbit_hosts': value => "${rabbit_host}:${rabbit_port}" } - } - - # By default rabbit_ha_queues is undef - if $rabbit_ha_queues == undef { - if size($rabbit_hosts) > 1 { - mistral_config { 'oslo_messaging_rabbit/rabbit_ha_queues': value => true } - } else { - mistral_config { 'oslo_messaging_rabbit/rabbit_ha_queues': value => false } - } - } else { - mistral_config { 'oslo_messaging_rabbit/rabbit_ha_queues': value => $rabbit_ha_queues } - } - + } else { + mistral_config { 'DEFAULT/rpc_backend': value => $rpc_backend } } } diff --git a/manifests/logging.pp b/manifests/logging.pp index 0bec8ea..e889122 100644 --- a/manifests/logging.pp +++ b/manifests/logging.pp @@ -120,30 +120,24 @@ class mistral::logging( $verbose_real = pick($::mistral::verbose,$verbose) $debug_real = pick($::mistral::debug,$debug) - if is_service_default($default_log_levels) { - $default_log_levels_real = $default_log_levels - } else { - $default_log_levels_real = join(sort(join_keys_to_values($default_log_levels, '=')), ',') - } - - mistral_config { - 'DEFAULT/use_syslog' : value => $use_syslog_real; - 'DEFAULT/use_stderr' : value => $use_stderr_real; - 'DEFAULT/syslog_log_facility' : value => $log_facility_real; - 'DEFAULT/log_dir' : value => $log_dir_real; - 'DEFAULT/verbose' : value => $verbose_real; - 'DEFAULT/debug' : value => $debug_real; - 'DEFAULT/default_log_levels' : value => $default_log_levels_real; - 'DEFAULT/logging_context_format_string' : value => $logging_context_format_string; - 'DEFAULT/logging_default_format_string' : value => $logging_default_format_string; - 'DEFAULT/logging_debug_format_suffix' : value => $logging_debug_format_suffix; - 'DEFAULT/logging_exception_prefix' : value => $logging_exception_prefix; - 'DEFAULT/log_config_append' : value => $log_config_append; - 'DEFAULT/publish_errors' : value => $publish_errors; - 'DEFAULT/fatal_deprecations' : value => $fatal_deprecations; - 'DEFAULT/instance_format' : value => $instance_format; - 'DEFAULT/instance_uuid_format' : value => $instance_uuid_format; - 'DEFAULT/log_date_format' : value => $log_date_format; + oslo::log { 'mistral_config': + use_syslog => $use_syslog_real, + use_stderr => $use_stderr_real, + syslog_log_facility => $log_facility_real, + log_dir => $log_dir_real, + verbose => $verbose_real, + debug => $debug_real, + default_log_levels => $default_log_levels, + logging_context_format_string => $logging_context_format_string, + logging_default_format_string => $logging_default_format_string, + logging_debug_format_suffix => $logging_debug_format_suffix, + logging_exception_prefix => $logging_exception_prefix, + log_config_append => $log_config_append, + publish_errors => $publish_errors, + fatal_deprecations => $fatal_deprecations, + instance_format => $instance_format, + instance_uuid_format => $instance_uuid_format, + log_date_format => $log_date_format, } } diff --git a/manifests/params.pp b/manifests/params.pp index fbda3cd..11a4acb 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -19,7 +19,6 @@ class mistral::params { $executor_service_name = 'openstack-mistral-executor' $mistral_wsgi_script_path = '/var/www/cgi-bin/mistral' $mistral_wsgi_script_source = '/usr/lib/python2.7/site-packages/mistral/api/wsgi.py' - $pymysql_package_name = undef } 'Debian': { $common_package_name = 'mistral' @@ -31,7 +30,6 @@ class mistral::params { $executor_service_name = 'mistral-executor' $mistral_wsgi_script_path = '/usr/lib/cgi-bin/mistral' $mistral_wsgi_script_source = '/usr/share/mistral-common/wsgi.py' - $pymysql_package_name = 'python-pymysql' } default: { fail("Unsupported osfamily: ${::osfamily} operatingsystem: \ diff --git a/metadata.json b/metadata.json index 3fab299..3d3bc00 100644 --- a/metadata.json +++ b/metadata.json @@ -30,6 +30,7 @@ { "name": "puppetlabs/apache", "version_requirement": ">=1.0.0 <2.0.0" }, { "name": "puppetlabs/inifile", "version_requirement": ">=1.0.0 <2.0.0" }, { "name": "puppetlabs/stdlib", "version_requirement": ">= 4.0.0 <5.0.0" }, - { "name": "openstack/openstacklib", "version_requirement": ">=8.0.0 <9.0.0" } + { "name": "openstack/openstacklib", "version_requirement": ">=8.0.0 <9.0.0" }, + { "name": "openstack/oslo", "version_requirement": "<9.0.0" } ] } diff --git a/releasenotes/notes/switch_to_oslo_messaging-70e92a6709162b1e.yaml b/releasenotes/notes/switch_to_oslo_messaging-70e92a6709162b1e.yaml new file mode 100644 index 0000000..31271b3 --- /dev/null +++ b/releasenotes/notes/switch_to_oslo_messaging-70e92a6709162b1e.yaml @@ -0,0 +1,5 @@ +--- +features: + - Use oslo module for messaging (rabbit) configuration. + Messaging related parameters were switched to $::os_service_default. + Docs string for parameter were updated according to oslo module. diff --git a/spec/classes/mistral_db_spec.rb b/spec/classes/mistral_db_spec.rb index 1169e63..95d56e2 100644 --- a/spec/classes/mistral_db_spec.rb +++ b/spec/classes/mistral_db_spec.rb @@ -84,14 +84,30 @@ describe 'mistral::db' do end it 'install the proper backend package' do - is_expected.to contain_package('mistral-backend-package').with( + is_expected.to contain_package('db_backend_package').with( :ensure => 'present', :name => 'python-pymysql', - :tag => 'openstack' + :tag => ['openstack'], ) end end - end + + + context 'with sqlite backend' do + let :params do + { :database_connection => 'sqlite:///var/lib/mistral/mistral.sqlite', } + end + + it 'install the proper backend package' do + is_expected.to contain_package('db_backend_package').with( + :ensure => 'present', + :name => 'python-pysqlite2', + :tag => ['openstack'], + ) + end + end + + end context 'on Redhat platforms' do let :facts do @@ -108,7 +124,7 @@ describe 'mistral::db' do { :database_connection => 'mysql+pymysql://mistral:mistral@localhost/mistral', } end - it { is_expected.not_to contain_package('mistral-backend-package') } + it { is_expected.not_to contain_package('db_backend_package') } end end diff --git a/spec/classes/mistral_init_spec.rb b/spec/classes/mistral_init_spec.rb index fd57465..7b4a710 100644 --- a/spec/classes/mistral_init_spec.rb +++ b/spec/classes/mistral_init_spec.rb @@ -2,7 +2,6 @@ require 'spec_helper' describe 'mistral' do let :req_params do { - :rabbit_password => 'guest', :database_connection => 'mysql://user:password@host/database', :keystone_password => 'foo', } @@ -30,15 +29,15 @@ describe 'mistral' do is_expected.to contain_mistral_config('DEFAULT/control_exchange').with(:value => 'openstack') is_expected.to contain_mistral_config('DEFAULT/report_interval').with(:value => '') is_expected.to contain_mistral_config('DEFAULT/service_down_time').with(:value => '') - is_expected.to contain_mistral_config('oslo_messaging_rabbit/rabbit_password').with(:value => 'guest', :secret => true) - is_expected.to contain_mistral_config('oslo_messaging_rabbit/rabbit_host').with(:value => '127.0.0.1') - is_expected.to contain_mistral_config('oslo_messaging_rabbit/rabbit_port').with(:value => '5672') - is_expected.to contain_mistral_config('oslo_messaging_rabbit/rabbit_hosts').with(:value => '127.0.0.1:5672') - is_expected.to contain_mistral_config('oslo_messaging_rabbit/rabbit_ha_queues').with(:value => false) - is_expected.to contain_mistral_config('oslo_messaging_rabbit/rabbit_virtual_host').with(:value => '/') - is_expected.to contain_mistral_config('oslo_messaging_rabbit/heartbeat_timeout_threshold').with_value('0') - is_expected.to contain_mistral_config('oslo_messaging_rabbit/heartbeat_rate').with_value('2') - is_expected.to contain_mistral_config('oslo_messaging_rabbit/rabbit_userid').with(:value => 'guest') + is_expected.to contain_mistral_config('oslo_messaging_rabbit/rabbit_password').with(:value => '', :secret => true) + is_expected.to contain_mistral_config('oslo_messaging_rabbit/rabbit_host').with(:value => '') + is_expected.to contain_mistral_config('oslo_messaging_rabbit/rabbit_port').with(:value => '') + is_expected.to contain_mistral_config('oslo_messaging_rabbit/rabbit_hosts').with(:value => '') + is_expected.to contain_mistral_config('oslo_messaging_rabbit/rabbit_ha_queues').with(:value => '') + is_expected.to contain_mistral_config('oslo_messaging_rabbit/rabbit_virtual_host').with(:value => '') + is_expected.to contain_mistral_config('oslo_messaging_rabbit/heartbeat_timeout_threshold').with_value('') + is_expected.to contain_mistral_config('oslo_messaging_rabbit/heartbeat_rate').with_value('') + is_expected.to contain_mistral_config('oslo_messaging_rabbit/rabbit_userid').with(:value => '') is_expected.to contain_mistral_config('oslo_messaging_rabbit/kombu_reconnect_delay').with(:value => '') is_expected.to contain_mistral_config('coordination/backend_url').with(:value => '') is_expected.to contain_mistral_config('coordination/heartbeat_interval').with(:value => '') @@ -66,8 +65,8 @@ describe 'mistral' do end it 'should contain many' do - is_expected.to contain_mistral_config('oslo_messaging_rabbit/rabbit_host').with(:value => nil) - is_expected.to contain_mistral_config('oslo_messaging_rabbit/rabbit_port').with(:value => nil) + is_expected.to contain_mistral_config('oslo_messaging_rabbit/rabbit_host').with(:value => '') + is_expected.to contain_mistral_config('oslo_messaging_rabbit/rabbit_port').with(:value => '') is_expected.to contain_mistral_config('oslo_messaging_rabbit/rabbit_hosts').with(:value => 'rabbit1:5672,rabbit2:5672') is_expected.to contain_mistral_config('oslo_messaging_rabbit/rabbit_ha_queues').with(:value => true) end @@ -79,10 +78,10 @@ describe 'mistral' do end it 'should contain many' do - is_expected.to contain_mistral_config('oslo_messaging_rabbit/rabbit_host').with(:value => nil) - is_expected.to contain_mistral_config('oslo_messaging_rabbit/rabbit_port').with(:value => nil) + is_expected.to contain_mistral_config('oslo_messaging_rabbit/rabbit_host').with(:value => '') + is_expected.to contain_mistral_config('oslo_messaging_rabbit/rabbit_port').with(:value => '') is_expected.to contain_mistral_config('oslo_messaging_rabbit/rabbit_hosts').with(:value => 'rabbit1:5672') - is_expected.to contain_mistral_config('oslo_messaging_rabbit/rabbit_ha_queues').with(:value => false) + is_expected.to contain_mistral_config('oslo_messaging_rabbit/rabbit_ha_queues').with(:value => '') end end @@ -147,10 +146,6 @@ describe 'mistral' do let :params do req_params.merge!({ :rabbit_use_ssl => false, - :kombu_ssl_ca_certs => '', - :kombu_ssl_certfile => '', - :kombu_ssl_keyfile => '', - :kombu_ssl_version => '' }) end @@ -168,7 +163,7 @@ describe 'mistral' do req_params end - it { is_expected.to contain_mistral_config('oslo_messaging_rabbit/amqp_durable_queues').with_value(false) } + it { is_expected.to contain_mistral_config('oslo_messaging_rabbit/amqp_durable_queues').with_value('') } end describe 'with amqp_durable_queues enabled' do