From 5886615df6118de821985eb2e0990997c7a1c377 Mon Sep 17 00:00:00 2001 From: Nicholas Hinds Date: Mon, 26 Jan 2015 11:37:38 +1300 Subject: [PATCH 1/3] Add parameter to allow purging plugins, handlers, extensions and mutators The default behaviour is not to purge, matching the existing behaviour. --- manifests/init.pp | 8 +++++++- manifests/package.pp | 4 ++++ spec/classes/sensu_package_spec.rb | 21 +++++++++++++++++++++ 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/manifests/init.pp b/manifests/init.pp index 744dc12338..cdc25d5d83 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -175,6 +175,11 @@ # Default: false # Valid values: true, false # +# [*purge_scripts*] +# Boolean. If unused plugins, handlers, extensions and mutators should be removed from the system +# Default: false +# Valid values: true, false +# # [*use_embedded_ruby*] # Boolean. If the embedded ruby should be used # Default: false @@ -234,6 +239,7 @@ $plugins = [], $plugins_dir = undef, $purge_config = false, + $purge_scripts = false, $use_embedded_ruby = false, $rubyopt = '', $gem_path = '', @@ -241,7 +247,7 @@ $dashboard = false, ){ - validate_bool($client, $server, $api, $install_repo, $purge_config, $safe_mode, $manage_services) + validate_bool($client, $server, $api, $install_repo, $purge_config, $purge_scripts, $safe_mode, $manage_services) validate_re($repo, ['^main$', '^unstable$'], "Repo must be 'main' or 'unstable'. Found: ${repo}") validate_re($version, ['^absent$', '^installed$', '^latest$', '^present$', '^[\d\.\-]+$'], "Invalid package version: ${version}") diff --git a/manifests/package.pp b/manifests/package.pp index 83f789c18b..d8db1fbb16 100644 --- a/manifests/package.pp +++ b/manifests/package.pp @@ -75,6 +75,8 @@ mode => '0555', owner => 'sensu', group => 'sensu', + recurse => true, + purge => $sensu::purge_scripts, require => Package['sensu'], } @@ -84,6 +86,8 @@ mode => '0555', owner => 'sensu', group => 'sensu', + recurse => true, + purge => $sensu::purge_scripts, require => Package['sensu'], } } diff --git a/spec/classes/sensu_package_spec.rb b/spec/classes/sensu_package_spec.rb index 6997193acc..82c2180bc5 100644 --- a/spec/classes/sensu_package_spec.rb +++ b/spec/classes/sensu_package_spec.rb @@ -14,6 +14,14 @@ :purge => false ) } end + [ '/etc/sensu/handlers', '/etc/sensu/extensions', '/etc/sensu/mutators', + '/etc/sensu/extensions/handlers', '/etc/sensu/plugins' ].each do |dir| + it { should contain_file(dir).with( + :ensure => 'directory', + :recurse => true, + :purge => false + ) } + end it { should contain_file('/etc/sensu/config.json').with_ensure('absent') } it { should contain_user('sensu') } it { should contain_group('sensu') } @@ -153,6 +161,19 @@ end end + + context 'purge_scripts' do + let(:params) { { :purge_scripts => true } } + + [ '/etc/sensu/handlers', '/etc/sensu/extensions', '/etc/sensu/mutators', + '/etc/sensu/extensions/handlers', '/etc/sensu/plugins' ].each do |dir| + it { should contain_file(dir).with( + :ensure => 'directory', + :recurse => true, + :purge => true + ) } + end + end end end From c54d234d30a71c5c348a0c85815564e29048113c Mon Sep 17 00:00:00 2001 From: Nicholas Hinds Date: Tue, 27 Jan 2015 08:35:46 +1300 Subject: [PATCH 2/3] Use the purge_config flag to purge plugins/handlers/extensions/mutators --- manifests/init.pp | 8 +------- manifests/package.pp | 4 ++-- spec/classes/sensu_package_spec.rb | 18 ++++-------------- 3 files changed, 7 insertions(+), 23 deletions(-) diff --git a/manifests/init.pp b/manifests/init.pp index cdc25d5d83..744dc12338 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -175,11 +175,6 @@ # Default: false # Valid values: true, false # -# [*purge_scripts*] -# Boolean. If unused plugins, handlers, extensions and mutators should be removed from the system -# Default: false -# Valid values: true, false -# # [*use_embedded_ruby*] # Boolean. If the embedded ruby should be used # Default: false @@ -239,7 +234,6 @@ $plugins = [], $plugins_dir = undef, $purge_config = false, - $purge_scripts = false, $use_embedded_ruby = false, $rubyopt = '', $gem_path = '', @@ -247,7 +241,7 @@ $dashboard = false, ){ - validate_bool($client, $server, $api, $install_repo, $purge_config, $purge_scripts, $safe_mode, $manage_services) + validate_bool($client, $server, $api, $install_repo, $purge_config, $safe_mode, $manage_services) validate_re($repo, ['^main$', '^unstable$'], "Repo must be 'main' or 'unstable'. Found: ${repo}") validate_re($version, ['^absent$', '^installed$', '^latest$', '^present$', '^[\d\.\-]+$'], "Invalid package version: ${version}") diff --git a/manifests/package.pp b/manifests/package.pp index d8db1fbb16..44f711ba79 100644 --- a/manifests/package.pp +++ b/manifests/package.pp @@ -76,7 +76,7 @@ owner => 'sensu', group => 'sensu', recurse => true, - purge => $sensu::purge_scripts, + purge => $sensu::purge_config, require => Package['sensu'], } @@ -87,7 +87,7 @@ owner => 'sensu', group => 'sensu', recurse => true, - purge => $sensu::purge_scripts, + purge => $sensu::purge_config, require => Package['sensu'], } } diff --git a/spec/classes/sensu_package_spec.rb b/spec/classes/sensu_package_spec.rb index 82c2180bc5..0b8d6216f0 100644 --- a/spec/classes/sensu_package_spec.rb +++ b/spec/classes/sensu_package_spec.rb @@ -8,18 +8,13 @@ it { should create_class('sensu::package') } it { should contain_package('sensu').with_ensure('latest') } it { should contain_file('/etc/default/sensu') } - [ '/etc/sensu/conf.d', '/etc/sensu/conf.d/handlers', '/etc/sensu/conf.d/checks' ].each do |dir| + [ '/etc/sensu/conf.d', '/etc/sensu/conf.d/handlers', '/etc/sensu/conf.d/checks', + '/etc/sensu/handlers', '/etc/sensu/extensions', '/etc/sensu/mutators', + '/etc/sensu/extensions/handlers', '/etc/sensu/plugins'].each do |dir| it { should contain_file(dir).with( :ensure => 'directory', - :purge => false - ) } - end - [ '/etc/sensu/handlers', '/etc/sensu/extensions', '/etc/sensu/mutators', - '/etc/sensu/extensions/handlers', '/etc/sensu/plugins' ].each do |dir| - it { should contain_file(dir).with( - :ensure => 'directory', :recurse => true, - :purge => false + :purge => false ) } end it { should contain_file('/etc/sensu/config.json').with_ensure('absent') } @@ -160,11 +155,6 @@ ) } end - end - - context 'purge_scripts' do - let(:params) { { :purge_scripts => true } } - [ '/etc/sensu/handlers', '/etc/sensu/extensions', '/etc/sensu/mutators', '/etc/sensu/extensions/handlers', '/etc/sensu/plugins' ].each do |dir| it { should contain_file(dir).with( From 4b9daf0bda9935c4141ac655b9efc6b8c9b734ff Mon Sep 17 00:00:00 2001 From: Nicholas Hinds Date: Tue, 27 Jan 2015 08:42:30 +1300 Subject: [PATCH 3/3] Ensure subdirectories of handlers/extensions/mutators/plugins are purged by setting force to true --- manifests/package.pp | 16 ++++------------ spec/classes/sensu_package_spec.rb | 13 +++---------- 2 files changed, 7 insertions(+), 22 deletions(-) diff --git a/manifests/package.pp b/manifests/package.pp index 44f711ba79..23779fc7f9 100644 --- a/manifests/package.pp +++ b/manifests/package.pp @@ -59,7 +59,8 @@ require => Package['sensu'], } - file { [ '/etc/sensu/conf.d', '/etc/sensu/conf.d/handlers', '/etc/sensu/conf.d/checks', '/etc/sensu/conf.d/filters', '/etc/sensu/conf.d/extensions' ]: + file { [ '/etc/sensu/conf.d', '/etc/sensu/conf.d/handlers', '/etc/sensu/conf.d/checks', '/etc/sensu/conf.d/filters', '/etc/sensu/conf.d/extensions', + '/etc/sensu/handlers', '/etc/sensu/extensions', '/etc/sensu/mutators', '/etc/sensu/extensions/handlers' ]: ensure => directory, owner => 'sensu', group => 'sensu', @@ -70,24 +71,15 @@ require => Package['sensu'], } - file { ['/etc/sensu/handlers', '/etc/sensu/extensions', '/etc/sensu/mutators', '/etc/sensu/extensions/handlers']: - ensure => directory, - mode => '0555', - owner => 'sensu', - group => 'sensu', - recurse => true, - purge => $sensu::purge_config, - require => Package['sensu'], - } - if $sensu::_manage_plugins_dir { file { '/etc/sensu/plugins': ensure => directory, mode => '0555', owner => 'sensu', group => 'sensu', - recurse => true, purge => $sensu::purge_config, + recurse => true, + force => true, require => Package['sensu'], } } diff --git a/spec/classes/sensu_package_spec.rb b/spec/classes/sensu_package_spec.rb index 0b8d6216f0..9c215a714a 100644 --- a/spec/classes/sensu_package_spec.rb +++ b/spec/classes/sensu_package_spec.rb @@ -146,7 +146,9 @@ context 'purge_config' do let(:params) { { :purge_config => true } } - [ '/etc/sensu/conf.d', '/etc/sensu/conf.d/handlers', '/etc/sensu/conf.d/checks' ].each do |dir| + [ '/etc/sensu/conf.d', '/etc/sensu/conf.d/handlers', '/etc/sensu/conf.d/checks', + '/etc/sensu/handlers', '/etc/sensu/extensions', '/etc/sensu/mutators', + '/etc/sensu/extensions/handlers', '/etc/sensu/plugins' ].each do |dir| it { should contain_file(dir).with( :ensure => 'directory', :purge => true, @@ -154,15 +156,6 @@ :force => true ) } end - - [ '/etc/sensu/handlers', '/etc/sensu/extensions', '/etc/sensu/mutators', - '/etc/sensu/extensions/handlers', '/etc/sensu/plugins' ].each do |dir| - it { should contain_file(dir).with( - :ensure => 'directory', - :recurse => true, - :purge => true - ) } - end end end