Add initial tests for the Puppet modules

This change implements the necessary bits and pieces for testing the
Puppet modules. Right now, it only run lint and syntax checker on the
modules.

The change also fixes a couple of issues with the existing code that
have been highlighted by the tests.

Change-Id: I4fd30baa23c474d75937b4f050b35c914efc4829
This commit is contained in:
Simon Pasquier 2015-08-17 11:48:52 +02:00
parent fd78371015
commit a0abd257af
26 changed files with 362 additions and 104 deletions

View File

@ -0,0 +1,7 @@
fixtures:
repositories:
stdlib:
repo: "git://github.com/puppetlabs/puppetlabs-stdlib"
ref: "4.7.0"
symlinks:
heka: "#{source_dir}"

View File

@ -0,0 +1,2 @@
spec/fixtures/modules/*
spec/fixtures/manifests/*

View File

@ -0,0 +1,24 @@
# Copyright 2015 Mirantis, Inc.
#
# 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.
source 'https://rubygems.org'
group :development, :test do
gem 'rake'
gem "puppet", ENV['PUPPET_VERSION'] || '~> 3.4.0'
gem 'rspec'
gem 'rspec-puppet'
gem 'rspec-puppet-facts'
gem 'puppetlabs_spec_helper'
gem 'metadata-json-lint'
end

View File

@ -0,0 +1,62 @@
GEM
remote: https://rubygems.org/
specs:
diff-lcs (1.2.5)
facter (1.7.6)
hiera (1.3.4)
json_pure
json (1.8.3)
json_pure (1.8.2)
metaclass (0.0.4)
metadata-json-lint (0.0.6)
json
spdx-licenses (~> 1.0)
mocha (1.1.0)
metaclass (~> 0.0.1)
puppet (3.4.3)
facter (~> 1.6)
hiera (~> 1.0)
rgen (~> 0.6.5)
puppet-lint (1.1.0)
puppet-syntax (2.0.0)
rake
puppetlabs_spec_helper (0.10.3)
mocha
puppet-lint
puppet-syntax
rake
rspec-puppet
rake (10.4.2)
rgen (0.6.6)
rspec (3.3.0)
rspec-core (~> 3.3.0)
rspec-expectations (~> 3.3.0)
rspec-mocks (~> 3.3.0)
rspec-core (3.3.2)
rspec-support (~> 3.3.0)
rspec-expectations (3.3.1)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.3.0)
rspec-mocks (3.3.2)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.3.0)
rspec-puppet (2.2.0)
rspec
rspec-puppet-facts (0.12.0)
facter
json
rspec-support (3.3.0)
spdx-licenses (1.0.0)
json
PLATFORMS
ruby
DEPENDENCIES
metadata-json-lint
puppet (~> 3.4.0)
puppetlabs_spec_helper
rake
rspec
rspec-puppet
rspec-puppet-facts

View File

@ -0,0 +1,25 @@
require 'puppetlabs_spec_helper/rake_tasks'
require 'puppet-lint/tasks/puppet-lint'
require 'puppet-syntax/tasks/puppet-syntax'
require 'metadata-json-lint/rake_task'
PuppetLint.configuration.fail_on_warnings = true
PuppetLint.configuration.send('disable_80chars')
PuppetLint.configuration.send('disable_class_inherits_from_params_class')
PuppetLint.configuration.send('disable_class_parameter_defaults')
exclude_paths = [
"pkg/**/*",
"vendor/**/*",
"spec/**/*",
]
PuppetLint.configuration.ignore_paths = exclude_paths
PuppetSyntax.exclude_paths = exclude_paths
desc "Run metadata_lint, lint, syntax, and spec tests."
task :test => [
:metadata_lint,
:lint,
:syntax,
:spec,
]

View File

