From 9f19d11c16532b6caa79b68ffc99f5a03210238c Mon Sep 17 00:00:00 2001 From: Emilien Macchi Date: Fri, 5 Feb 2016 06:31:27 +0100 Subject: [PATCH] Refactor puppet-mistral The module was written in a way that was not consistent with other Puppet OpenStack modules, the interface was very different. This patch: * add db.pp * update logging.pp with usual parameters * drop useless parameters in keystone/auth.pp * cleanup params.pp * drop services.pp, which is useless * Update unit tests * Add coordination support in init.pp * Some alignment issues * Add more doc in README * Stop including ::mistral in all classes * Include mistral::policy in mistral::api This is a non-backward compatible change, but since the module has no release and no stable branch, also very new, this is not something we need to care at this stage. People using this module at this stage will have to update their manifests otherwise their Puppet catalog will fail. Change-Id: I979e21caa71ee35337dc01b225878701868e966a --- README.md | 17 +- manifests/api.pp | 5 +- manifests/db.pp | 101 ++++++ manifests/engine.pp | 1 - manifests/executor.pp | 9 +- manifests/init.pp | 338 +++++++++++++++------ manifests/keystone/auth.pp | 52 +--- manifests/logging.pp | 260 ++++++---------- manifests/params.pp | 38 ++- manifests/services.pp | 100 ------ spec/classes/mistral_api_spec.rb | 2 +- spec/classes/mistral_db_spec.rb | 115 +++++++ spec/classes/mistral_engine_spec.rb | 1 - spec/classes/mistral_executor_spec.rb | 1 - spec/classes/mistral_init_spec.rb | 219 +++++++++++-- spec/classes/mistral_keystone_auth_spec.rb | 6 +- spec/classes/mistral_logging_spec.rb | 71 +++-- 17 files changed, 831 insertions(+), 505 deletions(-) create mode 100644 manifests/db.pp delete mode 100644 manifests/services.pp create mode 100644 spec/classes/mistral_db_spec.rb diff --git a/README.md b/README.md index a988e49..9c54759 100644 --- a/README.md +++ b/README.md @@ -71,19 +71,18 @@ Whether to hide the value from Puppet logs. Defaults to `false`. If value is equal to ensure_absent_val then the resource will behave as if `ensure => absent` was specified. Defaults to `` -Limitations ------------ -### Packages +Beaker-Rspec +------------ -For now there aren't supported packages for Mistral. - -Instructions for building the rpm on the trunk: - -1. Clone mistral repo to your machine: ```git clone https://github.com/openstack/mistral.git``` -2. In the mistral repo run the command: ```python ./setup.py bdist_rpm``` +This module has beaker-rspec tests +To run: +``shell +bundle install +bundle exec rspec spec/acceptance +`` Development ----------- diff --git a/manifests/api.pp b/manifests/api.pp index 863b56b..ffe4845 100644 --- a/manifests/api.pp +++ b/manifests/api.pp @@ -38,8 +38,11 @@ class mistral::api ( $allow_action_execution_deletion = $::os_service_default, ) { - include ::mistral include ::mistral::params + include ::mistral::policy + + Package['mistral-api'] -> Class['mistral::policy'] + Class['mistral::policy'] ~> Service['mistral-api'] package { 'mistral-api': ensure => $package_ensure, diff --git a/manifests/db.pp b/manifests/db.pp new file mode 100644 index 0000000..ca13f75 --- /dev/null +++ b/manifests/db.pp @@ -0,0 +1,101 @@ +# == Class: mistral::db +# +# Configure the Mistral database +# +# === Parameters +# +# [*database_connection*] +# Url used to connect to database. +# (Optional) Defaults to 'sqlite:////var/lib/mistral/mistral.sqlite' +# +# [*database_idle_timeout*] +# Timeout when db connections should be reaped. +# (Optional) Defaults to $::os_service_default +# +# [*database_min_pool_size*] +# Minimum number of SQL connections to keep open in a pool. +# (Optional) Defaults to $::os_service_default +# +# [*database_max_pool_size*] +# Maximum number of SQL connections to keep open in a pool. +# (Optional) Defaults to $::os_service_default +# +# [*database_max_retries*] +# Maximum db connection retries during startup. +# Setting -1 implies an infinite retry count. +# (Optional) Defaults to $::os_service_default +# +# [*database_retry_interval*] +# Interval between retries of opening a sql connection. +# (Optional) Defaults to $::os_service_default +# +# [*database_max_overflow*] +# If set, use this value for max_overflow with sqlalchemy. +# (Optional) Defaults to $::os_service_default +# +class mistral::db ( + $database_connection = 'sqlite:////var/lib/mistral/mistral.sqlite', + $database_idle_timeout = $::os_service_default, + $database_min_pool_size = $::os_service_default, + $database_max_pool_size = $::os_service_default, + $database_max_retries = $::os_service_default, + $database_retry_interval = $::os_service_default, + $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) + $database_idle_timeout_real = pick($::mistral::database_idle_timeout,$database_idle_timeout) + $database_min_pool_size_real = pick($::mistral::database_min_pool_size,$database_min_pool_size) + $database_max_pool_size_real = pick($::mistral::database_max_pool_size,$database_max_pool_size) + $database_max_retries_real = pick($::mistral::database_max_retries,$database_max_retries) + $database_retry_interval_real = pick($::mistral::database_retry_interval,$database_retry_interval) + $database_max_overflow_real = pick($::mistral::database_max_overflow,$database_max_overflow) + + 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; + } + +} diff --git a/manifests/engine.pp b/manifests/engine.pp index f6c7c2e..56bbd6d 100644 --- a/manifests/engine.pp +++ b/manifests/engine.pp @@ -43,7 +43,6 @@ class mistral::engine ( $execution_field_size_limit_kb = $::os_service_default, ) { - include ::mistral include ::mistral::params package { 'mistral-engine': diff --git a/manifests/executor.pp b/manifests/executor.pp index 5cca93d..29d115a 100644 --- a/manifests/executor.pp +++ b/manifests/executor.pp @@ -53,7 +53,6 @@ class mistral::executor ( $older_than = $::os_service_default, ) { - include ::mistral include ::mistral::params package { 'mistral-executor': @@ -80,11 +79,11 @@ class mistral::executor ( } mistral_config { - 'executor/host' : value => $host; - 'executor/topic' : value => $topic; - 'executor/version' : value => $version; + 'executor/host' : value => $host; + 'executor/topic' : value => $topic; + 'executor/version' : value => $version; 'execution_expiration_policy/evaluation_interval' : value => $evaluation_interval; - 'execution_expiration_policy/older_than' : value => $older_than; + 'execution_expiration_policy/older_than' : value => $older_than; } } diff --git a/manifests/init.pp b/manifests/init.pp index bd922a7..1c2b138 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -1,135 +1,293 @@ # == Class: mistral # -# Full description of class mistral here. +# Mistral base package & configuration # # === Parameters # [*package_ensure*] -# (Optional) Ensure state for package. -# Defaults to 'present' +# (Optional) Ensure state for package. +# Defaults to 'present'. # -# [*rpc_backend*] -# The rpc backend. Default 'rabbit' +# [*rpc_backend*] +# (optional) The rpc backend. +# Defaults to 'rabbit'. +# +# [*auth_uri*] +# (optional) Specifies the public Identity URI for Mistral to use. +# Default 'http://localhost:5000/v2.0/'. # -# [*auth_uri*] -# Specifies the public Identity URI for Mistral to use. -# Default 'http://localhost:5000/v2.0/' - # [*identity_uri*] -# Specifies the admin Identity URI for Mistral to use. -# Default 'http://localhost:35357/' +# (optional) Specifies the admin Identity URI for Mistral to use. +# Default 'http://localhost:35357/'. # -# [*admin_user*] -# The user name from 'mistral::keystone::auth'. Default 'mistral' +# [*keystone_user*] +# (optional) The name of the auth user +# Defaults to 'mistral'. # -# [*admin_tenant_name*] -# The tenant name from 'mistral::keystone::auth'. Default 'service' +# [*keystone_tenant*] +# (optional) The tenant of the auth user +# Defaults to 'services'. # -# [*admin_password*] -# The password from 'mistral::keystone::auth'. Default 'password' +# [*keystone_password*] +# (required) The password of the auth user. # -# [*log_dir*] -# Path to the log dir. Default '$::mistral::params::log_dir' +# [*log_dir*] +# (optional) Directory where logs should be stored. +# If set to boolean false or the $::os_service_default, it will not log to +# any directory. +# Defaults to '/var/log/mistral'. # -# [*mysql_vip*] -# ip for the my sql DB. Default '127.0.0.1' +# [*use_syslog*] +# (Optional) Use syslog for logging. +# Defaults to undef. # -# [*mistral_db_pass*] -# password for thr DB. Shulde be the same as mistral::db::mysql. -# Default 'password' +# [*use_stderr*] +# (optional) Use stderr for logging +# Defaults to undef. # -# [*auth_version*] -# Keystone Api version. Default 'v2.0' +# [*log_facility*] +# (Optional) Syslog facility to receive log lines. +# Defaults to undef. # -# [*rabbit_hostname*] -# The name/ip of rabbit. Default 'localhost' +# [*verbose*] +# (Optional) Should the daemons log verbose messages +# Defaults to undef. # -# [*rabbit_userid*] -# User id for rabbit. Default 'guest' +# [*debug*] +# (Optional) Should the daemons log debug messages +# Defaults to undef. # -# [*rabbit_password*] -# password for rabbit. Default 'guest' +# [*database_connection*] +# (optional) Url used to connect to database. +# Defaults to undef. +# +# [*database_idle_timeout*] +# Timeout when db connections should be reaped. +# (Optional) Defaults to undef. +# +# [*database_min_pool_size*] +# Minimum number of SQL connections to keep open in a pool. +# (Optional) Defaults to undef. +# +# [*database_max_pool_size*] +# Maximum number of SQL connections to keep open in a pool. +# (Optional) Defaults to undef. +# +# [*database_max_retries*] +# Maximum db connection retries during startup. +# Setting -1 implies an infinite retry count. +# (Optional) Defaults to undef. +# +# [*database_retry_interval*] +# Interval between retries of opening a sql connection. +# (Optional) Defaults to underf. +# +# [*database_max_overflow*] +# If set, use this value for max_overflow with sqlalchemy. +# (Optional) Defaults to undef. +# +# [*rabbit_host*] +# (Optional) IP or hostname of the rabbit server. +# Defaults to '127.0.0.1' # # [*rabbit_port*] -# The port of rabbit. Default $::os_service_default +# (Optional) Port of the rabbit server. +# Defaults to 5672. # -# [*auth_protocol*] -# Keystone protocol +# [*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. # -# DEPRECATED PARAMETERS +# [*rabbit_userid*] +# (Optional) User to connect to the rabbit server. +# Defaults to 'guest' # -# [*qpid_hostname*] -# The name/ip of qpid. Default undef +# [*rabbit_password*] +# (Required) Password to connect to the rabbit_server. +# Defaults to empty. Required if using the Rabbit (kombu) +# backend. # -# [*qpid_port*] -# The port of qpid. Default undef +# [*rabbit_virtual_host*] +# (Optional) Virtual_host to use. +# Defaults to '/' # -# [*qpid_username*] -# User name for qpid. Default undef +# [*rabbit_ha_queues*] +# (optional) Use HA queues in RabbitMQ (x-ha-policy: all). +# Defaults to undef # -# [*qpid_password*] -# password for qpid. Default undef +# [*rabbit_heartbeat_timeout_threshold*] +# (optional) Number of seconds after which the RabbitMQ broker is considered +# down if the heartbeat keepalive fails. Any value >0 enables heartbeats. +# 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 # -# [*qpid_protocol*] -# protocol for qpid. Default undef +# [*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 # -# [*qpid_tcp_nodelay*] -# Should tcp be no delay for qpid. Default undef +# [*rabbit_use_ssl*] +# (optional) Connect over SSL for RabbitMQ +# Defaults to false +# +# [*report_interval*] +# (optional) Interval, in seconds, between nodes reporting state to +# datastore (integer value). +# Defaults to $::os_service_default +# +# [*service_down_time*] +# (optional) Maximum time since last check-in for a service to be +# considered up (integer value). +# Defaults to $::os_service_default +# +# [*kombu_ssl_ca_certs*] +# (optional) SSL certification authority file (valid only if SSL enabled). +# Defaults to $::os_service_default +# +# [*kombu_ssl_certfile*] +# (optional) SSL cert file (valid only if SSL enabled). +# Defaults to $::os_service_default +# +# [*kombu_ssl_keyfile*] +# (optional) SSL key file (valid only if SSL enabled). +# Defaults to $::os_service_default +# +# [*kombu_ssl_version*] +# (optional) SSL version to use (valid only if SSL enabled). +# Valid values are TLSv1, SSLv23 and SSLv3. SSLv2 may be +# available on some distributions. +# Defaults to $::os_service_default +# +# [*kombu_reconnect_delay*] +# (optional) How long to wait before reconnecting in response to an AMQP +# consumer cancel notification. +# Defaults to $::os_service_default +# +# [*amqp_durable_queues*] +# Use durable queues in amqp. +# (Optional) Defaults to false. +# +# [*control_exchange*] +# (Optional) +# Defaults to 'openstack'. +# +# [*coordination_backend_url*] +# (optional) The backend URL to be used for coordination. +# Defaults to $::os_service_default +# +# [*coordination_heartbeat_interval*] +# (optional) Number of seconds between heartbeats for coordination. +# Defaults to $::os_service_default # class mistral( - $package_ensure = 'present', - $rpc_backend = 'rabbit', - $auth_uri = 'http://localhost:5000/v2.0/', - $identity_uri = 'http://localhost:35357/', - $admin_user = 'mistral', - $admin_tenant_name = 'services', - $admin_password = 'password', - $log_dir = $::mistral::params::log_dir, - $mysql_vip = '127.0.0.1', - $mistral_db_pass = 'password', - $auth_version = 'v2.0', - $auth_protocol = 'http', - $rabbit_hostname = 'localhost', - $rabbit_userid = 'guest', - $rabbit_password = 'guest', - $rabbit_port = $::os_service_default, - # DEPRECATED PARAMETERS - $qpid_hostname = undef, - $qpid_port = undef, - $qpid_username = undef, - $qpid_password = undef, - $qpid_protocol = undef, - $qpid_tcp_nodelay = undef, + $keystone_password, + $keystone_user = 'mistral', + $keystone_tenant = 'services', + $package_ensure = 'present', + $database_connection = undef, + $rpc_backend = 'rabbit', + $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, + $service_down_time = $::os_service_default, + $report_interval = $::os_service_default, + $kombu_ssl_ca_certs = $::os_service_default, + $kombu_ssl_certfile = $::os_service_default, + $kombu_ssl_keyfile = $::os_service_default, + $kombu_ssl_version = $::os_service_default, + $kombu_reconnect_delay = $::os_service_default, + $amqp_durable_queues = false, + $use_syslog = undef, + $use_stderr = undef, + $log_dir = '/var/log/mistral', + $log_facility = undef, + $verbose = undef, + $debug = undef, + $coordination_backend_url = $::os_service_default, + $coordination_heartbeat_interval = $::os_service_default, ){ include ::mistral::params + include ::mistral::db + include ::mistral::logging + + validate_string($keystone_password) + package { 'mistral-common': ensure => $package_ensure, name => $::mistral::params::common_package_name, tag => ['openstack', 'mistral-package'], } - $database_connection = "mysql://mistral:${mistral_db_pass}@${mysql_vip}/mistral" mistral_config { - 'DEFAULT/log_dir' : value => $log_dir; - 'DEFAULT/rpc_backend' : value => $rpc_backend; - 'keystone_authtoken/auth_uri' : value => $auth_uri; - 'keystone_authtoken/identity_uri' : value => $identity_uri; - 'keystone_authtoken/auth_version' : value => $auth_version; - 'keystone_authtoken/auth_protocol' : value => $auth_protocol; - 'keystone_authtoken/admin_user' : value => $admin_user; - 'keystone_authtoken/admin_password' : value => $admin_password; - 'keystone_authtoken/admin_tenant_name' : value => $admin_tenant_name; - 'database/connection' : value => $database_connection; - } - if $rpc_backend == 'qpid' { - warning('Qpid driver is removed from Oslo.messaging in the Mitaka release') + '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; + 'keystone_authtoken/admin_password': value => $keystone_password; + 'keystone_authtoken/admin_tenant_name': value => $keystone_tenant; + 'coordination/backend_url': value => $coordination_backend_url; + 'coordination/heartbeat_interval': value => $coordination_heartbeat_interval; + 'DEFAULT/control_exchange': value => $control_exchange; + 'DEFAULT/report_interval': value => $report_interval; + 'DEFAULT/service_down_time': value => $service_down_time; } + if $rpc_backend == 'rabbit' { - mistral_config { - 'oslo_messaging_rabbit/rabbit_host' : value => $rabbit_hostname; - 'oslo_messaging_rabbit/rabbit_port' : value => $rabbit_port; - 'oslo_messaging_rabbit/rabbit_userid' : value => $rabbit_userid; - 'oslo_messaging_rabbit/rabbit_password' : value => $rabbit_password; + + if ! $rabbit_password { + fail('Please specify a rabbit_password parameter.') } + + 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 } + } + } } diff --git a/manifests/keystone/auth.pp b/manifests/keystone/auth.pp index d4032ae..d16cd6a 100644 --- a/manifests/keystone/auth.pp +++ b/manifests/keystone/auth.pp @@ -45,7 +45,6 @@ # (optional) Name of the service. # Defaults to the value of auth_name. # -# # [*configure_service*] # Should mistral service be configured? Defaults to 'true'. # @@ -57,55 +56,6 @@ # (optional) Whether to configure the admin role for the service user. # Defaults to true # -# [*version*] -# (optional) DEPRECATED: Use public_url, internal_url and admin_url instead. -# API version endpoint. (Defaults to 'v2') -# Setting this parameter overrides public_url, internal_url and admin_url parameters. -# -# [*port*] -# (optional) DEPRECATED: Use public_url, internal_url and admin_url instead. -# Default port for endpoints. (Defaults to 8989) -# Setting this parameter overrides public_url, internal_url and admin_url parameters. -# -# [*public_port*] -# (optional) DEPRECATED: Use public_url, internal_url and admin_url instead. -# Default public port for endpoints. (Defaults to 8989) -# Setting this parameter overrides public_url, internal_url and admin_url parameters. -# -# [*public_protocol*] -# (optional) DEPRECATED: Use public_url instead. -# Protocol for public endpoint. (Defaults to 'http') -# Setting this parameter overrides public_url parameter. -# -# [*public_address*] -# (optional) DEPRECATED: Use public_url instead. -# Public address for endpoint. (Defaults to '127.0.0.1') -# Setting this parameter overrides public_url parameter. -# -# [*internal_protocol*] -# (optional) DEPRECATED: Use internal_url instead. -# Protocol for internal endpoint. (Defaults to 'http') -# Setting this parameter overrides internal_url parameter. -# -# [*internal_address*] -# (optional) DEPRECATED: Use internal_url instead. -# Internal address for endpoint. (Defaults to '127.0.0.1') -# Setting this parameter overrides internal_url parameter. -# -# [*admin_protocol*] -# (optional) DEPRECATED: Use admin_url instead. -# Protocol for admin endpoint. (Defaults to 'http') -# Setting this parameter overrides admin_url parameter. -# -# [*admin_address*] -# (optional) DEPRECATED: Use admin_url instead. -# Admin address for endpoint. (Defaults to '127.0.0.1') -# Setting this parameter overrides admin_url parameter. -# === Deprecation notes -# -# If any value is provided for public_protocol, public_address or port parameters, -# public_url will be completely ignored. The same applies for internal and admin parameters. -# class mistral::keystone::auth( $password, $email = 'mistral@localhost', @@ -121,7 +71,7 @@ class mistral::keystone::auth( $configure_service = true, $configure_user = true, $configure_user_role = true, - $service_description = 'Openstack workflow Service', + $service_description = 'OpenStack Workflow Service', ) { validate_string($password) diff --git a/manifests/logging.pp b/manifests/logging.pp index c454a8d..0bec8ea 100644 --- a/manifests/logging.pp +++ b/manifests/logging.pp @@ -1,211 +1,149 @@ -# Class mistral::logging +# == Class: mistral::logging # -# mistral extended logging configuration +# Mistral logging configuration # -# == parameters +# === Parameters +# +# [*verbose*] +# (Optional) Should the daemons log verbose messages +# Defaults to $::os_service_default +# +# [*debug*] +# (Optional) Should the daemons log debug messages +# Defaults to $::os_service_default +# +# [*use_syslog*] +# (Optional) Use syslog for logging. +# Defaults to $::os_service_default +# +# [*use_stderr*] +# (optional) Use stderr for logging +# Defaults to $::os_service_default +# +# [*log_facility*] +# (Optional) Syslog facility to receive log lines. +# Defaults to $::os_service_default +# +# [*log_dir*] +# (optional) Directory where logs should be stored. +# If set to boolean false or $::os_service_default, it will not log to any +# directory. +# Defaults to '/var/log/mistral' # # [*logging_context_format_string*] -# (optional) Format string to use for log messages with context. -# Defaults to undef. +# (Optional) Format string to use for log messages with context. +# Defaults to $::os_service_default # Example: '%(asctime)s.%(msecs)03d %(process)d %(levelname)s %(name)s\ # [%(request_id)s %(user_identity)s] %(instance)s%(message)s' # # [*logging_default_format_string*] -# (optional) Format string to use for log messages without context. -# Defaults to undef. +# (Optional) Format string to use for log messages without context. +# Defaults to $::os_service_default # Example: '%(asctime)s.%(msecs)03d %(process)d %(levelname)s %(name)s\ # [-] %(instance)s%(message)s' # # [*logging_debug_format_suffix*] -# (optional) Formatted data to append to log format when level is DEBUG. -# Defaults to undef. +# (Optional) Formatted data to append to log format when level is DEBUG. +# Defaults to $::os_service_default # Example: '%(funcName)s %(pathname)s:%(lineno)d' # # [*logging_exception_prefix*] -# (optional) Prefix each line of exception output with this format. -# Defaults to undef. +# (Optional) Prefix each line of exception output with this format. +# Defaults to $::os_service_default # Example: '%(asctime)s.%(msecs)03d %(process)d TRACE %(name)s %(instance)s' # # [*log_config_append*] # The name of an additional logging configuration file. -# Defaults to undef. +# Defaults to $::os_service_default # See https://docs.python.org/2/howto/logging.html # # [*default_log_levels*] # (optional) Hash of logger (keys) and level (values) pairs. -# Defaults to undef. +# Defaults to $::os_service_default. # Example: -# { 'amqp' => 'WARN', 'amqplib' => 'WARN', 'boto' => 'WARN', -# 'qpid' => 'WARN', 'sqlalchemy' => 'WARN', 'suds' => 'INFO', -# 'oslo.messaging' => 'INFO', 'iso8601' => 'WARN', -# 'requests.packages.urllib3.connectionpool' => 'WARN', -# 'urllib3.connectionpool' => 'WARN', -# 'websocket' => 'WARN', 'mistralmiddleware' => 'WARN', -# 'routes.middleware' => 'WARN', stevedore => 'WARN' } +# { 'amqp' => 'WARN', 'amqplib' => 'WARN', 'boto' => 'WARN', +# 'qpid' => 'WARN', 'sqlalchemy' => 'WARN', 'suds' => 'INFO', +# 'iso8601' => 'WARN', +# 'requests.packages.urllib3.connectionpool' => 'WARN' } # # [*publish_errors*] # (optional) Publish error events (boolean value). -# Defaults to undef (false if unconfigured). +# Defaults to $::os_service_default # # [*fatal_deprecations*] # (optional) Make deprecations fatal (boolean value) -# Defaults to undef (false if unconfigured). +# Defaults to $::os_service_default # # [*instance_format*] # (optional) If an instance is passed with the log message, format it # like this (string value). -# Defaults to undef. +# Defaults to $::os_service_default # Example: '[instance: %(uuid)s] ' # # [*instance_uuid_format*] # (optional) If an instance UUID is passed with the log message, format # it like this (string value). -# Defaults to undef. +# Defaults to $::os_service_default # Example: instance_uuid_format='[instance: %(uuid)s] ' - +# # [*log_date_format*] # (optional) Format string for %%(asctime)s in log records. -# Defaults to undef. +# Defaults to $::os_service_default # Example: 'Y-%m-%d %H:%M:%S' - +# class mistral::logging( - $logging_context_format_string = undef, - $logging_default_format_string = undef, - $logging_debug_format_suffix = undef, - $logging_exception_prefix = undef, - $log_config_append = undef, - $default_log_levels = undef, - $publish_errors = undef, - $fatal_deprecations = undef, - $instance_format = undef, - $instance_uuid_format = undef, - $log_date_format = undef, + $use_syslog = $::os_service_default, + $use_stderr = $::os_service_default, + $log_facility = $::os_service_default, + $log_dir = '/var/log/mistral', + $verbose = $::os_service_default, + $debug = $::os_service_default, + $logging_context_format_string = $::os_service_default, + $logging_default_format_string = $::os_service_default, + $logging_debug_format_suffix = $::os_service_default, + $logging_exception_prefix = $::os_service_default, + $log_config_append = $::os_service_default, + $default_log_levels = $::os_service_default, + $publish_errors = $::os_service_default, + $fatal_deprecations = $::os_service_default, + $instance_format = $::os_service_default, + $instance_uuid_format = $::os_service_default, + $log_date_format = $::os_service_default, ) { - if $logging_context_format_string { - mistral_config { - 'DEFAULT/logging_context_format_string' : - value => $logging_context_format_string; - } - } - else { - mistral_config { - 'DEFAULT/logging_context_format_string' : ensure => absent; - } - } + # NOTE(spredzy): In order to keep backward compatibility we rely on the pick function + # to use mistral:: if mistral::logging:: isn't specified. + $use_syslog_real = pick($::mistral::use_syslog,$use_syslog) + $use_stderr_real = pick($::mistral::use_stderr,$use_stderr) + $log_facility_real = pick($::mistral::log_facility,$log_facility) + $log_dir_real = pick($::mistral::log_dir,$log_dir) + $verbose_real = pick($::mistral::verbose,$verbose) + $debug_real = pick($::mistral::debug,$debug) - if $logging_default_format_string { - mistral_config { - 'DEFAULT/logging_default_format_string' : - value => $logging_default_format_string; - } - } - else { - mistral_config { - 'DEFAULT/logging_default_format_string' : ensure => absent; - } - } - - if $logging_debug_format_suffix { - mistral_config { - 'DEFAULT/logging_debug_format_suffix' : - value => $logging_debug_format_suffix; - } - } - else { - mistral_config { - 'DEFAULT/logging_debug_format_suffix' : ensure => absent; - } - } - - if $logging_exception_prefix { - mistral_config { - 'DEFAULT/logging_exception_prefix' : value => $logging_exception_prefix; - } - } - else { - mistral_config { - 'DEFAULT/logging_exception_prefix' : ensure => absent; - } - } - - if $log_config_append { - mistral_config { - 'DEFAULT/log_config_append' : value => $log_config_append; - } - } - else { - mistral_config { - 'DEFAULT/log_config_append' : ensure => absent; - } - } - - if $default_log_levels { - mistral_config { - 'DEFAULT/default_log_levels' : - value => join(sort(join_keys_to_values($default_log_levels, '=')), ','); - } - } - else { - mistral_config { - 'DEFAULT/default_log_levels' : ensure => absent; - } - } - - if $publish_errors { - mistral_config { - 'DEFAULT/publish_errors' : value => $publish_errors; - } - } - else { - mistral_config { - 'DEFAULT/publish_errors' : ensure => absent; - } - } - - if $fatal_deprecations { - mistral_config { - 'DEFAULT/fatal_deprecations' : value => $fatal_deprecations; - } - } - else { - mistral_config { - 'DEFAULT/fatal_deprecations' : ensure => absent; - } - } - - if $instance_format { - mistral_config { - 'DEFAULT/instance_format' : value => $instance_format; - } - } - else { - mistral_config { - 'DEFAULT/instance_format' : ensure => absent; - } - } - - if $instance_uuid_format { - mistral_config { - 'DEFAULT/instance_uuid_format' : value => $instance_uuid_format; - } - } - else { - mistral_config { - 'DEFAULT/instance_uuid_format' : ensure => absent; - } - } - - if $log_date_format { - mistral_config { - 'DEFAULT/log_date_format' : value => $log_date_format; - } - } - else { - mistral_config { - 'DEFAULT/log_date_format' : ensure => absent; - } - } + 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; + } } diff --git a/manifests/params.pp b/manifests/params.pp index bbe6481..a37439b 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -4,34 +4,30 @@ # class mistral::params { - $mistral_conf_dir = '/etc/mistral' - $mistral_conf = "${mistral_conf_dir}/mistral.conf" - $mistral_log_dir='/var/log/mistral' - $service_log_file="${mistral_log_dir}/mistral-server.log" - $client_package = 'python-mistralclient' - $log_dir ='/var/log/mistral' - $db_sync_command = "mistral-db-manage --config-file=${mistral_conf} upgrade head" - $db_populate_command = "mistral-db-manage --config-file=${mistral_conf} populate" - $update_service_command = '/usr/bin/systemctl daemon-reload' + $client_package = 'python-mistralclient' + $db_sync_command = 'mistral-db-manage --config-file=/etc/mistral/mistral.conf upgrade head' + $db_populate_command = 'mistral-db-manage --config-file=/etc/mistral/mistral.conf populate' case $::osfamily { 'RedHat': { - $common_package_name = 'openstack-mistral-common' - $api_package_name = 'openstack-mistral-api' - $api_service_name = 'openstack-mistral-api' - $engine_package_name = 'openstack-mistral-engine' - $engine_service_name = 'openstack-mistral-engine' + $common_package_name = 'openstack-mistral-common' + $api_package_name = 'openstack-mistral-api' + $api_service_name = 'openstack-mistral-api' + $engine_package_name = 'openstack-mistral-engine' + $engine_service_name = 'openstack-mistral-engine' $executor_package_name = 'openstack-mistral-executor' $executor_service_name = 'openstack-mistral-executor' + $pymysql_package_name = undef } 'Debian': { - $common_package_name = 'mistral' - $api_package_name = 'mistral-api' - $api_service_name = 'mistral-api' - $engine_package_name = 'mistral-engine' - $engine_service_name = 'mistral-engine' - $executor_package_name = 'mistral-executor' - $executor_service_name = 'mistral-executor' + $common_package_name = 'mistral' + $api_package_name = 'mistral-api' + $api_service_name = 'mistral-api' + $engine_package_name = 'mistral-engine' + $engine_service_name = 'mistral-engine' + $executor_package_name = 'mistral-executor' + $executor_service_name = 'mistral-executor' + $pymysql_package_name = 'python-pymysql' } default: { fail("Unsupported osfamily: ${::osfamily} operatingsystem: \ diff --git a/manifests/services.pp b/manifests/services.pp deleted file mode 100644 index 47ae1b8..0000000 --- a/manifests/services.pp +++ /dev/null @@ -1,100 +0,0 @@ -# == Class: mistral::services -# -# Start mistral services -# -# === Parameters -# -# [*is_engine*] -# start mistral engine? Defaults to 'true'. -# -# [*is_api*] -# start mistral api? Defaults to 'true'. -# -# [*is_executor*] -# start mistral executor? Defaults to 'true'. -# -# [*conf_file*] -# path to the conf file. Defaults '$::mistral::params::mistral_conf' -# -# [*log_file*] -# path to the service log file. Defaults '$::mistral::params::service_log_file' -# -class mistral::services( - $is_engine = true, - $is_api = true, - $is_executor = true, - $conf_file = $::mistral::params::mistral_conf, - $log_file = $::mistral::params::service_log_file -) inherits ::mistral::params { - if $is_engine { - notify { 'Start mistral-engine': } - - file { 'openstack-mistral-engine': - path => '/usr/lib/systemd/system/openstack-mistral-engine - .service', - owner => 'mistral', - group => 'mistral', - mode => '0644', - content => template('mistral/openstack-mistral-engine.service.erb'), - require => Package['mistral'] - } - - service { 'openstack-mistral-engine': - ensure => running, - enable => true, - require => File['openstack-mistral-engine'], - subscribe => File[$::mistral::params::mistral_conf] - } - } - - if $is_api { - notify { 'Start mistral-api': } - - file { 'openstack-mistral-api': - path => '/usr/lib/systemd/system/openstack-mistral-api.service', - owner => 'mistral', - group => 'mistral', - mode => '0644', - content => template('mistral/openstack-mistral-api.service.erb'), - require => Package['mistral'] - } - - service { 'openstack-mistral-api': - ensure => running, - enable => true, - require => File['openstack-mistral-api'], - subscribe => File[$::mistral::params::mistral_conf] - } - } - - if $is_executor { - notify { 'Start mistral-executor': } - - file { 'openstack-mistral-executor': - path => '/usr/lib/systemd/system/openstack-mistral-executor - .service', - owner => 'mistral', - group => 'mistral', - mode => '0644', - content => template('mistral/openstack-mistral-executor.service.erb'), - require => Package['mistral'] - } - - service { 'openstack-mistral-executor': - ensure => running, - enable => true, - require => File['openstack-mistral-executor'], - subscribe => File[$::mistral::params::mistral_conf] - } - } - - exec { 'update-service': - command => $::mistral::params::update_service_command, - path => '/usr/bin', - user => 'root', - logoutput => on_failure, - subscribe => [File['openstack-mistral-executor'], - File['openstack-mistral-api'], File['openstack-mistral-engine']] - } - -} diff --git a/spec/classes/mistral_api_spec.rb b/spec/classes/mistral_api_spec.rb index 623f152..6d08c0a 100644 --- a/spec/classes/mistral_api_spec.rb +++ b/spec/classes/mistral_api_spec.rb @@ -14,8 +14,8 @@ describe 'mistral::api' do context 'config params' do - it { is_expected.to contain_class('mistral') } it { is_expected.to contain_class('mistral::params') } + it { is_expected.to contain_class('mistral::policy') } it { is_expected.to contain_mistral_config('api/host').with_value( params[:bind_host] ) } it { is_expected.to contain_mistral_config('api/port').with_value( params[:bind_port] ) } diff --git a/spec/classes/mistral_db_spec.rb b/spec/classes/mistral_db_spec.rb new file mode 100644 index 0000000..1169e63 --- /dev/null +++ b/spec/classes/mistral_db_spec.rb @@ -0,0 +1,115 @@ +require 'spec_helper' + +describe 'mistral::db' do + + shared_examples 'mistral::db' do + + context 'with default parameters' do + + it { is_expected.to contain_mistral_config('database/connection').with_value('sqlite:////var/lib/mistral/mistral.sqlite').with_secret(true) } + it { is_expected.to contain_mistral_config('database/idle_timeout').with_value('') } + it { is_expected.to contain_mistral_config('database/min_pool_size').with_value('') } + it { is_expected.to contain_mistral_config('database/max_retries').with_value('') } + it { is_expected.to contain_mistral_config('database/retry_interval').with_value('') } + + end + + context 'with specific parameters' do + let :params do + { :database_connection => 'mysql+pymysql://mistral:mistral@localhost/mistral', + :database_idle_timeout => '3601', + :database_min_pool_size => '2', + :database_max_retries => '11', + :database_retry_interval => '11', } + end + + it { is_expected.to contain_mistral_config('database/connection').with_value('mysql+pymysql://mistral:mistral@localhost/mistral').with_secret(true) } + it { is_expected.to contain_mistral_config('database/idle_timeout').with_value('3601') } + it { is_expected.to contain_mistral_config('database/min_pool_size').with_value('2') } + it { is_expected.to contain_mistral_config('database/max_retries').with_value('11') } + it { is_expected.to contain_mistral_config('database/retry_interval').with_value('11') } + end + + context 'with postgresql backend' do + let :params do + { :database_connection => 'postgresql://mistral:mistral@localhost/mistral', } + end + + it 'install the proper backend package' do + is_expected.to contain_package('python-psycopg2').with(:ensure => 'present') + end + + end + + context 'with MySQL-python library as backend package' do + let :params do + { :database_connection => 'mysql://mistral:mistral@localhost/mistral', } + end + + it { is_expected.to contain_package('python-mysqldb').with(:ensure => 'present') } + end + + context 'with incorrect database_connection string' do + let :params do + { :database_connection => 'redis://mistral:mistral@localhost/mistral', } + end + + it_raises 'a Puppet::Error', /validate_re/ + end + + context 'with incorrect pymysql database_connection string' do + let :params do + { :database_connection => 'foo+pymysql://mistral:mistral@localhost/mistral', } + end + + it_raises 'a Puppet::Error', /validate_re/ + end + + end + + context 'on Debian platforms' do + let :facts do + OSDefaults.get_facts({ + :osfamily => 'Debian', + :operatingsystem => 'Debian', + :operatingsystemrelease => 'jessie' + }) + end + + it_configures 'mistral::db' + + context 'using pymysql driver' do + let :params do + { :database_connection => 'mysql+pymysql://mistral:mistral@localhost/mistral', } + end + + it 'install the proper backend package' do + is_expected.to contain_package('mistral-backend-package').with( + :ensure => 'present', + :name => 'python-pymysql', + :tag => 'openstack' + ) + end + end + end + + context 'on Redhat platforms' do + let :facts do + OSDefaults.get_facts({ + :osfamily => 'RedHat', + :operatingsystemrelease => '7.1', + }) + end + + it_configures 'mistral::db' + + context 'using pymysql driver' do + let :params do + { :database_connection => 'mysql+pymysql://mistral:mistral@localhost/mistral', } + end + + it { is_expected.not_to contain_package('mistral-backend-package') } + end + end + +end diff --git a/spec/classes/mistral_engine_spec.rb b/spec/classes/mistral_engine_spec.rb index 9cbf9a6..75adf71 100644 --- a/spec/classes/mistral_engine_spec.rb +++ b/spec/classes/mistral_engine_spec.rb @@ -15,7 +15,6 @@ describe 'mistral::engine' do context 'config params' do - it { is_expected.to contain_class('mistral') } it { is_expected.to contain_class('mistral::params') } it { is_expected.to contain_mistral_config('engine/host').with_value( params[:host] ) } diff --git a/spec/classes/mistral_executor_spec.rb b/spec/classes/mistral_executor_spec.rb index c785ef2..0e587f0 100644 --- a/spec/classes/mistral_executor_spec.rb +++ b/spec/classes/mistral_executor_spec.rb @@ -16,7 +16,6 @@ describe 'mistral::executor' do context 'config params' do - it { is_expected.to contain_class('mistral') } it { is_expected.to contain_class('mistral::params') } it { is_expected.to contain_mistral_config('executor/host').with_value( params[:host] ) } diff --git a/spec/classes/mistral_init_spec.rb b/spec/classes/mistral_init_spec.rb index a45c592..fd57465 100644 --- a/spec/classes/mistral_init_spec.rb +++ b/spec/classes/mistral_init_spec.rb @@ -1,58 +1,211 @@ require 'spec_helper' - describe 'mistral' do - - let :params do + let :req_params do { - :auth_uri => 'http://127.0.0.1:5000/', - :identity_uri => 'http://127.0.0.1:35357/', + :rabbit_password => 'guest', + :database_connection => 'mysql://user:password@host/database', + :keystone_password => 'foo', } end - shared_examples_for 'mistral' do + let :facts do + OSDefaults.get_facts({ + :osfamily => 'Debian', + :operatingsystem => 'Debian', + :operatingsystemrelease => 'jessie', + }) + end + describe 'with only required params' do + let :params do + req_params + end + + it { is_expected.to contain_class('mistral::logging') } it { is_expected.to contain_class('mistral::params') } + it { is_expected.to contain_class('mysql::bindings::python') } - it 'configures auth_uri' do - is_expected.to contain_mistral_config('keystone_authtoken/auth_uri').with_value( params[:auth_uri] ) - end - - it 'configures identity_uri' do - is_expected.to contain_mistral_config('keystone_authtoken/identity_uri').with_value( params[:identity_uri] ) - end - - it 'installs mistral package' do - is_expected.to contain_package('mistral-common').with( - :ensure => 'present', - :name => platform_params[:common_package_name], - :tag => ['openstack', 'mistral-package'], + it 'should contain default config' do + is_expected.to contain_mistral_config('DEFAULT/rpc_backend').with(:value => 'rabbit') + 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/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 => '') + is_expected.to contain_mistral_config('keystone_authtoken/auth_uri').with( + :value => 'http://localhost:5000/' + ) + is_expected.to contain_mistral_config('keystone_authtoken/identity_uri').with( + :value => 'http://localhost:35357/' + ) + is_expected.to contain_mistral_config('keystone_authtoken/admin_tenant_name').with( + :value => 'services' + ) + is_expected.to contain_mistral_config('keystone_authtoken/admin_user').with( + :value => 'mistral' + ) + is_expected.to contain_mistral_config('keystone_authtoken/admin_password').with( + :value => 'foo' ) end end - - context 'on Debian platforms' do - let :facts do - { :osfamily => 'Debian' } + describe 'with modified rabbit_hosts' do + let :params do + req_params.merge({'rabbit_hosts' => ['rabbit1:5672', 'rabbit2:5672']}) end - let :platform_params do - { :common_package_name => 'mistral' } + 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_hosts').with(:value => 'rabbit1:5672,rabbit2:5672') + is_expected.to contain_mistral_config('oslo_messaging_rabbit/rabbit_ha_queues').with(:value => true) end - - it_configures 'mistral' end - context 'on RedHat platforms' do - let :facts do - { :osfamily => 'RedHat' } + describe 'with a single rabbit_hosts entry' do + let :params do + req_params.merge({'rabbit_hosts' => ['rabbit1:5672']}) end - let :platform_params do - { :common_package_name => 'openstack-mistral-common' } + 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_hosts').with(:value => 'rabbit1:5672') + is_expected.to contain_mistral_config('oslo_messaging_rabbit/rabbit_ha_queues').with(:value => false) + end + end + + describe 'a single rabbit_host with enable ha queues' do + let :params do + req_params.merge({'rabbit_ha_queues' => true}) end - it_configures 'mistral' + it 'should contain rabbit_ha_queues' do + is_expected.to contain_mistral_config('oslo_messaging_rabbit/rabbit_ha_queues').with(:value => true) + end + end + + describe 'with rabbitmq heartbeats' do + let :params do + req_params.merge({'rabbit_heartbeat_timeout_threshold' => '60', 'rabbit_heartbeat_rate' => '10'}) + end + + it 'should contain heartbeat config' do + is_expected.to contain_mistral_config('oslo_messaging_rabbit/heartbeat_timeout_threshold').with_value('60') + is_expected.to contain_mistral_config('oslo_messaging_rabbit/heartbeat_rate').with_value('10') + end + end + + describe 'with SSL enabled with kombu' do + let :params do + req_params.merge!({ + :rabbit_use_ssl => true, + :kombu_ssl_ca_certs => '/path/to/ssl/ca/certs', + :kombu_ssl_certfile => '/path/to/ssl/cert/file', + :kombu_ssl_keyfile => '/path/to/ssl/keyfile', + :kombu_ssl_version => 'TLSv1' + }) + end + + it do + is_expected.to contain_mistral_config('oslo_messaging_rabbit/rabbit_use_ssl').with_value('true') + is_expected.to contain_mistral_config('oslo_messaging_rabbit/kombu_ssl_ca_certs').with_value('/path/to/ssl/ca/certs') + is_expected.to contain_mistral_config('oslo_messaging_rabbit/kombu_ssl_certfile').with_value('/path/to/ssl/cert/file') + is_expected.to contain_mistral_config('oslo_messaging_rabbit/kombu_ssl_keyfile').with_value('/path/to/ssl/keyfile') + is_expected.to contain_mistral_config('oslo_messaging_rabbit/kombu_ssl_version').with_value('TLSv1') + end + end + + describe 'with SSL enabled without kombu' do + let :params do + req_params.merge!({ + :rabbit_use_ssl => true, + }) + end + + it do + is_expected.to contain_mistral_config('oslo_messaging_rabbit/rabbit_use_ssl').with_value('true') + is_expected.to contain_mistral_config('oslo_messaging_rabbit/kombu_ssl_ca_certs').with_value('') + is_expected.to contain_mistral_config('oslo_messaging_rabbit/kombu_ssl_certfile').with_value('') + is_expected.to contain_mistral_config('oslo_messaging_rabbit/kombu_ssl_keyfile').with_value('') + is_expected.to contain_mistral_config('oslo_messaging_rabbit/kombu_ssl_version').with_value('') + end + end + + describe 'with SSL disabled' 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 + + it do + is_expected.to contain_mistral_config('oslo_messaging_rabbit/rabbit_use_ssl').with_value('false') + is_expected.to contain_mistral_config('oslo_messaging_rabbit/kombu_ssl_ca_certs').with_value('') + is_expected.to contain_mistral_config('oslo_messaging_rabbit/kombu_ssl_certfile').with_value('') + is_expected.to contain_mistral_config('oslo_messaging_rabbit/kombu_ssl_keyfile').with_value('') + is_expected.to contain_mistral_config('oslo_messaging_rabbit/kombu_ssl_version').with_value('') + end + end + + describe 'with amqp_durable_queues disabled' do + let :params do + req_params + end + + it { is_expected.to contain_mistral_config('oslo_messaging_rabbit/amqp_durable_queues').with_value(false) } + end + + describe 'with amqp_durable_queues enabled' do + let :params do + req_params.merge({ + :amqp_durable_queues => true, + }) + end + + it { is_expected.to contain_mistral_config('oslo_messaging_rabbit/amqp_durable_queues').with_value(true) } + end + + describe 'with postgresql' do + let :params do + req_params.merge({ + :database_connection => 'postgresql://user:drowssap@host/database', + :rabbit_password => 'guest', + }) + end + + it { is_expected.to_not contain_class('mysql::python') } + it { is_expected.to_not contain_class('mysql::bindings') } + it { is_expected.to_not contain_class('mysql::bindings::python') } + end + + describe 'with coordination' do + let :params do + req_params.merge({ + :coordination_backend_url => 'redis://127.0.0.1', + :coordination_heartbeat_interval => '10.0', + }) + end + + it 'should contain coordination config' do + is_expected.to contain_mistral_config('coordination/backend_url').with(:value => 'redis://127.0.0.1') + is_expected.to contain_mistral_config('coordination/heartbeat_interval').with(:value => '10.0') + end end end diff --git a/spec/classes/mistral_keystone_auth_spec.rb b/spec/classes/mistral_keystone_auth_spec.rb index 7154e28..7a5763f 100644 --- a/spec/classes/mistral_keystone_auth_spec.rb +++ b/spec/classes/mistral_keystone_auth_spec.rb @@ -28,7 +28,7 @@ describe 'mistral::keystone::auth' do it { is_expected.to contain_keystone_service('mistral::workflowv2').with( :ensure => 'present', - :description => 'Openstack workflow Service' + :description => 'OpenStack Workflow Service' ) } it { is_expected.to contain_keystone_endpoint('RegionOne/mistral::workflowv2').with( @@ -77,7 +77,7 @@ describe 'mistral::keystone::auth' do it { is_expected.to contain_keystone_user_role('mistral@services') } it { is_expected.to contain_keystone_service('mistral::workflowv2').with( :ensure => 'present', - :description => 'Openstack workflow Service' + :description => 'OpenStack Workflow Service' ) } end @@ -96,7 +96,7 @@ describe 'mistral::keystone::auth' do it { is_expected.not_to contain_keystone_user_role('mistral@services') } it { is_expected.to contain_keystone_service('mistral::workflowv2').with( :ensure => 'present', - :description => 'Openstack workflow Service' + :description => 'OpenStack Workflow Service' ) } end diff --git a/spec/classes/mistral_logging_spec.rb b/spec/classes/mistral_logging_spec.rb index de04985..d707d53 100644 --- a/spec/classes/mistral_logging_spec.rb +++ b/spec/classes/mistral_logging_spec.rb @@ -24,20 +24,53 @@ describe 'mistral::logging' do :instance_format => '[instance: %(uuid)s] ', :instance_uuid_format => '[instance: %(uuid)s] ', :log_date_format => '%Y-%m-%d %H:%M:%S', + :use_syslog => false, + :use_stderr => false, + :log_facility => 'LOG_USER', + :log_dir => '/var/log', + :verbose => true, + :debug => true, } end shared_examples_for 'mistral-logging' do + context 'with basic logging options and default settings' do + it_configures 'basic default logging settings' + end + + context 'with basic logging options and non-default settings' do + before { params.merge!( log_params ) } + it_configures 'basic non-default logging settings' + end + context 'with extended logging options' do before { params.merge!( log_params ) } it_configures 'logging params set' end - context 'without extended logging options' do - it_configures 'logging params unset' - end + end + shared_examples 'basic default logging settings' do + it 'configures mistral logging settins with default values' do + is_expected.to contain_mistral_config('DEFAULT/use_syslog').with(:value => '') + is_expected.to contain_mistral_config('DEFAULT/use_stderr').with(:value => '') + is_expected.to contain_mistral_config('DEFAULT/syslog_log_facility').with(:value => '') + is_expected.to contain_mistral_config('DEFAULT/log_dir').with(:value => '/var/log/mistral') + is_expected.to contain_mistral_config('DEFAULT/verbose').with(:value => '') + is_expected.to contain_mistral_config('DEFAULT/debug').with(:value => '') + end + end + + shared_examples 'basic non-default logging settings' do + it 'configures mistral logging settins with non-default values' do + is_expected.to contain_mistral_config('DEFAULT/use_syslog').with(:value => 'false') + is_expected.to contain_mistral_config('DEFAULT/use_stderr').with(:value => 'false') + is_expected.to contain_mistral_config('DEFAULT/syslog_log_facility').with(:value => 'LOG_USER') + is_expected.to contain_mistral_config('DEFAULT/log_dir').with(:value => '/var/log') + is_expected.to contain_mistral_config('DEFAULT/verbose').with(:value => 'true') + is_expected.to contain_mistral_config('DEFAULT/debug').with(:value => 'true') + end end shared_examples_for 'logging params set' do @@ -76,32 +109,16 @@ describe 'mistral::logging' do end end + on_supported_os({ + :supported_os => OSDefaults.get_supported_os + }).each do |os,facts| + context "on #{os}" do + let (:facts) do + facts.merge(OSDefaults.get_facts({:processorcount => 8})) + end - shared_examples_for 'logging params unset' do - [ :logging_context_format_string, :logging_default_format_string, - :logging_debug_format_suffix, :logging_exception_prefix, - :log_config_append, :publish_errors, - :default_log_levels, :fatal_deprecations, - :instance_format, :instance_uuid_format, - :log_date_format, ].each { |param| - it { is_expected.to contain_mistral_config("DEFAULT/#{param}").with_ensure('absent') } - } - end - - context 'on Debian platforms' do - let :facts do - { :osfamily => 'Debian' } + it_configures 'mistral-logging' end - - it_configures 'mistral-logging' - end - - context 'on RedHat platforms' do - let :facts do - { :osfamily => 'RedHat' } - end - - it_configures 'mistral-logging' end end