From 3d6aa6140b03072f79210b3cb6d982d4b8e749db Mon Sep 17 00:00:00 2001 From: Maksim Malchuk Date: Sat, 2 Jul 2016 00:55:38 +0300 Subject: [PATCH] Add atop configuration settings Now the atop setting are configurable from UI and can be overriden in hiera. Also, this change adds idempotency and fix noop tests. DocImpact Depends-On: Ie0e69f58183193455d5d036b45668a3476f1a693 Change-Id: I59cea9ea5ca31c20db2cf3eaaebe09bad0abdcf8 Closes-Bug: #1597250 Signed-off-by: Maksim Malchuk (cherry picked from commit a7f03d7c55446dd035b499046b6ffc86ec112bed) (cherry picked from commit a55cbdb8c812a3d1c4fd5be3a42d11b0e26809b9) --- .../puppet/osnailyfacter/manifests/atop.pp | 100 ++++++++++++++---- .../osnailyfacter/modular/tools/tools.pp | 14 ++- tests/noop/spec/hosts/tools/tools_spec.rb | 14 ++- 3 files changed, 103 insertions(+), 25 deletions(-) diff --git a/deployment/puppet/osnailyfacter/manifests/atop.pp b/deployment/puppet/osnailyfacter/manifests/atop.pp index 70776b700c..5f37343f40 100644 --- a/deployment/puppet/osnailyfacter/manifests/atop.pp +++ b/deployment/puppet/osnailyfacter/manifests/atop.pp @@ -20,46 +20,100 @@ # [*rotate*] # How many days keep binary logs. # Default is 7. +# +# [*custom_acct_file*] +# Location of the custom accounting file. (e.g. '/tmp/atop.d/atop.acct') +# Set 'undef' to disable accounting, 'false' to use atop default settings. +# Default is undef. +# class osnailyfacter::atop ( - $service_enabled = true, - $service_state = 'running', - $interval = '20', - $logpath = '/var/log/atop', - $rotate = '7', - ) { - $conf_file = $::osfamily ? { - 'Debian' => '/etc/default/atop', - 'RedHat' => '/etc/sysconfig/atop', - default => fail('Unsupported Operating System.'), + $service_enabled = true, + $service_state = $service_enabled ? { false => 'stopped', default => 'running' }, + $interval = '20', + $logpath = '/var/log/atop', + $rotate = '7', + $custom_acct_file = undef, +) { + + case $::osfamily { + 'Debian': { + $conf_file = '/etc/default/atop' + $acct_package = 'acct' + } + 'RedHat': { + $conf_file = '/etc/sysconfig/atop' + $acct_package = 'psacct' + } + default: { + fail("Unsupported platform: ${::osfamily}/${::operatingsystem}") + } } - package { 'atop': + $atop_retention = '/etc/cron.daily/atop_retention' + $atop_retention_ensure = $service_enabled ? { false => 'absent', default => 'file' } + + File { + ensure => file, + owner => 'root', + group => 'root', + mode => '0600' + } + + if $custom_acct_file { + validate_absolute_path($custom_acct_file) + $acct_file_dir = dirname($custom_acct_file) + + # Manage the parent directory + file { $acct_file_dir: + ensure => directory, + } -> + + file { $custom_acct_file: + } ~> + + exec { 'turns process accounting on': + path => ['/sbin', '/usr/sbin'], + command => "accton ${custom_acct_file}", + refreshonly => true, + } + + Package[$acct_package] -> Exec['turns process accounting on'] -> Service['atop'] + } + + package { ['atop', $acct_package]: ensure => 'installed', } -> + # Template uses: + # - $interval + # - $logpath + # - $custom_acct_file file { $conf_file: - ensure => present, + mode => '0644', content => template('osnailyfacter/atop.erb'), } ~> service { 'atop': ensure => $service_state, enable => $service_enabled, - } ~> - - exec { "ln -s ${logpath}/atop_current": - command => "ln -s ${logpath}/atop_$(date +%Y%m%d) ${logpath}/atop_current", - path => ['/bin', '/usr/bin'], - unless => "test -L ${logpath}/atop_current", - require => Service['atop']; - } + } -> # This file is used for atop binary log rotations by (ana)cron - file { '/etc/cron.daily/atop_retention': - owner => 'root', - group => 'root', + # Template uses: + # - $rotate + # - $logpath + file { $atop_retention: + ensure => $atop_retention_ensure, mode => '0755', content => template('osnailyfacter/atop_retention.erb'), } + if $service_enabled { + exec { 'initialize atop_current': + command => $atop_retention, + refreshonly => true, + subscribe => File[$atop_retention], + } + } + } diff --git a/deployment/puppet/osnailyfacter/modular/tools/tools.pp b/deployment/puppet/osnailyfacter/modular/tools/tools.pp index fe2a5747c1..14aea546e0 100644 --- a/deployment/puppet/osnailyfacter/modular/tools/tools.pp +++ b/deployment/puppet/osnailyfacter/modular/tools/tools.pp @@ -1,6 +1,18 @@ notice('MODULAR: tools.pp') -class { 'osnailyfacter::atop': } +$atop_hash = hiera('atop', {}) +$atop_enabled = pick($atop_hash['service_enabled'], true) +$atop_interval = pick($atop_hash['interval'], 20) +$atop_rotate = pick($atop_hash['rotate'], 7) + +$custom_acct_file = hiera('custom_accounting_file', undef) + +class { 'osnailyfacter::atop': + service_enabled => $atop_enabled, + interval => $atop_interval, + rotate => $atop_rotate, + custom_acct_file => $custom_acct_file, +} class { 'osnailyfacter::ssh': } diff --git a/tests/noop/spec/hosts/tools/tools_spec.rb b/tests/noop/spec/hosts/tools/tools_spec.rb index 7c8703a730..3e96bc106a 100644 --- a/tests/noop/spec/hosts/tools/tools_spec.rb +++ b/tests/noop/spec/hosts/tools/tools_spec.rb @@ -2,6 +2,11 @@ require 'spec_helper' require 'shared-examples' manifest = 'tools/tools.pp' +atop_hash = Noop.hiera 'atop', {} +atop_enabled = Noop.puppet_function 'pick', atop_hash['service_enabled'], true +atop_interval = Noop.puppet_function 'pick', atop_hash['interval'], 20 +atop_rotate = Noop.puppet_function 'pick', atop_hash['rotate'], 7 + describe manifest do shared_examples 'catalog' do it "should contain ssh host keygen exec for Debian OS only" do @@ -13,8 +18,15 @@ describe manifest do should_not contain_exec('host-ssh-keygen') end end + + it 'should declare tools classes' do + should contain_class('osnailyfacter::atop').with( + 'service_enabled' => atop_enabled, + 'interval' => atop_interval, + 'rotate' => atop_rotate, + ) + end end test_ubuntu_and_centos manifest end -