@ -17,6 +17,7 @@ define heka::output::dashboard (
$dashboard_address = '0.0.0.0',
$dashboard_port = '4352',
$ticker_interval = '30',
$ensure = present,
) {
include heka::params

View File

@ -3,7 +3,7 @@
"version": "1.0.0",
"author": "Simon Pasquier <spasquier@mirantis.com>",
"summary": "Puppet Heka Module",
"license": "Apache License 2.0",
"license": "Apache-2.0",
"source": "git://git.openstack.org/cgit/stackforge/fuel-plugin-lma-collector.git",
"project_page": "none",
"issues_url": "none",

View File

@ -0,0 +1,6 @@
--format
s
--colour
--loadby
mtime
--backtrace

View File

@ -1,30 +1,22 @@
# Copyright 2015 Mirantis, Inc.
# Copyright 2015 Mirantis, Inc.
#
# 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
# 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
# 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.
dir = File.expand_path(File.dirname(__FILE__))
$LOAD_PATH.unshift File.join(dir, 'lib')
# 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.
require 'rspec-puppet'
require 'mocha'
require 'puppet'
require 'rspec'
require 'spec/autorun'
fixture_path = File.expand_path(File.join(__FILE__, '..', 'fixtures'))
Spec::Runner.configure do |config|
config.mock_with :mocha
end
# We need this because the RAL uses 'should' as a method. This
# allows us the same behaviour but with a different method name.
class Object
alias :must :should
RSpec.configure do |c|
c.module_path = File.join(fixture_path, 'modules')
c.manifest_dir = File.join(fixture_path, 'manifests')
c.environmentpath = File.join(Dir.pwd, 'spec')
end

View File

@ -0,0 +1,8 @@
fixtures:
repositories:
stdlib:
repo: "git://github.com/puppetlabs/puppetlabs-stdlib"
ref: "4.7.0"
symlinks:
lma_collector: "#{source_dir}"
heka: "#{source_dir}/../heka"

View File

@ -0,0 +1,2 @@
spec/fixtures/modules/*
spec/fixtures/manifests/*

View File

@ -0,0 +1,24 @@
# Copyright 2015 Mirantis, Inc.
#
# 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.
source 'https://rubygems.org'
group :development, :test do
gem 'rake'
gem "puppet", ENV['PUPPET_VERSION'] || '~> 3.4.0'
gem 'rspec'
gem 'rspec-puppet'
gem 'rspec-puppet-facts'
gem 'puppetlabs_spec_helper'
gem 'metadata-json-lint'
end

View File

@ -0,0 +1,62 @@
GEM
remote: https://rubygems.org/
specs:
diff-lcs (1.2.5)
facter (1.7.6)
hiera (1.3.4)
json_pure
json (1.8.3)
json_pure (1.8.2)
metaclass (0.0.4)
metadata-json-lint (0.0.6)
json
spdx-licenses (~> 1.0)
mocha (1.1.0)
metaclass (~> 0.0.1)
puppet (3.4.3)
facter (~> 1.6)
hiera (~> 1.0)
rgen (~> 0.6.5)
puppet-lint (1.1.0)
puppet-syntax (2.0.0)
rake
puppetlabs_spec_helper (0.10.3)
mocha
puppet-lint
puppet-syntax
rake
rspec-puppet
rake (10.4.2)
rgen (0.6.6)
rspec (3.3.0)
rspec-core (~> 3.3.0)
rspec-expectations (~> 3.3.0)
rspec-mocks (~> 3.3.0)
rspec-core (3.3.2)
rspec-support (~> 3.3.0)
rspec-expectations (3.3.1)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.3.0)
rspec-mocks (3.3.2)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.3.0)
rspec-puppet (2.2.0)
rspec
rspec-puppet-facts (0.12.0)
facter
json
rspec-support (3.3.0)
spdx-licenses (1.0.0)
json
PLATFORMS
ruby
DEPENDENCIES
metadata-json-lint
puppet (~> 3.4.0)
puppetlabs_spec_helper
rake
rspec
rspec-puppet
rspec-puppet-facts

View File

@ -0,0 +1,25 @@
require 'puppetlabs_spec_helper/rake_tasks'
require 'puppet-lint/tasks/puppet-lint'
require 'puppet-syntax/tasks/puppet-syntax'
require 'metadata-json-lint/rake_task'
PuppetLint.configuration.fail_on_warnings = true
PuppetLint.configuration.send('disable_80chars')
PuppetLint.configuration.send('disable_class_inherits_from_params_class')
PuppetLint.configuration.send('disable_class_parameter_defaults')
exclude_paths = [
"pkg/**/*",
"vendor/**/*",
"spec/**/*",
]
PuppetLint.configuration.ignore_paths = exclude_paths
PuppetSyntax.exclude_paths = exclude_paths
desc "Run metadata_lint, lint, syntax, and spec tests."
task :test => [
:metadata_lint,
:lint,
:syntax,
:spec,
]

View File

@ -20,10 +20,10 @@ define lma_collector::collectd::python_script {
$python_module_path = $lma_collector::params::python_module_path
file { "${python_module_path}/${title}":
owner => 'root',
group => $collectd::params::root_group,
mode => '0644',
source => "puppet:///modules/lma_collector/collectd/${title}",
notify => Class['lma_collector::collectd::service'],
owner => 'root',
group => $collectd::params::root_group,
mode => '0644',
source => "puppet:///modules/lma_collector/collectd/${title}",
notify => Class['lma_collector::collectd::service'],
}
}

View File

