Skip to content

Commit

Permalink
Merge pull request #805 from traylenator/pythonaccept
Browse files Browse the repository at this point in the history
A collectd::plugin::python acceptance test
  • Loading branch information
traylenator authored Jun 6, 2018
2 parents 3700eb2 + 7ab43c2 commit e69dd24
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 1 deletion.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1407,6 +1407,9 @@ class { 'collectd::plugin::protocols':
```

#### Class: `collectd::plugin::python`
The plugin uses a fact `python_dir` to find the python load path for modules.
python must be installed as a pre-requisite for the this fact to give a
non-default value.

* `modulepaths` is an array of paths where will be Collectd looking for Python
modules, Puppet will ensure that each of specified directories exists and it
Expand Down
71 changes: 71 additions & 0 deletions spec/acceptance/class_plugin_python_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
require 'spec_helper_acceptance'

describe 'collectd::plugin::python class' do
context 'basic parameters' do
# Using puppet_apply as a helper
it 'works idempotently with no errors' do
pp = <<-EOS
class{'collectd::plugin::python':
}
EOS
# Run 3 times since the collectd_version
# fact is impossible until collectd is
# installed. This acceptance test happens
# to be first.
apply_manifest(pp, catch_failures: true)
apply_manifest(pp, catch_failures: true)
apply_manifest(pp, catch_changes: true)
end

describe service('collectd') do
it { is_expected.to be_running }
end
end

context 'trivial module' do
it 'works idempotently with no errors' do
pp = <<-EOS
if $facts['os']['family'] == 'Debian' {
# for collectdctl command
package{'collectd-utils':
ensure => present,
}
}
package{'python-pip':
ensure => present,
}
package{['collectd-connect-time']:
ensure => 'present',
provider => 'pip',
require => Package['python-pip'],
before => Service['collectd'],
}
class{'collectd::plugin::python':
logtraces => true,
interactive => false,
modules => {
'collectd_connect_time' => {
config => [{'target' => 'google.de'}],
},
},
}
class{'collectd::plugin::unixsock':
socketfile => '/var/run/collectd-sock',
}
EOS

# Run it twice and test for idempotency
apply_manifest(pp, catch_failures: true)
apply_manifest(pp, catch_changes: true)
shell('sleep 10')
end
describe service('collectd') do
it { is_expected.to be_running }
end
# Check metric is really there.
describe command('collectdctl -s /var/run/collectd-sock listval') do
its(:exit_status) { is_expected.to eq 0 }
its(:stdout) { is_expected.to match %r{google.de} }
end
end
end
4 changes: 3 additions & 1 deletion spec/classes/collectd_plugin_python_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@
end

it 'will ensure the two directories are here' do
is_expected.to contain_file('/tmp/')
is_expected.to contain_file('/tmp/').with(
require: 'Package[collectd]'
)
is_expected.to contain_file('/data/')
end
it 'will set two modulepath in the module conf' do
Expand Down
2 changes: 2 additions & 0 deletions spec/spec_helper_acceptance.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
# Install module and dependencies
puppet_module_install(source: proj_root, module_name: 'collectd')
hosts.each do |host|
# python is pre-requisite to the python_path fact.
on host, puppet('resource', 'package', 'python', 'ensure=installed')
on host, puppet('module', 'install', 'puppetlabs-apt'), acceptable_exit_codes: [0]
on host, puppet('module', 'install', 'puppetlabs-stdlib'), acceptable_exit_codes: [0]
on host, puppet('module', 'install', 'puppetlabs-concat'), acceptable_exit_codes: [0]
Expand Down

0 comments on commit e69dd24

Please sign in to comment.