Implement API service & dependencies

This patch rewrite puppet-gnocchi to be compliant with other modules.
It takes example at how puppet-aodh was written.

* Update init.pp to match Gnocchi requirements
* Update config.pp
* Add policy.pp
* Add storage.pp for carbonara
* Update db configuration
* Update keystone/auth.pp
* Add acceptance for API service for Centos only (not packaged on Ubuntu)
* Update unit tests

Change-Id: I82400b1e30f3700ab7a3d006b6bb143351bcc830
This commit is contained in:
Emilien Macchi 2015-10-22 14:59:01 -04:00
parent cfdcdd2249
commit feee911823
23 changed files with 1150 additions and 630 deletions

View File

@ -1,141 +1,151 @@
#
# Copyright (C) 2014 eNovance SAS <licensing@enovance.com>
#
# Author: Emilien Macchi <emilien.macchi@enovance.com>
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
# == Class gnocchi::api
#
# Configure API service in gnocchi
# Installs & configure the gnocchi api service
#
# == Parameters
#
# [*manage_service*]
# (optional) Whether to start/stop the service
# [*enabled*]
# (optional) Should the service be enabled.
# Defaults to true
#
# [*ensure_package*]
# (optional) Whether the gnocchi api package will be installed
# Defaults to 'present'
#
# [*keystone_password*]
# (required) Password used to authentication.
#
# [*verbose*]
# (optional) Rather to log the gnocchi api service at verbose level.
# Defaults to undef
#
# [*debug*]
# (optional) Rather to log the gnocchi api service at debug level.
# Defaults to undef
#
# [*log_file*]
# (optional) The path of file used for logging
# If set to boolean false, it will not log to any file.
# Defaults to undef
#
# [*use_syslog*]
# (Optional) Use syslog for logging.
# Defaults to undef
#
# [*use_stderr*]
# (optional) Use stderr for logging
# Defaults to undef
#
# [*log_facility*]
# (Optional) Syslog facility to receive log lines.
# Defaults to undef
#
# [*log_dir*]
# (optional) directory to which gnocchi logs are sent.
# If set to boolean false, it will not log to any directory.
# Defaults to undef
#
# [*keystone_tenant*]
# (optional) Tenant to authenticate to.
# Defaults to services.
#
# [*keystone_user*]
# (optional) User to authenticate as with keystone.
# Defaults to 'gnocchi'.
# [*enabled*]
# (optional) Whether to enable services.
# [*manage_service*]
# (optional) Whether the service should be managed by Puppet.
# Defaults to true.
#
# [*use_syslog*]
# (optional) Use syslog for logging.
# Defaults to false.
# [*keystone_user*]
# (optional) The name of the auth user
# Defaults to gnocchi
#
# [*log_facility*]
# (optional) Syslog facility to receive log lines.
# Defaults to 'LOG_USER'.
# [*keystone_tenant*]
# (optional) Tenant to authenticate with.
# Defaults to 'services'.
#
# [*purge_config*]
# (optional) Whether to set only the specified config options
# in the api config.
# Defaults to false.
# [*keystone_password*]
# Password to authenticate with.
# Mandatory.
#
# [*identity_uri*]
# [*keystone_auth_uri*]
# (optional) Public Identity API endpoint.
# Defaults to 'false'.
#
# [*keystone_identity_uri*]
# (optional) Complete admin Identity API endpoint.
# Defaults to 'http://127.0.0.1:35357'.
# Defaults to: false
#
class gnocchi::api(
$keystone_password,
$verbose = undef,
$debug = undef,
$use_syslog = undef,
$use_stderr = undef,
$log_facility = undef,
$log_dir = undef,
$log_file = undef,
$keystone_tenant = 'services',
$keystone_user = 'gnocchi',
$identity_uri = 'http://127.0.0.1:35357',
$enabled = true,
$use_syslog = false,
$log_facility = 'LOG_USER',
$purge_config = false,
# [*host*]
# (optional) The gnocchi api bind address.
# Defaults to 0.0.0.0
#
# [*port*]
# (optional) The gnocchi api port.
# Defaults to 8041
#
# [*workers*]
# (optional) Number of workers for Gnocchi API server.
# Defaults to $::processorcount
#
# [*max_limit*]
# (optional) The maximum number of items returned in a
# single response from a collection resource.
# Defaults to 1000
#
# [*package_ensure*]
# (optional) ensure state for package.
# Defaults to 'present'
#
# [*service_name*]
# (optional) Name of the service that will be providing the
# server functionality of gnocchi-api.
# If the value is 'httpd', this means gnocchi-api will be a web
# service, and you must use another class to configure that
# web service. For example, use class { 'gnocchi::wsgi::apache'...}
# to make gnocchi-api be a web app using apache mod_wsgi.
# Defaults to '$::gnocchi::params::api_service_name'
#
class gnocchi::api (
$manage_service = true,
$ensure_package = 'present',
) inherits gnocchi {
$enabled = true,
$package_ensure = 'present',
$keystone_user = 'gnocchi',
$keystone_tenant = 'services',
$keystone_password = false,
$keystone_auth_uri = false,
$keystone_identity_uri = false,
$host = '0.0.0.0',
$port = '8041',
$workers = $::processorcount,
$max_limit = 1000,
$service_name = $::gnocchi::params::api_service_name,
) inherits gnocchi::params {
require ::keystone::python
include ::gnocchi::logging
include ::gnocchi::db
include ::gnocchi::params
include ::gnocchi::policy
Gnocchi_config<||> ~> Exec['post-gnocchi_config']
Gnocchi_config<||> ~> Service['gnocchi-api']
validate_string($keystone_password)
Gnocchi_config<||> ~> Service[$service_name]
Class['gnocchi::policy'] ~> Service[$service_name]
Package['gnocchi-api'] -> Service[$service_name]
Package['gnocchi-api'] -> Service['gnocchi-api']
Package['gnocchi-api'] -> Class['gnocchi::policy']
package { 'gnocchi-api':
ensure => $package_ensure,
name => $::gnocchi::params::api_package_name,
tag => ['openstack', 'gnocchi-package'],
}
if $manage_service {
if $enabled {
$service_ensure = 'running'
} else {
$service_ensure = 'stopped'
}
}
if $service_name == $::gnocchi::params::api_service_name {
service { 'gnocchi-api':
ensure => $service_ensure,
name => $::gnocchi::params::api_service_name,
enable => $enabled,
hasstatus => true,
hasrestart => true,
require => Class['gnocchi::db'],
tag => ['gnocchi-service', 'gnocchi-db-sync-service'],
}
} elsif $service_name == 'httpd' {
include ::apache::params
service { 'gnocchi-api':
ensure => 'stopped',
name => $::gnocchi::params::api_service_name,
enable => false,
tag => ['gnocchi-service', 'gnocchi-db-sync-service'],
}
Class['gnocchi::db'] -> Service[$service_name]
# we need to make sure gnocchi-api/eventlet is stopped before trying to start apache
Service['gnocchi-api'] -> Service[$service_name]
} else {
fail('Invalid service_name. Either gnocchi/openstack-gnocchi-api for running as a standalone service, or httpd for being run by a httpd server')
}
# basic service config
gnocchi_config {
'keystone_authtoken/identity_uri': value => $identity_uri;
'keystone_authtoken/admin_user': value => $keystone_user;
'keystone_authtoken/admin_password': value => $keystone_password, secret => true;
'keystone_authtoken/admin_tenant_name': value => $keystone_tenant;
'keystone_authtoken/auth_uri' : value => $keystone_auth_uri;
'keystone_authtoken/admin_tenant_name' : value => $keystone_tenant;
'keystone_authtoken/admin_user' : value => $keystone_user;
'keystone_authtoken/admin_password' : value => $keystone_password, secret => true;
'api/host' : value => $host;
'api/port' : value => $port;
'api/workers' : value => $workers;
'api/max_limit' : value => $max_limit;
}
resources { 'gnocchi_config':
purge => $purge_config,
if $keystone_identity_uri {
gnocchi_config {
'keystone_authtoken/identity_uri': value => $keystone_identity_uri;
}
} else {
gnocchi_config {
'keystone_authtoken/identity_uri': ensure => absent;
}
}
gnocchi::generic_service { 'api':
enabled => $enabled,
manage_service => $manage_service,
ensure_package => $ensure_package,
package_name => $::gnocchi::params::api_package_name,
service_name => $::gnocchi::params::api_service_name,
}
}

View File

@ -1,11 +1,11 @@
# == Class: gnocchi::config
#
# This class is used to manage arbitrary Gnocchi configurations.
# This class is used to manage arbitrary gnocchi configurations.
#
# === Parameters
#
# [*gnocchi_config*]
# (optional) Allow configuration of arbitrary Gnocchi configurations.
# (optional) Allow configuration of arbitrary gnocchi configurations.
# The value is an hash of gnocchi_config resources. Example:
# { 'DEFAULT/foo' => { value => 'fooValue'},
# 'DEFAULT/bar' => { value => 'barValue'}

View File

@ -8,50 +8,18 @@
# Url used to connect to database.
# (Optional) Defaults to 'sqlite:////var/lib/gnocchi/gnocchi.sqlite'.
#
# [*database_idle_timeout*]
# Timeout when db connections should be reaped.
# (Optional) Defaults to 3600.
#
# [*database_max_retries*]
# Maximum number of database connection retries during startup.
# Setting -1 implies an infinite retry count.
# (Optional) Defaults to 10.
#
# [*database_retry_interval*]
# Interval between retries of opening a database connection.
# (Optional) Defaults to 10.
#
# [*database_min_pool_size*]
# Minimum number of SQL connections to keep open in a pool.
# (Optional) Defaults to 1.
#
# [*database_max_pool_size*]
# Maximum number of SQL connections to keep open in a pool.
# (Optional) Defaults to 10.
#
# [*database_max_overflow*]
# If set, use this value for max_overflow with sqlalchemy.
# (Optional) Defaults to 20.
# [*ensure_package*]
# (optional) The state of gnocchi packages
# Defaults to 'present'
#
class gnocchi::db (
$database_connection = 'sqlite:////var/lib/gnocchi/gnocchi.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,
) {
$ensure_package = 'present',
) inherits gnocchi::params {
# NOTE(spredzy): In order to keep backward compatibility we rely on the pick function
# to use gnocchi::<myparam> if gnocchi::db::<myparam> isn't specified.
$database_connection_real = pick($::gnocchi::database_connection, $database_connection)
$database_idle_timeout_real = pick($::gnocchi::database_idle_timeout, $database_idle_timeout)
$database_min_pool_size_real = pick($::gnocchi::database_min_pool_size, $database_min_pool_size)
$database_max_pool_size_real = pick($::gnocchi::database_max_pool_size, $database_max_pool_size)
$database_max_retries_real = pick($::gnocchi::database_max_retries, $database_max_retries)
$database_retry_interval_real = pick($::gnocchi::database_retry_interval, $database_retry_interval)
$database_max_overflow_real = pick($::gnocchi::database_max_overflow, $database_max_overflow)
validate_re($database_connection_real,
'(sqlite|mysql|postgresql):\/\/(\S+:\S+@\S+\/\S+)?')
@ -84,13 +52,13 @@ class gnocchi::db (
}
gnocchi_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;
'indexer/url': value => $database_connection_real, secret => true;
}
package { 'gnocchi-indexer-sqlalchemy':
ensure => $ensure_package,
name => $::gnocchi::params::indexer_package_name,
tag => ['openstack', 'gnocchi-package'],
}
}

View File

@ -1,62 +1,56 @@
# The gnocchi::db::mysql class implements mysql backend for gnocchi
#
# Copyright (C) 2014 eNovance SAS <licensing@enovance.com>
# This class can be used to create tables, users and grant
# privelege for a mysql gnocchi database.
#
# Author: Emilien Macchi <emilien.macchi@enovance.com>
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
# == Class: gnocchi::db::mysql
#
# The gnocchi::db::mysql class creates a MySQL database for gnocchi.
# It must be used on the MySQL server
#
# === Parameters
# == parameters
#
# [*password*]
# (required) Password that will be used for the gnocchi db user.
# (Mandatory) Password to connect to the database.
# Defaults to 'false'.
#
# [*dbname*]
# (optional) Name of gnocchi database.
# Defaults to gnocchi
# (Optional) Name of the database.
# Defaults to 'gnocchi'.
#
# [*user*]
# (optional) Name of gnocchi user.
# Defaults to gnocchi
# (Optional) User to connect to the database.
# Defaults to 'gnocchi'.
#
# [*host*]
# (optional) Host where user should be allowed all privileges for database.
# Defaults to 127.0.0.1
# (Optional) The default source host user is allowed to connect from.
# Defaults to '127.0.0.1'
#
# [*allowed_hosts*]
# (optional) Hosts allowed to use the database
# Defaults to undef.
# (Optional) Other hosts the user is allowed to connect from.
# Defaults to 'undef'.
#
# [*charset*]
# (optional) Charset of gnocchi database
# Defaults 'utf8'.
# (Optional) The database charset.
# Defaults to 'utf8'
#
# [*collate*]
# (optional) Charset collate of gnocchi database
# Defaults 'utf8_general_ci'.
# (Optional) The database collate.
# Only used with mysql modules >= 2.2.
# Defaults to 'utf8_general_ci'
#
# == Dependencies
# Class['mysql::server']
#
# == Examples
#
# == Authors
#
# == Copyright
#
class gnocchi::db::mysql(
$password,
$dbname = 'gnocchi',
$user = 'gnocchi',
$host = '127.0.0.1',
$allowed_hosts = undef,
$charset = 'utf8',
$collate = 'utf8_general_ci',
$allowed_hosts = undef
) {
validate_string($password)

View File

@ -1,27 +1,23 @@
#
# Copyright (C) 2014 eNovance SAS <licensing@enovance.com>
#
# Author: Emilien Macchi <emilien.macchi@enovance.com>
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
# Class to execute "gnocchi-dbsync"
#
class gnocchi::db::sync {
exec { 'gnocchi-dbsync':
# [*user*]
# (optional) User to run dbsync command.
# Defaults to 'gnocchi'
#
class gnocchi::db::sync (
$user = 'gnocchi',
){
exec { 'gnocchi-db-sync':
command => 'gnocchi-dbsync --config-file /etc/gnocchi/gnocchi.conf',
path => '/usr/bin',
user => 'gnocchi',
refreshonly => true,
subscribe => [Package['gnocchi-api'], Gnocchi_config['database/connection']],
user => $user,
logoutput => on_failure,
}
Package<| tag == 'gnocchi-package' |> ~> Exec['gnocchi-db-sync']
Exec['gnocchi-db-sync'] ~> Service<| tag == 'gnocchi-db-sync-service' |>
Gnocchi_config<||> ~> Exec['gnocchi-db-sync']
Gnocchi_config<| title == 'indexer/url' |> ~> Exec['gnocchi-db-sync']
}

View File

@ -1,93 +0,0 @@
#
# Copyright (C) 2014 eNovance SAS <licensing@enovance.com>
#
# Author: Emilien Macchi <emilien.macchi@enovance.com>
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
# == Define: gnocchi::generic_service
#
# This defined type implements basic gnocchi services.
# It is introduced to attempt to consolidate
# common code.
#
# It also allows users to specify ad-hoc services
# as needed
#
# This define creates a service resource with title gnocchi-${name} and
# conditionally creates a package resource with title gnocchi-${name}
#
# === Parameters:
#
# [*package_name*]
# (mandatory) The package name (for the generic_service)
#
# [*service_name*]
# (mandatory) The service name (for the generic_service)
#
# [*enabled*]
# (optional) Define if the service must be enabled or not
# Defaults to false.
#
# [*manage_service*]
# (optional) Manage or not the service (if a service_name is provided).
# Defaults to true.
#
# [*ensure_package*]
# (optional) Control the ensure parameter for the package ressource.
# Defaults to 'present'.
#
define gnocchi::generic_service(
$package_name,
$service_name,
$enabled = false,
$manage_service = true,
$ensure_package = 'present'
) {
include ::gnocchi::params
include ::gnocchi::db::sync
$gnocchi_title = "gnocchi-${name}"
Exec['post-gnocchi_config'] ~> Service<| title == $gnocchi_title |>
Exec<| title == 'gnocchi-dbsync' |> ~> Service<| title == $gnocchi_title |>
if ($package_name) {
if !defined(Package[$package_name]) {
package { $gnocchi_title:
ensure => $ensure_package,
name => $package_name,
notify => Service[$gnocchi_title],
tag => ['openstack', 'gnocchi-package'],
}
}
}
if $service_name {
if $manage_service {
if $enabled {
$service_ensure = 'running'
} else {
$service_ensure = 'stopped'
}
}
service { $gnocchi_title:
ensure => $service_ensure,
name => $service_name,
enable => $enabled,
hasstatus => true,
tag => 'gnocchi-service',
}
}
}

View File

@ -1,69 +1,68 @@
# == Class: gnocchi
#
# Copyright (C) 2014 eNovance SAS <licensing@enovance.com>
# Full description of class gnocchi here.
#
# Author: Emilien Macchi <emilien.macchi@enovance.com>
# === Parameters
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
# [*ensure_package*]
# (optional) The state of gnocchi packages
# Defaults to 'present'
#
# http://www.apache.org/licenses/LICENSE-2.0
# [*log_dir*]
# (optional) Directory where logs should be stored.
# If set to boolean false, it will not log to any directory.
# Defaults to undef
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
# gnocchi::init
# [*state_path*]
# (optional) Directory for storing state.
# Defaults to '/var/lib/gnocchi'
#
# Gnocchi base config
# [*lock_path*]
# (optional) Directory for lock files.
# On RHEL will be '/var/lib/gnocchi/tmp' and on Debian '/var/lock/gnocchi'
# Defaults to $::gnocchi::params::lock_path
#
# == Parameters
# [*verbose*]
# (optional) Set log output to verbose output.
# Defaults to undef
#
# [*debug*]
# (optional) Set log output to debug output.
# Defaults to undef
#
# [*use_syslog*]
# (optional) Use syslog for logging
# Defaults to undef
#
# [*use_stderr*]
# (optional) Use stderr for logging
# Defaults to undef
#
# [*log_facility*]
# (optional) Syslog facility to receive log lines.
# Defaults to undef
#
# [*database_connection*]
# (optional) Connection url to connect to gnocchi database.
# Defaults to undef
# (optional) Connection url for the gnocchi database.
# Defaults to undef.
#
# [*database_idle_timeout*]
# (optional) Timeout before idle db connections are 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
#
class gnocchi(
class gnocchi (
$ensure_package = 'present',
$verbose = undef,
$debug = undef,
$use_syslog = undef,
$use_stderr = undef,
$log_facility = undef,
$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,
) {
include ::gnocchi::params
) inherits gnocchi::params {
exec { 'post-gnocchi_config':
command => '/bin/echo "Gnocchi config has changed"',
refreshonly => true,
include ::gnocchi::db
include ::gnocchi::logging
package { 'gnocchi':
ensure => $ensure_package,
name => $::gnocchi::params::common_package_name,
tag => ['openstack', 'gnocchi-package'],
}
}

View File

@ -1,86 +1,53 @@
#
# Copyright (C) 2014 eNovance SAS <licensing@enovance.com>
#
# Author: Emilien Macchi <emilien.macchi@enovance.com>
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
# gnocchi::keystone::auth
# == Class: gnocchi::keystone::auth
#
# Configures Gnocchi user, service and endpoint in Keystone.
#
# === Parameters
#
# [*password*]
# (required) Password for Gnocchi user.
# (required) Password for gnocchi user.
#
# [*auth_name*]
# Username for Gnocchi service. Defaults to 'gnocchi'.
# Username for gnocchi service. Defaults to 'gnocchi'.
#
# [*email*]
# Email for Gnocchi user. Defaults to 'gnocchi@localhost'.
# Email for gnocchi user. Defaults to 'gnocchi@localhost'.
#
# [*tenant*]
# Tenant for Gnocchi user. Defaults to 'services'.
# Tenant for gnocchi user. Defaults to 'services'.
#
# [*configure_endpoint*]
# Should Gnocchi endpoint be configured? Defaults to 'true'.
# Should gnocchi endpoint be configured? Defaults to 'true'.
#
# [*configure_user*]
# Should Gnocchi user be configured? Defaults to 'true'.
# (Optional) Should the service user be configured?
# Defaults to 'true'.
#
# [*configure_user_role*]
# Should Gnocchi user/role association be configured? Defaults to 'true'.
# (Optional) Should the admin role be configured for the service user?
# Defaults to 'true'.
#
# [*service_type*]
# Type of service. Defaults to 'gnocchi'.
#
# [*service_description*]
# Description for keystone service. Optional. Defaults to 'OpenStack Datapoint Service'.
#
# [*public_protocol*]
# Protocol for public endpoint. Defaults to 'http'.
#
# [*public_address*]
# Public address for endpoint. Defaults to '127.0.0.1'.
#
# [*public_port*]
# Port for public endpoint.
# Defaults to '8041'.
#
# [*admin_protocol*]
# Protocol for admin endpoint. Defaults to 'http'.
#
# [*admin_address*]
# Admin address for endpoint. Defaults to '127.0.0.1'.
#
# [*admin_port*]
# Port for admin endpoint.
# Defaults to '8041'.
#
# [*internal_protocol*]
# Protocol for internal endpoint. Defaults to 'http'.
#
# [*internal_address*]
# Internal address for endpoint. Defaults to '127.0.0.1'.
#
# [*internal_port*]
# Port for internal endpoint.
# Defaults to '8041'.
# Type of service. Defaults to 'key-manager'.
#
# [*region*]
# Region for endpoint. Defaults to 'RegionOne'.
#
# [*service_name*]
# (optional) Name of the service.
# Defaults to the value of auth_name.
#
# [*public_url*]
# (optional) The endpoint's public url. (Defaults to 'http://127.0.0.1:8041')
# This url should *not* contain any trailing '/'.
#
# [*admin_url*]
# (optional) The endpoint's admin url. (Defaults to 'http://127.0.0.1:8041')
# This url should *not* contain any trailing '/'.
#
# [*internal_url*]
# (optional) The endpoint's internal url. (Defaults to 'http://127.0.0.1:8041')
# This url should *not* contain any trailing '/'.
#
class gnocchi::keystone::auth (
$password,
@ -90,36 +57,31 @@ class gnocchi::keystone::auth (
$configure_endpoint = true,
$configure_user = true,
$configure_user_role = true,
$service_type = 'gnocchi',
$service_description = 'OpenStack Datapoint Service',
$public_protocol = 'http',
$public_address = '127.0.0.1',
$public_port = '8041',
$admin_protocol = 'http',
$admin_address = '127.0.0.1',
$admin_port = '8041',
$internal_protocol = 'http',
$internal_address = '127.0.0.1',
$internal_port = '8041',
$region = 'RegionOne'
$service_name = undef,
$service_type = 'metric',
$region = 'RegionOne',
$public_url = 'http://127.0.0.1:8041',
$internal_url = 'http://127.0.0.1:8041',
$admin_url = 'http://127.0.0.1:8041',
) {
Keystone_user_role["${auth_name}@${tenant}"] ~> Service <| name == 'gnocchi-api' |>
Keystone_endpoint["${region}/${auth_name}"] ~> Service <| name == 'gnocchi-api' |>
$real_service_name = pick($service_name, $auth_name)
keystone::resource::service_identity { $auth_name:
configure_user => true,
configure_user_role => true,
keystone::resource::service_identity { 'gnocchi':
configure_user => $configure_user,
configure_user_role => $configure_user_role,
configure_endpoint => $configure_endpoint,
service_name => $real_service_name,
service_type => $service_type,
service_description => $service_description,
service_description => 'OpenStack Metric Service',
region => $region,
auth_name => $auth_name,
password => $password,
email => $email,
tenant => $tenant,
public_url => "${public_protocol}://${public_address}:${public_port}",
internal_url => "${internal_protocol}://${internal_address}:${internal_port}",
admin_url => "${admin_protocol}://${admin_address}:${admin_port}",
public_url => $public_url,
internal_url => $internal_url,
admin_url => $admin_url,
}
}

View File

@ -29,11 +29,6 @@
# If set to boolean false, it will not log to any directory.
# Defaults to '/var/log/gnocchi'
#
# [*log_file*]
# (optional) The path of file used for logging
# If set to boolean false, it will not log to any file.
# Default to '/var/log/gnocchi-api.log'
#
# [*logging_context_format_string*]
# (optional) Format string to use for log messages with context.
# Defaults to undef.
@ -100,7 +95,6 @@ class gnocchi::logging(
$use_stderr = true,
$log_facility = 'LOG_USER',
$log_dir = '/var/log/gnocchi',
$log_file = '/var/log/gnocchi/gnocchi-api.log',
$verbose = false,
$debug = false,
$logging_context_format_string = undef,
@ -118,13 +112,12 @@ class gnocchi::logging(
# NOTE(spredzy): In order to keep backward compatibility we rely on the pick function
# to use gnocchi::<myparam> first then gnocchi::logging::<myparam>.
$use_syslog_real = pick($::gnocchi::api::use_syslog,$use_syslog)
$use_stderr_real = pick($::gnocchi::api::use_stderr,$use_stderr)
$log_facility_real = pick($::gnocchi::api::log_facility,$log_facility)
$log_dir_real = pick($::gnocchi::api::log_dir,$log_dir)
$log_file_real = pick($::gnocchi::api::log_file,$log_file)
$verbose_real = pick($::gnocchi::api::verbose,$verbose)
$debug_real = pick($::gnocchi::api::debug,$debug)
$use_syslog_real = pick($::gnocchi::use_syslog,$use_syslog)
$use_stderr_real = pick($::gnocchi::use_stderr,$use_stderr)
$log_facility_real = pick($::gnocchi::log_facility,$log_facility)
$log_dir_real = pick($::gnocchi::log_dir,$log_dir)
$verbose_real = pick($::gnocchi::verbose,$verbose)
$debug_real = pick($::gnocchi::debug,$debug)
gnocchi_config {
'DEFAULT/debug' : value => $debug_real;
@ -132,7 +125,6 @@ class gnocchi::logging(
'DEFAULT/use_stderr' : value => $use_stderr_real;
'DEFAULT/use_syslog' : value => $use_syslog_real;
'DEFAULT/log_dir' : value => $log_dir_real;
'DEFAULT/log_file' : value => $log_file_real;
'DEFAULT/syslog_log_facility': value => $log_facility_real;
}

View File

@ -4,14 +4,24 @@ class gnocchi::params {
case $::osfamily {
'RedHat': {
$sqlite_package_name = undef
$common_package_name = 'openstack-gnocchi-common'
$api_package_name = 'openstack-gnocchi-api'
$api_service_name = 'openstack-gnocchi-api'
$sqlite_package_name = undef
$indexer_package_name = 'openstack-gnocchi-indexer-sqlalchemy'
$carbonara_package_name = 'openstack-gnocchi-carbonara'
$gnocchi_wsgi_script_path = '/var/www/cgi-bin/gnocchi'
$gnocchi_wsgi_script_source = '/usr/lib/python2.7/site-packages/gnocchi/rest/app.wsgi'
}
'Debian': {
$sqlite_package_name = 'python-pysqlite2'
$common_package_name = 'gnocchi-common'
$api_package_name = 'gnocchi-api'
$api_service_name = 'gnocchi-api'
$sqlite_package_name = 'python-pysqlite2'
$indexer_package_name = 'gnocchi-indexer-sqlalchemy'
$carbonara_package_name = 'gnocchi-carbonara'
$gnocchi_wsgi_script_path = '/usr/lib/cgi-bin/gnocchi'
$gnocchi_wsgi_script_source = '/usr/share/gnocchi-common/app.wsgi'
}
default: {
fail("Unsupported osfamily: ${::osfamily} operatingsystem")

39
manifests/policy.pp Normal file
View File

@ -0,0 +1,39 @@
# == Class: gnocchi::policy
#
# Configure the gnocchi policies
#
# === Parameters
#
# [*policies*]
# (optional) Set of policies to configure for gnocchi
# Example :
# {
# 'gnocchi-context_is_admin' => {
# 'key' => 'context_is_admin',
# 'value' => 'true'
# },
# 'gnocchi-default' => {
# 'key' => 'default',
# 'value' => 'rule:admin_or_owner'
# }
# }
# Defaults to empty hash.
#
# [*policy_path*]
# (optional) Path to the nova policy.json file
# Defaults to /etc/gnocchi/policy.json
#
class gnocchi::policy (
$policies = {},
$policy_path = '/etc/gnocchi/policy.json',
) {
validate_hash($policies)
Openstacklib::Policy::Base {
file_path => $policy_path,
}
create_resources('openstacklib::policy::base', $policies)
}

33
manifests/storage.pp Normal file
View File

@ -0,0 +1,33 @@
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
# gnocchi::storage
#
# Storage backend for Gnocchi
#
# == Parameters
#
# [*package_ensure*]
# (optional) ensure state for package.
# Defaults to 'present'
#
class gnocchi::storage(
$package_ensure = 'present',
) inherits gnocchi::params {
package { 'gnocchi-carbonara':
ensure => $package_ensure,
name => $::gnocchi::params::carbonara_package_name,
tag => ['openstack', 'gnocchi-package'],
}
}

128
manifests/wsgi/apache.pp Normal file
View File

@ -0,0 +1,128 @@
#
# Copyright (C) 2015 eNovance SAS <licensing@enovance.com>
#
# Author: Emilien Macchi <emilien.macchi@enovance.com>
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
# Class to serve gnocchi API with apache mod_wsgi in place of gnocchi-api service.
#
# Serving gnocchi API from apache is the recommended way to go for production
# because of limited performance for concurrent accesses when running eventlet.
#
# When using this class you should disable your gnocchi-api service.
#
# == Parameters
#
# [*servername*]
# The servername for the virtualhost.
# Optional. Defaults to $::fqdn
#
# [*port*]
# The port.
# Optional. Defaults to 8041
#
# [*bind_host*]
# The host/ip address Apache will listen on.
# Optional. Defaults to undef (listen on all ip addresses).
#
# [*path*]
# The prefix for the endpoint.
# Optional. Defaults to '/'
#
# [*ssl*]
# Use ssl ? (boolean)
# Optional. Defaults to true
#
# [*workers*]
# Number of WSGI workers to spawn.
# Optional. Defaults to 1
#
# [*priority*]
# (optional) The priority for the vhost.
# Defaults to '10'
#
# [*threads*]
# (optional) The number of threads for the vhost.
# Defaults to $::processorcount
#
# [*ssl_cert*]
# [*ssl_key*]
# [*ssl_chain*]
# [*ssl_ca*]
# [*ssl_crl_path*]
# [*ssl_crl*]
# [*ssl_certs_dir*]
# apache::vhost ssl parameters.
# Optional. Default to apache::vhost 'ssl_*' defaults.
#
# == Dependencies
#
# requires Class['apache'] & Class['gnocchi']
#
# == Examples
#
# include apache
#
# class { 'gnocchi::wsgi::apache': }
#
class gnocchi::wsgi::apache (
$servername = $::fqdn,
$port = 8041,
$bind_host = undef,
$path = '/',
$ssl = true,
$workers = 1,
$ssl_cert = undef,
$ssl_key = undef,
$ssl_chain = undef,
$ssl_ca = undef,
$ssl_crl_path = undef,
$ssl_crl = undef,
$ssl_certs_dir = undef,
$threads = $::processorcount,
$priority = '10',
) {
include ::gnocchi::params
include ::apache
include ::apache::mod::wsgi
if $ssl {
include ::apache::mod::ssl
}
::openstacklib::wsgi::apache { 'gnocchi_wsgi':
bind_host => $bind_host,
bind_port => $port,
group => 'gnocchi',
path => $path,
priority => $priority,
servername => $servername,
ssl => $ssl,
ssl_ca => $ssl_ca,
ssl_cert => $ssl_cert,
ssl_certs_dir => $ssl_certs_dir,
ssl_chain => $ssl_chain,
ssl_crl => $ssl_crl,
ssl_crl_path => $ssl_crl_path,
ssl_key => $ssl_key,
threads => $threads,
user => 'gnocchi',
workers => $workers,
wsgi_daemon_process => 'gnocchi',
wsgi_process_group => 'gnocchi',
wsgi_script_dir => $::gnocchi::params::gnocchi_wsgi_script_path,
wsgi_script_file => 'app',
wsgi_script_source => $::gnocchi::params::gnocchi_wsgi_script_source,
}
}

View File

@ -1 +1,116 @@
require 'spec_helper_acceptance'
describe 'basic gnocchi' do
context 'default parameters' do
it 'should work with no errors' do
pp= <<-EOS
Exec { logoutput => 'on_failure' }
# Common resources
case $::osfamily {
'Debian': {
include ::apt
class { '::openstack_extras::repo::debian::ubuntu':
release => 'liberty',
repo => 'proposed',
package_require => true,
}
}
'RedHat': {
class { '::openstack_extras::repo::redhat::redhat':
manage_rdo => false,
repo_hash => {
'openstack-common-testing' => {
'baseurl' => 'http://cbs.centos.org/repos/cloud7-openstack-common-testing/x86_64/os/',
'descr' => 'openstack-common-testing',
'gpgcheck' => 'no',
},
'openstack-liberty-testing' => {
'baseurl' => 'http://cbs.centos.org/repos/cloud7-openstack-liberty-testing/x86_64/os/',
'descr' => 'openstack-liberty-testing',
'gpgcheck' => 'no',
},
'openstack-liberty-trunk' => {
'baseurl' => 'http://trunk.rdoproject.org/centos7-liberty/current-passed-ci/',
'descr' => 'openstack-liberty-trunk',
'gpgcheck' => 'no',
},
},
}
package { 'openstack-selinux': ensure => 'latest' }
}
default: {
fail("Unsupported osfamily (${::osfamily})")
}
}
class { '::mysql::server': }
# Keystone resources, needed by Gnocchi to run
class { '::keystone::db::mysql':
password => 'keystone',
}
class { '::keystone':
verbose => true,
debug => true,
database_connection => 'mysql://keystone:keystone@127.0.0.1/keystone',
admin_token => 'admin_token',
enabled => true,
}
class { '::keystone::roles::admin':
email => 'test@example.tld',
password => 'a_big_secret',
}
class { '::keystone::endpoint':
public_url => "https://${::fqdn}:5000/",
admin_url => "https://${::fqdn}:35357/",
}
class { '::gnocchi::db::mysql':
password => 'a_big_secret',
}
class { '::gnocchi::keystone::auth':
password => 'a_big_secret',
}
case $::osfamily {
'Debian': {
warning('Gnocchi is not yet packaged on Ubuntu systems.')
}
'RedHat': {
class { '::gnocchi':
verbose => true,
debug => true,
database_connection => 'mysql://gnocchi:a_big_secret@127.0.0.1/gnocchi?charset=utf8',
}
class { '::gnocchi::api':
enabled => true,
keystone_password => 'a_big_secret',
keystone_identity_uri => 'http://127.0.0.1:35357/',
service_name => 'httpd',
}
class { '::gnocchi::db::sync': }
class { '::gnocchi::storage': }
class { '::gnocchi::storage::file': }
include ::apache
class { '::gnocchi::wsgi::apache':
ssl => false,
}
}
}
EOS
# Run it twice and test for idempotency
apply_manifest(pp, :catch_failures => true)
apply_manifest(pp, :catch_changes => true)
end
if os[:family].casecmp('RedHat') == 0
describe port(8041) do
it { is_expected.to be_listening }
end
end
end
end

View File

@ -1,56 +1,137 @@
#
# Unit tests for gnocchi::api
#
require 'spec_helper'
describe 'gnocchi::api' do
let :pre_condition do
"class { 'gnocchi': }
include ::gnocchi::db"
end
let :params do
{ :keystone_password => 'passw0rd',
{ :enabled => true,
:manage_service => true,
:keystone_password => 'gnocchi-passw0rd',
:keystone_tenant => 'services',
:keystone_user => 'gnocchi',
:identity_uri => 'https://identity.os.net:5000',
:keystone_tenant => '_services_',
:package_ensure => 'latest',
:port => '8041',
:max_limit => '1000',
:host => '0.0.0.0',
}
end
shared_examples 'gnocchi-api' do
shared_examples_for 'gnocchi-api' do
context 'with default parameters' do
it 'contains the logging class' do
is_expected.to contain_class('gnocchi::logging')
context 'without required parameter keystone_password' do
before { params.delete(:keystone_password) }
it { expect { is_expected.to raise_error(Puppet::Error) } }
end
it 'installs gnocchi-api package and service' do
is_expected.to contain_service('gnocchi-api').with(
:name => platform_params[:api_service_name],
:ensure => 'running',
:hasstatus => true,
:enable => true
)
it { is_expected.to contain_class('gnocchi::params') }
it { is_expected.to contain_class('gnocchi::policy') }
it 'installs gnocchi-api package' do
is_expected.to contain_package('gnocchi-api').with(
:ensure => 'latest',
:name => platform_params[:api_package_name],
:ensure => 'present',
:notify => 'Service[gnocchi-api]'
:tag => ['openstack', 'gnocchi-package'],
)
end
it 'configures gnocchi-api with default parameters' do
is_expected.to contain_gnocchi_config('keystone_authtoken/identity_uri').with_value(params[:identity_uri])
is_expected.to contain_gnocchi_config('keystone_authtoken/admin_tenant_name').with_value(params[:keystone_tenant])
is_expected.to contain_gnocchi_config('keystone_authtoken/admin_user').with_value(params[:keystone_user])
is_expected.to contain_gnocchi_config('keystone_authtoken/admin_password').with_value(params[:keystone_password])
is_expected.to contain_gnocchi_config('keystone_authtoken/admin_password').with_value(params[:keystone_password]).with_secret(true)
it 'configures keystone authentication middleware' do
is_expected.to contain_gnocchi_config('keystone_authtoken/admin_tenant_name').with_value( params[:keystone_tenant] )
is_expected.to contain_gnocchi_config('keystone_authtoken/admin_user').with_value( params[:keystone_user] )
is_expected.to contain_gnocchi_config('keystone_authtoken/admin_password').with_value( params[:keystone_password] )
is_expected.to contain_gnocchi_config('keystone_authtoken/admin_password').with_value( params[:keystone_password] ).with_secret(true)
is_expected.to contain_gnocchi_config('api/host').with_value( params[:host] )
is_expected.to contain_gnocchi_config('api/port').with_value( params[:port] )
is_expected.to contain_gnocchi_config('api/max_limit').with_value( params[:max_limit] )
is_expected.to contain_gnocchi_config('api/workers').with_value('2')
end
[{:enabled => true}, {:enabled => false}].each do |param_hash|
context "when service should be #{param_hash[:enabled] ? 'enabled' : 'disabled'}" do
before do
params.merge!(param_hash)
end
it 'configures gnocchi-api service' do
is_expected.to contain_service('gnocchi-api').with(
:ensure => (params[:manage_service] && params[:enabled]) ? 'running' : 'stopped',
:name => platform_params[:api_service_name],
:enable => params[:enabled],
:hasstatus => true,
:hasrestart => true,
:require => 'Class[Gnocchi::Db]',
:tag => ['gnocchi-service', 'gnocchi-db-sync-service'],
)
end
end
end
context 'with disabled service managing' do
before do
params.merge!({
:manage_service => false,
:enabled => false })
end
it 'configures gnocchi-api service' do
is_expected.to contain_service('gnocchi-api').with(
:ensure => nil,
:name => platform_params[:api_service_name],
:enable => false,
:hasstatus => true,
:hasrestart => true,
:tag => ['gnocchi-service', 'gnocchi-db-sync-service'],
)
end
end
context 'when running gnocchi-api in wsgi' do
before do
params.merge!({ :service_name => 'httpd' })
end
let :pre_condition do
"include ::apache
include ::gnocchi::db
class { 'gnocchi': }"
end
it 'configures gnocchi-api service with Apache' do
is_expected.to contain_service('gnocchi-api').with(
:ensure => 'stopped',
:name => platform_params[:api_service_name],
:enable => false,
:tag => ['gnocchi-service', 'gnocchi-db-sync-service'],
)
end
end
context 'when service_name is not valid' do
before do
params.merge!({ :service_name => 'foobar' })
end
let :pre_condition do
"include ::apache
include ::gnocchi::db
class { 'gnocchi': }"
end
it_raises 'a Puppet::Error', /Invalid service_name/
end
end
context 'on Debian platforms' do
let :facts do
{
:osfamily => 'Debian'
}
{ :osfamily => 'Debian',
:operatingsystem => 'Debian',
:operatingsystemrelease => '8.0',
:concat_basedir => '/var/lib/puppet/concat',
:fqdn => 'some.host.tld',
:processorcount => 2 }
end
let :platform_params do
@ -63,9 +144,12 @@ describe 'gnocchi::api' do
context 'on RedHat platforms' do
let :facts do
{
:osfamily => 'RedHat'
}
{ :osfamily => 'RedHat',
:operatingsystem => 'RedHat',
:operatingsystemrelease => '7.1',
:fqdn => 'some.host.tld',
:concat_basedir => '/var/lib/puppet/concat',
:processorcount => 2 }
end
let :platform_params do
@ -76,4 +160,48 @@ describe 'gnocchi::api' do
it_configures 'gnocchi-api'
end
describe 'with custom auth_uri' do
let :facts do
{ :osfamily => 'RedHat' }
end
before do
params.merge!({
:keystone_auth_uri => 'https://foo.bar:1234/',
})
end
it 'should configure custom auth_uri correctly' do
is_expected.to contain_gnocchi_config('keystone_authtoken/auth_uri').with_value( 'https://foo.bar:1234/' )
end
end
describe "with custom keystone identity_uri" do
let :facts do
{ :osfamily => 'RedHat' }
end
before do
params.merge!({
:keystone_identity_uri => 'https://foo.bar:1234/',
})
end
it 'configures identity_uri' do
is_expected.to contain_gnocchi_config('keystone_authtoken/identity_uri').with_value("https://foo.bar:1234/");
end
end
describe "with custom keystone identity_uri and auth_uri" do
let :facts do
{ :osfamily => 'RedHat' }
end
before do
params.merge!({
:keystone_identity_uri => 'https://foo.bar:35357/',
:keystone_auth_uri => 'https://foo.bar:5000/v2.0/',
})
end
it 'configures identity_uri and auth_uri but deprecates old auth settings' do
is_expected.to contain_gnocchi_config('keystone_authtoken/identity_uri').with_value("https://foo.bar:35357/");
is_expected.to contain_gnocchi_config('keystone_authtoken/auth_uri').with_value("https://foo.bar:5000/v2.0/");
end
end
end

View File

@ -1,6 +1,3 @@
#
# Unit tests for gnocchi::db::mysql
#
require 'spec_helper'
describe 'gnocchi::db::mysql' do
@ -12,84 +9,54 @@ describe 'gnocchi::db::mysql' do
]
end
let :params do
{ :dbname => 'gnocchi',
:password => 's3cr3t',
:user => 'gnocchi',
:charset => 'utf8',
:collate => 'utf8_general_ci',
:host => '127.0.0.1',
}
end
shared_examples_for 'gnocchi mysql database' do
context 'when omiting the required parameter password' do
before { params.delete(:password) }
it { expect { is_expected.to raise_error(Puppet::Error) } }
end
it 'creates a mysql database' do
is_expected.to contain_openstacklib__db__mysql('gnocchi').with(
:user => params[:user],
:dbname => params[:dbname],
:password_hash => '*58C036CDA51D8E8BBBBF2F9EA5ABF111ADA444F0',
:host => params[:host],
:charset => params[:charset]
)
end
context 'overriding allowed_hosts param to array' do
before :each do
params.merge!(
:allowed_hosts => ['127.0.0.1','%']
)
end
it {
is_expected.to contain_openstacklib__db__mysql('gnocchi').with(
:user => params[:user],
:dbname => params[:dbname],
:password_hash => '*58C036CDA51D8E8BBBBF2F9EA5ABF111ADA444F0',
:host => params[:host],
:charset => params[:charset],
:allowed_hosts => ['127.0.0.1','%']
)}
end
context 'overriding allowed_hosts param to string' do
before :each do
params.merge!(
:allowed_hosts => '192.168.1.1'
)
end
it {
is_expected.to contain_openstacklib__db__mysql('gnocchi').with(
:user => params[:user],
:dbname => params[:dbname],
:password_hash => '*58C036CDA51D8E8BBBBF2F9EA5ABF111ADA444F0',
:host => params[:host],
:charset => params[:charset],
:allowed_hosts => '192.168.1.1'
)}
end
end
context 'on Debian platforms' do
let :facts do
{ :osfamily => 'Debian' }
end
it_configures 'gnocchi mysql database'
let :params do
{
'password' => 'fooboozoo_default_password',
}
end
context 'on RedHat platforms' do
let :facts do
{ :osfamily => 'RedHat' }
describe 'with only required params' do
it { is_expected.to contain_openstacklib__db__mysql('gnocchi').with(
'user' => 'gnocchi',
'password_hash' => '*3DDF34A86854A312A8E2C65B506E21C91800D206',
'dbname' => 'gnocchi',
'host' => '127.0.0.1',
'charset' => 'utf8',
:collate => 'utf8_general_ci',
)}
end
it_configures 'gnocchi mysql database'
describe "overriding allowed_hosts param to array" do
let :params do
{
:password => 'gnocchipass',
:allowed_hosts => ['127.0.0.1','%']
}
end
end
describe "overriding allowed_hosts param to string" do
let :params do
{
:password => 'gnocchipass2',
:allowed_hosts => '192.168.1.1'
}
end
end
describe "overriding allowed_hosts param equals to host param " do
let :params do
{
:password => 'gnocchipass2',
:allowed_hosts => '127.0.0.1'
}
end
end
end

View File

@ -5,35 +5,23 @@ describe 'gnocchi::db' do
shared_examples 'gnocchi::db' do
context 'with default parameters' do
it { is_expected.to contain_gnocchi_config('indexer/url').with_value('sqlite:////var/lib/gnocchi/gnocchi.sqlite').with_secret(true) }
it { is_expected.to contain_gnocchi_config('database/connection').with_value('sqlite:////var/lib/gnocchi/gnocchi.sqlite').with_secret(true) }
it { is_expected.to contain_gnocchi_config('database/idle_timeout').with_value('3600') }
it { is_expected.to contain_gnocchi_config('database/min_pool_size').with_value('1') }
it { is_expected.to contain_gnocchi_config('database/max_pool_size').with_value('10') }
it { is_expected.to contain_gnocchi_config('database/max_overflow').with_value('20') }
it { is_expected.to contain_gnocchi_config('database/max_retries').with_value('10') }
it { is_expected.to contain_gnocchi_config('database/retry_interval').with_value('10') }
it 'installs packages' do
is_expected.to contain_package('gnocchi-indexer-sqlalchemy').with(
:name => platform_params[:gnocchi_indexer_package],
:ensure => 'present',
:tag => ['openstack', 'gnocchi-package']
)
end
end
context 'with specific parameters' do
let :params do
{ :database_connection => 'mysql://gnocchi:gnocchi@localhost/gnocchi',
:database_idle_timeout => '3601',
:database_min_pool_size => '2',
:database_max_pool_size => '21',
:database_max_retries => '11',
:database_max_overflow => '21',
:database_retry_interval => '11', }
{ :database_connection => 'mysql://gnocchi:gnocchi@localhost/gnocchi' }
end
it { is_expected.to contain_gnocchi_config('database/connection').with_value('mysql://gnocchi:gnocchi@localhost/gnocchi').with_secret(true) }
it { is_expected.to contain_gnocchi_config('database/idle_timeout').with_value('3601') }
it { is_expected.to contain_gnocchi_config('database/min_pool_size').with_value('2') }
it { is_expected.to contain_gnocchi_config('database/max_retries').with_value('11') }
it { is_expected.to contain_gnocchi_config('database/max_pool_size').with_value('21') }
it { is_expected.to contain_gnocchi_config('database/max_overflow').with_value('21') }
it { is_expected.to contain_gnocchi_config('database/retry_interval').with_value('11') }
it { is_expected.to contain_gnocchi_config('indexer/url').with_value('mysql://gnocchi:gnocchi@localhost/gnocchi').with_secret(true) }
end
@ -66,6 +54,10 @@ describe 'gnocchi::db' do
}
end
let :platform_params do
{ :gnocchi_indexer_package => 'gnocchi-indexer-sqlalchemy' }
end
it_configures 'gnocchi::db'
end
@ -76,6 +68,10 @@ describe 'gnocchi::db' do
}
end
let :platform_params do
{ :gnocchi_indexer_package => 'openstack-gnocchi-indexer-sqlalchemy' }
end
it_configures 'gnocchi::db'
end

View File

@ -1,23 +1,35 @@
#
# Unit tests for gnocchi::init
#
require 'spec_helper'
describe 'gnocchi' do
shared_examples_for 'gnocchi' do
it {
is_expected.to contain_class('gnocchi::params')
is_expected.to contain_exec('post-gnocchi_config')
}
shared_examples 'gnocchi' do
context 'with default parameters' do
it 'contains the logging class' do
is_expected.to contain_class('gnocchi::logging')
end
it 'installs packages' do
is_expected.to contain_package('gnocchi').with(
:name => platform_params[:gnocchi_common_package],
:ensure => 'present',
:tag => ['openstack', 'gnocchi-package']
)
end
end
end
context 'on Debian platforms' do
let :facts do
{ :osfamily => 'Debian' }
{ :osfamily => 'Debian',
:operatingsystem => 'Debian' }
end
it_configures 'gnocchi'
let :platform_params do
{ :gnocchi_common_package => 'gnocchi-common' }
end
it_behaves_like 'gnocchi'
end
context 'on RedHat platforms' do
@ -25,6 +37,11 @@ describe 'gnocchi' do
{ :osfamily => 'RedHat' }
end
it_configures 'gnocchi'
let :platform_params do
{ :gnocchi_common_package => 'openstack-gnocchi-common' }
end
it_behaves_like 'gnocchi'
end
end

View File

@ -1,6 +1,7 @@
#
# Unit tests for gnocchi::keystone::auth
#
require 'spec_helper'
describe 'gnocchi::keystone::auth' do
@ -27,47 +28,96 @@ describe 'gnocchi::keystone::auth' do
it { is_expected.to contain_keystone_service('gnocchi').with(
:ensure => 'present',
:type => 'gnocchi',
:description => 'OpenStack Datapoint Service'
:type => 'metric',
:description => 'OpenStack Metric Service'
) }
it { is_expected.to contain_keystone_endpoint('RegionOne/gnocchi').with(
:ensure => 'present',
:public_url => "http://127.0.0.1:8041",
:admin_url => "http://127.0.0.1:8041",
:internal_url => "http://127.0.0.1:8041"
:public_url => 'http://127.0.0.1:8041',
:admin_url => 'http://127.0.0.1:8041',
:internal_url => 'http://127.0.0.1:8041',
) }
end
describe 'when overriding public_protocol, public_port and public_address' do
describe 'when overriding URL parameters' do
let :params do
{ :password => 'gnocchi_password',
:public_protocol => 'https',
:public_port => '80',
:public_address => '10.10.10.10',
:admin_port => '81',
:internal_port => '82',
:internal_address => '10.10.10.11',
:admin_address => '10.10.10.12' }
: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_endpoint('RegionOne/gnocchi').with(
:ensure => 'present',
:public_url => "https://10.10.10.10:80",
:internal_url => "http://10.10.10.11:82",
:admin_url => "http://10.10.10.12:81"
: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
describe 'when overriding auth name' do
let :params do
{ :password => 'foo',
:auth_name => 'gnocchy' }
:auth_name => 'gnocchiany' }
end
it { is_expected.to contain_keystone_user('gnocchy') }
it { is_expected.to contain_keystone_user_role('gnocchy@services') }
it { is_expected.to contain_keystone_service('gnocchy') }
it { is_expected.to contain_keystone_endpoint('RegionOne/gnocchy') }
it { is_expected.to contain_keystone_user('gnocchiany') }
it { is_expected.to contain_keystone_user_role('gnocchiany@services') }
it { is_expected.to contain_keystone_service('gnocchiany') }
it { is_expected.to contain_keystone_endpoint('RegionOne/gnocchiany') }
end
describe 'when overriding service name' do
let :params do
{ :service_name => 'gnocchi_service',
:auth_name => 'gnocchi',
:password => 'gnocchi_password' }
end
it { is_expected.to contain_keystone_user('gnocchi') }
it { is_expected.to contain_keystone_user_role('gnocchi@services') }
it { is_expected.to contain_keystone_service('gnocchi_service') }
it { is_expected.to contain_keystone_endpoint('RegionOne/gnocchi_service') }
end
describe 'when disabling user configuration' do
let :params do
{
:password => 'gnocchi_password',
:configure_user => false
}
end
it { is_expected.not_to contain_keystone_user('gnocchi') }
it { is_expected.to contain_keystone_user_role('gnocchi@services') }
it { is_expected.to contain_keystone_service('gnocchi').with(
:ensure => 'present',
:type => 'metric',
:description => 'OpenStack Metric Service'
) }
end
describe 'when disabling user and user role configuration' do
let :params do
{
:password => 'gnocchi_password',
:configure_user => false,
:configure_user_role => false
}
end
it { is_expected.not_to contain_keystone_user('gnocchi') }
it { is_expected.not_to contain_keystone_user_role('gnocchi@services') }
it { is_expected.to contain_keystone_service('gnocchi').with(
:ensure => 'present',
:type => 'metric',
:description => 'OpenStack Metric Service'
) }
end
end

View File

@ -28,7 +28,6 @@ describe 'gnocchi::logging' do
:use_stderr => false,
:log_facility => 'LOG_FOO',
:log_dir => '/var/log',
:log_file => '/var/log/foo.log',
:verbose => true,
:debug => true,
}
@ -61,7 +60,6 @@ describe 'gnocchi::logging' do
is_expected.to contain_gnocchi_config('DEFAULT/use_syslog').with(:value => 'false')
is_expected.to contain_gnocchi_config('DEFAULT/use_stderr').with(:value => 'true')
is_expected.to contain_gnocchi_config('DEFAULT/log_dir').with(:value => '/var/log/gnocchi')
is_expected.to contain_gnocchi_config('DEFAULT/log_file').with(:value => '/var/log/gnocchi/gnocchi-api.log')
is_expected.to contain_gnocchi_config('DEFAULT/verbose').with(:value => 'false')
is_expected.to contain_gnocchi_config('DEFAULT/debug').with(:value => 'false')
end
@ -73,7 +71,6 @@ describe 'gnocchi::logging' do
is_expected.to contain_gnocchi_config('DEFAULT/use_stderr').with(:value => 'false')
is_expected.to contain_gnocchi_config('DEFAULT/syslog_log_facility').with(:value => 'LOG_FOO')
is_expected.to contain_gnocchi_config('DEFAULT/log_dir').with(:value => '/var/log')
is_expected.to contain_gnocchi_config('DEFAULT/log_file').with(:value => '/var/log/foo.log')
is_expected.to contain_gnocchi_config('DEFAULT/verbose').with(:value => 'true')
is_expected.to contain_gnocchi_config('DEFAULT/debug').with(:value => 'true')
end

View File

@ -0,0 +1,41 @@
require 'spec_helper'
describe 'gnocchi::policy' do
shared_examples_for 'gnocchi policies' do
let :params do
{
:policy_path => '/etc/gnocchi/policy.json',
:policies => {
'context_is_admin' => {
'key' => 'context_is_admin',
'value' => 'foo:bar'
}
}
}
end
it 'set up the policies' do
is_expected.to contain_openstacklib__policy__base('context_is_admin').with({
:key => 'context_is_admin',
:value => 'foo:bar'
})
end
end
context 'on Debian platforms' do
let :facts do
{ :osfamily => 'Debian' }
end
it_configures 'gnocchi policies'
end
context 'on RedHat platforms' do
let :facts do
{ :osfamily => 'RedHat' }
end
it_configures 'gnocchi policies'
end
end

View File

@ -0,0 +1,47 @@
require 'spec_helper'
describe 'gnocchi::storage' do
let :params do
{ :package_ensure => 'latest' }
end
shared_examples_for 'gnocchi-storage' do
it { is_expected.to contain_class('gnocchi::params') }
it 'installs gnocchi-carbonara package' do
is_expected.to contain_package('gnocchi-carbonara').with(
:ensure => 'latest',
:name => platform_params[:carbonara_package_name],
:tag => ['openstack', 'gnocchi-package'],
)
end
end
context 'on Debian platforms' do
let :facts do
{ :osfamily => 'Debian',
:operatingsystem => 'Debian' }
end
let :platform_params do
{ :carbonara_package_name => 'gnocchi-carbonara' }
end
it_configures 'gnocchi-storage'
end
context 'on RedHat platforms' do
let :facts do
{ :osfamily => 'RedHat',
:operatingsystem => 'RedHat' }
end
let :platform_params do
{ :carbonara_package_name => 'openstack-gnocchi-carbonara' }
end
it_configures 'gnocchi-storage'
end
end

View File

@ -0,0 +1,124 @@
require 'spec_helper'
describe 'gnocchi::wsgi::apache' do
let :global_facts do
{
:processorcount => 42,
:concat_basedir => '/var/lib/puppet/concat',
:fqdn => 'some.host.tld'
}
end
shared_examples_for 'apache serving gnocchi with mod_wsgi' do
it { is_expected.to contain_service('httpd').with_name(platform_parameters[:httpd_service_name]) }
it { is_expected.to contain_class('gnocchi::params') }
it { is_expected.to contain_class('apache') }
it { is_expected.to contain_class('apache::mod::wsgi') }
describe 'with default parameters' do
it { is_expected.to contain_file("#{platform_parameters[:wsgi_script_path]}").with(
'ensure' => 'directory',
'owner' => 'gnocchi',
'group' => 'gnocchi',
'require' => 'Package[httpd]'
)}
it { is_expected.to contain_file('gnocchi_wsgi').with(
'ensure' => 'file',
'path' => "#{platform_parameters[:wsgi_script_path]}/app",
'source' => platform_parameters[:wsgi_script_source],
'owner' => 'gnocchi',
'group' => 'gnocchi',
'mode' => '0644'
)}
it { is_expected.to contain_file('gnocchi_wsgi').that_requires("File[#{platform_parameters[:wsgi_script_path]}]") }
it { is_expected.to contain_apache__vhost('gnocchi_wsgi').with(
'servername' => 'some.host.tld',
'ip' => nil,
'port' => '8041',
'docroot' => "#{platform_parameters[:wsgi_script_path]}",
'docroot_owner' => 'gnocchi',
'docroot_group' => 'gnocchi',
'ssl' => 'true',
'wsgi_daemon_process' => 'gnocchi',
'wsgi_process_group' => 'gnocchi',
'wsgi_script_aliases' => { '/' => "#{platform_parameters[:wsgi_script_path]}/app" },
'require' => 'File[gnocchi_wsgi]'
)}
it { is_expected.to contain_file("#{platform_parameters[:httpd_ports_file]}") }
end
describe 'when overriding parameters using different ports' do
let :params do
{
:servername => 'dummy.host',
:bind_host => '10.42.51.1',
:port => 12345,
:ssl => false,
:workers => 37,
}
end
it { is_expected.to contain_apache__vhost('gnocchi_wsgi').with(
'servername' => 'dummy.host',
'ip' => '10.42.51.1',
'port' => '12345',
'docroot' => "#{platform_parameters[:wsgi_script_path]}",
'docroot_owner' => 'gnocchi',
'docroot_group' => 'gnocchi',
'ssl' => 'false',
'wsgi_daemon_process' => 'gnocchi',
'wsgi_process_group' => 'gnocchi',
'wsgi_script_aliases' => { '/' => "#{platform_parameters[:wsgi_script_path]}/app" },
'require' => 'File[gnocchi_wsgi]'
)}
it { is_expected.to contain_file("#{platform_parameters[:httpd_ports_file]}") }
end
end
context 'on RedHat platforms' do
let :facts do
global_facts.merge({
:osfamily => 'RedHat',
:operatingsystemrelease => '7.0'
})
end
let :platform_parameters do
{
:httpd_service_name => 'httpd',
:httpd_ports_file => '/etc/httpd/conf/ports.conf',
:wsgi_script_path => '/var/www/cgi-bin/gnocchi',
:wsgi_script_source => '/usr/lib/python2.7/site-packages/gnocchi/rest/app.wsgi'
}
end
it_configures 'apache serving gnocchi with mod_wsgi'
end
context 'on Debian platforms' do
let :facts do
global_facts.merge({
:osfamily => 'Debian',
:operatingsystem => 'Debian',
:operatingsystemrelease => '7.0'
})
end
let :platform_parameters do
{
:httpd_service_name => 'apache2',
:httpd_ports_file => '/etc/apache2/ports.conf',
:wsgi_script_path => '/usr/lib/cgi-bin/gnocchi',
:wsgi_script_source => '/usr/share/gnocchi-common/app.wsgi'
}
end
it_configures 'apache serving gnocchi with mod_wsgi'
end
end