Commit b68dbb2c authored by Raphaël Pinson's avatar Raphaël Pinson
Browse files

Cleanup core library

parent 7897ca9e
fixtures:
repositories:
stdlib:
repo: git://github.com/puppetlabs/puppetlabs-stdlib.git
ref: 4.1.0
augeasproviders_apache:
repo: git://github.com/hercules-team/augeasproviders_apache.git
augeasproviders_grub:
repo: git://github.com/hercules-team/augeasproviders_grub.git
mount_providers:
repo: git://github.com/puppetlabs/puppetlabs-mount_providers.git
ref: 0.0.2
augeasproviders_mounttab:
repo: git://github.com/hercules-team/augeasproviders_mounttab.git
augeasproviders_nagios:
repo: git://github.com/hercules-team/augeasproviders_nagios.git
augeasproviders_pam:
repo: git://github.com/hercules-team/augeasproviders_pam.git
augeasproviders_postgresql:
repo: git://github.com/hercules-team/augeasproviders_postgresql.git
augeasproviders_puppet:
repo: git://github.com/hercules-team/augeasproviders_puppet.git
augeasproviders_shellvar:
repo: git://github.com/hercules-team/augeasproviders_shellvar.git
augeasproviders_ssh:
repo: git://github.com/hercules-team/augeasproviders_ssh.git
augeasproviders_sysctl:
repo: git://github.com/hercules-team/augeasproviders_sysctl.git
augeasproviders_syslog:
repo: git://github.com/hercules-team/augeasproviders_syslog.git
symlinks:
"augeasproviders": "#{source_dir}"
......@@ -12,11 +12,6 @@ exclude_paths = [
task :default => [:spec, :yard, :syntax, :lint]
desc "Run acceptance tests"
RSpec::Core::RakeTask.new(:acceptance) do |t|
t.pattern = 'spec/acceptance'
end
YARD::Rake::YardocTask.new do |t|
t.options = []
end
......
# Class: augeasproviders::instances: See README.md for documentation
#
# [Remember: No empty lines between comments and class definition]
class augeasproviders::instances (
$apache_directive_hash = $augeasproviders::params::apache_directive_hash,
$apache_setenv_hash = $augeasproviders::params::apache_setenv_hash,
$host_hash = $augeasproviders::params::host_hash,
$kernel_parameter_hash = $augeasproviders::params::kernel_parameter_hash,
$mailalias_hash = $augeasproviders::params::mailalias_hash,
$mounttab_hash = $augeasproviders::params::mounttab_hash,
$nrpe_command_hash = $augeasproviders::params::nrpe_command_hash,
$pam_hash = $augeasproviders::params::pam_hash,
$pg_hba_hash = $augeasproviders::params::pg_hba_hash,
$puppet_auth_hash = $augeasproviders::params::puppet_auth_hash,
$shellvar_hash = $augeasproviders::params::shellvar_hash,
$sshd_config_hash = $augeasproviders::params::sshd_config_hash,
$sshd_config_subsystem_hash = $augeasproviders::params::sshd_config_subsystem_hash,
$sysctl_hash = $augeasproviders::params::sysctl_hash,
$syslog_hash = $augeasproviders::params::syslog_hash,
$resource_defaults = $augeasproviders::params::resource_defaults
) inherits augeasproviders::params {
validate_hash($resource_defaults)
if $apache_directive_hash and !empty($apache_directive_hash) {
validate_hash($apache_directive_hash)
create_resources(apache_directive, $apache_directive_hash, $resource_defaults['apache_directive'])
}
if $apache_setenv_hash and !empty($apache_setenv_hash) {
validate_hash($apache_setenv_hash)
create_resources(apache_setenv, $apache_setenv_hash, $resource_defaults['apache_setenv'])
}
if $host_hash and !empty($host_hash) {
validate_hash($host_hash)
create_resources(host, $host_hash, $resource_defaults['host'])
}
if $kernel_parameter_hash and !empty($kernel_parameter_hash) {
validate_hash($kernel_parameter_hash)
create_resources(kernel_parameter, $kernel_parameter_hash, $resource_defaults['kernel_parameter'])
}
if $mailalias_hash and !empty($mailalias_hash) {
validate_hash($mailalias_hash)
create_resources(mailalias, $mailalias_hash, $resource_defaults['mailalias'])
}
if $mounttab_hash and !empty($mounttab_hash) {
validate_hash($mounttab_hash)
create_resources(mounttab, $mounttab_hash, $resource_defaults['mounttab'])
}
if $nrpe_command_hash and !empty($nrpe_command_hash) {
validate_hash($nrpe_command_hash)
create_resources(nrpe_command, $nrpe_command_hash, $resource_defaults['nrpe_command'])
}
if $pam_hash and !empty($pam_hash) {
validate_hash($pam_hash)
create_resources(pam, $pam_hash, $resource_defaults['pam'])
}
if $pg_hba_hash and !empty($pg_hba_hash) {
validate_hash($pg_hba_hash)
create_resources(pg_hba, $pg_hba_hash, $resource_defaults['pg_hba'])
}
if $puppet_auth_hash and !empty($puppet_auth_hash) {
validate_hash($puppet_auth_hash)
create_resources(puppet_auth, $puppet_auth_hash, $resource_defaults['puppet_auth'])
}
if $shellvar_hash and !empty($shellvar_hash) {
validate_hash($shellvar_hash)
create_resources(shellvar, $shellvar_hash, $resource_defaults['shellvar'])
}
if $sshd_config_hash and !empty($sshd_config_hash) {
validate_hash($sshd_config_hash)
create_resources(sshd_config, $sshd_config_hash, $resource_defaults['sshd_config'])
}
if $sshd_config_subsystem_hash and !empty($sshd_config_subsystem_hash) {
validate_hash($sshd_config_subsystem_hash)
create_resources(sshd_config_subsystem, $sshd_config_subsystem_hash, $resource_defaults['sshd_config_subsystem'])
}
if $sysctl_hash and !empty($sysctl_hash) {
validate_hash($sysctl_hash)
create_resources(sysctl, $sysctl_hash, $resource_defaults['sysctl'])
}
if $syslog_hash and !empty($syslog_hash) {
validate_hash($syslog_hash)
create_resources(syslog, $syslog_hash, $resource_defaults['syslog'])
}
}
# Class: augeasproviders::augeasproviders_params
#
# Defines all the variables used in the module.
#
class augeasproviders::params {
$apache_directive_hash = $::augeasproviders_apache_directive_hash ? {
undef => false,
default => $::augeasproviders_apache_directive_hash,
}
$apache_setenv_hash = $::augeasproviders_apache_setenv_hash ? {
undef => false,
default => $::augeasproviders_apache_setenv_hash,
}
$host_hash = $::augeasproviders_host_hash ? {
undef => false,
default => $::augeasproviders_host_hash,
}
$kernel_parameter_hash = $::augeasproviders_kernel_parameter_hash ? {
undef => false,
default => $::augeasproviders_kernel_parameter_hash,
}
$mailalias_hash = $::augeasproviders_mailalias_hash ? {
undef => false,
default => $::augeasproviders_mailalias_hash,
}
$mounttab_hash = $::augeasproviders_mounttab_hash ? {
undef => false,
default => $::augeasproviders_mounttab_hash,
}
$nrpe_command_hash = $::augeasproviders_nrpe_command_hash ? {
undef => false,
default => $::augeasproviders_nrpe_command_hash,
}
$pam_hash = $::augeasproviders_pam_hash ? {
undef => false,
default => $::augeasproviders_pam_hash,
}
$pg_hba_hash = $::augeasproviders_pg_hba_hash ? {
undef => false,
default => $::augeasproviders_pg_hba_hash,
}
$puppet_auth_hash = $::augeasproviders_puppet_auth_hash ? {
undef => false,
default => $::augeasproviders_puppet_auth_hash,
}
$shellvar_hash = $::augeasproviders_shellvar_hash ? {
undef => false,
default => $::augeasproviders_shellvar_hash,
}
$sshd_config_hash = $::augeasproviders_sshd_config_hash ? {
undef => false,
default => $::augeasproviders_sshd_config_hash,
}
$sshd_config_subsystem_hash = $::augeasproviders_sshd_config_subsystem_hash ? {
undef => false,
default => $::augeasproviders_sshd_config_subsystem_hash,
}
$sysctl_hash = $::augeasproviders_sysctl_hash ? {
undef => false,
default => $::augeasproviders_sysctl_hash,
}
$syslog_hash = $::augeasproviders_syslog_hash ? {
undef => false,
default => $::augeasproviders_syslog_hash,
}
$defaults = {
'ensure' => 'present',
'provider' => 'augeas',
}
$resource_defaults = {
'apache_directive' => $defaults,
'apache_setenv' => $defaults,
'host' => $defaults,
'kernel_parameter' => merge($defaults, {'provider' => undef}),
'mailalias' => $defaults,
'mounttab' => $defaults,
'nrpe_command' => $defaults,
'pam' => $defaults,
'pg_hba' => $defaults,
'puppet_auth' => $defaults,
'shellvar' => $defaults,
'sshd_config' => $defaults,
'sshd_config_subsystem' => $defaults,
'sysctl' => $defaults,
'syslog' => $defaults,
}
}
require 'spec_helper_acceptance'
describe 'augeasproviders::instances class' do
context 'when sysctl_hash is defined' do
it 'should run successfully' do
pp =<<-EOS
class { 'augeasproviders::instances':
sysctl_hash => { 'net.ipv4.ip_forward' => { 'value' => '1' } },
}
EOS
apply_manifest(pp, :catch_failures => true)
expect(apply_manifest(pp, :catch_failures => true).exit_code).to be_zero
end
describe linux_kernel_parameter('net.ipv4.ip_forward') do
its(:value) { should eq 1 }
end
end
context 'when augeasproviders_sysctl_hash is defined' do
it 'should run successfully' do
pp =<<-EOS
$augeasproviders_sysctl_hash = { 'net.ipv4.ip_forward' => { 'value' => '0' } }
class { 'augeasproviders::instances': }
EOS
apply_manifest(pp, :catch_failures => true)
expect(apply_manifest(pp, :catch_failures => true).exit_code).to be_zero
end
describe linux_kernel_parameter('net.ipv4.ip_forward') do
its(:value) { should eq 0 }
end
end
end
HOSTS:
centos-65-x64:
roles:
- master
platform: el-6-x86_64
box : centos-65-x64-virtualbox-nocm
box_url : http://puppet-vagrant-boxes.puppetlabs.com/centos-65-x64-virtualbox-nocm.box
hypervisor : vagrant
CONFIG:
log_level: debug
type: foss
HOSTS:
centos-65-x64:
roles:
- master
platform: el-6-x86_64
box : centos-65-x64-virtualbox-nocm
box_url : http://puppet-vagrant-boxes.puppetlabs.com/centos-65-x64-virtualbox-nocm.box
hypervisor : vagrant
CONFIG:
log_level: debug
type: foss
require 'spec_helper'
describe 'augeasproviders::instances' do
it { should create_class('augeasproviders::instances') }
it { should contain_class('augeasproviders::params') }
context "when resource_defaults => 'foo'" do
let(:params) {{ :resource_defaults => 'foo' }}
it { expect { should create_class('augeasproviders::instances') }.to raise_error(Puppet::Error, /is not a Hash/) }
end
[
'apache_directive',
'apache_setenv',
'host',
'kernel_parameter',
'mailalias',
'mounttab',
'nrpe_command',
'pam',
'pg_hba',
'puppet_auth',
'shellvar',
'sshd_config',
'sshd_config_subsystem',
'sysctl',
'syslog',
].each do |type|
describe "#{type} instances" do
include_context type
include_examples 'validate_hash param', "#{type}_hash"
include_examples 'validate_hash top-scope param', "augeasproviders_#{type}_hash"
end
end
end
shared_examples_for 'apache_directive resource' do
it { should have_apache_directive_resource_count(1) }
it do
should contain_apache_directive('StartServers').only_with({
'name' => 'StartServers',
'ensure' => 'present',
'args' => '3',
'target' => '/etc/httpd/conf/httpd.conf',
'provider' => 'augeas',
})
end
end
shared_context 'apache_directive' do
it { should have_apache_directive_resource_count(0) }
let :example_params do
{'StartServers' => {'args' => '3', 'target' => '/etc/httpd/conf/httpd.conf'}}
end
context "when apache_directive_hash is a Hash" do
let(:params) {{ :apache_directive_hash => example_params }}
let(:facts) {{}}
include_examples 'apache_directive resource'
end
context "when ::augeasproviders_apache_directive_hash is a Hash" do
let(:params) {{}}
let(:facts) {{ :augeasproviders_apache_directive_hash => example_params }}
include_examples 'apache_directive resource'
end
end
shared_examples_for 'apache_setenv resource' do
it { should have_apache_setenv_resource_count(1) }
it do
should contain_apache_setenv('FOO').only_with({
'name' => 'FOO',
'ensure' => 'present',
'value' => 'bar',
'provider' => 'augeas',
})
end
end
shared_context 'apache_setenv' do
it { should have_apache_setenv_resource_count(0) }
let :example_params do
{'FOO' => {'value' => 'bar'}}
end
context "when apache_setenv_hash is a Hash" do
let(:params) {{ :apache_setenv_hash => example_params }}
let(:facts) {{}}
include_examples 'apache_setenv resource'
end
context "when ::augeasproviders_apache_setenv_hash is a Hash" do
let(:params) {{}}
let(:facts) {{ :augeasproviders_apache_setenv_hash => example_params }}
include_examples 'apache_setenv resource'
end
end
shared_examples_for 'host resource' do
it { should have_host_resource_count(1) }
it do
should contain_host('foo').only_with({
'name' => 'foo',
'ensure' => 'present',
'ip' => '192.168.1.1',
'provider' => 'augeas',
})
end
end
shared_context 'host' do
it { should have_host_resource_count(0) }
let :example_params do
{'foo' => {'ip' => '192.168.1.1'}}
end
context "when host_hash is a Hash" do
let(:params) {{ :host_hash => example_params }}
let(:facts) {{}}
include_examples 'host resource'
end
context "when ::augeasproviders_host_hash is a Hash" do
let(:params) {{}}
let(:facts) {{ :augeasproviders_host_hash => example_params }}
include_examples 'host resource'
end
end
shared_examples_for 'kernel_parameter resource' do
it { should have_kernel_parameter_resource_count(1) }
it do
should contain_kernel_parameter('elevator').only_with({
'name' => 'elevator',
'ensure' => 'present',
'value' => 'deadline',
})
end
end
shared_context 'kernel_parameter' do
it { should have_kernel_parameter_resource_count(0) }
let :example_params do
{'elevator' => {'value' => 'deadline'}}
end
context "when kernel_parameter_hash is a Hash" do
let(:params) {{ :kernel_parameter_hash => example_params }}
let(:facts) {{}}
include_examples 'kernel_parameter resource'
end
context "when ::augeasproviders_kernel_parameter_hash is a Hash" do
let(:params) {{}}
let(:facts) {{ :augeasproviders_kernel_parameter_hash => example_params }}
include_examples 'kernel_parameter resource'
end
end
shared_examples_for 'mailalias resource' do
it { should have_mailalias_resource_count(1) }
it do
should contain_mailalias('foo').only_with({
'name' => 'foo',
'ensure' => 'present',
'recipient' => 'bar',
'provider' => 'augeas',
})
end
end
shared_context 'mailalias' do
it { should have_mailalias_resource_count(0) }
let :example_params do
{'foo' => {'recipient' => 'bar'}}
end
context "when mailalias_hash is a Hash" do
let(:params) {{ :mailalias_hash => example_params }}
let(:facts) {{}}
include_examples 'mailalias resource'
end
context "when ::augeasproviders_mailalias_hash is a Hash" do
let(:params) {{}}
let(:facts) {{ :augeasproviders_mailalias_hash => example_params }}
include_examples 'mailalias resource'
end
end
shared_examples_for 'mounttab resource' do
it { should have_mounttab_resource_count(1) }
it do
should contain_mounttab('/mnt').only_with({
'name' => '/mnt',
'ensure' => 'present',
'device' => '/dev/myvg/mytest',
'fstype' => 'ext4',
'options' => 'defaults',
'provider' => 'augeas',
})
end
end
shared_context 'mounttab' do
it { should have_mounttab_resource_count(0) }
let :example_params do
{'/mnt' => {'device' => '/dev/myvg/mytest', 'fstype' => 'ext4', 'options' => 'defaults'}}
end
context "when mounttab_hash is a Hash" do
let(:params) {{ :mounttab_hash => example_params }}
let(:facts) {{}}
include_examples 'mounttab resource'
end
context "when ::augeasproviders_mounttab_hash is a Hash" do
let(:params) {{}}
let(:facts) {{ :augeasproviders_mounttab_hash => example_params }}
include_examples 'mounttab resource'
end
end
shared_examples_for 'nrpe_command resource' do
it { should have_nrpe_command_resource_count(1) }
it do
should contain_nrpe_command('check_foo').only_with({
'name' => 'check_foo',
'ensure' => 'present',
'command' => '/usr/bin/check_foo',
'provider' => 'augeas',
})
end
end
shared_context 'nrpe_command' do
it { should have_nrpe_command_resource_count(0) }
let :example_params do
{'check_foo' => {'command' => '/usr/bin/check_foo'}}
end
context "when nrpe_command_hash is a Hash" do
let(:params) {{ :nrpe_command_hash => example_params }}
let(:facts) {{}}
include_examples 'nrpe_command resource'
end
context "when ::augeasproviders_nrpe_command_hash is a Hash" do
let(:params) {{}}
let(:facts) {{ :augeasproviders_nrpe_command_hash => example_params }}
include_examples 'nrpe_command resource'
end
end
shared_examples_for 'pam resource' do
it { should have_pam_resource_count(1) }
it do
should contain_pam('Add pam_test.so to auth for system-auth').only_with({
'name' => 'Add pam_test.so to auth for system-auth',
'service' => 'system-auth',
'type' => 'auth',
'control' => 'sufficient',
'module' => 'pam_test.so',
'arguments' => 'test_me_out',
'position' => 'before module pam_deny.so',
'target' => '/etc/pam.d/system-auth',
'provider' => 'augeas',
'ensure' => 'present',