From 344f6adb36910f3f6cb447669d7b32aed8a624a2 Mon Sep 17 00:00:00 2001 From: Morgan Haskel Date: Thu, 11 Sep 2014 12:18:05 -0400 Subject: [PATCH 1/2] Try to remove all the platform dependent stuff And updated the tests to work as planned --- spec/acceptance/concat_spec.rb | 35 ++++---- spec/acceptance/deprecation_warnings_spec.rb | 79 ++++++++++--------- .../fragments_are_always_replaced_spec.rb | 56 ++++++++----- spec/acceptance/quoted_paths_spec.rb | 21 +++-- 4 files changed, 108 insertions(+), 83 deletions(-) diff --git a/spec/acceptance/concat_spec.rb b/spec/acceptance/concat_spec.rb index 31c1647..2b4fc91 100644 --- a/spec/acceptance/concat_spec.rb +++ b/spec/acceptance/concat_spec.rb @@ -2,17 +2,25 @@ require 'spec_helper_acceptance' case fact('osfamily') when 'AIX' - username = 'root' - groupname = 'system' + username = 'root' + groupname = 'system' + scriptname = 'concatfragments.sh' when 'Darwin' - username = 'root' - groupname = 'wheel' + username = 'root' + groupname = 'wheel' + scriptname = 'concatfragments.sh' when 'windows' - username = 'Administrator' - groupname = 'Administrators' + username = 'Administrator' + groupname = 'Administrators' + scriptname = 'concatfragments.rb' +when 'solaris' + username = 'root' + groupname = 'root' + scriptname = 'concatfragments.rb' else - username = 'root' - groupname = 'root' + username = 'root' + groupname = 'root' + scriptname = 'concatfragments.sh' end describe 'basic concat test' do @@ -28,7 +36,6 @@ describe 'basic concat test' do describe file("#{default['puppetvardir']}/concat") do it { should be_directory } it { should be_owned_by username } - it { should be_grouped_into groupname } it("should be mode", :unless => (fact('osfamily') == 'AIX')) { should be_mode 755 } @@ -36,15 +43,13 @@ describe 'basic concat test' do describe file("#{default['puppetvardir']}/concat/bin") do it { should be_directory } it { should be_owned_by username } - it { should be_grouped_into groupname } it("should be mode", :unless => (fact('osfamily') == 'AIX')) { should be_mode 755 } end - describe file("#{default['puppetvardir']}/concat/bin/concatfragments.sh") do + describe file("#{default['puppetvardir']}/concat/bin/#{scriptname}") do it { should be_file } it { should be_owned_by username } - #it { should be_grouped_into groupname } it("should be mode", :unless => (fact('osfamily') == 'AIX')) { should be_mode 755 } @@ -52,7 +57,6 @@ describe 'basic concat test' do describe file("#{default['puppetvardir']}/concat/#{safe_basedir}_file") do it { should be_directory } it { should be_owned_by username } - it { should be_grouped_into groupname } it("should be mode", :unless => (fact('osfamily') == 'AIX')) { should be_mode 750 } @@ -60,7 +64,6 @@ describe 'basic concat test' do describe file("#{default['puppetvardir']}/concat/#{safe_basedir}_file/fragments") do it { should be_directory } it { should be_owned_by username } - it { should be_grouped_into groupname } it("should be mode", :unless => (fact('osfamily') == 'AIX')) { should be_mode 750 } @@ -68,7 +71,6 @@ describe 'basic concat test' do describe file("#{default['puppetvardir']}/concat/#{safe_basedir}_file/fragments.concat") do it { should be_file } it { should be_owned_by username } - it { should be_grouped_into groupname } it("should be mode", :unless => (fact('osfamily') == 'AIX')) { should be_mode 640 } @@ -76,7 +78,6 @@ describe 'basic concat test' do describe file("#{default['puppetvardir']}/concat/#{safe_basedir}_file/fragments.concat.out") do it { should be_file } it { should be_owned_by username } - it { should be_grouped_into groupname } it("should be mode", :unless => (fact('osfamily') == 'AIX')) { should be_mode 640 } @@ -127,7 +128,6 @@ describe 'basic concat test' do describe file("#{default['puppetvardir']}/concat/#{safe_basedir}_file/fragments/01_1") do it { should be_file } it { should be_owned_by username } - it { should be_grouped_into groupname } it("should be mode", :unless => (fact('osfamily') == 'AIX')) { should be_mode 640 } @@ -135,7 +135,6 @@ describe 'basic concat test' do describe file("#{default['puppetvardir']}/concat/#{safe_basedir}_file/fragments/02_2") do it { should be_file } it { should be_owned_by username } - it { should be_grouped_into groupname } it("should be mode", :unless => (fact('osfamily') == 'AIX')) { should be_mode 640 } diff --git a/spec/acceptance/deprecation_warnings_spec.rb b/spec/acceptance/deprecation_warnings_spec.rb index 6f8fce1..93ad411 100644 --- a/spec/acceptance/deprecation_warnings_spec.rb +++ b/spec/acceptance/deprecation_warnings_spec.rb @@ -1,6 +1,7 @@ require 'spec_helper_acceptance' describe 'deprecation warnings' do + basedir = default.tmpdir('concat') shared_examples 'has_warning'do |pp, w| it 'applies the manifest twice with a stderr regex' do @@ -11,11 +12,11 @@ describe 'deprecation warnings' do context 'concat gnu parameter' do pp = <<-EOS - concat { '/tmp/concat/file': + concat { '#{basedir}/file': gnu => 'foo', } concat::fragment { 'foo': - target => '/tmp/concat/file', + target => '#{basedir}/file', content => 'bar', } EOS @@ -28,11 +29,11 @@ describe 'deprecation warnings' do ['true', 'yes', 'on'].each do |warn| context warn do pp = <<-EOS - concat { '/tmp/concat/file': + concat { '#{basedir}/file': warn => '#{warn}', } concat::fragment { 'foo': - target => '/tmp/concat/file', + target => '#{basedir}/file', content => 'bar', } EOS @@ -40,7 +41,7 @@ describe 'deprecation warnings' do it_behaves_like 'has_warning', pp, w - describe file('/tmp/concat/file') do + describe file("#{basedir}/file") do it { should be_file } it { should contain '# This file is managed by Puppet. DO NOT EDIT.' } it { should contain 'bar' } @@ -51,11 +52,11 @@ describe 'deprecation warnings' do ['false', 'no', 'off'].each do |warn| context warn do pp = <<-EOS - concat { '/tmp/concat/file': + concat { '#{basedir}/file': warn => '#{warn}', } concat::fragment { 'foo': - target => '/tmp/concat/file', + target => '#{basedir}/file', content => 'bar', } EOS @@ -63,7 +64,7 @@ describe 'deprecation warnings' do it_behaves_like 'has_warning', pp, w - describe file('/tmp/concat/file') do + describe file("#{basedir}/file") do it { should be_file } it { should_not contain '# This file is managed by Puppet. DO NOT EDIT.' } it { should contain 'bar' } @@ -75,37 +76,39 @@ describe 'deprecation warnings' do context 'concat::fragment ensure parameter' do context 'target file exists' do before(:all) do - shell("/bin/echo 'file1 contents' > /tmp/concat/file1") - end - after(:all) do - # XXX this test may leave behind a symlink in the fragment directory - # which could cause warnings and/or breakage from the subsequent tests - # unless we clean it up. - shell('rm -rf /tmp/concat /var/lib/puppet/concat') - shell('mkdir -p /tmp/concat') + shell("/bin/echo 'file1 contents' > #{basedir}/file1") + pp = <<-EOS + file { '#{basedir}': + ensure => directory, + } + file { '#{basedir}/file1': + content => "file1 contents\n", + } + EOS + apply_manifest(pp) end pp = <<-EOS - concat { '/tmp/concat/file': } + concat { '#{basedir}/file': } concat::fragment { 'foo': - target => '/tmp/concat/file', - ensure => '/tmp/concat/file1', + target => '#{basedir}/file', + ensure => '#{basedir}/file1', } EOS w = 'Passing a value other than \'present\' or \'absent\' as the $ensure parameter to concat::fragment is deprecated. If you want to use the content of a file as a fragment please use the $source parameter.' it_behaves_like 'has_warning', pp, w - describe file('/tmp/concat/file') do + describe file("#{basedir}/file") do it { should be_file } it { should contain 'file1 contents' } end describe 'the fragment can be changed from a symlink to a plain file' do pp = <<-EOS - concat { '/tmp/concat/file': } + concat { '#{basedir}/file': } concat::fragment { 'foo': - target => '/tmp/concat/file', + target => '#{basedir}/file', content => 'new content', } EOS @@ -115,7 +118,7 @@ describe 'deprecation warnings' do apply_manifest(pp, :catch_changes => true) end - describe file('/tmp/concat/file') do + describe file("#{basedir}/file") do it { should be_file } it { should contain 'new content' } it { should_not contain 'file1 contents' } @@ -125,25 +128,25 @@ describe 'deprecation warnings' do context 'target does not exist' do pp = <<-EOS - concat { '/tmp/concat/file': } + concat { '#{basedir}/file': } concat::fragment { 'foo': - target => '/tmp/concat/file', - ensure => '/tmp/concat/file1', + target => '#{basedir}/file', + ensure => '#{basedir}/file1', } EOS w = 'Passing a value other than \'present\' or \'absent\' as the $ensure parameter to concat::fragment is deprecated. If you want to use the content of a file as a fragment please use the $source parameter.' it_behaves_like 'has_warning', pp, w - describe file('/tmp/concat/file') do + describe file("#{basedir}/file") do it { should be_file } end describe 'the fragment can be changed from a symlink to a plain file' do pp = <<-EOS - concat { '/tmp/concat/file': } + concat { '#{basedir}/file': } concat::fragment { 'foo': - target => '/tmp/concat/file', + target => '#{basedir}/file', content => 'new content', } EOS @@ -153,7 +156,7 @@ describe 'deprecation warnings' do apply_manifest(pp, :catch_changes => true) end - describe file('/tmp/concat/file') do + describe file("#{basedir}/file") do it { should be_file } it { should contain 'new content' } end @@ -164,9 +167,9 @@ describe 'deprecation warnings' do context 'concat::fragment mode parameter' do pp = <<-EOS - concat { '/tmp/concat/file': } + concat { '#{basedir}/file': } concat::fragment { 'foo': - target => '/tmp/concat/file', + target => '#{basedir}/file', content => 'bar', mode => 'bar', } @@ -178,9 +181,9 @@ describe 'deprecation warnings' do context 'concat::fragment owner parameter' do pp = <<-EOS - concat { '/tmp/concat/file': } + concat { '#{basedir}/file': } concat::fragment { 'foo': - target => '/tmp/concat/file', + target => '#{basedir}/file', content => 'bar', owner => 'bar', } @@ -192,9 +195,9 @@ describe 'deprecation warnings' do context 'concat::fragment group parameter' do pp = <<-EOS - concat { '/tmp/concat/file': } + concat { '#{basedir}/file': } concat::fragment { 'foo': - target => '/tmp/concat/file', + target => '#{basedir}/file', content => 'bar', group => 'bar', } @@ -206,9 +209,9 @@ describe 'deprecation warnings' do context 'concat::fragment backup parameter' do pp = <<-EOS - concat { '/tmp/concat/file': } + concat { '#{basedir}/file': } concat::fragment { 'foo': - target => '/tmp/concat/file', + target => '#{basedir}/file', content => 'bar', backup => 'bar', } diff --git a/spec/acceptance/fragments_are_always_replaced_spec.rb b/spec/acceptance/fragments_are_always_replaced_spec.rb index 2c999f7..ac714a9 100644 --- a/spec/acceptance/fragments_are_always_replaced_spec.rb +++ b/spec/acceptance/fragments_are_always_replaced_spec.rb @@ -1,25 +1,31 @@ require 'spec_helper_acceptance' describe 'concat::fragment replace' do + basedir = default.tmpdir('concat') + context 'should create fragment files' do before(:all) do - shell('rm -rf /tmp/concat /var/lib/puppet/concat') - shell('mkdir /tmp/concat') + pp = <<-EOS + file { '#{basedir}': + ensure => directory, + } + EOS + apply_manifest(pp) end pp1 = <<-EOS - concat { '/tmp/concat/foo': } + concat { '#{basedir}/foo': } concat::fragment { '1': - target => '/tmp/concat/foo', + target => '#{basedir}/foo', content => 'caller has replace unset run 1', } EOS pp2 = <<-EOS - concat { '/tmp/concat/foo': } + concat { '#{basedir}/foo': } concat::fragment { '1': - target => '/tmp/concat/foo', + target => '#{basedir}/foo', content => 'caller has replace unset run 2', } EOS @@ -31,7 +37,7 @@ describe 'concat::fragment replace' do apply_manifest(pp2, :catch_changes => true) end - describe file('/tmp/concat/foo') do + describe file("#{basedir}/foo") do it { should be_file } it { should_not contain 'caller has replace unset run 1' } it { should contain 'caller has replace unset run 2' } @@ -40,25 +46,29 @@ describe 'concat::fragment replace' do context 'should replace its own fragment files when caller has File { replace=>true } set' do before(:all) do - shell('rm -rf /tmp/concat /var/lib/puppet/concat') - shell('mkdir /tmp/concat') + pp = <<-EOS + file { '#{basedir}': + ensure => directory, + } + EOS + apply_manifest(pp) end pp1 = <<-EOS File { replace=>true } - concat { '/tmp/concat/foo': } + concat { '#{basedir}/foo': } concat::fragment { '1': - target => '/tmp/concat/foo', + target => '#{basedir}/foo', content => 'caller has replace true set run 1', } EOS pp2 = <<-EOS File { replace=>true } - concat { '/tmp/concat/foo': } + concat { '#{basedir}/foo': } concat::fragment { '1': - target => '/tmp/concat/foo', + target => '#{basedir}/foo', content => 'caller has replace true set run 2', } EOS @@ -70,7 +80,7 @@ describe 'concat::fragment replace' do apply_manifest(pp2, :catch_changes => true) end - describe file('/tmp/concat/foo') do + describe file("#{basedir}/foo") do it { should be_file } it { should_not contain 'caller has replace true set run 1' } it { should contain 'caller has replace true set run 2' } @@ -79,25 +89,29 @@ describe 'concat::fragment replace' do context 'should replace its own fragment files even when caller has File { replace=>false } set' do before(:all) do - shell('rm -rf /tmp/concat /var/lib/puppet/concat') - shell('mkdir /tmp/concat') + pp = <<-EOS + file { '#{basedir}': + ensure => directory, + } + EOS + apply_manifest(pp) end pp1 = <<-EOS File { replace=>false } - concat { '/tmp/concat/foo': } + concat { '#{basedir}/foo': } concat::fragment { '1': - target => '/tmp/concat/foo', + target => '#{basedir}/foo', content => 'caller has replace false set run 1', } EOS pp2 = <<-EOS File { replace=>false } - concat { '/tmp/concat/foo': } + concat { '#{basedir}/foo': } concat::fragment { '1': - target => '/tmp/concat/foo', + target => '#{basedir}/foo', content => 'caller has replace false set run 2', } EOS @@ -109,7 +123,7 @@ describe 'concat::fragment replace' do apply_manifest(pp2, :catch_changes => true) end - describe file('/tmp/concat/foo') do + describe file("#{basedir}/foo") do it { should be_file } it { should_not contain 'caller has replace false set run 1' } it { should contain 'caller has replace false set run 2' } diff --git a/spec/acceptance/quoted_paths_spec.rb b/spec/acceptance/quoted_paths_spec.rb index 0b6695d..028901a 100644 --- a/spec/acceptance/quoted_paths_spec.rb +++ b/spec/acceptance/quoted_paths_spec.rb @@ -1,21 +1,30 @@ require 'spec_helper_acceptance' describe 'quoted paths' do + basedir = default.tmpdir('concat') + before(:all) do - shell('rm -rf "/tmp/concat test" /var/lib/puppet/concat') - shell('mkdir -p "/tmp/concat test"') + pp = <<-EOS + file { '#{basedir}': + ensure => directory, + } + file { '#{basedir}/concat test': + ensure => directory, + } + EOS + apply_manifest(pp) end context 'path with blanks' do pp = <<-EOS - concat { '/tmp/concat test/foo': + concat { '#{basedir}/concat test/foo': } concat::fragment { '1': - target => '/tmp/concat test/foo', + target => '#{basedir}/concat test/foo', content => 'string1', } concat::fragment { '2': - target => '/tmp/concat test/foo', + target => '#{basedir}/concat test/foo', content => 'string2', } EOS @@ -25,7 +34,7 @@ describe 'quoted paths' do apply_manifest(pp, :catch_changes => true) end - describe file('/tmp/concat test/foo') do + describe file("#{basedir}/concat test/foo") do it { should be_file } it { should contain "string1\nsring2" } end From 0cb0b1ab0b27d6bd7cad0fe861fff7f75db142b5 Mon Sep 17 00:00:00 2001 From: Morgan Haskel Date: Thu, 11 Sep 2014 12:46:42 -0400 Subject: [PATCH 2/2] Work-around. --- spec/spec_helper_acceptance.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/spec/spec_helper_acceptance.rb b/spec/spec_helper_acceptance.rb index 363f4d0..48306ee 100644 --- a/spec/spec_helper_acceptance.rb +++ b/spec/spec_helper_acceptance.rb @@ -24,7 +24,11 @@ RSpec.configure do |c| c.before :suite do # Install module and dependencies hosts.each do |host| - copy_module_to(host, :source => proj_root, :module_name => 'concat') + on host, "mkdir -p #{host['distmoduledir']}/concat" + %w(files lib manifests metadata.json).each do |file| + scp_to host, "#{proj_root}/#{file}", "#{host['distmoduledir']}/concat" + end + #copy_module_to(host, :source => proj_root, :module_name => 'concat') on host, puppet('module','install','puppetlabs-stdlib'), { :acceptable_exit_codes => [0,1] } end end