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 <mmalchuk@mirantis.com> (cherry picked from commita7f03d7c55
) (cherry picked from commita55cbdb8c8
)
This commit is contained in:
parent
1a40ebf404
commit
3d6aa6140b
@ -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',
|
||||
$service_state = $service_enabled ? { false => 'stopped', default => '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.'),
|
||||
$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],
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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': }
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user