diff --git a/.gitignore b/.gitignore index 12b6e4d..15c55ef 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,11 @@ +pkg/ Gemfile.lock -spec/fixtures/modules/* -spec/fixtures/manifests/site.pp -*.swp -pkg vendor/ +spec/fixtures/ +.vagrant/ +.bundle/ +coverage/ +.idea/ +*.swp +*.iml openstack/ diff --git a/.gitreview b/.gitreview new file mode 100644 index 0000000..4e234b1 --- /dev/null +++ b/.gitreview @@ -0,0 +1,4 @@ +[gerrit] +host=review.openstack.org +port=29418 +project=openstack/puppet-congress.git diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..d67af2f --- /dev/null +++ b/Gemfile @@ -0,0 +1,21 @@ +source ENV['GEM_SOURCE'] || "https://rubygems.org" + +group :development, :test, :system_tests do + gem 'puppet-openstack_spec_helper', + :require => 'false', + :git => 'https://git.openstack.org/openstack/puppet-openstack_spec_helper' +end + +if facterversion = ENV['FACTER_GEM_VERSION'] + gem 'facter', facterversion, :require => false +else + gem 'facter', :require => false +end + +if puppetversion = ENV['PUPPET_GEM_VERSION'] + gem 'puppet', puppetversion, :require => false +else + gem 'puppet', :require => false +end + +# vim:ft=ruby diff --git a/LICENSE b/LICENSE index 8c06f5e..13f6ec4 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,4 @@ -Copyright 2015 OpenStack Foundation +Copyright 2016 OpenStack Foundation Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/README.md b/README.md index 1851ad3..0a6d9ac 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ congress Overview -------- -The congress module is a part of [OpenStack](https://github.com/openstack), an effort by the Openstack infrastructure team to provide continuous integration testing and code review for Openstack and Openstack community projects not part of the core software. The module its self is used to flexibly configure and manage the FIXME service for Openstack. +The congress module is a part of [OpenStack](https://www.openstack.org), an effort by the OpenStack infrastructure team to provide continuous integration testing and code review for OpenStack and OpenStack community projects not part of the core software. The module its self is used to flexibly configure and manage the policy service for OpenStack. Module Description ------------------ @@ -26,7 +26,7 @@ Setup **What the congress module affects** -* [congress](https://wiki.openstack.org/wiki/congress), the FIXME service for Openstack. +* [Congress](https://wiki.openstack.org/wiki/Congress), the policy service for OpenStack. ### Installing congress @@ -35,7 +35,7 @@ Setup ### Beginning with congress -To utilize the congress module's functionality you will need to declare multiple resources. The following is a modified excerpt from the [openstack module](https://github.com/stackfoge/puppet-openstack). This is not an exhaustive list of all the components needed, we recommend you consult and understand the [openstack module](https://github.com/stackforge/puppet-openstack) and the [core openstack](http://docs.openstack.org) documentation. +To utilize the congress module's functionality you will need to declare multiple resources. Implementation -------------- @@ -63,14 +63,14 @@ bundle exec rake acceptance For more information on writing and running beaker-rspec tests visit the documentation: -* https://github.com/puppetlabs/beaker/wiki/How-to-Write-a-Beaker-Test-for-a-Module +* https://github.com/puppetlabs/beaker-rspec/blob/master/README.md Development ----------- Developer documentation for the entire puppet-openstack project. -* https://wiki.openstack.org/wiki/Puppet +* http://docs.openstack.org/developer/puppet-openstack-guide/ Contributors ------------ diff --git a/Rakefile b/Rakefile new file mode 100644 index 0000000..168d108 --- /dev/null +++ b/Rakefile @@ -0,0 +1 @@ +require 'puppet-openstack_spec_helper/rake_tasks' diff --git a/lib/puppet/provider/congress_config/ini_setting.rb b/lib/puppet/provider/congress_config/ini_setting.rb index 3d324b6..9aecd76 100644 --- a/lib/puppet/provider/congress_config/ini_setting.rb +++ b/lib/puppet/provider/congress_config/ini_setting.rb @@ -1,27 +1,10 @@ Puppet::Type.type(:congress_config).provide( :ini_setting, - :parent => Puppet::Type.type(:ini_setting).provider(:ruby) + :parent => Puppet::Type.type(:openstack_config).provider(:ini_setting) ) do - def section - resource[:name].split('/', 2).first - end - - def setting - resource[:name].split('/', 2).last - end - - def separator - '=' - end - def self.file_path '/etc/congress/congress.conf' end - # added for backwards compatibility with older versions of inifile - def file_path - self.class.file_path - end - end diff --git a/lib/puppet/type/congress_config.rb b/lib/puppet/type/congress_config.rb index 3b76fc6..86a3c67 100644 --- a/lib/puppet/type/congress_config.rb +++ b/lib/puppet/type/congress_config.rb @@ -3,7 +3,7 @@ Puppet::Type.newtype(:congress_config) do ensurable newparam(:name, :namevar => true) do - desc 'Section/setting name to manage from /etc/congress/congress.conf' + desc 'Section/setting name to manage from congress.conf' newvalues(/\S+\/\S+/) end @@ -14,6 +14,7 @@ Puppet::Type.newtype(:congress_config) do value.capitalize! if value =~ /^(true|false)$/i value end + newvalues(/^[\S ]*$/) def is_to_s( currentvalue ) if resource.secret? @@ -39,4 +40,14 @@ Puppet::Type.newtype(:congress_config) do defaultto false end + + newparam(:ensure_absent_val) do + desc 'A value that is specified as the value property will behave as if ensure => absent was specified' + defaultto('') + end + + autorequire(:package) do + 'congress' + end + end diff --git a/manifests/client.pp b/manifests/client.pp deleted file mode 100644 index bb016e4..0000000 --- a/manifests/client.pp +++ /dev/null @@ -1,27 +0,0 @@ -# == Class: congress::client -# -# Installs congress client. -# -# === Parameters -# -# [*ensure*] -# (optional) Ensure state of the package. -# Defaults to 'present'. -# -class congress::client ( - $ensure = 'present' -) { - - package { 'python-congressclient': - ensure => $ensure, - tag => 'openstack', - } - - if $ensure == 'present' { - include '::openstacklib::openstackclient' - } else { - class { '::openstacklib::openstackclient': - package_ensure => $ensure, - } - } -} diff --git a/manifests/db.pp b/manifests/db.pp index 33dccc4..53bd0a8 100644 --- a/manifests/db.pp +++ b/manifests/db.pp @@ -1,97 +1,58 @@ # == Class: congress::db # -# Configure the congress database connection +# Configure the congress database # # === Parameters # # [*database_connection*] -# Url used to connect to database. -# (Optional) Defaults to 'sqlite:////var/lib/congress/congress.sqlite'. +# (Optional) Url used to connect to database. +# Defaults to "sqlite:////var/lib/congress/congress.sqlite". # # [*database_idle_timeout*] -# Timeout when db connections should be reaped. -# (Optional) Defaults to 3600. +# (Optional) Timeout when db connections should be reaped. +# Defaults to $::os_service_default # # [*database_max_retries*] -# Maximum number of database connection retries during startup. +# (Optional) Maximum number of database connection retries during startup. # Setting -1 implies an infinite retry count. -# (Optional) Defaults to 10. +# Defaults to $::os_service_default # # [*database_retry_interval*] -# Interval between retries of opening a database connection. -# (Optional) Defaults to 10. +# (Optional) Interval between retries of opening a database connection. +# Defaults to $::os_service_default # # [*database_min_pool_size*] -# Minimum number of SQL connections to keep open in a pool. -# (Optional) Defaults to 1. +# (Optional) Minimum number of SQL connections to keep open in a pool. +# Defaults to $::os_service_default # # [*database_max_pool_size*] -# Maximum number of SQL connections to keep open in a pool. -# (Optional) Defaults to 10. +# (Optional)Maximum number of SQL connections to keep open in a pool. +# Defaults to $::os_service_default # # [*database_max_overflow*] -# If set, use this value for max_overflow with sqlalchemy. -# (Optional) Defaults to 20. +# (Optional) If set, use this value for max_overflow with sqlalchemy. +# Defaults to $::os_service_default # class congress::db ( $database_connection = 'sqlite:////var/lib/congress/congress.sqlite', - $database_idle_timeout = 3600, - $database_min_pool_size = 1, - $database_max_pool_size = 10, - $database_max_retries = 10, - $database_retry_interval = 10, - $database_max_overflow = 20, + $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, ) { - # NOTE(spredzy): In order to keep backward compatibility we rely on the pick function - # to use congress:: if congress::db:: isn't specified. - $database_connection_real = pick($::congress::database_connection, $database_connection) - $database_idle_timeout_real = pick($::congress::database_idle_timeout, $database_idle_timeout) - $database_min_pool_size_real = pick($::congress::database_min_pool_size, $database_min_pool_size) - $database_max_pool_size_real = pick($::congress::database_max_pool_size, $database_max_pool_size) - $database_max_retries_real = pick($::congress::database_max_retries, $database_max_retries) - $database_retry_interval_real = pick($::congress::database_retry_interval, $database_retry_interval) - $database_max_overflow_real = pick($::congress::database_max_overflow, $database_max_overflow) + validate_re($database_connection, + '^(sqlite|mysql(\+pymysql)?|postgresql):\/\/(\S+:\S+@\S+\/\S+)?') - validate_re($database_connection_real, - '(sqlite|mysql|postgresql):\/\/(\S+:\S+@\S+\/\S+)?') - - if $database_connection_real { - case $database_connection_real { - /^mysql:\/\//: { - $backend_package = false - require 'mysql::bindings' - require 'mysql::bindings::python' - } - /^postgresql:\/\//: { - $backend_package = false - require 'postgresql::lib::python' - } - /^sqlite:\/\//: { - $backend_package = $::congress::params::sqlite_package_name - } - default: { - fail('Unsupported backend configured') - } - } - - if $backend_package and !defined(Package[$backend_package]) { - package {'congress-backend-package': - ensure => present, - name => $backend_package, - tag => 'openstack', - } - } - - congress_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 { 'congress_config': + connection => $database_connection, + idle_timeout => $database_idle_timeout, + min_pool_size => $database_min_pool_size, + max_retries => $database_max_retries, + retry_interval => $database_retry_interval, + max_pool_size => $database_max_pool_size, + max_overflow => $database_max_overflow, } - } diff --git a/manifests/db/mysql.pp b/manifests/db/mysql.pp index 456b812..8531b1b 100644 --- a/manifests/db/mysql.pp +++ b/manifests/db/mysql.pp @@ -1,7 +1,7 @@ # The congress::db::mysql class implements mysql backend for congress # # This class can be used to create tables, users and grant -# privelege for a mysql congress database. +# privilege for a mysql congress database. # # == parameters # diff --git a/manifests/db/sync.pp b/manifests/db/sync.pp index bb07f7e..7e28650 100644 --- a/manifests/db/sync.pp +++ b/manifests/db/sync.pp @@ -1,13 +1,22 @@ # -# Class to execute "congress-manage db_sync +# Class to execute congress-manage db_sync # -class congress::db::sync { - exec { 'congress-manage db_sync': +# == Parameters +# +# [*extra_params*] +# (optional) String of extra command line parameters to append +# to the congress-dbsync command. +# Defaults to undef +# +class congress::db::sync( + $extra_params = undef, +) { + exec { 'congress-db-sync': + command => "congress-manage db_sync ${extra_params}", path => '/usr/bin', user => 'congress', refreshonly => true, - subscribe => [Package['congress'], congress_config['database/connection']], - require => User['congress'], + subscribe => [Package['congress'], Congress_config['database/connection']], } Exec['congress-manage db_sync'] ~> Service<| title == 'congress' |> diff --git a/manifests/init.pp b/manifests/init.pp index c970470..57f3e04 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -1,413 +1,11 @@ # == Class: congress # -# Module for managing congress config +# Full description of class congress here. # # === Parameters # -# [*keystone_password*] -# (required) Password used to authentication. -# -# [*package_ensure*] -# (optional) Desired ensure state of packages. -# accepts latest or specific versions. -# Defaults to present. -# -# [*client_package_ensure*] -# (optional) Desired ensure state of the client package. -# accepts latest or specific versions. -# Defaults to present. -# -# [*bind_host*] -# (optional) The IP address that congress binds to. -# Default to '0.0.0.0'. -# -# [*bind_port*] -# (optional) Port that congress binds to. -# Defaults to '1789' -# -# [*verbose*] -# (optional) Rather congress should log at verbose level. -# Defaults to undef. -# -# [*debug*] -# (optional) Rather congress should log at debug level. -# Defaults to undef. -# -# [*auth_type*] -# (optional) Type is authorization being used. -# Defaults to 'keystone' -# -# [*auth_uri*] -# (optional) Complete public Identity API endpoint. -# Defaults to false. -# -# [*identity_uri*] -# (optional) Complete admin Identity API endpoint. -# Defaults to: false -# -# [*keystone_tenant*] -# (optional) Tenant to authenticate to. -# Defaults to services. -# -# [*keystone_user*] -# (optional) User to authenticate as with keystone. -# Defaults to 'congress'. -# -# [*manage_service*] -# (Optional) If Puppet should manage service startup / shutdown. -# Defaults to true. -# -# [*enabled*] -# (optional) If the congress services should be enabled. -# Default to true. -# -# [*database_connection*] -# (optional) Url used to connect to database. -# Defaults to undef. -# -# [*database_idle_timeout*] -# (optional) Timeout when db connections should be reaped. -# Defaults to undef. -# -# [*database_max_retries*] -# (optional) Maximum number of database connection retries during startup. -# Setting -1 implies an infinite retry count. -# (Defaults to undef) -# -# [*database_retry_interval*] -# (optional) Interval between retries of opening a database connection. -# (Defaults to undef) -# -# [*database_min_pool_size*] -# (optional) Minimum number of SQL connections to keep open in a pool. -# Defaults to: undef -# -# [*database_max_pool_size*] -# (optional) Maximum number of SQL connections to keep open in a pool. -# Defaults to: undef -# -# [*database_max_overflow*] -# (optional) If set, use this value for max_overflow with sqlalchemy. -# Defaults to: undef -# -# [*rpc_backend*] -# (Optional) Use these options to configure the RabbitMQ message system. -# Defaults to 'rabbit' -# -# [*control_exchange*] -# (Optional) -# Defaults to 'openstack'. -# -# [*rabbit_host*] -# (Optional) IP or hostname of the rabbit server. -# Defaults to '127.0.0.1' -# -# [*rabbit_port*] -# (Optional) Port of the rabbit server. -# Defaults to 5672. -# -# [*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. -# -# [*rabbit_userid*] -# (Optional) User to connect to the rabbit server. -# Defaults to 'guest' -# -# [*rabbit_password*] -# (Required) Password to connect to the rabbit_server. -# Defaults to empty. Required if using the Rabbit (kombu) -# backend. -# -# [*rabbit_virtual_host*] -# (Optional) Virtual_host to use. -# Defaults to '/' -# -# [*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 -# -# [*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 -# -# [*rabbit_use_ssl*] -# (optional) Connect over SSL for RabbitMQ -# Defaults to false -# -# [*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. -# -# [*service_provider*] -# (optional) Provider, that can be used for congress service. -# Default value defined in congress::params for given operation system. -# If you use Pacemaker or another Cluster Resource Manager, you can make -# custom service provider for changing start/stop/status behavior of service, -# and set it here. -# -# [*service_name*] -# (optional) Name of the service that will be providing the -# server functionality of congress. -# Defaults to '$::congress::params::service_name' -# -# [*sync_db*] -# (Optional) Run db sync on the node. -# Defaults to true -# -# == Dependencies -# None -# -# == Examples -# -# class { 'congress': -# keystone_password => 'congress', -# keystone_tenant => 'service', -# auth_uri => 'http://192.168.122.6:5000/', -# identity_uri => 'http://192.168.122.6:35357/', -# database_connection => 'mysql://congress:password@192.168.122.6/congress', -# rabbit_host => '192.168.122.6', -# rabbit_password => 'guest', -# } -# -# class { 'congress::db::mysql': -# password => 'password', -# host => '%', -# } -# -# class { 'congress::keystone::auth': -# password => 'congress', -# tenant => 'service', -# admin_url => 'http://192.168.122.6:1789', -# internal_url => 'http://192.168.122.6:1789', -# public_url => 'http://192.168.122.6:1789', -# region => 'regionOne', -# } -# -# == Authors -# -# Dan Radez -# -# == Copyright -# -# Copyright 2015 Red Hat Inc, unless otherwise noted. -# +class congress { -class congress( - $keystone_password, - $package_ensure = 'present', - $client_package_ensure = 'present', - $bind_host = '0.0.0.0', - $bind_port = '1789', - $verbose = undef, - $debug = undef, - $auth_type = 'keystone', - $auth_uri = false, - $identity_uri = false, - $keystone_tenant = 'services', - $keystone_user = 'congress', - $manage_service = true, - $enabled = true, - $database_connection = undef, - $database_idle_timeout = undef, - $database_max_retries = undef, - $database_retry_interval = undef, - $database_min_pool_size = undef, - $database_max_pool_size = undef, - $database_max_overflow = undef, - $rpc_backend = 'rabbit', - $control_exchange = 'congress', - $rabbit_host = '127.0.0.1', - $rabbit_port = 5672, - $rabbit_hosts = false, - $rabbit_virtual_host = '/', - $rabbit_heartbeat_timeout_threshold = 0, - $rabbit_heartbeat_rate = 2, - $rabbit_userid = 'guest', - $rabbit_password = false, - $rabbit_use_ssl = false, - $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, - $service_provider = $::congress::params::service_provider, - $service_name = $::congress::params::service_name, -) inherits congress::params { - congress_config { - 'DEFAULT/drivers' : value => 'congress.datasources.neutronv2_driver.NeutronV2Driver,congress.datasources.glancev2_driver.GlanceV2Driver,congress.datasources.nova_driver.NovaDriver,congress.datasources.keystone_driver.KeystoneDriver,congress.datasources.ceilometer_driver.CeilometerDriver,congress.datasources.cinder_driver.CinderDriver'; - 'DEFAULT/policy_path' : value => '/etc/congress/snapshot/'; - 'DEFAULT/log_file' : value => 'congress.log'; - 'DEFAULT/log_dir' : value => '/var/log/congress/'; - } - - if $identity_uri { - congress_config { 'keystone_authtoken/identity_uri': value => $identity_uri; } - congress_config { 'keystone_authtoken/auth_url' : value => $identity_uri; } - } else { - congress_config { 'keystone_authtoken/identity_uri': ensure => absent; } - } - - if $auth_uri { - congress_config { 'keystone_authtoken/auth_uri': value => $auth_uri; } - } else { - congress_config { 'keystone_authtoken/auth_uri': ensure => absent; } - } - - if $auth_type == 'keystone' { - congress_config { - 'keystone_authtoken/project_name' : value => $keystone_tenant; - 'keystone_authtoken/username' : value => $keystone_user; - 'keystone_authtoken/password' : value => $keystone_password, secret => true; - } - } - - Congress_config<||> ~> Service[$service_name] - Congress_config<||> ~> Exec<| title == 'congress-manage db_sync'|> - - include ::congress::db include ::congress::params - if $sync_db { - include ::congress::db::sync - Class['::congress::db::sync'] ~> Service[$service_name] - } - if $rpc_backend == 'rabbit' { - - if ! $rabbit_password { - fail('Please specify a rabbit_password parameter.') - } - - congress_config { - 'DEFAULT/rabbit_password': value => $rabbit_password, secret => true; - 'DEFAULT/rabbit_userid': value => $rabbit_userid; - 'DEFAULT/rabbit_virtual_host': value => $rabbit_virtual_host; - 'DEFAULT/control_exchange': value => $control_exchange; - #'DEFAULT/rabbit_use_ssl': value => $rabbit_use_ssl; - #'DEFAULT/kombu_reconnect_delay': value => $kombu_reconnect_delay; - #'DEFAULT/heartbeat_timeout_threshold': value => $rabbit_heartbeat_timeout_threshold; - #'DEFAULT/heartbeat_rate': value => $rabbit_heartbeat_rate; - #'DEFAULT/amqp_durable_queues': value => $amqp_durable_queues; - } - - if $rabbit_use_ssl { - congress_config { - 'DEFAULT/kombu_ssl_version' : value => $kombu_ssl_version; - 'DEFAULT/kombu_ssl_ca_certs' : value => $kombu_ssl_ca_certs; - 'DEFAULT/kombu_ssl_certfile' : value => $kombu_ssl_certfile; - 'DEFAULT/kombu_ssl_keyfile' : value => $kombu_ssl_keyfile; - } - } - - if $rabbit_hosts { - congress_config { 'DEFAULT/rabbit_hosts': value => join($rabbit_hosts, ',') } - congress_config { 'DEFAULT/rabbit_ha_queues': value => true } - congress_config { 'DEFAULT/rabbit_host': ensure => absent } - congress_config { 'DEFAULT/rabbit_port': ensure => absent } - } else { - congress_config { 'DEFAULT/rabbit_host': value => $rabbit_host } - congress_config { 'DEFAULT/rabbit_port': value => $rabbit_port } - congress_config { 'DEFAULT/rabbit_hosts': value => "${rabbit_host}:${rabbit_port}" } - congress_config { 'DEFAULT/rabbit_ha_queues': value => false } - } - - } - - package { 'congress': - ensure => $package_ensure, - name => $::congress::params::package_name, - tag => ['openstack', 'congress-package'], - } - if $client_package_ensure == 'present' { - include '::congress::client' - } else { - class { '::congress::client': - ensure => $client_package_ensure, - } - } - - group { 'congress': - ensure => present, - system => true, - require => Package['congress'], - } - - user { 'congress': - ensure => 'present', - gid => 'congress', - system => true, - require => Package['congress'], - } - - file { ['/etc/congress', '/var/log/congress', '/var/lib/congress']: - ensure => directory, - mode => '0750', - owner => 'congress', - group => 'congress', - require => Package['congress'], - notify => Service[$service_name], - } - - file { '/etc/congress/congress.conf': - ensure => present, - mode => '0600', - owner => 'congress', - group => 'congress', - require => Package['congress'], - notify => Service[$service_name], - } - - congress_config { - 'DEFAULT/bind_host': value => $bind_host; - 'DEFAULT/bind_port': value => $bind_port; - } - - if $manage_service { - if $enabled { - $service_ensure = 'running' - } else { - $service_ensure = 'stopped' - } - } - - class { '::congress::service': - ensure => $service_ensure, - service_name => $service_name, - enable => $enabled, - hasstatus => true, - hasrestart => true, - provider => $service_provider, - } } diff --git a/manifests/keystone/auth.pp b/manifests/keystone/auth.pp index c5cae1a..fd43127 100644 --- a/manifests/keystone/auth.pp +++ b/manifests/keystone/auth.pp @@ -28,27 +28,29 @@ # Defaults to 'true'. # # [*service_type*] -# Type of service. Defaults to 'NFV'. -# -# [*admin_url*] -# (optional) The endpoint's admin url. (Defaults to 'http://127.0.0.1:1789') -# This url should *not* contain any version or trailing '/'. -# -# [*internal_url*] -# (optional) The endpoint's internal url. (Defaults to 'http://127.0.0.1:1789') -# This url should *not* contain any version or trailing '/'. -# -# [*public_url*] -# (optional) The endpoint's public url. (Defaults to 'http://127.0.0.1:1789') -# This url should *not* contain any version or trailing '/'. +# Type of service. Defaults to 'policy'. # # [*region*] # Region for endpoint. Defaults to 'RegionOne'. # # [*service_name*] # (optional) Name of the service. -# Defaults to the value of auth_name. +# Defaults to the value of 'congress'. # +# [*service_description*] +# (optional) Description of the service. +# Default to 'congress policy Service' +# +# [*public_url*] +# (optional) The endpoint's public url. (Defaults to 'http://127.0.0.1:1789') +# This url should *not* contain any trailing '/'. +# +# [*admin_url*] +# (optional) The endpoint's admin url. (Defaults to 'http://127.0.0.1:1789') +# This url should *not* contain any trailing '/'. +# +# [*internal_url*] +# (optional) The endpoint's internal url. (Defaults to 'http://127.0.0.1:1789') # class congress::keystone::auth ( $password, @@ -58,36 +60,35 @@ class congress::keystone::auth ( $configure_endpoint = true, $configure_user = true, $configure_user_role = true, - $service_name = undef, + $service_name = 'congress', + $service_description = 'congress Policy Service', $service_type = 'policy', + $region = 'RegionOne', + $public_url = 'http://127.0.0.1:1789', $admin_url = 'http://127.0.0.1:1789', $internal_url = 'http://127.0.0.1:1789', - $public_url = 'http://127.0.0.1:1789', - $region = 'RegionOne' ) { - $real_service_name = pick($service_name, $auth_name) - if $configure_user_role { Keystone_user_role["${auth_name}@${tenant}"] ~> Service <| name == 'congress-server' |> } - Keystone_endpoint["${region}/${real_service_name}"] ~> Service <| name == 'congress-server' |> + Keystone_endpoint["${region}/${service_name}::${service_type}"] ~> Service <| name == 'congress-server' |> keystone::resource::service_identity { 'congress': configure_user => $configure_user, configure_user_role => $configure_user_role, configure_endpoint => $configure_endpoint, - service_name => $real_service_name, + service_name => $service_name, service_type => $service_type, - service_description => 'congress VNF Manager service', + service_description => $service_description, region => $region, auth_name => $auth_name, password => $password, email => $email, tenant => $tenant, - admin_url => "${admin_url}/", - internal_url => "${internal_url}/", - public_url => "${public_url}/", + public_url => $public_url, + internal_url => $internal_url, + admin_url => $admin_url, } } diff --git a/manifests/logging.pp b/manifests/logging.pp index 7bcdc00..6d9b452 100644 --- a/manifests/logging.pp +++ b/manifests/logging.pp @@ -4,61 +4,61 @@ # # == parameters # -# [*verbose*] -# (Optional) Should the daemons log verbose messages -# Defaults to false. -# # [*debug*] # (Optional) Should the daemons log debug messages -# Defaults to false. +# Defaults to $::os_service_default # # [*use_syslog*] # (Optional) Use syslog for logging. -# Defaults to false. +# Defaults to $::os_service_default # # [*use_stderr*] # (optional) Use stderr for logging -# Defaults to true. +# Defaults to $::os_service_default # -# [*log_facility*] +# [*syslog_log_facility*] # (Optional) Syslog facility to receive log lines. -# Defaults to 'LOG_USER'. +# Defaults to $::os_service_default # # [*log_dir*] # (optional) Directory where logs should be stored. # If set to boolean false, it will not log to any directory. # Defaults to '/var/log/congress'. # +# [*log_file*] +# (optional) File where logs should be stored. +# Defaults to '/var/log/congress/congress.log' +# # [*logging_context_format_string*] # (optional) Format string to use for log messages with context. -# Defaults to undef. +# 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. +# 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. +# 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. +# 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. +# (optional) The name of an additional logging configuration file. +# 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', @@ -70,11 +70,11 @@ # # [*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 @@ -85,167 +85,51 @@ # [*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 congress::logging( - $use_syslog = false, - $use_stderr = true, - $log_facility = 'LOG_USER', + $use_syslog = $::os_service_default, + $use_stderr = $::os_service_default, + $syslog_log_facility = $::os_service_default, $log_dir = '/var/log/congress', - $verbose = false, - $debug = false, - $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, + $log_file = '/var/log/congress/congress.log', + $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, ) { - congress_config { - 'DEFAULT/use_syslog' : value => $use_syslog; - 'DEFAULT/use_stderr' : value => $use_stderr; - 'DEFAULT/log_dir' : value => $log_dir; - 'DEFAULT/verbose' : value => $verbose; - 'DEFAULT/debug' : value => $debug; - 'DEFAULT/syslog_log_facility' : value => $log_facility; + oslo::log { 'congress_config': + use_stderr => $use_stderr, + use_syslog => $use_syslog, + log_dir => $log_dir, + log_file => $log_file, + debug => $debug, + 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, + default_log_levels => $default_log_levels, + publish_errors => $publish_errors, + fatal_deprecations => $fatal_deprecations, + instance_format => $instance_format, + instance_uuid_format => $instance_uuid_format, + log_date_format => $log_date_format, + syslog_log_facility => $syslog_log_facility, } - - if $logging_context_format_string { - congress_config { - 'DEFAULT/logging_context_format_string' : - value => $logging_context_format_string; - } - } - else { - congress_config { - 'DEFAULT/logging_context_format_string' : ensure => absent; - } - } - - if $logging_default_format_string { - congress_config { - 'DEFAULT/logging_default_format_string' : - value => $logging_default_format_string; - } - } - else { - congress_config { - 'DEFAULT/logging_default_format_string' : ensure => absent; - } - } - - if $logging_debug_format_suffix { - congress_config { - 'DEFAULT/logging_debug_format_suffix' : - value => $logging_debug_format_suffix; - } - } - else { - congress_config { - 'DEFAULT/logging_debug_format_suffix' : ensure => absent; - } - } - - if $logging_exception_prefix { - congress_config { - 'DEFAULT/logging_exception_prefix' : value => $logging_exception_prefix; - } - } - else { - congress_config { - 'DEFAULT/logging_exception_prefix' : ensure => absent; - } - } - - if $log_config_append { - congress_config { - 'DEFAULT/log_config_append' : value => $log_config_append; - } - } - else { - congress_config { - 'DEFAULT/log_config_append' : ensure => absent; - } - } - - if $default_log_levels { - congress_config { - 'DEFAULT/default_log_levels' : - value => join(sort(join_keys_to_values($default_log_levels, '=')), ','); - } - } - else { - congress_config { - 'DEFAULT/default_log_levels' : ensure => absent; - } - } - - if $publish_errors { - congress_config { - 'DEFAULT/publish_errors' : value => $publish_errors; - } - } - else { - congress_config { - 'DEFAULT/publish_errors' : ensure => absent; - } - } - - if $fatal_deprecations { - congress_config { - 'DEFAULT/fatal_deprecations' : value => $fatal_deprecations; - } - } - else { - congress_config { - 'DEFAULT/fatal_deprecations' : ensure => absent; - } - } - - if $instance_format { - congress_config { - 'DEFAULT/instance_format' : value => $instance_format; - } - } - else { - congress_config { - 'DEFAULT/instance_format' : ensure => absent; - } - } - - if $instance_uuid_format { - congress_config { - 'DEFAULT/instance_uuid_format' : value => $instance_uuid_format; - } - } - else { - congress_config { - 'DEFAULT/instance_uuid_format' : ensure => absent; - } - } - - if $log_date_format { - congress_config { - 'DEFAULT/log_date_format' : value => $log_date_format; - } - } - else { - congress_config { - 'DEFAULT/log_date_format' : ensure => absent; - } - } - - } diff --git a/manifests/params.pp b/manifests/params.pp index f2ceed0..66993dc 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -1,31 +1,15 @@ -# -# This class contains the platform differences for congress +# Parameters for puppet-congress # class congress::params { - $client_package_name = 'python-congressclient' case $::osfamily { - 'Debian': { - $package_name = 'congress' - $service_name = 'congress' - $python_memcache_package_name = 'python-memcache' - $sqlite_package_name = 'python-pysqlite2' - $paste_config = undef - case $::operatingsystem { - 'Debian': { - $service_provider = undef - } - default: { - $service_provider = 'upstart' - } - } - } 'RedHat': { - $package_name = 'openstack-congress' - $service_name = 'openstack-congress' - $python_memcache_package_name = 'python-memcached' - $sqlite_package_name = undef - $service_provider = undef } - } + 'Debian': { + } + default: { + fail("Unsupported osfamily: ${::osfamily} operatingsystem") + } + + } # Case $::osfamily } diff --git a/manifests/policy.pp b/manifests/policy.pp index cdca472..8ec8ae9 100644 --- a/manifests/policy.pp +++ b/manifests/policy.pp @@ -36,4 +36,6 @@ class congress::policy ( create_resources('openstacklib::policy::base', $policies) + oslo::policy { 'congress_config': policy_file => $policy_path } + } diff --git a/manifests/service.pp b/manifests/service.pp deleted file mode 100644 index f802e9a..0000000 --- a/manifests/service.pp +++ /dev/null @@ -1,55 +0,0 @@ -# == Class congress::service -# -# Encapsulates the congress service to a class. -# This allows resources that require congress to -# require this class, which can optionally -# validate that the service can actually accept -# connections. -# -# === Parameters -# -# [*ensure*] -# (optional) The desired state of the congress service -# Defaults to undef -# -# [*service_name*] -# (optional) The name of the congress service -# Defaults to $::congress::params::service_name -# -# [*enable*] -# (optional) Whether to enable the congress service -# Defaults to true -# -# [*hasstatus*] -# (optional) Whether the congress service has status -# Defaults to true -# -# [*hasrestart*] -# (optional) Whether the congress service has restart -# Defaults to true -# -# [*provider*] -# (optional) Provider for congress service -# Defaults to $::congress::params::service_provider -# -class congress::service( - $ensure = undef, - $service_name = $::congress::params::service_name, - $enable = true, - $hasstatus = true, - $hasrestart = true, - $provider = $::congress::params::service_provider, -) { - include ::congress::params - - service { 'congress': - ensure => $ensure, - name => $service_name, - enable => $enable, - hasstatus => $hasstatus, - hasrestart => $hasrestart, - provider => $provider, - tag => 'congress-service', - } - -} diff --git a/metadata.json b/metadata.json index e94dd68..c78eb80 100644 --- a/metadata.json +++ b/metadata.json @@ -1,13 +1,13 @@ { - "name": "puppet-congress", + "name": "openstack-congress", "version": "0.0.1", "author": "OpenStack Contributors", - "summary": "Puppet module for OpenStack congress", + "summary": "Puppet module for OpenStack Congress", "license": "Apache-2.0", "source": "git://github.com/openstack/puppet-congress.git", "project_page": "https://launchpad.net/puppet-congress", "issues_url": "https://bugs.launchpad.net/puppet-congress", - "description": "Installs and configures OpenStack congress.", + "description": "Installs and configures OpenStack Congress.", "operatingsystem_support": [ { "operatingsystem": "Debian", @@ -29,6 +29,7 @@ "dependencies": [ { "name": "puppetlabs/inifile", "version_requirement": ">=1.0.0 <2.0.0" }, { "name": "puppetlabs/stdlib", "version_requirement": ">= 4.2.0 <5.0.0" }, - { "name": "stackforge/openstacklib", "version_requirement": ">=5.0.0 <6.0.0" } + { "name": "openstack/openstacklib", "version_requirement": ">=8.0.0 <9.0.0" }, + { "name": "openstack/oslo", "version_requirement": "<9.0.0" } ] } diff --git a/spec/acceptance/nodesets/centos-70-x64.yml b/spec/acceptance/nodesets/centos-70-x64.yml new file mode 100644 index 0000000..5f097e9 --- /dev/null +++ b/spec/acceptance/nodesets/centos-70-x64.yml @@ -0,0 +1,11 @@ +HOSTS: + centos-server-70-x64: + roles: + - master + platform: el-7-x86_64 + box: puppetlabs/centos-7.0-64-nocm + box_url: https://vagrantcloud.com/puppetlabs/centos-7.0-64-nocm + hypervisor: vagrant +CONFIG: + log_level: debug + type: foss diff --git a/spec/acceptance/nodesets/default.yml b/spec/acceptance/nodesets/default.yml new file mode 100644 index 0000000..486b6a3 --- /dev/null +++ b/spec/acceptance/nodesets/default.yml @@ -0,0 +1,10 @@ +HOSTS: + ubuntu-server-14.04-amd64: + roles: + - master + platform: ubuntu-14.04-amd64 + box: puppetlabs/ubuntu-14.04-64-nocm + box_url: https://vagrantcloud.com/puppetlabs/ubuntu-14.04-64-nocm + hypervisor: vagrant +CONFIG: + type: foss diff --git a/spec/acceptance/nodesets/nodepool-centos7.yml b/spec/acceptance/nodesets/nodepool-centos7.yml new file mode 100644 index 0000000..c552874 --- /dev/null +++ b/spec/acceptance/nodesets/nodepool-centos7.yml @@ -0,0 +1,10 @@ +HOSTS: + centos-70-x64: + roles: + - master + platform: el-7-x86_64 + hypervisor: none + ip: 127.0.0.1 +CONFIG: + type: foss + set_env: false diff --git a/spec/acceptance/nodesets/nodepool-trusty.yml b/spec/acceptance/nodesets/nodepool-trusty.yml new file mode 100644 index 0000000..9fc624e --- /dev/null +++ b/spec/acceptance/nodesets/nodepool-trusty.yml @@ -0,0 +1,10 @@ +HOSTS: + ubuntu-14.04-amd64: + roles: + - master + platform: ubuntu-14.04-amd64 + hypervisor: none + ip: 127.0.0.1 +CONFIG: + type: foss + set_env: false diff --git a/spec/acceptance/nodesets/nodepool-xenial.yml b/spec/acceptance/nodesets/nodepool-xenial.yml new file mode 100644 index 0000000..99dd318 --- /dev/null +++ b/spec/acceptance/nodesets/nodepool-xenial.yml @@ -0,0 +1,10 @@ +HOSTS: + ubuntu-16.04-amd64: + roles: + - master + platform: ubuntu-16.04-amd64 + hypervisor: none + ip: 127.0.0.1 +CONFIG: + type: foss + set_env: false diff --git a/spec/acceptance/nodesets/ubuntu-server-1404-x64.yml b/spec/acceptance/nodesets/ubuntu-server-1404-x64.yml new file mode 100644 index 0000000..8001929 --- /dev/null +++ b/spec/acceptance/nodesets/ubuntu-server-1404-x64.yml @@ -0,0 +1,11 @@ +HOSTS: + ubuntu-server-14.04-amd64: + roles: + - master + platform: ubuntu-14.04-amd64 + box: puppetlabs/ubuntu-14.04-64-nocm + box_url: https://vagrantcloud.com/puppetlabs/ubuntu-14.04-64-nocm + hypervisor: vagrant +CONFIG: + log_level: debug + type: foss diff --git a/spec/classes/congress_db_mysql_spec.rb b/spec/classes/congress_db_mysql_spec.rb index 6370bac..0a75346 100644 --- a/spec/classes/congress_db_mysql_spec.rb +++ b/spec/classes/congress_db_mysql_spec.rb @@ -3,60 +3,71 @@ require 'spec_helper' describe 'congress::db::mysql' do let :pre_condition do - [ - 'include mysql::server', - 'include congress::db::sync' - ] + 'include mysql::server' end - let :facts do - { :osfamily => 'Debian' } + let :required_params do + { :password => 'fooboozoo_default_password', } end - let :params do - { - 'password' => 'fooboozoo_default_password', - } - end + shared_examples_for 'congress-db-mysql' do + context 'with only required params' do + let :params do + required_params + end - describe 'with only required params' do - it { is_expected.to contain_openstacklib__db__mysql('congress').with( - 'user' => 'congress', - 'password_hash' => '*3DDF34A86854A312A8E2C65B506E21C91800D206', - 'dbname' => 'congress', - 'host' => '127.0.0.1', - 'charset' => 'utf8', - :collate => 'utf8_general_ci', - )} - end + it { is_expected.to contain_openstacklib__db__mysql('congress').with( + :user => 'congress', + :password_hash => '*3DDF34A86854A312A8E2C65B506E21C91800D206', + :dbname => 'congress', + :host => '127.0.0.1', + :charset => 'utf8', + :collate => 'utf8_general_ci', + )} + end - describe "overriding allowed_hosts param to array" do - let :params do - { - :password => 'congresspass', + context 'overriding allowed_hosts param to array' do + let :params do + { :allowed_hosts => ['127.0.0.1','%'] }.merge(required_params) + end + + it { is_expected.to contain_openstacklib__db__mysql('congress').with( + :user => 'congress', + :password_hash => '*3DDF34A86854A312A8E2C65B506E21C91800D206', + :dbname => 'congress', + :host => '127.0.0.1', + :charset => 'utf8', + :collate => 'utf8_general_ci', :allowed_hosts => ['127.0.0.1','%'] - } + )} end - end - describe "overriding allowed_hosts param to string" do - let :params do - { - :password => 'congresspass2', + describe 'overriding allowed_hosts param to string' do + let :params do + { :allowed_hosts => '192.168.1.1' }.merge(required_params) + end + + it { is_expected.to contain_openstacklib__db__mysql('congress').with( + :user => 'congress', + :password_hash => '*3DDF34A86854A312A8E2C65B506E21C91800D206', + :dbname => 'congress', + :host => '127.0.0.1', + :charset => 'utf8', + :collate => 'utf8_general_ci', :allowed_hosts => '192.168.1.1' - } + )} end - end - describe "overriding allowed_hosts param equals to host param " do - let :params do - { - :password => 'congresspass2', - :allowed_hosts => '127.0.0.1' - } + 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()) + end + + it_behaves_like 'congress-db-mysql' end - end - end diff --git a/spec/classes/congress_db_postgresql_spec.rb b/spec/classes/congress_db_postgresql_spec.rb index 74abbdb..d05aade 100644 --- a/spec/classes/congress_db_postgresql_spec.rb +++ b/spec/classes/congress_db_postgresql_spec.rb @@ -2,57 +2,36 @@ require 'spec_helper' describe 'congress::db::postgresql' do - let :req_params do - { :password => 'pw' } - end - let :pre_condition do 'include postgresql::server' end - context 'on a RedHat osfamily' do - let :facts do - { - :osfamily => 'RedHat', - :operatingsystemrelease => '7.0', - :concat_basedir => '/var/lib/puppet/concat' - } - end + let :required_params do + { :password => 'pw' } + end + shared_examples_for 'congress-db-postgresql' do context 'with only required parameters' do let :params do - req_params + required_params end it { is_expected.to contain_postgresql__server__db('congress').with( :user => 'congress', - :password => 'md5c530c33636c58ae83ca933f39319273e' + :password => 'md5a2f665ba4d66aae91c2a86eedd8e564e' )} end - end - context 'on a Debian osfamily' do - let :facts do - { - :operatingsystemrelease => '7.8', - :operatingsystem => 'Debian', - :osfamily => 'Debian', - :concat_basedir => '/var/lib/puppet/concat' - } - end - - context 'with only required parameters' do - let :params do - req_params + 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({ :concat_basedir => '/var/lib/puppet/concat' })) end - it { is_expected.to contain_postgresql__server__db('congress').with( - :user => 'congress', - :password => 'md5c530c33636c58ae83ca933f39319273e' - )} + it_behaves_like 'congress-db-postgresql' end - end - end diff --git a/spec/classes/congress_db_spec.rb b/spec/classes/congress_db_spec.rb index 3b84993..8b32963 100644 --- a/spec/classes/congress_db_spec.rb +++ b/spec/classes/congress_db_spec.rb @@ -4,18 +4,18 @@ describe 'congress::db' do shared_examples 'congress::db' do context 'with default parameters' do - it { is_expected.to contain_congress_config('database/connection').with_value('mysql://congress:secrete@localhost:3306/congress') } - it { is_expected.to contain_congress_config('database/idle_timeout').with_value('3600') } - it { is_expected.to contain_congress_config('database/min_pool_size').with_value('1') } - it { is_expected.to contain_congress_config('database/max_retries').with_value('10') } - it { is_expected.to contain_congress_config('database/retry_interval').with_value('10') } - it { is_expected.to contain_congress_config('database/max_pool_size').with_value('10') } - it { is_expected.to contain_congress_config('database/max_overflow').with_value('20') } + it { is_expected.to contain_congress_config('database/connection').with_value('sqlite:////var/lib/congress/congress.sqlite') } + it { is_expected.to contain_congress_config('database/idle_timeout').with_value('') } + it { is_expected.to contain_congress_config('database/min_pool_size').with_value('') } + it { is_expected.to contain_congress_config('database/max_retries').with_value('') } + it { is_expected.to contain_congress_config('database/retry_interval').with_value('') } + it { is_expected.to contain_congress_config('database/max_pool_size').with_value('') } + it { is_expected.to contain_congress_config('database/max_overflow').with_value('') } end context 'with specific parameters' do let :params do - { :database_connection => 'mysql://congress:congress@localhost/congress', + { :database_connection => 'mysql+pymysql://congress:congress@localhost/congress', :database_idle_timeout => '3601', :database_min_pool_size => '2', :database_max_retries => '11', @@ -25,7 +25,7 @@ describe 'congress::db' do } end - it { is_expected.to contain_congress_config('database/connection').with_value('mysql://congress:congress@localhost/congress') } + it { is_expected.to contain_congress_config('database/connection').with_value('mysql+pymysql://congress:congress@localhost/congress') } it { is_expected.to contain_congress_config('database/idle_timeout').with_value('3601') } it { is_expected.to contain_congress_config('database/min_pool_size').with_value('2') } it { is_expected.to contain_congress_config('database/max_retries').with_value('11') } @@ -45,34 +45,70 @@ describe 'congress::db' do end + context 'with MySQL-python library as backend package' do + let :params do + { :database_connection => 'mysql://congress:congress@localhost/congress', } + 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 => 'sqlite://congress:congress@localhost/congress', } + { :database_connection => 'foodb://congress:congress@localhost/congress', } end it_raises 'a Puppet::Error', /validate_re/ end - end - context 'on Debian platforms' do - let :facts do - { :osfamily => 'Debian', - :operatingsystem => 'Debian', - :operatingsystemrelease => 'jessie', - } + context 'with incorrect pymysql database_connection string' do + let :params do + { :database_connection => 'foo+pymysql://congress:congress@localhost/congress', } + end + + it_raises 'a Puppet::Error', /validate_re/ end - it_configures 'congress::db' end - context 'on Redhat platforms' do - let :facts do - { :osfamily => 'RedHat', - :operatingsystemrelease => '7.1', - } + shared_examples_for 'congress::db on Debian' do + context 'using pymysql driver' do + let :params do + { :database_connection => 'mysql+pymysql://congress:congress@localhost/congress', } + end + + it 'install the proper backend package' do + is_expected.to contain_package('db_backend_package').with( + :ensure => 'present', + :name => 'python-pymysql', + :tag => 'openstack' + ) + end end - - it_configures 'congress::db' end + shared_examples_for 'congress::db on RedHat' do + context 'using pymysql driver' do + let :params do + { :database_connection => 'mysql+pymysql://congress:congress@localhost/congress', } + end + + it 'install the proper backend package' do + is_expected.not_to contain_package('db_backend_package') + end + 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()) + end + + it_configures 'congress::db' + it_configures "congress::db on #{facts[:osfamily]}" + end + end end diff --git a/spec/classes/congress_keystone_auth_spec.rb b/spec/classes/congress_keystone_auth_spec.rb index 3cb7e59..ec529b3 100644 --- a/spec/classes/congress_keystone_auth_spec.rb +++ b/spec/classes/congress_keystone_auth_spec.rb @@ -5,119 +5,124 @@ require 'spec_helper' describe 'congress::keystone::auth' do + shared_examples_for 'congress-keystone-auth' do + context 'with default class parameters' do + let :params do + { :password => 'congress_password', + :tenant => 'foobar' } + end - let :facts do - { :osfamily => 'Debian' } - end + it { is_expected.to contain_keystone_user('congress').with( + :ensure => 'present', + :password => 'congress_password', + ) } - describe 'with default class parameters' do - let :params do - { :password => 'congress_password', - :tenant => 'foobar' } + it { is_expected.to contain_keystone_user_role('congress@foobar').with( + :ensure => 'present', + :roles => ['admin'] + )} + + it { is_expected.to contain_keystone_service('congress::policy').with( + :ensure => 'present', + :description => 'congress Policy Service' + ) } + + it { is_expected.to contain_keystone_endpoint('RegionOne/congress::policy').with( + :ensure => 'present', + :public_url => 'http://127.0.0.1:1789', + :admin_url => 'http://127.0.0.1:1789', + :internal_url => 'http://127.0.0.1:1789', + ) } end - it { is_expected.to contain_keystone_user('congress').with( - :ensure => 'present', - :password => 'congress_password', - ) } + context 'when overriding URL parameters' do + let :params do + { :password => 'congress_password', + :public_url => 'https://10.10.10.10:80', + :internal_url => 'http://10.10.10.11:81', + :admin_url => 'http://10.10.10.12:81', } + end - it { is_expected.to contain_keystone_user_role('congress@foobar').with( - :ensure => 'present', - :roles => ['admin'] - )} - - it { is_expected.to contain_keystone_service('congress').with( - :ensure => 'present', - :type => 'FIXME', - :description => 'congress FIXME Service' - ) } - - it { is_expected.to contain_keystone_endpoint('RegionOne/congress').with( - :ensure => 'present', - :public_url => 'http://127.0.0.1:FIXME', - :admin_url => 'http://127.0.0.1:FIXME', - :internal_url => 'http://127.0.0.1:FIXME', - ) } - end - - describe 'when overriding URL paramaters' do - let :params do - { :password => 'congress_password', + it { is_expected.to contain_keystone_endpoint('RegionOne/congress::policy').with( + :ensure => 'present', :public_url => 'https://10.10.10.10:80', :internal_url => 'http://10.10.10.11:81', - :admin_url => 'http://10.10.10.12:81', } + :admin_url => 'http://10.10.10.12:81', + ) } end - it { is_expected.to contain_keystone_endpoint('RegionOne/congress').with( - :ensure => 'present', - :public_url => 'https://10.10.10.10:80', - :internal_url => 'http://10.10.10.11:81', - :admin_url => 'http://10.10.10.12:81', - ) } - end + context 'when overriding auth name' do + let :params do + { :password => 'foo', + :auth_name => 'congressy' } + end - describe 'when overriding auth name' do - let :params do - { :password => 'foo', - :auth_name => 'congressy' } + it { is_expected.to contain_keystone_user('congressy') } + it { is_expected.to contain_keystone_user_role('congressy@services') } + it { is_expected.to contain_keystone_service('congress::policy') } + it { is_expected.to contain_keystone_endpoint('RegionOne/congress::policy') } end - it { is_expected.to contain_keystone_user('congressy') } - it { is_expected.to contain_keystone_user_role('congressy@services') } - it { is_expected.to contain_keystone_service('congressy') } - it { is_expected.to contain_keystone_endpoint('RegionOne/congressy') } - end + context 'when overriding service name' do + let :params do + { :service_name => 'congress_service', + :auth_name => 'congress', + :password => 'congress_password' } + end - describe 'when overriding service name' do - let :params do - { :service_name => 'congress_service', - :auth_name => 'congress', - :password => 'congress_password' } + it { is_expected.to contain_keystone_user('congress') } + it { is_expected.to contain_keystone_user_role('congress@services') } + it { is_expected.to contain_keystone_service('congress_service::policy') } + it { is_expected.to contain_keystone_endpoint('RegionOne/congress_service::policy') } end - it { is_expected.to contain_keystone_user('congress') } - it { is_expected.to contain_keystone_user_role('congress@services') } - it { is_expected.to contain_keystone_service('congress_service') } - it { is_expected.to contain_keystone_endpoint('RegionOne/congress_service') } - end + context 'when disabling user configuration' do - describe 'when disabling user configuration' do + let :params do + { + :password => 'congress_password', + :configure_user => false + } + end + + it { is_expected.not_to contain_keystone_user('congress') } + it { is_expected.to contain_keystone_user_role('congress@services') } + it { is_expected.to contain_keystone_service('congress::policy').with( + :ensure => 'present', + :description => 'congress Policy Service' + ) } - let :params do - { - :password => 'congress_password', - :configure_user => false - } end - it { is_expected.not_to contain_keystone_user('congress') } - it { is_expected.to contain_keystone_user_role('congress@services') } - it { is_expected.to contain_keystone_service('congress').with( - :ensure => 'present', - :type => 'FIXME', - :description => 'congress FIXME Service' - ) } + context 'when disabling user and user role configuration' do - end + let :params do + { + :password => 'congress_password', + :configure_user => false, + :configure_user_role => false + } + end - describe 'when disabling user and user role configuration' do + it { is_expected.not_to contain_keystone_user('congress') } + it { is_expected.not_to contain_keystone_user_role('congress@services') } + it { is_expected.to contain_keystone_service('congress::policy').with( + :ensure => 'present', + :description => 'congress Policy Service' + ) } - let :params do - { - :password => 'congress_password', - :configure_user => false, - :configure_user_role => false - } end - - it { is_expected.not_to contain_keystone_user('congress') } - it { is_expected.not_to contain_keystone_user_role('congress@services') } - it { is_expected.to contain_keystone_service('congress').with( - :ensure => 'present', - :type => 'FIXME', - :description => 'congress FIXME Service' - ) } - 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()) + end + + it_behaves_like 'congress-keystone-auth' + end + end end diff --git a/spec/classes/congress_logging_spec.rb b/spec/classes/congress_logging_spec.rb index 0bfb994..fa70465 100644 --- a/spec/classes/congress_logging_spec.rb +++ b/spec/classes/congress_logging_spec.rb @@ -26,9 +26,9 @@ describe 'congress::logging' do :log_date_format => '%Y-%m-%d %H:%M:%S', :use_syslog => true, :use_stderr => false, - :log_facility => 'LOG_FOO', + :syslog_log_facility => 'LOG_FOO', :log_dir => '/var/log', - :verbose => true, + :log_file => '/var/log/congress.log', :debug => true, } end @@ -56,24 +56,24 @@ describe 'congress::logging' do end shared_examples 'basic default logging settings' do - it 'configures ceilometer logging settins with default values' do - is_expected.to contain_ceilometer_config('DEFAULT/use_syslog').with(:value => 'false') - is_expected.to contain_ceilometer_config('DEFAULT/use_stderr').with(:value => 'true') - is_expected.to contain_ceilometer_config('DEFAULT/syslog_log_facility').with(:value => 'LOG_USER') - is_expected.to contain_ceilometer_config('DEFAULT/log_dir').with(:value => '/var/log/congress') - is_expected.to contain_ceilometer_config('DEFAULT/verbose').with(:value => 'false') - is_expected.to contain_ceilometer_config('DEFAULT/debug').with(:value => 'false') + it 'configures congress logging settins with default values' do + is_expected.to contain_congress_config('DEFAULT/use_syslog').with(:value => '') + is_expected.to contain_congress_config('DEFAULT/use_stderr').with(:value => '') + is_expected.to contain_congress_config('DEFAULT/syslog_log_facility').with(:value => '') + is_expected.to contain_congress_config('DEFAULT/log_dir').with(:value => '/var/log/congress') + is_expected.to contain_congress_config('DEFAULT/log_file').with(:value => '/var/log/congress/congress.log') + is_expected.to contain_congress_config('DEFAULT/debug').with(:value => '') end end shared_examples 'basic non-default logging settings' do - it 'configures ceilometer logging settins with non-default values' do - is_expected.to contain_ceilometer_config('DEFAULT/use_syslog').with(:value => 'true') - is_expected.to contain_ceilometer_config('DEFAULT/use_stderr').with(:value => 'false') - is_expected.to contain_ceilometer_config('DEFAULT/syslog_log_facility').with(:value => 'LOG_FOO') - is_expected.to contain_ceilometer_config('DEFAULT/log_dir').with(:value => '/var/log') - is_expected.to contain_ceilometer_config('DEFAULT/verbose').with(:value => 'true') - is_expected.to contain_ceilometer_config('DEFAULT/debug').with(:value => 'true') + it 'configures congress logging settins with non-default values' do + is_expected.to contain_congress_config('DEFAULT/use_syslog').with(:value => 'true') + is_expected.to contain_congress_config('DEFAULT/use_stderr').with(:value => 'false') + is_expected.to contain_congress_config('DEFAULT/syslog_log_facility').with(:value => 'LOG_FOO') + is_expected.to contain_congress_config('DEFAULT/log_dir').with(:value => '/var/log') + is_expected.to contain_congress_config('DEFAULT/log_file').with(:value => '/var/log/congress.log') + is_expected.to contain_congress_config('DEFAULT/debug').with(:value => 'true') end end @@ -121,24 +121,19 @@ describe 'congress::logging' do :default_log_levels, :fatal_deprecations, :instance_format, :instance_uuid_format, :log_date_format, ].each { |param| - it { is_expected.to contain_congress_config("DEFAULT/#{param}").with_ensure('absent') } + it { is_expected.to contain_congress_config("DEFAULT/#{param}").with_value('') } } end - context 'on Debian platforms' do - let :facts do - { :osfamily => 'Debian' } + 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()) + end + + it_behaves_like 'congress-logging' end - - it_configures 'congress-logging' end - - context 'on RedHat platforms' do - let :facts do - { :osfamily => 'RedHat' } - end - - it_configures 'congress-logging' - end - end diff --git a/spec/classes/congress_policy_spec.rb b/spec/classes/congress_policy_spec.rb index d4e08ca..b88f0e1 100644 --- a/spec/classes/congress_policy_spec.rb +++ b/spec/classes/congress_policy_spec.rb @@ -1,8 +1,7 @@ require 'spec_helper' describe 'congress::policy' do - - shared_examples_for 'congress policies' do + shared_examples_for 'congress-policies' do let :params do { :policy_path => '/etc/congress/policy.json', @@ -23,19 +22,15 @@ describe 'congress::policy' do end end - context 'on Debian platforms' do - let :facts do - { :osfamily => 'Debian' } + 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()) + end + + it_behaves_like 'congress-policies' end - - it_configures 'congress policies' - end - - context 'on RedHat platforms' do - let :facts do - { :osfamily => 'RedHat' } - end - - it_configures 'congress policies' end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb new file mode 100644 index 0000000..9d725cf --- /dev/null +++ b/spec/spec_helper.rb @@ -0,0 +1,13 @@ +require 'puppetlabs_spec_helper/module_spec_helper' +require 'shared_examples' + +require 'puppet-openstack_spec_helper/defaults' +require 'rspec-puppet-facts' +include RspecPuppetFacts + +RSpec.configure do |c| + c.alias_it_should_behave_like_to :it_configures, 'configures' + c.alias_it_should_behave_like_to :it_raises, 'raises' +end + +at_exit { RSpec::Puppet::Coverage.report! } diff --git a/spec/spec_helper_acceptance.rb b/spec/spec_helper_acceptance.rb new file mode 100644 index 0000000..9196bc9 --- /dev/null +++ b/spec/spec_helper_acceptance.rb @@ -0,0 +1 @@ +require 'puppet-openstack_spec_helper/beaker_spec_helper' diff --git a/spec/unit/provider/congress_config/ini_setting_spec.rb b/spec/unit/provider/congress_config/ini_setting_spec.rb index 0c4b9fa..17b1d32 100644 --- a/spec/unit/provider/congress_config/ini_setting_spec.rb +++ b/spec/unit/provider/congress_config/ini_setting_spec.rb @@ -30,7 +30,7 @@ provider_class = Puppet::Type.type(:congress_config).provider(:ini_setting) describe provider_class do it 'should default to the default setting when no other one is specified' do - resource = Puppet::Type::congress_config.new( + resource = Puppet::Type::Congress_config.new( {:name => 'DEFAULT/foo', :value => 'bar'} ) provider = provider_class.new(resource) @@ -39,7 +39,7 @@ describe provider_class do end it 'should allow setting to be set explicitly' do - resource = Puppet::Type::congress_config.new( + resource = Puppet::Type::Congress_config.new( {:name => 'dude/foo', :value => 'bar'} ) provider = provider_class.new(resource) @@ -48,7 +48,7 @@ describe provider_class do end it 'should ensure absent when is specified as a value' do - resource = Puppet::Type::congress_config.new( + resource = Puppet::Type::Congress_config.new( {:name => 'dude/foo', :value => ''} ) provider = provider_class.new(resource) @@ -57,7 +57,7 @@ describe provider_class do end it 'should ensure absent when value matches ensure_absent_val' do - resource = Puppet::Type::congress_config.new( + resource = Puppet::Type::Congress_config.new( {:name => 'dude/foo', :value => 'foo', :ensure_absent_val => 'foo' } ) provider = provider_class.new(resource) diff --git a/spec/unit/type/congress_config_spec.rb b/spec/unit/type/congress_config_spec.rb index 22a70a1..f2a33bd 100644 --- a/spec/unit/type/congress_config_spec.rb +++ b/spec/unit/type/congress_config_spec.rb @@ -52,7 +52,7 @@ describe 'Puppet::Type.type(:congress_config)' do it 'should autorequire the package that install the file' do catalog = Puppet::Resource::Catalog.new - package = Puppet::Type.type(:package).new(:name => 'congress-common') + package = Puppet::Type.type(:package).new(:name => 'congress') catalog.add_resource package, @congress_config dependency = @congress_config.autorequire expect(dependency.size).to eq(1)