diff --git a/manifests/fragment.pp b/manifests/fragment.pp index b6a2b02..f9ee2a7 100644 --- a/manifests/fragment.pp +++ b/manifests/fragment.pp @@ -1,126 +1,127 @@ # == Define: concat::fragment # # Puts a file fragment into a directory previous setup using concat # # === Options: # # [*target*] # The file that these fragments belong to # [*content*] # If present puts the content into the file # [*source*] # If content was not specified, use the source # [*order*] # By default all files gets a 10_ prefix in the directory you can set it to # anything else using this to influence the order of the content in the file # [*ensure*] # Present/Absent or destination to a file to include another file # [*mode*] # Deprecated # [*owner*] # Deprecated # [*group*] # Deprecated # [*backup*] # Deprecated # define concat::fragment( $target, $content = undef, $source = undef, $order = '10', $ensure = undef, $mode = undef, $owner = undef, $group = undef, $backup = undef ) { validate_string($target) validate_string($content) if !(is_string($source) or is_array($source)) { fail('$source is not a string or an Array.') } if !(is_string($order) or is_integer($order)) { fail('$order is not a string or integer.') } elsif (is_string($order) and $order =~ /[:\n\/]/) { fail("Order cannot contain '/', ':', or '\n'.") } if $mode { warning('The $mode parameter to concat::fragment is deprecated and has no effect') } if $owner { warning('The $owner parameter to concat::fragment is deprecated and has no effect') } if $group { warning('The $group parameter to concat::fragment is deprecated and has no effect') } if $backup { warning('The $backup parameter to concat::fragment is deprecated and has no effect') } + $my_backup = concat_getparam(Concat[$target], 'backup') if $ensure == undef { $my_ensure = concat_getparam(Concat[$target], 'ensure') } else { if ! ($ensure in [ 'present', 'absent' ]) { warning('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.') } $my_ensure = $ensure } include concat::setup $safe_name = regsubst($name, '[/:\n]', '_', 'GM') $safe_target_name = regsubst($target, '[/:\n]', '_', 'GM') $concatdir = $concat::setup::concatdir $fragdir = "${concatdir}/${safe_target_name}" $fragowner = $concat::setup::fragment_owner $fraggroup = $concat::setup::fragment_group $fragmode = $concat::setup::fragment_mode # The file type's semantics are problematic in that ensure => present will # not over write a pre-existing symlink. We are attempting to provide # backwards compatiblity with previous concat::fragment versions that # supported the file type's ensure => /target syntax # be paranoid and only allow the fragment's file resource's ensure param to # be file, absent, or a file target $safe_ensure = $my_ensure ? { '' => 'file', undef => 'file', 'file' => 'file', 'present' => 'file', 'absent' => 'absent', default => $my_ensure, } # if it looks line ensure => /target syntax was used, fish that out if ! ($my_ensure in ['', 'present', 'absent', 'file' ]) { $ensure_target = $my_ensure } else { $ensure_target = undef } # the file type's semantics only allows one of: ensure => /target, content, # or source if ($ensure_target and $source) or ($ensure_target and $content) or ($source and $content) { fail('You cannot specify more than one of $content, $source, $ensure => /target') } if ! ($content or $source or $ensure_target) { crit('No content, source or symlink specified') } file { "${fragdir}/fragments/${order}_${safe_name}": ensure => $safe_ensure, owner => $fragowner, group => $fraggroup, mode => $fragmode, source => $source, content => $content, - backup => false, + backup => $my_backup, replace => true, alias => "concat_fragment_${name}", notify => Exec["concat_${target}"] } } diff --git a/manifests/setup.pp b/manifests/setup.pp index 3d34725..c5aedd8 100644 --- a/manifests/setup.pp +++ b/manifests/setup.pp @@ -1,68 +1,64 @@ # === Class: concat::setup # # Sets up the concat system. This is a private class. # # [$concatdir] # is where the fragments live and is set on the fact concat_basedir. # Since puppet should always manage files in $concatdir and they should # not be deleted ever, /tmp is not an option. # # It also copies out the concatfragments.{sh,rb} file to ${concatdir}/bin # class concat::setup { if $caller_module_name != $module_name { warning("${name} is deprecated as a public API of the ${module_name} module and should no longer be directly included in the manifest.") } if $::concat_basedir { $concatdir = $::concat_basedir } else { fail ('$concat_basedir not defined. Try running again with pluginsync=true on the [master] and/or [main] section of your node\'s \'/etc/puppet/puppet.conf\'.') } # owner,group and mode of fragment files (on windows owner and access rights should # be inherited from concatdir and not explicitly set to avoid problems) $fragment_owner = $::osfamily ? { 'windows' => undef, default => $::id } $fragment_mode = $::osfamily ? { 'windows' => undef, default => '0640' } # test on gid fact availability to support older facter versions if defined('$gid') and $::gid and $::osfamily != 'Windows' { $fragment_group = $::gid } else { $fragment_group = undef } $script_name = 'concatfragments.rb' $script_path = "${concatdir}/bin/${script_name}" $default_owner = $::osfamily ? { 'windows' => undef, default => $::id } $default_group = $default_owner ? { 'root' => '0', default => undef } $script_mode = $::osfamily ? { 'windows' => undef, default => '0755' } $script_command = $::osfamily? { 'windows' => "ruby.exe '${script_path}'", 'openbsd' => "/usr/local/bin/ruby21 '${script_path}'", default => $script_path } - File { - backup => false, - } - file { $script_path: ensure => file, owner => $default_owner, group => $default_group, mode => $script_mode, source => "puppet:///modules/concat/${script_name}", } file { [ $concatdir, "${concatdir}/bin" ]: ensure => directory, owner => $default_owner, group => $default_group, mode => '0755', } } diff --git a/spec/acceptance/nodesets/default.yml b/spec/acceptance/nodesets/default.yml index 0639835..b826851 100644 --- a/spec/acceptance/nodesets/default.yml +++ b/spec/acceptance/nodesets/default.yml @@ -1,10 +1,10 @@ HOSTS: - centos-64-x64: + centos-66-x64: roles: - master platform: el-6-x86_64 - box : centos-64-x64-vbox4210-nocm - box_url : http://puppet-vagrant-boxes.puppetlabs.com/centos-64-x64-vbox4210-nocm.box + box : puppetlabs/centos-6.6-64-nocm + box_url : http://puppet-vagrant-boxes.puppetlabs.com/centos-6.6-64-nocm hypervisor : vagrant CONFIG: type: git diff --git a/spec/unit/classes/concat_setup_spec.rb b/spec/unit/classes/concat_setup_spec.rb index 84ba282..c6ff93e 100644 --- a/spec/unit/classes/concat_setup_spec.rb +++ b/spec/unit/classes/concat_setup_spec.rb @@ -1,102 +1,98 @@ require 'spec_helper' describe 'concat::setup', :type => :class do shared_examples 'setup' do |concatdir| concatdir = '/foo' if concatdir.nil? let(:facts) do { :concat_basedir => concatdir, :caller_module_name => 'Test', :osfamily => 'Debian', :id => 'root', :is_pe => false, } end it do should contain_file("#{concatdir}/bin/concatfragments.rb").with({ :mode => '0755', :owner => 'root', :group => 0, :source => 'puppet:///modules/concat/concatfragments.rb', - :backup => false, }) end [concatdir, "#{concatdir}/bin"].each do |file| it do should contain_file(file).with({ :ensure => 'directory', :mode => '0755', :owner => 'root', :group => 0, - :backup => false, }) end end end context 'facts' do context 'concat_basedir =>' do context '/foo' do it_behaves_like 'setup', '/foo' end end end # facts context 'deprecated as a public class' do it 'should create a warning' do skip('rspec-puppet support for testing warning()') end end context "on osfamily Solaris" do concatdir = '/foo' let(:facts) do { :concat_basedir => concatdir, :caller_module_name => 'Test', :osfamily => 'Solaris', :id => 'root', :is_pe => false, } end it do should contain_file("#{concatdir}/bin/concatfragments.rb").with({ :ensure => 'file', :owner => 'root', :group => 0, :mode => '0755', :source => 'puppet:///modules/concat/concatfragments.rb', - :backup => false, }) end end # on osfamily Solaris context "on osfamily windows" do concatdir = '/foo' let(:facts) do { :concat_basedir => concatdir, :caller_module_name => 'Test', :osfamily => 'windows', :id => 'batman', :is_pe => false, } end it do should contain_file("#{concatdir}/bin/concatfragments.rb").with({ :ensure => 'file', :owner => nil, :group => nil, :mode => nil, :source => 'puppet:///modules/concat/concatfragments.rb', - :backup => false, }) end end # on osfamily windows end diff --git a/spec/unit/defines/concat_fragment_spec.rb b/spec/unit/defines/concat_fragment_spec.rb index 1dc7c38..6cf3e42 100644 --- a/spec/unit/defines/concat_fragment_spec.rb +++ b/spec/unit/defines/concat_fragment_spec.rb @@ -1,330 +1,330 @@ require 'spec_helper' describe 'concat::fragment', :type => :define do shared_examples 'fragment' do |title, params| params = {} if params.nil? p = { :content => nil, :source => nil, :order => 10, :ensure => 'present', }.merge(params) safe_name = title.gsub(/[\/\n]/, '_') safe_target_name = p[:target].gsub(/[\/\n]/, '_') concatdir = '/var/lib/puppet/concat' fragdir = "#{concatdir}/#{safe_target_name}" id = 'root' gid = 'root' if p[:ensure] == 'absent' safe_ensure = p[:ensure] else safe_ensure = 'file' end let(:title) { title } let(:facts) do { :concat_basedir => concatdir, :id => id, :gid => gid, :osfamily => 'Debian', :path => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin', :is_pe => false, } end let(:params) { params } let(:pre_condition) do "concat{ '#{p[:target]}': }" end it do should contain_class('concat::setup') should contain_concat(p[:target]) should contain_file("#{fragdir}/fragments/#{p[:order]}_#{safe_name}").with({ :ensure => safe_ensure, :owner => id, :group => gid, :mode => '0640', :source => p[:source], :content => p[:content], :alias => "concat_fragment_#{title}", - :backup => false, + :backup => 'puppet', }) end end context 'title' do ['0', '1', 'a', 'z'].each do |title| it_behaves_like 'fragment', title, { :target => '/etc/motd', } end end # title context 'target =>' do ['./etc/motd', 'etc/motd', 'motd_header'].each do |target| context target do it_behaves_like 'fragment', target, { :target => '/etc/motd', } end end context 'false' do let(:title) { 'motd_header' } let(:facts) {{ :concat_basedir => '/tmp', :is_pe => false }} let(:params) {{ :target => false }} it 'should fail' do expect { should }.to raise_error(Puppet::Error, /is not a string/) end end end # target => context 'ensure =>' do ['present', 'absent'].each do |ens| context ens do it_behaves_like 'fragment', 'motd_header', { :ensure => ens, :target => '/etc/motd', } end end context 'any value other than \'present\' or \'absent\'' do let(:title) { 'motd_header' } let(:facts) {{ :concat_basedir => '/tmp', :is_pe => false }} let(:params) {{ :ensure => 'invalid', :target => '/etc/motd' }} it 'should create a warning' do skip('rspec-puppet support for testing warning()') end end end # ensure => context 'content =>' do ['', 'ashp is our hero'].each do |content| context content do it_behaves_like 'fragment', 'motd_header', { :content => content, :target => '/etc/motd', } end end context 'false' do let(:title) { 'motd_header' } let(:facts) {{ :concat_basedir => '/tmp', :is_pe => false }} let(:params) {{ :content => false, :target => '/etc/motd' }} it 'should fail' do expect { should }.to raise_error(Puppet::Error, /is not a string/) end end end # content => context 'source =>' do ['', '/foo/bar', ['/foo/bar', '/foo/baz']].each do |source| context source do it_behaves_like 'fragment', 'motd_header', { :source => source, :target => '/etc/motd', } end end context 'false' do let(:title) { 'motd_header' } let(:facts) {{ :concat_basedir => '/tmp', :is_pe => false }} let(:params) {{ :source => false, :target => '/etc/motd' }} it 'should fail' do expect { should }.to raise_error(Puppet::Error, /is not a string or an Array/) end end end # source => context 'order =>' do ['', '42', 'a', 'z'].each do |order| context '\'\'' do it_behaves_like 'fragment', 'motd_header', { :order => order, :target => '/etc/motd', } end end context 'false' do let(:title) { 'motd_header' } let(:facts) {{ :concat_basedir => '/tmp', :is_pe => false }} let(:params) {{ :order => false, :target => '/etc/motd' }} it 'should fail' do expect { should }.to raise_error(Puppet::Error, /is not a string or integer/) end end context '123:456' do let(:title) { 'motd_header' } let(:facts) {{ :concat_basedir => '/tmp', :is_pe => false }} let(:params) {{ :order => '123:456', :target => '/etc/motd' }} it 'should fail' do expect { should }.to raise_error(Puppet::Error, /cannot contain/) end end context '123/456' do let(:title) { 'motd_header' } let(:facts) {{ :concat_basedir => '/tmp', :is_pe => false }} let(:params) {{ :order => '123/456', :target => '/etc/motd' }} it 'should fail' do expect { should }.to raise_error(Puppet::Error, /cannot contain/) end end context '123\n456' do let(:title) { 'motd_header' } let(:facts) {{ :concat_basedir => '/tmp', :is_pe => false }} let(:params) {{ :order => "123\n456", :target => '/etc/motd' }} it 'should fail' do expect { should }.to raise_error(Puppet::Error, /cannot contain/) end end end # order => context 'more than one content source' do error_msg = 'You cannot specify more than one of $content, $source, $ensure => /target' context 'ensure => target and source' do let(:title) { 'motd_header' } let(:facts) do { :concat_basedir => '/tmp', :osfamily => 'Debian', :id => 'root', :is_pe => false, :gid => 'root', } end let(:params) do { :target => '/etc/motd', :ensure => '/foo', :source => '/bar', } end it 'should fail' do expect { should }.to raise_error(Puppet::Error, /#{Regexp.escape(error_msg)}/m) end end context 'ensure => target and content' do let(:title) { 'motd_header' } let(:facts) do { :concat_basedir => '/tmp', :osfamily => 'Debian', :id => 'root', :is_pe => false, :gid => 'root', } end let(:params) do { :target => '/etc/motd', :ensure => '/foo', :content => 'bar', } end it 'should fail' do expect { should }.to raise_error(Puppet::Error, /#{Regexp.escape(error_msg)}/m) end end context 'source and content' do let(:title) { 'motd_header' } let(:facts) do { :concat_basedir => '/tmp', :osfamily => 'Debian', :id => 'root', :is_pe => false, :gid => 'root', } end let(:params) do { :target => '/etc/motd', :source => '/foo', :content => 'bar', } end it 'should fail' do expect { should }.to raise_error(Puppet::Error, /#{Regexp.escape(error_msg)}/m) end end end # more than one content source describe 'deprecated parameter' do context 'mode =>' do context '1755' do it_behaves_like 'fragment', 'motd_header', { :mode => '1755', :target => '/etc/motd', } it 'should create a warning' do skip('rspec-puppet support for testing warning()') end end end # mode => context 'owner =>' do context 'apenny' do it_behaves_like 'fragment', 'motd_header', { :owner => 'apenny', :target => '/etc/motd', } it 'should create a warning' do skip('rspec-puppet support for testing warning()') end end end # owner => context 'group =>' do context 'apenny' do it_behaves_like 'fragment', 'motd_header', { :group => 'apenny', :target => '/etc/motd', } it 'should create a warning' do skip('rspec-puppet support for testing warning()') end end end # group => context 'backup =>' do context 'foo' do it_behaves_like 'fragment', 'motd_header', { :backup => 'foo', :target => '/etc/motd', } it 'should create a warning' do skip('rspec-puppet support for testing warning()') end end end # backup => end # deprecated params end