Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added cuda GPU plugin #645

Merged
merged 3 commits into from Feb 12, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 10 additions & 0 deletions README.md
Expand Up @@ -106,6 +106,7 @@ documentation for each plugin for configurable attributes.
* `cpu` (see [collectd::plugin::cpu](#class-collectdplugincpu) below)
* `cpufreq` (see [collectd::plugin::cpufreq](#class-collectdplugincpufreq) below)
* `csv` (see [collectd::plugin::csv](#class-collectdplugincsv) below)
* `cuda` (see [collectd::plugin::cuda](#class-collectdplugincuda) below)
* `curl` (see [collectd::plugin::curl](#class-collectdplugincurl) below)
* `curl_json` (see [collectd::plugin::curl_json](#class-collectdplugincurl_json)
below)
Expand Down Expand Up @@ -357,6 +358,15 @@ class { 'collectd::plugin::csv':
}
```


### Class: `collectd::plugin::cuda`

```puppet
class { 'collectd::plugin::cuda':
}
```


### Class: `collectd::plugin::curl`

```puppet
Expand Down
59 changes: 59 additions & 0 deletions manifests/plugin/cuda.pp
@@ -0,0 +1,59 @@
# Class: collectd::plugin::cuda
#
# @see https://pypi.python.org/pypi/collectd-cuda
#
# Configures cuda metrics collection. Optionally installs the plugin
# Note, it is up to you to support package installation and sources
#
# @param ensure Optional[String] Passed to package and collectd::plugin resources (both). Default: present
# @param manage_package Optional[Boolean] Toggles installation of plugin. Default: undef
# @param package_name Optional[String] Name of plugin package to install. Default: collectd-cuda
# @param package_provider Optional[String] Passed to package resource. Default: pip
# @param provider_proxy Optional[String] Proxy for provider. Default: undef
class collectd::plugin::cuda (
Optional[String] $ensure = 'present',
Optional[Boolean] $manage_package = undef,
Optional[String] $package_name = 'collectd-cuda',
Optional[String] $package_provider = 'pip',
Optional[String] $provider_proxy = undef,
) {
include ::collectd

$_manage_package = pick($manage_package, $::collectd::manage_package)

if ($_manage_package) {
if (!defined(Package['python-pip'])) {
package { 'python-pip': ensure => 'present', }

Package[$package_name] {
require => Package['python-pip'],
}

if $::osfamily == 'RedHat' {
# Epel is installed in install.pp if manage_repo is true
# python-pip doesn't exist in base for RedHat. Need epel installed first
if (defined(Yum::Install['epel-release'])) {
Package['python-pip'] {
require => Yum::Install['epel-release'],
}
}
}
}
}

if ($_manage_package) and ($provider_proxy) {
$install_options = [{'--proxy' => $provider_proxy}]
} else {
$install_options = undef
}

package { $package_name:
ensure => $ensure,
provider => $package_provider,
install_options => $install_options,
}

collectd::plugin::python::module { 'collectd_cuda.collectd_plugin':
ensure => $ensure,
}
}
62 changes: 62 additions & 0 deletions spec/classes/collectd_plugin_cuda_spec.rb
@@ -0,0 +1,62 @@
require 'spec_helper'

describe 'collectd::plugin::cuda', type: :class do
let :facts do
{
osfamily: 'RedHat',
collectd_version: '5.5.1',
operatingsystemmajrelease: '7',
operatingsystem: 'CentOS',
python_dir: '/usr/local/lib/python2.7/dist-packages'
}
end

context 'package ensure' do
context ':ensure => present' do
it 'import collectd_cuda.collectd_plugin in python-config' do
is_expected.to contain_concat_fragment('collectd_plugin_python_conf_collectd_cuda.collectd_plugin').with_content(%r{Import "collectd_cuda.collectd_plugin"})
end
end
end

context ':ensure => absent' do
let :params do
{ ensure: 'absent' }
end

it 'Will remove python-config' do
is_expected.not_to contain_concat__fragment('collectd_plugin_python_conf_collectd_cuda.collectd_plugin').with(ensure: 'present')
end
end

# based on manage_package from dns spec but I added support for multiple providers
describe 'with manage_package parameter' do
[false, true].each do |value|
context "set to #{value}" do
%w(present absent).each do |ensure_value|
%w(pip yum).each do |provider|
%w(collectd-cuda collectd_cuda).each do |packagename|
context "and ensure set to #{ensure_value} for package #{packagename} with package_provider #{provider}" do
let :params do
{
ensure: ensure_value,
manage_package: value,
package_name: packagename,
package_provider: provider
}
end

it do
is_expected.to contain_package(packagename).with(
'ensure' => ensure_value,
'provider' => provider
)
end
end # packagename
end # ensure set
end # provider
end # present absent
end # context set
end # 'true', true
end # describe with manage_package
end