From bc3c755e4677058ab10135e97b45518e0421e56a Mon Sep 17 00:00:00 2001 From: Phil Friderici Date: Thu, 13 Jul 2017 12:15:03 +0000 Subject: [PATCH] (GH-599) Pass gem_install_options to sensu::plugin class --- manifests/plugin.pp | 39 +++++++++++++++++++++---------- spec/defines/sensu_plugin_spec.rb | 20 ++++++++++++++++ 2 files changed, 47 insertions(+), 12 deletions(-) diff --git a/manifests/plugin.pp b/manifests/plugin.pp index 66cd626447..247f097707 100644 --- a/manifests/plugin.pp +++ b/manifests/plugin.pp @@ -43,16 +43,25 @@ # Boolean. When using url source, disable certificate checking for HTTPS # Default: false # Valid values: true, false +# +# [*gem_install_options*] +# Optional configuration to use for the installation of the +# sensu plugin gem with sensu_gem provider. +# See: https://docs.puppetlabs.com/references/latest/type.html#package-attribute-install_options +# Default: $::sensu::gem_install_options +# Example value: [{ '-p' => 'http://user:pass@myproxy.company.org:8080' }] +# define sensu::plugin ( - $type = 'file', - $install_path = '/etc/sensu/plugins', - $purge = true, - $recurse = true, - $force = true, - $pkg_version = 'latest', - $pkg_provider = $::sensu::sensu_plugin_provider, - $pkg_checksum = undef, - $nocheckcertificate = false, + $type = 'file', + $install_path = '/etc/sensu/plugins', + $purge = true, + $recurse = true, + $force = true, + $pkg_version = 'latest', + $pkg_provider = $::sensu::sensu_plugin_provider, + $pkg_checksum = undef, + $nocheckcertificate = false, + $gem_install_options = $::sensu::gem_install_options, ) { File { @@ -126,10 +135,16 @@ require => Package[$sensu::package::pkg_title], } } - 'package': { + 'package': { + $gem_install_options_real = $pkg_provider ? { + 'gem' => $gem_install_options, + default => undef, + } + package { $name: - ensure => $pkg_version, - provider => $pkg_provider, + ensure => $pkg_version, + provider => $pkg_provider, + install_options => $gem_install_options_real, } } default: { diff --git a/spec/defines/sensu_plugin_spec.rb b/spec/defines/sensu_plugin_spec.rb index ea65acdec9..b9bd4409f5 100644 --- a/spec/defines/sensu_plugin_spec.rb +++ b/spec/defines/sensu_plugin_spec.rb @@ -124,6 +124,14 @@ class { '::sensu': let(:params) { { :type => 'package' } } it { should contain_package('sensu-plugins').with_ensure('latest') } + + it do + should contain_package('sensu-plugins').with({ + 'ensure' => 'latest', + 'provider' => nil, + 'install_options' => nil, + }) + end end context 'set pkg_version' do @@ -143,6 +151,18 @@ class { '::sensu': it { should contain_package('sensu-plugins').with_provider(nil) } end + + # without pkg_provider => gem gem_install_options will be ignored + context 'set gem_install_options' do + let(:params) { { :type => 'package', :gem_install_options => [{ '-p' => 'http://user:pass@myproxy.company.org:8080' }] } } + it { should contain_package('sensu-plugins').with_install_options(nil) } + end + + context 'set gem_install_options and pkg_provider = gem' do + let(:params) { { :type => 'package', :gem_install_options => [{ '-p' => 'http://user:pass@myproxy.company.org:8080' }], :pkg_provider => 'gem' } } + it { should contain_package('sensu-plugins').with_install_options([{ '-p' => 'http://user:pass@myproxy.company.org:8080' }]) } + end + end #package context 'default' do