summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorvarac <varacanero@zeromail.org>2016-03-16 22:03:36 +0100
committervarac <varacanero@zeromail.org>2016-03-16 22:03:36 +0100
commit6c633f8606e04aad29f40a3fc0fcfdcb4b293715 (patch)
tree63d7c8a54a643cc628b9b4f7a3b941d9f508c4ad /spec
parent503e9296860e4d844a1ee391331996db87e0bfa6 (diff)
parent87dc315597e8ed27c2e0907615ede8a3f1521b7a (diff)
Merge remote-tracking branch 'shared/master' into leap_masterHEADmaster
Diffstat (limited to 'spec')
-rw-r--r--spec/classes/munin_client_base_spec.rb86
-rw-r--r--spec/classes/munin_client_spec.rb50
-rw-r--r--spec/classes/munin_host_cgi_spec.rb57
-rw-r--r--spec/classes/munin_host_spec.rb47
-rw-r--r--spec/classes/munin_plugins_interfaces_spec.rb44
-rw-r--r--spec/defines/munin_plugin_spec.rb57
-rw-r--r--spec/spec_helper.rb11
-rw-r--r--spec/spec_helper_system.rb27
8 files changed, 379 insertions, 0 deletions
diff --git a/spec/classes/munin_client_base_spec.rb b/spec/classes/munin_client_base_spec.rb
new file mode 100644
index 0000000..fdf1403
--- /dev/null
+++ b/spec/classes/munin_client_base_spec.rb
@@ -0,0 +1,86 @@
+require 'spec_helper'
+
+describe 'munin::client::base' do
+ let :default_facts do
+ {
+ :fqdn => 'munin-node.example.org',
+ }
+ end
+
+ let :pre_condition do
+ 'include munin::client'
+ end
+
+ context 'on Debian' do
+ let :facts do
+ { :osfamily => 'Debian' }.merge(default_facts)
+ end
+
+ it 'should compile' do
+ should contain_class('munin::client::base')
+ end
+
+ it 'should set up munin-node' do
+ should contain_service('munin-node').with({
+ :ensure => 'running',
+ :enable => true,
+ :hasstatus => true,
+ :hasrestart => true,
+ })
+
+ should contain_file('/etc/munin').with({
+ :ensure => 'directory',
+ :mode => '0755',
+ :owner => 'root',
+ :group => 0,
+ })
+
+ should contain_file('/etc/munin/munin-node.conf').
+ with_content(/^host_name munin-node.example.org$/).
+ with_content(/^allow \^127\\\.0\\\.0\\\.1\$$/).
+ with_content(/^host \*$/).
+ with_content(/^port 4949$/)
+
+ should contain_munin__register('munin-node.example.org').with({
+ :host => 'munin-node.example.org',
+ :port => '4949',
+ :use_ssh => false,
+ :config => [ 'use_node_name yes', 'load.load.warning 5', 'load.load.critical 10'],
+ :export_tag => 'munin',
+ })
+
+ should contain_class('munin::plugins::base')
+ end
+
+ it 'should contain the Debian specific values' do
+ should contain_file('/etc/munin/munin-node.conf').
+ with_content(/^log_file \/var\/log\/munin\/munin-node.log$/).
+ with_content(/^group root$/)
+ end
+ end
+
+ context 'on CentOS' do
+ let :facts do
+ { :osfamily => 'CentOS' }.merge(default_facts)
+ end
+
+ it 'should contain the CentOS specific values' do
+ should contain_file('/etc/munin/munin-node.conf').
+ with_content(/^log_file \/var\/log\/munin-node\/munin-node.log$/).
+ with_content(/^group root$/)
+ end
+ end
+
+ # Disabled because the required openbsd module is not in the requirements
+ context 'on OpenBSD', :if => false do
+ let :facts do
+ { :osfamily => 'OpenBSD' }.merge(default_facts)
+ end
+
+ it 'should contain the config OpenBSD specific values' do
+ should contain_file('/etc/munin/munin-node.conf').
+ with_content(/^log_file \/var\/log\/munin-node\/munin-node.log$/).
+ with_content(/^group 0$/)
+ end
+ end
+end
diff --git a/spec/classes/munin_client_spec.rb b/spec/classes/munin_client_spec.rb
new file mode 100644
index 0000000..f7fc5e9
--- /dev/null
+++ b/spec/classes/munin_client_spec.rb
@@ -0,0 +1,50 @@
+require 'spec_helper'
+
+describe 'munin::client' do
+ shared_examples 'debian-client' do |os, codename|
+ let(:facts) {{
+ :operatingsystem => os,
+ :osfamily => 'Debian',
+ :lsbdistcodename => codename,
+ }}
+ it { should contain_package('munin-node') }
+ it { should contain_package('iproute') }
+ it { should contain_file('/etc/munin/munin-node.conf') }
+ it { should contain_class('munin::client::debian') }
+ end
+
+ shared_examples 'redhat-client' do |os, codename|
+ let(:facts) {{
+ :operatingsystem => os,
+ :osfamily => 'RedHat',
+ :lsbdistcodename => codename,
+ }}
+ it { should contain_package('munin-node') }
+ it { should contain_file('/etc/munin/munin-node.conf') }
+ end
+
+ context 'on debian-like system' do
+ it_behaves_like 'debian-client', 'Debian', 'squeeze'
+ it_behaves_like 'debian-client', 'Debian', 'wheezy'
+ it_behaves_like 'debian-client', 'Ubuntu', 'precise'
+ end
+
+ context 'on redhat-like system' do
+ it_behaves_like 'redhat-client', 'CentOS', '6'
+ # not supported yet
+ # it_behaves_like 'redhat', 'RedHat', '6'
+ end
+
+ context 'gentoo' do
+ let(:facts) {{
+ :operatingsystem => 'Gentoo',
+ :osfamily => 'Gentoo',
+ :lsbdistcodename => '',
+ :interfaces => 'lo,eth0',
+ }}
+ it { should contain_package('munin-node') }
+ it { should contain_file('/etc/munin/munin-node.conf') }
+ it { should contain_class('munin::client::gentoo') }
+ end
+
+end
diff --git a/spec/classes/munin_host_cgi_spec.rb b/spec/classes/munin_host_cgi_spec.rb
new file mode 100644
index 0000000..52c5c22
--- /dev/null
+++ b/spec/classes/munin_host_cgi_spec.rb
@@ -0,0 +1,57 @@
+require 'spec_helper'
+
+describe 'munin::host::cgi' do
+ #let :pre_condition do
+ # 'include munin::client'
+ #end
+
+ context 'on Debian' do
+ let :facts do
+ { :operatingsystem => 'Debian' }
+ end
+
+ it 'should compile' do
+ should contain_class('munin::host::cgi')
+ end
+
+ it 'should exec set_modes_for_cgi' do
+ should contain_exec('set_modes_for_cgi').with({
+ :command => 'chgrp www-data /var/log/munin /var/log/munin/munin-graph.log && chmod g+w /var/log/munin /var/log/munin/munin-graph.log && find /var/www/munin/* -maxdepth 1 -type d -exec chgrp -R www-data {} \; && find /var/www/munin/* -maxdepth 1 -type d -exec chmod -R g+w {} \;',
+ :refreshonly => true,
+ :subscribe => 'Concat::Fragment[munin.conf.header]',
+ })
+ end
+
+ it 'should contain logrotate.conf' do
+ should contain_file('/etc/logrotate.d/munin').with({
+ :content => /^ create 660 munin www-data$/,
+ :group => 0,
+ :mode => '0644',
+ :owner => 'root',
+ })
+ end
+ end
+
+ context 'on CentOS' do
+ let :facts do
+ { :operatingsystem => 'CentOS' }
+ end
+
+ it 'should exec set_modes_for_cgi' do
+ should contain_exec('set_modes_for_cgi').with({
+ :command => 'chgrp apache /var/log/munin /var/log/munin/munin-graph.log && chmod g+w /var/log/munin /var/log/munin/munin-graph.log && find /var/www/html/munin/* -maxdepth 1 -type d -exec chgrp -R apache {} \; && find /var/www/html/munin/* -maxdepth 1 -type d -exec chmod -R g+w {} \;',
+ :refreshonly => true,
+ :subscribe => 'Concat::Fragment[munin.conf.header]',
+ })
+ end
+
+ it 'should contain logrotate.conf' do
+ should contain_file('/etc/logrotate.d/munin').with({
+ :content => /^ create 660 munin apache$/,
+ :group => 0,
+ :mode => '0644',
+ :owner => 'root',
+ })
+ end
+ end
+end
diff --git a/spec/classes/munin_host_spec.rb b/spec/classes/munin_host_spec.rb
new file mode 100644
index 0000000..df002ce
--- /dev/null
+++ b/spec/classes/munin_host_spec.rb
@@ -0,0 +1,47 @@
+require 'spec_helper'
+
+describe 'munin::host' do
+ shared_examples 'debian-host' do |os, codename|
+ let(:facts) {{
+ :operatingsystem => os,
+ :osfamily => 'Debian',
+ :lsbdistcodename => codename,
+ :concat_basedir => '/var/lib/puppet/concat',
+ }}
+ it { should contain_package('munin') }
+ it { should contain_file('/etc/munin/munin.conf') }
+ it { should contain_class('munin::host') }
+ end
+
+ shared_examples 'redhat-host' do |os, codename|
+ let(:facts) {{
+ :operatingsystem => os,
+ :osfamily => 'RedHat',
+ :lsbdistcodename => codename,
+ :concat_basedir => '/var/lib/puppet/concat',
+ }}
+ it { should contain_package('munin') }
+ it { should contain_file('/etc/munin/munin.conf') }
+ it { should contain_class('munin::host') }
+ end
+
+ context 'on debian-like system' do
+ it_behaves_like 'debian-host', 'Debian', 'squeeze'
+ it_behaves_like 'debian-host', 'Debian', 'wheezy'
+ it_behaves_like 'debian-host', 'Ubuntu', 'precise'
+ end
+
+ context 'on redhat-like system' do
+ it_behaves_like 'redhat-host', 'CentOS', '6'
+ end
+
+ context 'on Gentoo' do
+ let(:facts) {{
+ :osfamily => 'Gentoo',
+ :concat_basedir => '/var/lib/puppet/concat',
+ }}
+ it { should contain_package('munin') }
+ it { should contain_file('/etc/munin/munin.conf') }
+ it { should contain_class('munin::host') }
+ end
+end
diff --git a/spec/classes/munin_plugins_interfaces_spec.rb b/spec/classes/munin_plugins_interfaces_spec.rb
new file mode 100644
index 0000000..7e3c418
--- /dev/null
+++ b/spec/classes/munin_plugins_interfaces_spec.rb
@@ -0,0 +1,44 @@
+require 'spec_helper'
+
+describe 'munin::plugins::interfaces' do
+ context 'on CentOS' do
+ let :facts do
+ {
+ :operatingsystem => 'CentOS',
+ :interfaces => 'lo,eth0,sit0',
+ }
+ end
+
+ it 'should compile' do
+ should contain_class('munin::plugins::interfaces')
+ end
+
+ it 'should create plugins for each interface' do
+ # lo
+ should contain_munin__plugin('if_lo').with_ensure('if_')
+ should contain_munin__plugin('if_err_lo').with_ensure('if_err_')
+
+ # eth0
+ should contain_munin__plugin('if_eth0').with_ensure('if_')
+ should contain_munin__plugin('if_err_eth0').with_ensure('if_err_')
+ end
+
+ it 'should not create plugins for sit0' do
+ should_not contain_munin__plugin('if_sit0')
+ should_not contain_munin__plugin('if_err_sit0')
+ end
+ end
+
+ context 'on OpenBSD' do
+ let :facts do
+ {
+ :operatingsystem => 'OpenBSD',
+ :interfaces => 'eth0',
+ }
+ end
+
+ it 'should use if_errcoll_ instead of if_err_' do
+ should contain_munin__plugin('if_errcoll_eth0').with_ensure('if_errcoll_')
+ end
+ end
+end
diff --git a/spec/defines/munin_plugin_spec.rb b/spec/defines/munin_plugin_spec.rb
new file mode 100644
index 0000000..0e7306a
--- /dev/null
+++ b/spec/defines/munin_plugin_spec.rb
@@ -0,0 +1,57 @@
+require 'spec_helper'
+
+describe 'munin::plugin' do
+ let(:title) { 'users' }
+ let(:facts) do
+ { :operatingsystem => 'CentOS' }
+ end
+ context 'present' do
+ it { should contain_file('/etc/munin/plugins/users').with(
+ :ensure => 'link',
+ :target => '/usr/share/munin/plugins/users'
+ ) }
+ it { should_not contain_file('/etc/munin/plugin-conf.d/users.conf') }
+ end
+
+ context 'present and config' do
+ let(:params) do
+ { :config => 'env.user root' }
+ end
+ it { should contain_file('/etc/munin/plugins/users').with(
+ :ensure => 'link',
+ :target => '/usr/share/munin/plugins/users',
+ :notify => 'Service[munin-node]'
+ ) }
+ it { should contain_file('/etc/munin/plugin-conf.d/users.conf').with(
+ :content => "[users]\nenv.user root\n",
+ :owner => 'root',
+ :group => 0,
+ :mode => '0640'
+ ) }
+ end
+
+ context 'present and config as an array' do
+ let(:params) do
+ { :config => [ 'env.user root', 'env.group root' ] }
+ end
+ it { should contain_file('/etc/munin/plugins/users').with(
+ :ensure => 'link',
+ :target => '/usr/share/munin/plugins/users',
+ :notify => 'Service[munin-node]'
+ ) }
+ it { should contain_file('/etc/munin/plugin-conf.d/users.conf').with(
+ :content => "[users]\nenv.user root\nenv.group root\n",
+ :owner => 'root',
+ :group => 0,
+ :mode => '0640'
+ ) }
+ end
+
+ context 'absent' do
+ let(:params) do
+ { :ensure => 'absent' }
+ end
+ it { should_not contain_file('/etc/munin/plugins/users') }
+ it { should_not contain_file('/etc/munin/plugin-conf.d/users.conf') }
+ end
+end
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
new file mode 100644
index 0000000..70ab1fb
--- /dev/null
+++ b/spec/spec_helper.rb
@@ -0,0 +1,11 @@
+require 'puppetlabs_spec_helper/module_spec_helper'
+
+fixture_path = File.expand_path(File.join(__FILE__, '..', 'fixtures'))
+
+RSpec.configure do |c|
+ c.module_path = File.join(fixture_path, 'modules')
+ c.manifest_dir = File.join(fixture_path, 'manifests')
+end
+
+Puppet::Util::Log.level = :warning
+Puppet::Util::Log.newdestination(:console)
diff --git a/spec/spec_helper_system.rb b/spec/spec_helper_system.rb
new file mode 100644
index 0000000..9adfea9
--- /dev/null
+++ b/spec/spec_helper_system.rb
@@ -0,0 +1,27 @@
+require 'rspec-system/spec_helper'
+require 'rspec-system-puppet/helpers'
+require 'rspec-system-serverspec/helpers'
+include Serverspec::Helper::RSpecSystem
+include Serverspec::Helper::DetectOS
+include RSpecSystemPuppet::Helpers
+
+RSpec.configure do |c|
+ # Project root
+ proj_root = File.expand_path(File.join(File.dirname(__FILE__), '..'))
+
+ # Enable colour
+ c.tty = true
+
+ c.include RSpecSystemPuppet::Helpers
+
+ # This is where we 'setup' the nodes before running our tests
+ c.before :suite do
+ # Install puppet
+ puppet_install
+
+ # Install modules and dependencies
+ puppet_module_install(:source => proj_root, :module_name => 'munin')
+ shell('puppet module install puppetlabs-stdlib')
+ shell('puppet module install puppetlabs-concat')
+ end
+end