Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor spec tests #31

Merged
merged 6 commits into from
Nov 8, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@ doc/
metadata.json
coverage/
spec/fixtures/modules/*
Gemfile.lock
18 changes: 16 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ Defaults:root !requiretty
## Compatibility ##
-------------------

* Debian 7
* EL 6
* Ubuntu 12.04 LTS

===

Expand Down Expand Up @@ -145,9 +147,9 @@ Whether the client should run right after boot

agent_sysconfig
---------------
The location of the /etc/sysconfig/puppet file.
The location of puppet agent sysconfig file.

- *Default*: /etc/sysconfig/puppet
- *Default*: use defaults based on osfamily

daemon_name
-----------
Expand Down Expand Up @@ -179,6 +181,12 @@ The group for dashboard installation.

- *Default*: puppet-dashboard

sysconfig_path
-------------------
The location of puppet dashboard sysconfig file.

- *Default*: use defaults based on osfamily

external_node_script_path
-------------------------
The script to call from puppet to get manifests from dashboard.
Expand Down Expand Up @@ -470,6 +478,12 @@ puppet::agent::is_puppet_master: 'true'

### Parameters ###

sysconfig_path
--------------
The location of puppet master sysconfig file.

- *Default*: use defaults based on osfamily

rack_dir
--------
The rack directory path.
Expand Down
22 changes: 20 additions & 2 deletions manifests/agent.pp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
$run_in_noop = 'false',
$cron_command = '/usr/bin/puppet agent --onetime --ignorecache --no-daemonize --no-usecacheonfailure --detailed-exitcodes --no-splay',
$run_at_boot = 'true',
$agent_sysconfig = '/etc/sysconfig/puppet',
$agent_sysconfig = 'USE_DEFAULTS',
$daemon_name = 'puppet',
) {

Expand All @@ -29,6 +29,24 @@
fail('puppet::agent::env must be set')
}

case $::osfamily {
'RedHat': {
$default_agent_sysconfig = '/etc/sysconfig/puppet'
}
'Debian': {
$default_agent_sysconfig = '/etc/default/puppet'
}
default: {
fail("puppet::agent supports osfamilies Debian and RedHat. Detected osfamily is <${::osfamily}>.")
}
}

if $agent_sysconfig == 'USE_DEFAULTS' {
$agent_sysconfig_real = $default_agent_sysconfig
} else {
$agent_sysconfig_real = $agent_sysconfig
}

case $is_puppet_master {
'true': {
$config_content = undef
Expand Down Expand Up @@ -99,7 +117,7 @@

file { 'puppet_agent_sysconfig':
ensure => file,
path => $agent_sysconfig,
path => $agent_sysconfig_real,
content => template('puppet/agent_sysconfig.erb'),
owner => 'root',
group => 'root',
Expand Down
21 changes: 20 additions & 1 deletion manifests/dashboard.pp
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,32 @@
$dashboard_package = 'puppet-dashboard',
$dashboard_user = 'puppet-dashboard',
$dashboard_group = 'puppet-dashboard',
$sysconfig_path = 'USE_DEFAULTS',
$external_node_script_path = '/usr/share/puppet-dashboard/bin/external_node',
$dashboard_fqdn = "puppet.${::domain}",
$port = '3000',
) {

validate_absolute_path($external_node_script_path)

case $::osfamily {
'RedHat': {
$default_sysconfig_path = '/etc/sysconfig/puppet-dashboard'
}
'Debian': {
$default_sysconfig_path = '/etc/default/puppet-dashboard'
}
default: {
fail("puppet::dashboard supports osfamilies Debian and RedHat. Detected osfamily is <${::osfamily}>.")
}
}

if $sysconfig_path == 'USE_DEFAULTS' {
$sysconfig_path_real = $default_sysconfig_path
} else {
$sysconfig_path_real = $sysconfig_path
}

package { 'puppet_dashboard':
ensure => present,
name => $dashboard_package,
Expand All @@ -28,7 +47,7 @@

file { 'dashboard_sysconfig':
ensure => file,
path => '/etc/sysconfig/puppet-dashboard',
path => $sysconfig_path_real,
content => template('puppet/dashboard_sysconfig.erb'),
owner => 'root',
group => 'root',
Expand Down
22 changes: 21 additions & 1 deletion manifests/master.pp
Original file line number Diff line number Diff line change
@@ -1,17 +1,36 @@
# == Class: puppet::master
#
class puppet::master (
$sysconfig_path = 'USE_DEFAULTS',
$rack_dir = '/usr/share/puppet/rack/puppetmasterd',
$puppet_user = 'puppet',
$manage_firewall = undef,
) {

case $::osfamily {
'RedHat': {
$default_sysconfig_path = '/etc/sysconfig/puppetmaster'
}
'Debian': {
$default_sysconfig_path = '/etc/default/puppetmaster'
}
default: {
fail("puppet::master supports osfamilies Debian and RedHat. Detected osfamily is <${::osfamily}>.")
}
}

include apache::mod::ssl
include common
include passenger
include puppet::lint
include puppet::master::maintenance

if $sysconfig_path == 'USE_DEFAULTS' {
$sysconfig_path_real = $default_sysconfig_path
} else {
$sysconfig_path_real = $sysconfig_path
}

if $manage_firewall == true {
firewall { '8140 open port 8140 for Puppet Master':
action => 'accept',
Expand All @@ -30,8 +49,9 @@

file { '/etc/puppet/fileserver.conf': }

file { '/etc/sysconfig/puppetmaster':
file { 'puppetmaster_sysconfig':
ensure => file,
path => $sysconfig_path_real,
content => template('puppet/puppetmaster_sysconfig.erb'),
}

Expand Down
98 changes: 73 additions & 25 deletions spec/classes/agent_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@
describe 'class puppet::agent' do

context 'Puppet agent configfile' do
let(:params) { {:env => 'production' } }
it {
should include_class('puppet::agent')
should contain_file('puppet_config').with({
let(:facts) { { :osfamily => 'RedHat' } }
let(:params) { { :env => 'production' } }

it { should include_class('puppet::agent') }

it { should contain_file('puppet_config').with({
'path' => '/etc/puppet/puppet.conf',
'owner' => 'root',
'group' => 'root',
Expand All @@ -16,11 +18,13 @@
}
end

context 'Puppet agent sysconfig' do
let(:params) { {:env => 'production' } }
it {
should include_class('puppet::agent')
should contain_file('puppet_agent_sysconfig').with({
context 'Puppet agent sysconfig file on osfamily RedHat' do
let(:facts) { { :osfamily => 'RedHat' } }
let(:params) { { :env => 'production' } }

it { should include_class('puppet::agent') }

it { should contain_file('puppet_agent_sysconfig').with({
'path' => '/etc/sysconfig/puppet',
'owner' => 'root',
'group' => 'root',
Expand All @@ -29,32 +33,76 @@
}
end

context 'Puppet agent sysconfig content' do
let(:params) { {:env => 'production' } }
it {
should include_class('puppet::agent')
should contain_file('puppet_agent_sysconfig') \
.with_content(/^#PUPPET_SERVER=puppet$/)
context 'Puppet agent sysconfig file on osfamily Debian' do
let(:facts) { { :osfamily => 'Debian' } }
let(:params) { { :env => 'production' } }

it { should include_class('puppet::agent') }

it { should contain_file('puppet_agent_sysconfig').with({
'path' => '/etc/default/puppet',
'owner' => 'root',
'group' => 'root',
'mode' => '0644',
})
}
end

context 'Puppet agent sysconfig file on invalid osfamily' do
let(:facts) { { :osfamily => 'invalid' } }
let(:params) { { :env => 'production' } }

it 'should fail' do
expect {
should include_class('puppet::agent')
}.to raise_error(Puppet::Error,/puppet::agent supports osfamilies Debian and RedHat. Detected osfamily is <invalid>./)
end
end

context 'Puppet agent sysconfig content on osfamily RedHat' do
let(:facts) { { :osfamily => 'RedHat' } }
let(:params) { { :env => 'production' } }

it { should include_class('puppet::agent') }

it { should contain_file('puppet_agent_sysconfig').with_content(/^#PUPPET_SERVER=puppet$/) }
end

context 'Puppet agent sysconfig content on osfamily Debian' do
let(:facts) { { :osfamily => 'Debian' } }
let(:params) { { :env => 'production' } }

it { should include_class('puppet::agent') }

it { should contain_file('puppet_agent_sysconfig').with_content(/^#PUPPET_SERVER=puppet$/) }
end

context 'Puppet agent cron' do
let(:params) { {:run_method => 'cron',
:env => 'production' } }
it {
should include_class('puppet::agent')
should contain_cron('puppet_agent').with({
let(:facts) { { :osfamily => 'RedHat' } }
let(:params) do
{ :run_method => 'cron',
:env => 'production',
}
end

it { should include_class('puppet::agent') }

it { should contain_cron('puppet_agent').with({
'user' => 'root',
})
}
end

context 'Puppet agent cron at boot' do
let(:params) { {:run_method => 'cron',
:env => 'production' } }
it {
should include_class('puppet::agent')
should contain_cron('puppet_agent_once_at_boot').with({
let(:facts) { { :osfamily => 'RedHat' } }
let(:params) do
{ :run_method => 'cron',
:env => 'production',
}
end

it { should include_class('puppet::agent') }
it { should contain_cron('puppet_agent_once_at_boot').with({
'user' => 'root',
'special' => 'reboot',
})
Expand Down
Loading