Unify logrotate files into templates
authorEwoud Kohl van Wijngaarden <e.kohlvanwijngaarden@oxilion.nl>
Tue, 2 Jul 2013 21:07:00 +0000 (23:07 +0200)
committerEwoud Kohl van Wijngaarden <e.kohlvanwijngaarden@oxilion.nl>
Wed, 20 Nov 2013 13:34:32 +0000 (14:34 +0100)
files/config/host/logrotate.Debian [deleted file]
manifests/host/cgi.pp
spec/classes/munin_host_cgi_spec.rb [new file with mode: 0644]
templates/logrotate.conf.erb [moved from files/config/host/logrotate.CentOS with 92% similarity]

diff --git a/files/config/host/logrotate.Debian b/files/config/host/logrotate.Debian
deleted file mode 100644 (file)
index 732c871..0000000
+++ /dev/null
@@ -1,35 +0,0 @@
-/var/log/munin/munin-update.log {
-        daily
-        missingok
-        rotate 7
-        compress
-        notifempty
-        create 640 munin adm
-}
-
-/var/log/munin/munin-graph.log {
-        daily
-        missingok
-        rotate 7
-        compress
-        notifempty
-        create 660 munin www-data
-}
-
-/var/log/munin/munin-html.log {
-        daily
-        missingok
-        rotate 7
-        compress
-        notifempty
-        create 640 munin adm
-}
-
-/var/log/munin/munin-limits.log {
-        daily
-        missingok
-        rotate 7
-        compress
-        notifempty
-        create 640 munin adm
-}
index 5b0ecbb..9951a48 100644 (file)
@@ -30,13 +30,9 @@ class munin::host::cgi(
   }
 
   file{'/etc/logrotate.d/munin':
-    source => [ "puppet:///modules/site_munin/config/host/${::fqdn}/logrotate",
-                "puppet:///modules/site_munin/config/host/logrotate.${::operatingsystem}",
-                'puppet:///modules/site_munin/config/host/logrotate',
-                "puppet:///modules/munin/config/host/logrotate.${::operatingsystem}",
-                'puppet:///modules/munin/config/host/logrotate' ],
-    owner  => root,
-    group  => 0,
-    mode   => '0644',
+    content => template("${module_name}/logrotate.conf.erb"),
+    owner   => root,
+    group   => 0,
+    mode    => '0644',
   }
 }
diff --git a/spec/classes/munin_host_cgi_spec.rb b/spec/classes/munin_host_cgi_spec.rb
new file mode 100644 (file)
index 0000000..301f964
--- /dev/null
@@ -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 include_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
similarity index 92%
rename from files/config/host/logrotate.CentOS
rename to templates/logrotate.conf.erb
index 411de3f..0e3e6ca 100644 (file)
@@ -13,7 +13,7 @@
         rotate 7
         compress
         notifempty
-        create 660 munin apache
+        create 660 munin <%= @apache_user %>
 }
 
 /var/log/munin/munin-html.log {