Merge pull request #64 from cprice-puppet/feature/master/support-enabling-report-processor

Add support for enabling puppetdb report processor
This commit is contained in:
Ken Barber 2013-05-28 16:15:08 -07:00
commit b45fca9689
7 changed files with 150 additions and 4 deletions

View file

@ -2,6 +2,22 @@
Release notes for the puppetlabs-puppetdb module.
------------------------------------------
#### 1.4.0 - 2013/05/13
This feature release provides support for managing the puppetdb report
processor on your master.
To enable the report processor, you can do something like this:
class { 'puppetdb::master::config':
manage_report_processor => true,
enable_reports => true
}
This will add the 'puppetdb' report processor to the list of `reports`
inside your master's `puppet.conf` file.
------------------------------------------

View file

@ -1,5 +1,5 @@
name 'puppetlabs-puppetdb'
version '1.3.0'
version '1.4.0'
source 'git://github.com/puppetlabs/puppetlabs-puppetdb.git'
author 'Puppet Labs'
description 'PuppetDB resource types'
@ -7,7 +7,7 @@ summary 'PuppetDB resource types'
license 'ASL 2.0'
project_page 'https://github.com/puppetlabs/puppetlabs-puppetdb'
dependency 'cprice404/inifile', '>= 0.9.0'
dependency 'cprice404/inifile', '>= 0.10.3'
dependency 'puppetlabs/postgresql', '2.x'
dependency 'puppetlabs/firewall', '>= 0.0.4'
dependency 'puppetlabs/stdlib', '>= 1.0.0'

View file

@ -282,6 +282,10 @@ If true, the module will overwrite the puppet master's routes file to configure
If true, the module will manage the puppet master's storeconfig settings (defaults to true).
####`manage_report_processor`
If true, the module will manage the 'reports' field in the puppet.conf file to enable or disable the puppetdb report processor. Defaults to 'false'.
####`manage_config`
If true, the module will store values from puppetdb_server and puppetdb_port parameters in the puppetdb configuration file.
If false, an existing puppetdb configuration file will be used to retrieve server and port values.
@ -289,6 +293,10 @@ If false, an existing puppetdb configuration file will be used to retrieve serve
####`strict_validation`
If true, the module will fail if puppetdb is not reachable, otherwise it will preconfigure puppetdb without checking.
####`enable_reports`
Ignored unless `manage_report_processor` is `true`, in which case this setting will determine whether or not the puppetdb report processor is enabled (`true`) or disabled (`false`) in the puppet.conf file.
####`puppet_confdir`
Puppet's config directory (defaults to `/etc/puppet`).

View file

@ -21,8 +21,15 @@
# and puppetdb_port parameters in the puppetdb configuration file.
# If false, an existing puppetdb configuration file will be used
# to retrieve server and port values.
# ['manage_report_processor'] - If true, the module will manage the 'reports' field
# in the puppet.conf file to enable or disable the puppetdb
# report processor. Defaults to 'false'.
# ['strict_validation'] - If true, the module will fail if puppetdb is not reachable,
# otherwise it will preconfigure puppetdb without checking.
# ['enable_reports'] - Ignored unless 'manage_report_processor' is `true`, in which
# case this setting will determine whether or not the puppetdb
# report processor is enabled (`true`) or disabled (`false`) in
# the puppet.conf file.
# ['puppet_confdir'] - Puppet's config directory; defaults to /etc/puppet
# ['puppet_conf'] - Puppet's config file; defaults to /etc/puppet/puppet.conf
# ['puppetdb_version'] - The version of the `puppetdb` package that should
@ -57,8 +64,10 @@ class puppetdb::master::config(
$puppetdb_port = 8081,
$manage_routes = true,
$manage_storeconfigs = true,
$manage_report_processor = false,
$manage_config = true,
$strict_validation = true,
$enable_reports = false,
$puppet_confdir = $puppetdb::params::puppet_confdir,
$puppet_conf = $puppetdb::params::puppet_conf,
$puppetdb_version = $puppetdb::params::puppetdb_version,
@ -103,9 +112,20 @@ class puppetdb::master::config(
# it polls it automatically.
if ($manage_storeconfigs) {
class { 'puppetdb::master::storeconfigs':
puppet_conf => $puppet_conf,
puppet_conf => $puppet_conf,
require => $strict_validation ? { true => Puppetdb_conn_validator['puppetdb_conn'], default => Package[$terminus_package] },
}
}
}
# Conditionally manage the puppetdb report processor setting in `puppet.conf`.
# We don't need to trigger a restart of the puppet master service for this one,
# because it polls it automatically.
if ($manage_report_processor) {
class { 'puppetdb::master::report_processor':
puppet_conf => $puppet_conf,
enable => $enable_reports,
require => $strict_validation ? { true => Puppetdb_conn_validator['puppetdb_conn'], default => Package[$terminus_package] },
}
}
if ($manage_config) {

View file

@ -0,0 +1,35 @@
# Class: puppetdb::master::report_processor
#
# This class configures the puppet master to enable the puppetdb report
# processor
# Parameters:
# ['puppet_conf'] - The puppet config file (defaults to /etc/puppet/puppet.conf)
#
# Actions:
# - Configures the puppet master to use the puppetdb report processor
#
# Requires:
# - Inifile
#
# Sample Usage:
# class { 'puppetdb::master::report_processor':
# puppet_conf => '/etc/puppet/puppet.conf',
# enable => true
# }
#
#
class puppetdb::master::report_processor(
$puppet_conf = $puppetdb::params::puppet_conf,
$enable = false
) inherits puppetdb::params {
ini_subsetting { "puppet.conf/reports/puppetdb":
path => $puppet_conf,
section => 'master',
setting => 'reports',
subsetting => 'puppetdb',
subsetting_separator => ',',
ensure => $enable ? { true => present, default => absent }
}
}

View file

@ -43,4 +43,27 @@ class { 'puppetdb::master::config': }
end
end
end
describe 'enabling report processor' do
let(:pp) do
pp = <<-EOS
class { 'puppetdb::master::config':
manage_report_processor => true,
enable_reports => true
}
EOS
end
it 'should add the puppetdb report processor to puppet.conf' do
puppet_apply(pp) do |r|
r[:exit_code].should_not eq(1)
end
system_run("cat /etc/puppet/puppet.conf") do |r|
r[:stdout].should =~ /^reports\s*=\s*([^,]+,)*puppetdb(,[^,]+)*$/
end
end
end
end

View file

@ -0,0 +1,44 @@
require 'spec_helper'
describe 'puppetdb::master::report_processor', :type => :class do
context 'on a supported platform' do
let(:facts) do
{
:osfamily => 'RedHat',
:clientcert => 'test.domain.local',
}
end
it { should include_class('puppetdb::master::report_processor') }
describe 'when using default values' do
it { should contain_ini_subsetting('puppet.conf/reports/puppetdb').
with(
'ensure' => 'absent',
'path' => '/etc/puppet/puppet.conf',
'section' => 'master',
'setting' => 'reports',
'subsetting' => 'puppetdb',
'subsetting_separator' => ','
)}
end
describe 'when enabling reports' do
let(:params) do
{
'enable' => true
}
end
it { should contain_ini_subsetting('puppet.conf/reports/puppetdb').
with(
'ensure' => 'present',
'path' => '/etc/puppet/puppet.conf',
'section' => 'master',
'setting' => 'reports',
'subsetting' => 'puppetdb',
'subsetting_separator' => ','
)}
end
end
end