From e60652699dc0529b58dd0629896086a8b3f54b38 Mon Sep 17 00:00:00 2001 From: Ingo Dyck Date: Sat, 13 Dec 2014 23:39:21 +0000 Subject: [PATCH] plugin::python introduce ensure parameter --- manifests/plugin/python.pp | 5 +- spec/defines/collectd_plugin_python_spec.rb | 67 +++++++++++++++++++++ 2 files changed, 71 insertions(+), 1 deletion(-) create mode 100644 spec/defines/collectd_plugin_python_spec.rb diff --git a/manifests/plugin/python.pp b/manifests/plugin/python.pp index dca4ade7b..2c2c3919f 100644 --- a/manifests/plugin/python.pp +++ b/manifests/plugin/python.pp @@ -3,6 +3,7 @@ $modulepath, $module, $script_source, + $ensure = present, $config = {}, $order = '10', ) { @@ -14,13 +15,14 @@ # This is deprecated file naming ensuring old style file removed, and should be removed in next major relese file { "${name}.load-deprecated": - path => "${conf_dir}/${name}.conf", ensure => absent, + path => "${conf_dir}/${name}.conf", } # End deprecation file { "${name}.load": + ensure => $ensure, path => "${conf_dir}/${order}-${name}.conf", owner => 'root', group => $collectd::params::root_group, @@ -31,6 +33,7 @@ file { "${name}.script": + ensure => $ensure, path => "${modulepath}/${module}.py", owner => 'root', group => $collectd::params::root_group, diff --git a/spec/defines/collectd_plugin_python_spec.rb b/spec/defines/collectd_plugin_python_spec.rb new file mode 100644 index 000000000..85951caff --- /dev/null +++ b/spec/defines/collectd_plugin_python_spec.rb @@ -0,0 +1,67 @@ +require 'spec_helper' + +describe 'collectd::plugin::python', :type => :define do + + context ':ensure => present' do + let :facts do + { + :osfamily => 'Debian' + } + end + let (:title) {'elasticsearch'} + let :params do + { + :modulepath => '/usr/lib/collectd', + :module => 'elasticsearch', + :script_source => 'puppet:///modules/myorg/elasticsearch_collectd_python.py', + :config => {'Cluster' => 'elasticsearch'}, + } + end + + it 'Will create /etc/collectd/conf.d/10-elasticsearch.conf' do + should contain_file('elasticsearch.load').with({ + :ensure => 'present', + :path => '/etc/collectd/conf.d/10-elasticsearch.conf', + :content => "\n Globals true\n\n\n\n ModulePath \"/usr/lib/collectd\"\n\n Import \"elasticsearch\"\n\n \n Verbose false\n\t\tCluster \"elasticsearch\"\n \n\n", + }) + end + it 'Will create /usr/lib/collectd/elasticsearch.py' do + should contain_file('elasticsearch.script').with({ + :ensure => 'present', + :path => '/usr/lib/collectd/elasticsearch.py', + #:content => "\n \n SecurityLevel \"Encrypt\"\n Username \"foo\"\n Password \"bar\"\n Interface \"eth0\"\n\n \n\n", + }) + end + end + + context ':ensure => absent' do + let :facts do + { + :osfamily => 'Debian' + } + end + let (:title) {'elasticsearch'} + let :params do + { + :ensure => 'absent', + :modulepath => '/usr/lib/collectd', + :module => 'elasticsearch', + :script_source => 'puppet:///modules/myorg/elasticsearch_collectd_python.py', + :config => {'Cluster' => 'elasticsearch'}, + } + end + it 'Will not create /etc/collectd/conf.d/10-elasticsearch.conf' do + should contain_file('elasticsearch.load').with({ + :ensure => 'absent', + :path => '/etc/collectd/conf.d/10-elasticsearch.conf', + }) + end + it 'Will not create /usr/lib/collectd/elasticsearch.py' do + should contain_file('elasticsearch.script').with({ + :ensure => 'absent', + :path => '/usr/lib/collectd/elasticsearch.py', + }) + end + end + +end