@ -45,7 +45,6 @@ class lma_collector::collectd::service (
if $service_manage {
service { 'collectd':
ensure => $_service_ensure,
name => $service_name,
enable => $service_enable,
}
}

View File

@ -20,7 +20,7 @@ class lma_collector::logs::system {
config_dir => $lma_collector::params::config_dir,
filename => "${lma_collector::params::plugins_dir}/decoders/generic_syslog.lua" ,
config => {
syslog_pattern => $lma_collector::params::syslog_pattern,
syslog_pattern => $lma_collector::params::syslog_pattern,
fallback_syslog_pattern => $lma_collector::params::fallback_syslog_pattern
},
notify => Class['lma_collector::service'],

View File

@ -17,7 +17,7 @@ class lma_collector::metrics::service_status (
$timeout = $lma_collector::params::service_status_timeout,
) inherits lma_collector::params {
validate_string($metrics_regexp)
validate_string($metrics_matcher)
$payload_name = $lma_collector::params::service_status_payload_name

View File

@ -47,7 +47,9 @@ class lma_collector::nagios (
password => $password,
encoder => 'nagios',
timeout => $lma_collector::params::nagios_timeout,
headers => {'Content-Type' => 'application/x-www-form-urlencoded'},
headers => {
'Content-Type' => 'application/x-www-form-urlencoded'
},
require => Heka::Encoder::Sandbox['nagios'],
notify => Class['lma_collector::service'],
}

View File

@ -23,12 +23,12 @@ class lma_collector::notifications::cinder (
include cinder::params
cinder_config {
'DEFAULT/notification_topics': value => join($topics, ','),
cinder_config { 'DEFAULT/notification_topics':
value => join($topics, ','),
notify => Service[$::cinder::params::volume_service],
}
cinder_config {
'DEFAULT/notification_driver': value => $driver,
cinder_config { 'DEFAULT/notification_driver':
value => $driver,
notify => Service[$::cinder::params::volume_service],
}

View File

@ -22,16 +22,16 @@ class lma_collector::notifications::compute (
include nova::params
nova_config {
'DEFAULT/notification_topics': value => join($topics, ','),
nova_config { 'DEFAULT/notification_topics':
value => join($topics, ','),
notify => Service[$::nova::params::compute_service_name],
}
nova_config {
'DEFAULT/notification_driver': value => $driver,
nova_config { 'DEFAULT/notification_driver':
value => $driver,
notify => Service[$::nova::params::compute_service_name],
}
nova_config {
'DEFAULT/notify_on_state_change': value => 'vm_and_task_state',
nova_config { 'DEFAULT/notify_on_state_change':
value => 'vm_and_task_state',
notify => Service[$::nova::params::compute_service_name],
}

View File

@ -94,16 +94,16 @@ class lma_collector::notifications::controller (
# Nova
include nova::params
nova_config {
'DEFAULT/notification_topics': value => $notification_topics,
nova_config { 'DEFAULT/notification_topics':
value => $notification_topics,
notify => Service[$::nova::params::api_service_name, $::nova::params::conductor_service_name, $::nova::params::scheduler_service_name],
}
nova_config {
'DEFAULT/notification_driver': value => $driver,
nova_config { 'DEFAULT/notification_driver':
value => $driver,
notify => Service[$::nova::params::api_service_name, $::nova::params::conductor_service_name, $::nova::params::scheduler_service_name],
}
nova_config {
'DEFAULT/notify_on_state_change': value => 'vm_and_task_state',
nova_config { 'DEFAULT/notify_on_state_change':
value => 'vm_and_task_state',
notify => Service[$::nova::params::api_service_name, $::nova::params::conductor_service_name, $::nova::params::scheduler_service_name],
}
@ -115,12 +115,12 @@ class lma_collector::notifications::controller (
# Cinder
include cinder::params
cinder_config {
'DEFAULT/notification_topics': value => $notification_topics,
cinder_config { 'DEFAULT/notification_topics':
value => $notification_topics,
notify => Service[$::cinder::params::api_service, $::cinder::params::scheduler_service],
}
cinder_config {
'DEFAULT/notification_driver': value => $driver,
cinder_config { 'DEFAULT/notification_driver':
value => $driver,
notify => Service[$::cinder::params::api_service, $::cinder::params::scheduler_service],
}
@ -132,12 +132,12 @@ class lma_collector::notifications::controller (
# Keystone
include keystone::params
keystone_config {
'DEFAULT/notification_topics': value => $notification_topics,
keystone_config { 'DEFAULT/notification_topics':
value => $notification_topics,
notify => Service[$::keystone::params::service_name],
}
keystone_config {
'DEFAULT/notification_driver': value => $driver,
keystone_config { 'DEFAULT/notification_driver':
value => $driver,
notify => Service[$::keystone::params::service_name],
}
@ -149,12 +149,12 @@ class lma_collector::notifications::controller (
# Neutron
include neutron::params
neutron_config {
'DEFAULT/notification_topics': value => $notification_topics,
neutron_config { 'DEFAULT/notification_topics':
value => $notification_topics,
notify => Service[$::neutron::params::server_service],
}
neutron_config {
'DEFAULT/notification_driver': value => $driver,
neutron_config { 'DEFAULT/notification_driver':
value => $driver,
notify => Service[$::neutron::params::server_service],
}
@ -169,28 +169,28 @@ class lma_collector::notifications::controller (
# Default value is 'image.localhost' for Glance
$glance_publisher_id = "image.${::hostname}"
glance_api_config {
'DEFAULT/notification_topics': value => $notification_topics,
glance_api_config { 'DEFAULT/notification_topics':
value => $notification_topics,
notify => Service[$::glance::params::api_service_name],
}
glance_api_config {
'DEFAULT/notification_driver': value => $driver,
glance_api_config { 'DEFAULT/notification_driver':
value => $driver,
notify => Service[$::glance::params::api_service_name],
}
glance_api_config {
'DEFAULT/default_publisher_id': value => $glance_publisher_id,
glance_api_config { 'DEFAULT/default_publisher_id':
value => $glance_publisher_id,
notify => Service[$::glance::params::api_service_name],
}
glance_registry_config {
'DEFAULT/notification_topics': value => $notification_topics,
glance_registry_config { 'DEFAULT/notification_topics':
value => $notification_topics,
notify => Service[$::glance::params::registry_service_name],
}
glance_registry_config {
'DEFAULT/notification_driver': value => $driver,
glance_registry_config { 'DEFAULT/notification_driver':
value => $driver,
notify => Service[$::glance::params::registry_service_name],
}
glance_registry_config {
'DEFAULT/default_publisher_id': value => $glance_publisher_id,
glance_registry_config { 'DEFAULT/default_publisher_id':
value => $glance_publisher_id,
notify => Service[$::glance::params::registry_service_name],
}
@ -212,16 +212,16 @@ class lma_collector::notifications::controller (
# heat-engine is no longer managed by pacemaker and rollback to a traditional
# service restart.
exec { $reload_heat_engine:
command => '/usr/bin/pkill -10 heat-engine',
command => '/usr/bin/pkill -10 heat-engine',
refreshonly => true,
}
heat_config {
'DEFAULT/notification_topics': value => $notification_topics,
heat_config { 'DEFAULT/notification_topics':
value => $notification_topics,
notify => [Service[$::heat::params::api_service_name], Exec[$reload_heat_engine]],
}
heat_config {
'DEFAULT/notification_driver': value => $driver,
heat_config { 'DEFAULT/notification_driver':
value => $driver,
notify => [Service[$::heat::params::api_service_name], Exec[$reload_heat_engine]],
}

View File

@ -3,7 +3,7 @@
"version": "1.0.0",
"author": "Simon Pasquier <spasquier@mirantis.com>",
"summary": "Puppet LMA Collector Module",
"license": "Apache License 2.0",
"license": "Apache-2.0",
"source": "git://git.openstack.org/cgit/stackforge/fuel-plugin-lma-collector.git",
"project_page": "none",
"issues_url": "none",

View File

@ -0,0 +1,6 @@
--format
s
--colour
--loadby
mtime
--backtrace

View File

@ -1,30 +1,22 @@
# Copyright 2015 Mirantis, Inc.
# Copyright 2015 Mirantis, Inc.
#
# 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
# 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
# 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.
dir = File.expand_path(File.dirname(__FILE__))
$LOAD_PATH.unshift File.join(dir, 'lib')
# 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.
require 'rspec-puppet'
require 'mocha'
require 'puppet'
require 'rspec'
require 'spec/autorun'
fixture_path = File.expand_path(File.join(__FILE__, '..', 'fixtures'))
Spec::Runner.configure do |config|
config.mock_with :mocha
end
# We need this because the RAL uses 'should' as a method. This
# allows us the same behaviour but with a different method name.
class Object
alias :must :should
RSpec.configure do |c|
c.module_path = File.join(fixture_path, 'modules')
c.manifest_dir = File.join(fixture_path, 'manifests')
c.environmentpath = File.join(Dir.pwd, 'spec')
end

19
tox.ini Normal file
View File

@ -0,0 +1,19 @@
[tox]
envlist = heka,lma_collector
skipsdist = True
[testenv:heka]
deps =
changedir = {toxinidir}/deployment_scripts/puppet/modules/{envname}
whitelist_externals = bundle
commands =
bundle install
bundle exec rake test
[testenv:lma_collector]
deps =
changedir = {toxinidir}/deployment_scripts/puppet/modules/{envname}
whitelist_externals = bundle
commands =
bundle install
bundle exec rake test