From 7b5ae3fb20f7f0f48d6d2de4063de5a87c47a15e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javier=20B=C3=A9rtoli?= Date: Sat, 28 Dec 2013 07:22:23 -0300 Subject: [PATCH 1/4] Add extra lookups methods To be able to seach for module::varname, as it is the proposed format in puppet documentation --- lib/puppet/parser/functions/params_lookup.rb | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/lib/puppet/parser/functions/params_lookup.rb b/lib/puppet/parser/functions/params_lookup.rb index 53aad84..c97e521 100644 --- a/lib/puppet/parser/functions/params_lookup.rb +++ b/lib/puppet/parser/functions/params_lookup.rb @@ -3,8 +3,10 @@ # # This function lookups for a variable value in various locations # following this order (first match is returned) +# - Hiera backend (if present) for modulename::varname # - Hiera backend (if present) for modulename_varname # - Hiera backend (if present) for varname (if second argument is 'global') +# - Top Scope Variable ::modulename::varname # - Top Scope Variable ::modulename_varname # - Top Scope Variable ::varname (if second argument is 'global') # - Module default: ::modulename::params::varname @@ -21,8 +23,10 @@ module Puppet::Parser::Functions newfunction(:params_lookup, :type => :rvalue, :doc => <<-EOS This fuction looks for the given variable name in a set of different sources: +- Hiera, if available ('modulename::varname') - Hiera, if available ('modulename_varname') - Hiera, if available (if second argument is 'global') +- ::modulename::varname - ::modulename_varname - ::varname (if second argument is 'global') - ::modulename::params::varname @@ -39,6 +43,9 @@ module Puppet::Parser::Functions # Hiera Lookup if Puppet::Parser::Functions.function('hiera') + value = function_hiera(["#{module_name}::#{var_name}", '']) + return value if (not value.nil?) && (value != :undefined) && (value != '') + value = function_hiera(["#{module_name}_#{var_name}", '']) return value if (not value.nil?) && (value != :undefined) && (value != '') @@ -46,6 +53,10 @@ module Puppet::Parser::Functions return value if (not value.nil?) && (value != :undefined) && (value != '') end + # Top Scope Variable Lookup (::modulename::varname) + value = lookupvar("::#{module_name}::#{var_name}") + return value if (not value.nil?) && (value != :undefined) && (value != '') + # Top Scope Variable Lookup (::modulename_varname) value = lookupvar("::#{module_name}_#{var_name}") return value if (not value.nil?) && (value != :undefined) && (value != '') From 551035667f49c5a3a882386ebc53f402ad90ff57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javier=20B=C3=A9rtoli?= Date: Sat, 28 Dec 2013 07:48:41 -0300 Subject: [PATCH 2/4] Update spec_helper and fixtures to new versions --- .fixtures.yml | 3 ++- spec/spec_helper.rb | 23 +---------------------- 2 files changed, 3 insertions(+), 23 deletions(-) diff --git a/.fixtures.yml b/.fixtures.yml index c2f8921..c8063a7 100644 --- a/.fixtures.yml +++ b/.fixtures.yml @@ -1,5 +1,6 @@ fixtures: repositories: - "concat": "git://github.com/example42/puppet-concat.git" + "stdlib": "git://github.com/puppetlabs/puppetlabs-stdlib.git" + "concat": "git://github.com/puppetlabs/puppetlabs-concat.git" symlinks: "puppi": "#{source_dir}" diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 9a20c1f..2c6f566 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,22 +1 @@ -# Based on https://github.com/puppetlabs/puppetlabs-ntp/blob/master/spec/spec_helper.rb -# Thanks to Ken Barber for advice about http://projects.puppetlabs.com/issues/11191 -require 'puppet' -require 'rspec-puppet' -require 'tmpdir' - -RSpec.configure do |c| - c.before :each do - @puppetdir = Dir.mktmpdir("puppi") - manifestdir = File.join(@puppetdir, "manifests") - Dir.mkdir(manifestdir) - FileUtils.touch(File.join(manifestdir, "site.pp")) - Puppet[:confdir] = @puppetdir - end - - c.after :each do -# FileUtils.remove_entry_secure(@puppetdir) # This breaks with multiple spec files - FileUtils.rm_rf(Dir.glob('/tmp/puppi20*') , :secure => true) - end - - c.module_path = File.join(File.dirname(__FILE__), '../../') -end +require 'puppetlabs_spec_helper/module_spec_helper' From 01f9936ec18c38a5747665ac7f95bda8c46f2ba4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javier=20B=C3=A9rtoli?= Date: Sat, 28 Dec 2013 07:49:23 -0300 Subject: [PATCH 3/4] Fix specs to new rspec version --- spec/defines/puppi_check_spec.rb | 3 +-- spec/defines/puppi_deploy_spec.rb | 3 +-- spec/defines/puppi_helper_spec.rb | 3 +-- spec/defines/puppi_info_spec.rb | 3 +-- spec/defines/puppi_initialize_spec.rb | 4 +--- spec/defines/puppi_log_spec.rb | 3 +-- spec/defines/puppi_project_spec.rb | 4 +--- spec/defines/puppi_report_spec.rb | 4 +--- spec/defines/puppi_rollback_spec.rb | 3 +-- spec/defines/puppi_run_spec.rb | 3 +-- spec/defines/puppi_todo_spec.rb | 3 +-- 11 files changed, 11 insertions(+), 25 deletions(-) diff --git a/spec/defines/puppi_check_spec.rb b/spec/defines/puppi_check_spec.rb index 2d4738c..aa6a878 100644 --- a/spec/defines/puppi_check_spec.rb +++ b/spec/defines/puppi_check_spec.rb @@ -19,8 +19,7 @@ should contain_file('Puppi_check_myapp_50_get').with_ensure('present') end it 'should populate correctly the puppi::check step file' do - content = catalogue.resource('file', 'Puppi_check_myapp_50_get').send(:parameters)[:content] - content.should match "/usr/lib/nagios/plugins/echo\n" + should contain_file('Puppi_check_myapp_50_get').with_content("/usr/lib/nagios/plugins/echo\n") end end diff --git a/spec/defines/puppi_deploy_spec.rb b/spec/defines/puppi_deploy_spec.rb index 48d9271..a1969ba 100644 --- a/spec/defines/puppi_deploy_spec.rb +++ b/spec/defines/puppi_deploy_spec.rb @@ -18,8 +18,7 @@ should contain_file('/etc/puppi/projects/myapp/deploy/50-get').with_ensure('present') end it 'should populate correctly the puppi::deploy step file' do - content = catalogue.resource('file', '/etc/puppi/projects/myapp/deploy/50-get').send(:parameters)[:content] - content.should match "su - root -c \"export project=myapp && /etc/puppi/scripts/echo \"\n" + should contain_file('/etc/puppi/projects/myapp/deploy/50-get').with_content("su - root -c \"export project=myapp && /etc/puppi/scripts/echo \"\n") end end diff --git a/spec/defines/puppi_helper_spec.rb b/spec/defines/puppi_helper_spec.rb index 70f65c0..7a112f3 100644 --- a/spec/defines/puppi_helper_spec.rb +++ b/spec/defines/puppi_helper_spec.rb @@ -13,8 +13,7 @@ should contain_file('puppi_helper_spec').with_ensure('present') end it 'should populate correctly the helper file' do - content = catalogue.resource('file', 'puppi_helper_spec').send(:parameters)[:content] - content.should match('info:') + should contain_file('puppi_helper_spec').with_content(/info:/) end end diff --git a/spec/defines/puppi_info_spec.rb b/spec/defines/puppi_info_spec.rb index 6fbad1d..7dcc99f 100644 --- a/spec/defines/puppi_info_spec.rb +++ b/spec/defines/puppi_info_spec.rb @@ -17,8 +17,7 @@ should contain_file('/etc/puppi/info/sample').with_ensure('present') end it 'should populate correctly the puppi::info step file' do - content = catalogue.resource('file', '/etc/puppi/info/sample').send(:parameters)[:content] - content.should match(/myownscript/) + should contain_file('/etc/puppi/info/sample').with_content(/myownscript/) end end diff --git a/spec/defines/puppi_initialize_spec.rb b/spec/defines/puppi_initialize_spec.rb index 5a12ca7..158a600 100644 --- a/spec/defines/puppi_initialize_spec.rb +++ b/spec/defines/puppi_initialize_spec.rb @@ -18,9 +18,7 @@ should contain_file('/etc/puppi/projects/myapp/initialize/50-get').with_ensure('present') end it 'should populate correctly the puppi::initialize step file' do - content = catalogue.resource('file', '/etc/puppi/projects/myapp/initialize/50-get').send(:parameters)[:content] - content.should match "su - root -c \"export project=myapp && /etc/puppi/scripts/echo \"\n" - # content.should match(/myapp,get/) + should contain_file('/etc/puppi/projects/myapp/initialize/50-get').with_content("su - root -c \"export project=myapp && /etc/puppi/scripts/echo \"\n") end end diff --git a/spec/defines/puppi_log_spec.rb b/spec/defines/puppi_log_spec.rb index 97f0530..7fd8e91 100644 --- a/spec/defines/puppi_log_spec.rb +++ b/spec/defines/puppi_log_spec.rb @@ -15,8 +15,7 @@ should contain_file('/etc/puppi/logs/mylog').with_ensure('present') end it 'should populate correctly the puppi::log step file' do - content = catalogue.resource('file', '/etc/puppi/logs/mylog').send(:parameters)[:content] - content.should match(/mylog.log/) + should contain_file('/etc/puppi/logs/mylog').with_content(/mylog.log/) end end diff --git a/spec/defines/puppi_project_spec.rb b/spec/defines/puppi_project_spec.rb index cfa1ba7..fbbf8ba 100644 --- a/spec/defines/puppi_project_spec.rb +++ b/spec/defines/puppi_project_spec.rb @@ -18,9 +18,7 @@ should contain_file('/etc/puppi/projects/myapp/report/50-get').with_ensure('present') end it 'should populate correctly the puppi::report step file' do - content = catalogue.resource('file', '/etc/puppi/projects/myapp/report/50-get').send(:parameters)[:content] - content.should match "su - root -c \"export project=myapp && /etc/puppi/scripts/echo \"\n" - # content.should match(/myapp,get/) + should contain_file('/etc/puppi/projects/myapp/report/50-get').with_content("su - root -c \"export project=myapp && /etc/puppi/scripts/echo \"\n") end end diff --git a/spec/defines/puppi_report_spec.rb b/spec/defines/puppi_report_spec.rb index cfa1ba7..fbbf8ba 100644 --- a/spec/defines/puppi_report_spec.rb +++ b/spec/defines/puppi_report_spec.rb @@ -18,9 +18,7 @@ should contain_file('/etc/puppi/projects/myapp/report/50-get').with_ensure('present') end it 'should populate correctly the puppi::report step file' do - content = catalogue.resource('file', '/etc/puppi/projects/myapp/report/50-get').send(:parameters)[:content] - content.should match "su - root -c \"export project=myapp && /etc/puppi/scripts/echo \"\n" - # content.should match(/myapp,get/) + should contain_file('/etc/puppi/projects/myapp/report/50-get').with_content("su - root -c \"export project=myapp && /etc/puppi/scripts/echo \"\n") end end diff --git a/spec/defines/puppi_rollback_spec.rb b/spec/defines/puppi_rollback_spec.rb index 6910eb5..2d4cbe5 100644 --- a/spec/defines/puppi_rollback_spec.rb +++ b/spec/defines/puppi_rollback_spec.rb @@ -18,8 +18,7 @@ should contain_file('/etc/puppi/projects/myapp/rollback/50-get').with_ensure('present') end it 'should populate correctly the puppi::rollback step file' do - content = catalogue.resource('file', '/etc/puppi/projects/myapp/rollback/50-get').send(:parameters)[:content] - content.should match "su - root -c \"export project=myapp && /etc/puppi/scripts/echo \"\n" + should contain_file('/etc/puppi/projects/myapp/rollback/50-get').with_content("su - root -c \"export project=myapp && /etc/puppi/scripts/echo \"\n") end end diff --git a/spec/defines/puppi_run_spec.rb b/spec/defines/puppi_run_spec.rb index eaa5e54..324410a 100644 --- a/spec/defines/puppi_run_spec.rb +++ b/spec/defines/puppi_run_spec.rb @@ -12,8 +12,7 @@ describe 'Test puppi run exe creation' do it 'should create a puppi::run exec' do - content = catalogue.resource('exec', 'Run_Puppi_myapp').send(:parameters)[:command] - content.should match /puppi deploy myapp/ + should contain_exec('Run_Puppi_myapp').with_command(/puppi deploy myapp/) end end diff --git a/spec/defines/puppi_todo_spec.rb b/spec/defines/puppi_todo_spec.rb index 124bdde..4838522 100644 --- a/spec/defines/puppi_todo_spec.rb +++ b/spec/defines/puppi_todo_spec.rb @@ -17,8 +17,7 @@ should contain_file('/etc/puppi/todo/mytodo').with_ensure('present') end it 'should populate correctly the puppi::todo step file' do - content = catalogue.resource('file', '/etc/puppi/todo/mytodo').send(:parameters)[:content] - content.should match(/check_test/) + should contain_file('/etc/puppi/todo/mytodo').with_content(/check_test/) end end From c1200ad586cb0182e0ed9d6fa9fad5448767015f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javier=20B=C3=A9rtoli?= Date: Sat, 28 Dec 2013 08:46:32 -0300 Subject: [PATCH 4/4] Fix travis integration --- .travis.yml | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/.travis.yml b/.travis.yml index dffeca9..c70dfda 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,19 +2,26 @@ language: ruby rvm: - 1.8.7 - 1.9.3 -script: - - "rake spec SPEC_OPTS='--format documentation'" + - 2.0.0 +script: "bundle exec rake spec SPEC_OPTS='--format documentation'" env: - - PUPPET_VERSION="~> 2.6.0" - - PUPPET_VERSION="~> 2.7.0" - - PUPPET_VERSION="~> 3.0.0" - - PUPPET_VERSION="~> 3.1.0" + - PUPPET_GEM_VERSION="~> 2.6.0" + - PUPPET_GEM_VERSION="~> 2.7.0" + - PUPPET_GEM_VERSION="~> 3.0.0" + - PUPPET_GEM_VERSION="~> 3.1.0" + - PUPPET_GEM_VERSION="~> 3.2.0" matrix: exclude: + - rvm: 1.8.7 + env: PUPPET_GEM_VERSION="~> 2.7.0" - rvm: 1.9.3 - env: PUPPET_VERSION="~> 2.6.0" - gemfile: .gemfile - + env: PUPPET_GEM_VERSION="~> 2.7.0" + - rvm: 2.0.0 + env: PUPPET_GEM_VERSION="~> 2.7.0" + - rvm: 2.0.0 + env: PUPPET_GEM_VERSION="~> 3.0.0" + - rvm: 2.0.0 + env: PUPPET_GEM_VERSION="~> 3.1.0" gemfile: .gemfile notifications: email: