Skip to content

Commit

Permalink
Add python as explicit dependency to python plugin
Browse files Browse the repository at this point in the history
Particularly on Ubuntu it nescesary to install python explicitly
otherwise the directory `/usr/local/lib/python2.7` does
not exist. Collectd itself only requires python-lib.
  • Loading branch information
traylenator committed May 31, 2018
1 parent 91fda29 commit c731ab7
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 13 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1395,6 +1395,9 @@ class { 'collectd::plugin::protocols':
collectd with the name of the exception and the message (default: `false`)
* `conf_name` name of the file that will contain the python module configuration
(default: `python-config.conf`)
* `python_manager` Should a python package be installed. (default `true`)
* `python_package` Name of python package to install. (default `python`)
* `python_package_ensure` Ensure state of python package to install. (default `present`)

See [collectd-python documentation](https://collectd.org/documentation/manpages/collectd-python.5.shtml)
for more details.
Expand Down
34 changes: 22 additions & 12 deletions manifests/plugin/python.pp
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
# See http://collectd.org/documentation/manpages/collectd.conf.5.shtml#plugin_python
class collectd::plugin::python (
# Python 2 defaults to 'ascii' and Python 3 to 'utf-8'
$encoding = undef,
$ensure = 'present',
$encoding = undef,
$ensure = 'present',
# Unlike most other plugins, this one should set "Globals true". This will cause collectd
# to export the name of all objects in the Python interpreter for all plugins to see.
Boolean $globals = true,
Boolean $interactive = false,
$interval = undef,
Boolean $logtraces = false,
$manage_package = undef,
Array $modulepaths = [],
Hash $modules = {},
$order = '10',
$conf_name = 'python-config.conf',
Boolean $globals = true,
Boolean $interactive = false,
$interval = undef,
Boolean $logtraces = false,
$manage_package = undef,
Array $modulepaths = [],
Hash $modules = {},
$order = '10',
$conf_name = 'python-config.conf',
Boolean $manage_python = true,
String $python_package = 'python',
String $python_package_ensure = 'present',
) {

include ::collectd
Expand Down Expand Up @@ -47,6 +50,13 @@
globals => $globals,
}

if $manage_python {
ensure_packages([$python_package], { ensure => $python_package_ensure })
$_module_dir_require = [Package[$collectd::package_name],Package[$python_package]]
} else {
$_module_dir_require = Package[$collectd::package_name]
}

$ensure_modulepath = $ensure ? {
'absent' => $ensure,
default => 'directory',
Expand All @@ -60,7 +70,7 @@
'purge' => $::collectd::purge_config,
'force' => true,
'group' => $collectd::config_group,
'require' => Package[$collectd::package_name]
'require' => $_module_dir_require,
}
)

Expand Down
38 changes: 37 additions & 1 deletion spec/classes/collectd_plugin_python_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@

context ':ensure => present' do
context ':ensure => present and default parameters' do
it 'install python package' do
is_expected.to contain_package('python').with(ensure: 'present')
end
it 'ensures that $modulepaths exits' do
is_expected.to contain_file('/usr/local/lib/python2.7/dist-packages').with(ensure: 'directory')
end
Expand Down Expand Up @@ -48,6 +51,37 @@
)
end
end
context ':ensure => present and python package specified' do
let :params do
{
python_package: 'mypython',
python_package_ensure: '1.2.3',
manage_python: true
}
end

it 'install specified python package' do
is_expected.to contain_package('mypython').with(ensure: '1.2.3')
end
end

context ':ensure => present, moduledirs and manage_python false' do
let :params do
{
modulepaths: ['/tmp/', '/data/'],
manage_python: false
}
end

it 'install specified python package' do
is_expected.not_to contain_package('python')
end
it 'will ensure one directory is here here' do
is_expected.to contain_file('/tmp/').with(
require: 'Package[collectd]'
)
end
end

context ':ensure => present and multiple $modulepaths' do
let :params do
Expand All @@ -57,7 +91,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]{:name=>"collectd"}, Package[python]{:name=>"python"}]'
)
is_expected.to contain_file('/data/')
end
it 'will set two modulepath in the module conf' do
Expand Down

0 comments on commit c731ab7

Please sign in to comment.