adding cookiecutter files

This commit is contained in:
Dan Radez 2015-11-07 06:10:42 -05:00
parent 1e35208a69
commit 1def594f3f
15 changed files with 1029 additions and 0 deletions

7
.gitignore vendored Normal file
View File

@ -0,0 +1,7 @@
Gemfile.lock
spec/fixtures/modules/*
spec/fixtures/manifests/site.pp
*.swp
pkg
vendor/
openstack/

4
.gitreview Normal file
View File

@ -0,0 +1,4 @@
[gerrit]
host=review.openstack.org
port=29418
project=openstack/puppet-tacker.git

78
README.md Normal file
View File

@ -0,0 +1,78 @@
tacker
=======
#### Table of Contents
1. [Overview - What is the tacker module?](#overview)
2. [Module Description - What does the module do?](#module-description)
3. [Setup - The basics of getting started with tacker](#setup)
4. [Implementation - An under-the-hood peek at what the module is doing](#implementation)
5. [Limitations - OS compatibility, etc.](#limitations)
6. [Development - Guide for contributing to the module](#development)
7. [Contributors - Those with commits](#contributors)
Overview
--------
The tacker 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.
Module Description
------------------
The tacker module is a thorough attempt to make Puppet capable of managing the entirety of tacker. This includes manifests to provision region specific endpoint and database connections. Types are shipped as part of the tacker module to assist in manipulation of configuration files.
Setup
-----
**What the tacker module affects**
* [Tacker](https://wiki.openstack.org/wiki/Tacker), the FIXME service for Openstack.
### Installing tacker
tacker is not currently in Puppet Forge, but is anticipated to be added soon. Once that happens, you'll be able to install tacker with:
puppet module install openstack/tacker
### Beginning with tacker
To utilize the tacker 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.
Implementation
--------------
### tacker
tacker is a combination of Puppet manifest and ruby code to delivery configuration and extra functionality through types and providers.
Limitations
------------
* All the tacker types use the CLI tools and so need to be ran on the tacker node.
Beaker-Rspec
------------
This module has beaker-rspec tests
To run the tests on the default vagrant node:
```shell
bundle install
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
Development
-----------
Developer documentation for the entire puppet-openstack project.
* https://wiki.openstack.org/wiki/Puppet
Contributors
------------
* https://github.com/openstack/puppet-tacker/graphs/contributors

251
manifests/logging.pp Normal file
View File

@ -0,0 +1,251 @@
# Class tacker::logging
#
# tacker logging configuration
#
# == parameters
#
# [*verbose*]
# (Optional) Should the daemons log verbose messages
# Defaults to false.
#
# [*debug*]
# (Optional) Should the daemons log debug messages
# Defaults to false.
#
# [*use_syslog*]
# (Optional) Use syslog for logging.
# Defaults to false.
#
# [*use_stderr*]
# (optional) Use stderr for logging
# Defaults to true.
#
# [*log_facility*]
# (Optional) Syslog facility to receive log lines.
# Defaults to 'LOG_USER'.
#
# [*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/tacker'.
#
# [*logging_context_format_string*]
# (optional) Format string to use for log messages with context.
# Defaults to undef.
# 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.
# 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.
# Example: '%(funcName)s %(pathname)s:%(lineno)d'
#
# [*logging_exception_prefix*]
# (optional) Prefix each line of exception output with this format.
# Defaults to undef.
# 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.
# See https://docs.python.org/2/howto/logging.html
#
# [*default_log_levels*]
# (optional) Hash of logger (keys) and level (values) pairs.
# Defaults to undef.
# Example:
# { 'amqp' => 'WARN', 'amqplib' => 'WARN', 'boto' => 'WARN',
# 'qpid' => 'WARN', 'sqlalchemy' => 'WARN', 'suds' => 'INFO',
# 'oslo.messaging' => 'INFO', 'iso8601' => 'WARN',
# 'requests.packages.urllib3.connectionpool' => 'WARN',
# 'urllib3.connectionpool' => 'WARN',
# 'websocket' => 'WARN', 'tackermiddleware' => 'WARN',
# 'routes.middleware' => 'WARN', stevedore => 'WARN' }
#
# [*publish_errors*]
# (optional) Publish error events (boolean value).
# Defaults to undef (false if unconfigured).
#
# [*fatal_deprecations*]
# (optional) Make deprecations fatal (boolean value)
# Defaults to undef (false if unconfigured).
#
# [*instance_format*]
# (optional) If an instance is passed with the log message, format it
# like this (string value).
# Defaults to undef.
# Example: '[instance: %(uuid)s] '
#
# [*instance_uuid_format*]
# (optional) If an instance UUID is passed with the log message, format
# it like this (string value).
# Defaults to undef.
# Example: instance_uuid_format='[instance: %(uuid)s] '
#
# [*log_date_format*]
# (optional) Format string for %%(asctime)s in log records.
# Defaults to undef.
# Example: 'Y-%m-%d %H:%M:%S'
class tacker::logging(
$use_syslog = false,
$use_stderr = true,
$log_facility = 'LOG_USER',
$log_dir = '/var/log/tacker',
$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,
) {
tacker_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;
}
if $logging_context_format_string {
tacker_config {
'DEFAULT/logging_context_format_string' :
value => $logging_context_format_string;
}
}
else {
tacker_config {
'DEFAULT/logging_context_format_string' : ensure => absent;
}
}
if $logging_default_format_string {
tacker_config {
'DEFAULT/logging_default_format_string' :
value => $logging_default_format_string;
}
}
else {
tacker_config {
'DEFAULT/logging_default_format_string' : ensure => absent;
}
}
if $logging_debug_format_suffix {
tacker_config {
'DEFAULT/logging_debug_format_suffix' :
value => $logging_debug_format_suffix;
}
}
else {
tacker_config {
'DEFAULT/logging_debug_format_suffix' : ensure => absent;
}
}
if $logging_exception_prefix {
tacker_config {
'DEFAULT/logging_exception_prefix' : value => $logging_exception_prefix;
}
}
else {
tacker_config {
'DEFAULT/logging_exception_prefix' : ensure => absent;
}
}
if $log_config_append {
tacker_config {
'DEFAULT/log_config_append' : value => $log_config_append;
}
}
else {
tacker_config {
'DEFAULT/log_config_append' : ensure => absent;
}
}
if $default_log_levels {
tacker_config {
'DEFAULT/default_log_levels' :
value => join(sort(join_keys_to_values($default_log_levels, '=')), ',');
}
}
else {
tacker_config {
'DEFAULT/default_log_levels' : ensure => absent;
}
}
if $publish_errors {
tacker_config {
'DEFAULT/publish_errors' : value => $publish_errors;
}
}
else {
tacker_config {
'DEFAULT/publish_errors' : ensure => absent;
}
}
if $fatal_deprecations {
tacker_config {
'DEFAULT/fatal_deprecations' : value => $fatal_deprecations;
}
}
else {
tacker_config {
'DEFAULT/fatal_deprecations' : ensure => absent;
}
}
if $instance_format {
tacker_config {
'DEFAULT/instance_format' : value => $instance_format;
}
}
else {
tacker_config {
'DEFAULT/instance_format' : ensure => absent;
}
}
if $instance_uuid_format {
tacker_config {
'DEFAULT/instance_uuid_format' : value => $instance_uuid_format;
}
}
else {
tacker_config {
'DEFAULT/instance_uuid_format' : ensure => absent;
}
}
if $log_date_format {
tacker_config {
'DEFAULT/log_date_format' : value => $log_date_format;
}
}
else {
tacker_config {
'DEFAULT/log_date_format' : ensure => absent;
}
}
}

34
metadata.json Normal file
View File

@ -0,0 +1,34 @@
{
"name": "puppet-tacker",
"version": "0.0.1",
"author": "OpenStack Contributors",
"summary": "Puppet module for OpenStack Tacker",
"license": "Apache-2.0",
"source": "git://github.com/openstack/puppet-tacker.git",
"project_page": "https://launchpad.net/puppet-tacker",
"issues_url": "https://bugs.launchpad.net/puppet-tacker",
"description": "Installs and configures OpenStack Tacker.",
"operatingsystem_support": [
{
"operatingsystem": "Debian",
"operatingsystemrelease": ["8"]
},
{
"operatingsystem": "Fedora",
"operatingsystemrelease": ["21","22"]
},
{
"operatingsystem": "RedHat",
"operatingsystemrelease": ["7"]
},
{
"operatingsystem": "Ubuntu",
"operatingsystemrelease": ["14.04"]
}
],
"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" }
]
}

View File

@ -0,0 +1,62 @@
require 'spec_helper'
describe 'tacker::db::mysql' do
let :pre_condition do
[
'include mysql::server',
'include tacker::db::sync'
]
end
let :facts do
{ :osfamily => 'Debian' }
end
let :params do
{
'password' => 'fooboozoo_default_password',
}
end
describe 'with only required params' do
it { is_expected.to contain_openstacklib__db__mysql('tacker').with(
'user' => 'tacker',
'password_hash' => '*3DDF34A86854A312A8E2C65B506E21C91800D206',
'dbname' => 'tacker',
'host' => '127.0.0.1',
'charset' => 'utf8',
:collate => 'utf8_general_ci',
)}
end
describe "overriding allowed_hosts param to array" do
let :params do
{
:password => 'tackerpass',
:allowed_hosts => ['127.0.0.1','%']
}
end
end
describe "overriding allowed_hosts param to string" do
let :params do
{
:password => 'tackerpass2',
:allowed_hosts => '192.168.1.1'
}
end
end
describe "overriding allowed_hosts param equals to host param " do
let :params do
{
:password => 'tackerpass2',
:allowed_hosts => '127.0.0.1'
}
end
end
end

View File

@ -0,0 +1,58 @@
require 'spec_helper'
describe 'tacker::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
context 'with only required parameters' do
let :params do
req_params
end
it { is_expected.to contain_postgresql__server__db('tacker').with(
:user => 'tacker',
:password => 'md5c530c33636c58ae83ca933f39319273e'
)}
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
end
it { is_expected.to contain_postgresql__server__db('tacker').with(
:user => 'tacker',
:password => 'md5c530c33636c58ae83ca933f39319273e'
)}
end
end
end

View File

@ -0,0 +1,78 @@
require 'spec_helper'
describe 'tacker::db' do
shared_examples 'tacker::db' do
context 'with default parameters' do
it { is_expected.to contain_tacker_config('database/connection').with_value('mysql://tacker:secrete@localhost:3306/tacker') }
it { is_expected.to contain_tacker_config('database/idle_timeout').with_value('3600') }
it { is_expected.to contain_tacker_config('database/min_pool_size').with_value('1') }
it { is_expected.to contain_tacker_config('database/max_retries').with_value('10') }
it { is_expected.to contain_tacker_config('database/retry_interval').with_value('10') }
it { is_expected.to contain_tacker_config('database/max_pool_size').with_value('10') }
it { is_expected.to contain_tacker_config('database/max_overflow').with_value('20') }
end
context 'with specific parameters' do
let :params do
{ :database_connection => 'mysql://tacker:tacker@localhost/tacker',
:database_idle_timeout => '3601',
:database_min_pool_size => '2',
:database_max_retries => '11',
:database_retry_interval => '11',
:database_max_pool_size => '11',
:database_max_overflow => '21',
}
end
it { is_expected.to contain_tacker_config('database/connection').with_value('mysql://tacker:tacker@localhost/tacker') }
it { is_expected.to contain_tacker_config('database/idle_timeout').with_value('3601') }
it { is_expected.to contain_tacker_config('database/min_pool_size').with_value('2') }
it { is_expected.to contain_tacker_config('database/max_retries').with_value('11') }
it { is_expected.to contain_tacker_config('database/retry_interval').with_value('11') }
it { is_expected.to contain_tacker_config('database/max_pool_size').with_value('11') }
it { is_expected.to contain_tacker_config('database/max_overflow').with_value('21') }
end
context 'with postgresql backend' do
let :params do
{ :database_connection => 'postgresql://tacker:tacker@localhost/tacker', }
end
it 'install the proper backend package' do
is_expected.to contain_package('python-psycopg2').with(:ensure => 'present')
end
end
context 'with incorrect database_connection string' do
let :params do
{ :database_connection => 'sqlite://tacker:tacker@localhost/tacker', }
end
it_raises 'a Puppet::Error', /validate_re/
end
end
context 'on Debian platforms' do
let :facts do
{ :osfamily => 'Debian',
:operatingsystem => 'Debian',
:operatingsystemrelease => 'jessie',
}
end
it_configures 'tacker::db'
end
context 'on Redhat platforms' do
let :facts do
{ :osfamily => 'RedHat',
:operatingsystemrelease => '7.1',
}
end
it_configures 'tacker::db'
end
end

View File

@ -0,0 +1,123 @@
#
# Unit tests for tacker::keystone::auth
#
require 'spec_helper'
describe 'tacker::keystone::auth' do
let :facts do
{ :osfamily => 'Debian' }
end
describe 'with default class parameters' do
let :params do
{ :password => 'tacker_password',
:tenant => 'foobar' }
end
it { is_expected.to contain_keystone_user('tacker').with(
:ensure => 'present',
:password => 'tacker_password',
) }
it { is_expected.to contain_keystone_user_role('tacker@foobar').with(
:ensure => 'present',
:roles => ['admin']
)}
it { is_expected.to contain_keystone_service('tacker').with(
:ensure => 'present',
:type => 'FIXME',
:description => 'tacker FIXME Service'
) }
it { is_expected.to contain_keystone_endpoint('RegionOne/tacker').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 => 'tacker_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_endpoint('RegionOne/tacker').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
describe 'when overriding auth name' do
let :params do
{ :password => 'foo',
:auth_name => 'tackery' }
end
it { is_expected.to contain_keystone_user('tackery') }
it { is_expected.to contain_keystone_user_role('tackery@services') }
it { is_expected.to contain_keystone_service('tackery') }
it { is_expected.to contain_keystone_endpoint('RegionOne/tackery') }
end
describe 'when overriding service name' do
let :params do
{ :service_name => 'tacker_service',
:auth_name => 'tacker',
:password => 'tacker_password' }
end
it { is_expected.to contain_keystone_user('tacker') }
it { is_expected.to contain_keystone_user_role('tacker@services') }
it { is_expected.to contain_keystone_service('tacker_service') }
it { is_expected.to contain_keystone_endpoint('RegionOne/tacker_service') }
end
describe 'when disabling user configuration' do
let :params do
{
:password => 'tacker_password',
:configure_user => false
}
end
it { is_expected.not_to contain_keystone_user('tacker') }
it { is_expected.to contain_keystone_user_role('tacker@services') }
it { is_expected.to contain_keystone_service('tacker').with(
:ensure => 'present',
:type => 'FIXME',
:description => 'tacker FIXME Service'
) }
end
describe 'when disabling user and user role configuration' do
let :params do
{
:password => 'tacker_password',
:configure_user => false,
:configure_user_role => false
}
end
it { is_expected.not_to contain_keystone_user('tacker') }
it { is_expected.not_to contain_keystone_user_role('tacker@services') }
it { is_expected.to contain_keystone_service('tacker').with(
:ensure => 'present',
:type => 'FIXME',
:description => 'tacker FIXME Service'
) }
end
end

View File

@ -0,0 +1,144 @@
require 'spec_helper'
describe 'tacker::logging' do
let :params do
{
}
end
let :log_params do
{
:logging_context_format_string => '%(asctime)s.%(msecs)03d %(process)d %(levelname)s %(name)s [%(request_id)s %(user_identity)s] %(instance)s%(message)s',
:logging_default_format_string => '%(asctime)s.%(msecs)03d %(process)d %(levelname)s %(name)s [-] %(instance)s%(message)s',
:logging_debug_format_suffix => '%(funcName)s %(pathname)s:%(lineno)d',
:logging_exception_prefix => '%(asctime)s.%(msecs)03d %(process)d TRACE %(name)s %(instance)s',
:log_config_append => '/etc/tacker/logging.conf',
:publish_errors => true,
:default_log_levels => {
'amqp' => 'WARN', 'amqplib' => 'WARN', 'boto' => 'WARN',
'qpid' => 'WARN', 'sqlalchemy' => 'WARN', 'suds' => 'INFO',
'iso8601' => 'WARN',
'requests.packages.urllib3.connectionpool' => 'WARN' },
:fatal_deprecations => true,
:instance_format => '[instance: %(uuid)s] ',
:instance_uuid_format => '[instance: %(uuid)s] ',
:log_date_format => '%Y-%m-%d %H:%M:%S',
:use_syslog => true,
:use_stderr => false,
:log_facility => 'LOG_FOO',
:log_dir => '/var/log',
:verbose => true,
:debug => true,
}
end
shared_examples_for 'tacker-logging' do
context 'with basic logging options and default settings' do
it_configures 'basic default logging settings'
end
context 'with basic logging options and non-default settings' do
before { params.merge!( log_params ) }
it_configures 'basic non-default logging settings'
end
context 'with extended logging options' do
before { params.merge!( log_params ) }
it_configures 'logging params set'
end
context 'without extended logging options' do
it_configures 'logging params unset'
end
end
shared_examples 'basic default logging settings' do
it 'configures 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/tacker')
is_expected.to contain_ceilometer_config('DEFAULT/verbose').with(:value => 'false')
is_expected.to contain_ceilometer_config('DEFAULT/debug').with(:value => 'false')
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')
end
end
shared_examples_for 'logging params set' do
it 'enables logging params' do
is_expected.to contain_tacker_config('DEFAULT/logging_context_format_string').with_value(
'%(asctime)s.%(msecs)03d %(process)d %(levelname)s %(name)s [%(request_id)s %(user_identity)s] %(instance)s%(message)s')
is_expected.to contain_tacker_config('DEFAULT/logging_default_format_string').with_value(
'%(asctime)s.%(msecs)03d %(process)d %(levelname)s %(name)s [-] %(instance)s%(message)s')
is_expected.to contain_tacker_config('DEFAULT/logging_debug_format_suffix').with_value(
'%(funcName)s %(pathname)s:%(lineno)d')
is_expected.to contain_tacker_config('DEFAULT/logging_exception_prefix').with_value(
'%(asctime)s.%(msecs)03d %(process)d TRACE %(name)s %(instance)s')
is_expected.to contain_tacker_config('DEFAULT/log_config_append').with_value(
'/etc/tacker/logging.conf')
is_expected.to contain_tacker_config('DEFAULT/publish_errors').with_value(
true)
is_expected.to contain_tacker_config('DEFAULT/default_log_levels').with_value(
'amqp=WARN,amqplib=WARN,boto=WARN,iso8601=WARN,qpid=WARN,requests.packages.urllib3.connectionpool=WARN,sqlalchemy=WARN,suds=INFO')
is_expected.to contain_tacker_config('DEFAULT/fatal_deprecations').with_value(
true)
is_expected.to contain_tacker_config('DEFAULT/instance_format').with_value(
'[instance: %(uuid)s] ')
is_expected.to contain_tacker_config('DEFAULT/instance_uuid_format').with_value(
'[instance: %(uuid)s] ')
is_expected.to contain_tacker_config('DEFAULT/log_date_format').with_value(
'%Y-%m-%d %H:%M:%S')
end
end
shared_examples_for 'logging params unset' do
[ :logging_context_format_string, :logging_default_format_string,
:logging_debug_format_suffix, :logging_exception_prefix,
:log_config_append, :publish_errors,
:default_log_levels, :fatal_deprecations,
:instance_format, :instance_uuid_format,
:log_date_format, ].each { |param|
it { is_expected.to contain_tacker_config("DEFAULT/#{param}").with_ensure('absent') }
}
end
context 'on Debian platforms' do
let :facts do
{ :osfamily => 'Debian' }
end
it_configures 'tacker-logging'
end
context 'on RedHat platforms' do
let :facts do
{ :osfamily => 'RedHat' }
end
it_configures 'tacker-logging'
end
end

View File

@ -0,0 +1,41 @@
require 'spec_helper'
describe 'tacker::policy' do
shared_examples_for 'tacker policies' do
let :params do
{
:policy_path => '/etc/tacker/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 'tacker policies'
end
context 'on RedHat platforms' do
let :facts do
{ :osfamily => 'RedHat' }
end
it_configures 'tacker policies'
end
end

5
spec/shared_examples.rb Normal file
View File

@ -0,0 +1,5 @@
shared_examples_for "a Puppet::Error" do |description|
it "with message matching #{description.inspect}" do
expect { is_expected.to have_class_count(1) }.to raise_error(Puppet::Error, description)
end
end

View File

@ -0,0 +1,68 @@
#
# these tests are a little concerning b/c they are hacking around the
# modulepath, so these tests will not catch issues that may eventually arise
# related to loading these plugins.
# I could not, for the life of me, figure out how to programatcally set the modulepath
$LOAD_PATH.push(
File.join(
File.dirname(__FILE__),
'..',
'..',
'..',
'fixtures',
'modules',
'inifile',
'lib')
)
$LOAD_PATH.push(
File.join(
File.dirname(__FILE__),
'..',
'..',
'..',
'fixtures',
'modules',
'openstacklib',
'lib')
)
require 'spec_helper'
provider_class = Puppet::Type.type(:tacker_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::Tacker_config.new(
{:name => 'DEFAULT/foo', :value => 'bar'}
)
provider = provider_class.new(resource)
expect(provider.section).to eq('DEFAULT')
expect(provider.setting).to eq('foo')
end
it 'should allow setting to be set explicitly' do
resource = Puppet::Type::Tacker_config.new(
{:name => 'dude/foo', :value => 'bar'}
)
provider = provider_class.new(resource)
expect(provider.section).to eq('dude')
expect(provider.setting).to eq('foo')
end
it 'should ensure absent when <SERVICE DEFAULT> is specified as a value' do
resource = Puppet::Type::Tacker_config.new(
{:name => 'dude/foo', :value => '<SERVICE DEFAULT>'}
)
provider = provider_class.new(resource)
provider.exists?
expect(resource[:ensure]).to eq :absent
end
it 'should ensure absent when value matches ensure_absent_val' do
resource = Puppet::Type::Tacker_config.new(
{:name => 'dude/foo', :value => 'foo', :ensure_absent_val => 'foo' }
)
provider = provider_class.new(resource)
provider.exists?
expect(resource[:ensure]).to eq :absent
end
end

View File

@ -0,0 +1,64 @@
require 'puppet'
require 'puppet/type/tacker_config'
describe 'Puppet::Type.type(:tacker_config)' do
before :each do
@tacker_config = Puppet::Type.type(:tacker_config).new(:name => 'DEFAULT/foo', :value => 'bar')
end
it 'should require a name' do
expect {
Puppet::Type.type(:tacker_config).new({})
}.to raise_error(Puppet::Error, 'Title or name must be provided')
end
it 'should not expect a name with whitespace' do
expect {
Puppet::Type.type(:tacker_config).new(:name => 'f oo')
}.to raise_error(Puppet::Error, /Parameter name failed/)
end
it 'should fail when there is no section' do
expect {
Puppet::Type.type(:tacker_config).new(:name => 'foo')
}.to raise_error(Puppet::Error, /Parameter name failed/)
end
it 'should not require a value when ensure is absent' do
Puppet::Type.type(:tacker_config).new(:name => 'DEFAULT/foo', :ensure => :absent)
end
it 'should accept a valid value' do
@tacker_config[:value] = 'bar'
expect(@tacker_config[:value]).to eq('bar')
end
it 'should not accept a value with whitespace' do
@tacker_config[:value] = 'b ar'
expect(@tacker_config[:value]).to eq('b ar')
end
it 'should accept valid ensure values' do
@tacker_config[:ensure] = :present
expect(@tacker_config[:ensure]).to eq(:present)
@tacker_config[:ensure] = :absent
expect(@tacker_config[:ensure]).to eq(:absent)
end
it 'should not accept invalid ensure values' do
expect {
@tacker_config[:ensure] = :latest
}.to raise_error(Puppet::Error, /Invalid value/)
end
it 'should autorequire the package that install the file' do
catalog = Puppet::Resource::Catalog.new
package = Puppet::Type.type(:package).new(:name => 'tacker-common')
catalog.add_resource package, @tacker_config
dependency = @tacker_config.autorequire
expect(dependency.size).to eq(1)
expect(dependency[0].target).to eq(@tacker_config)
expect(dependency[0].source).to eq(package)
end
end

12
tests/init.pp Normal file
View File

@ -0,0 +1,12 @@
# The baseline for module testing used by Puppet Labs is that each manifest
# should have a corresponding test manifest that declares that class or defined
# type.
#
# Tests are then run by using puppet apply --noop (to check for compilation
# errors and view a log of events) or by fully applying the test in a virtual
# environment (to compare the resulting system state to the desired state).
#
# Learn more about module testing here:
# http://docs.puppetlabs.com/guides/tests_smoke.html
#
include ::tacker