diff --git a/Puppetfile b/Puppetfile index ec65fc465..1699e8537 100644 --- a/Puppetfile +++ b/Puppetfile @@ -55,7 +55,7 @@ mod 'horizon', :git => 'https://github.com/stackforge/puppet-horizon.git' mod 'inifile', - :commit => '6b399c2bc6b34fd01c704dd5836c61935cf9e4f1', + :commit => 'be5fc47f00466a2e6293145b3a0d4fcb586bcf15', :git => 'https://github.com/puppetlabs/puppetlabs-inifile.git' mod 'ipa', diff --git a/inifile/.gitignore b/inifile/.gitignore index b5b7a00d6..b5db85e05 100644 --- a/inifile/.gitignore +++ b/inifile/.gitignore @@ -5,3 +5,5 @@ spec/fixtures/ .vagrant/ .bundle/ coverage/ +.idea/ +*.iml diff --git a/inifile/Gemfile b/inifile/Gemfile index 12fd363ea..6bfe6bf45 100644 --- a/inifile/Gemfile +++ b/inifile/Gemfile @@ -1,5 +1,15 @@ source ENV['GEM_SOURCE'] || "https://rubygems.org" +def location_for(place, fake_version = nil) + if place =~ /^(git:[^#]*)#(.*)/ + [fake_version, { :git => $1, :branch => $2, :require => false }].compact + elsif place =~ /^file:\/\/(.*)/ + ['>= 0', { :path => File.expand_path($1), :require => false }] + else + [place, { :require => false }] + end +end + group :development, :unit_tests do gem 'rake', :require => false gem 'rspec-puppet', :require => false @@ -10,19 +20,24 @@ group :development, :unit_tests do gem 'json', :require => false end +beaker_rspec_version = ENV['BEAKER_RSPEC_VERSION'] group :system_tests do - gem 'beaker-rspec', :require => false + if beaker_rspec_version + gem 'beaker-rspec', *location_for(beaker_rspec_version) + else + gem 'beaker-rspec', :require => false + end gem 'serverspec', :require => false end if facterversion = ENV['FACTER_GEM_VERSION'] - gem 'facter', facterversion, :require => false + gem 'facter', *location_for(facterversion) else gem 'facter', :require => false end if puppetversion = ENV['PUPPET_GEM_VERSION'] - gem 'puppet', puppetversion, :require => false + gem 'puppet', *location_for(puppetversion) else gem 'puppet', :require => false end diff --git a/inifile/lib/puppet/type/ini_setting.rb b/inifile/lib/puppet/type/ini_setting.rb index 450623143..662c74c11 100644 --- a/inifile/lib/puppet/type/ini_setting.rb +++ b/inifile/lib/puppet/type/ini_setting.rb @@ -28,15 +28,9 @@ newparam(:key_val_separator) do desc 'The separator string to use between each setting name and value. ' + - 'Defaults to " = ", but you could use this to override e.g. whether ' + - 'or not the separator should include whitespace.' + 'Defaults to " = ", but you could use this to override e.g. ": ", or' + + 'whether or not the separator should include whitespace.' defaultto(" = ") - - validate do |value| - unless value.scan('=').size == 1 - raise Puppet::Error, ":key_val_separator must contain exactly one = character." - end - end end newproperty(:value) do diff --git a/inifile/lib/puppet/type/ini_subsetting.rb b/inifile/lib/puppet/type/ini_subsetting.rb index 847e31797..0db073850 100644 --- a/inifile/lib/puppet/type/ini_subsetting.rb +++ b/inifile/lib/puppet/type/ini_subsetting.rb @@ -37,15 +37,9 @@ newparam(:key_val_separator) do desc 'The separator string to use between each setting name and value. ' + - 'Defaults to " = ", but you could use this to override e.g. whether ' + - 'or not the separator should include whitespace.' + 'Defaults to " = ", but you could use this to override e.g. ": ", or' + + 'whether or not the separator should include whitespace.' defaultto(" = ") - - validate do |value| - unless value.scan('=').size == 1 - raise Puppet::Error, ":key_val_separator must contain exactly one = character." - end - end end newparam(:quote_char) do diff --git a/inifile/lib/puppet/util/ini_file.rb b/inifile/lib/puppet/util/ini_file.rb index a5cefa763..c1884ce55 100644 --- a/inifile/lib/puppet/util/ini_file.rb +++ b/inifile/lib/puppet/util/ini_file.rb @@ -5,11 +5,15 @@ module Puppet module Util class IniFile - @@SECTION_REGEX = /^\s*\[([^\]]*)\]\s*$/ - @@SETTING_REGEX = /^(\s*)([^\s=]*)(\s*=\s*)(.*)\s*$/ - @@COMMENTED_SETTING_REGEX = /^(\s*)[#;]+(\s*)([^\s=]*)(\s*=[ \t]*)(.*)\s*$/ - def initialize(path, key_val_separator = ' = ') + + k_v_s = key_val_separator.strip + + @@SECTION_REGEX = /^\s*\[([^\]]*)\]\s*$/ + @@SETTING_REGEX = /^(\s*)([^\s#{k_v_s}]*)(\s*#{k_v_s}\s*)(.*)\s*$/ + @@COMMENTED_SETTING_REGEX = /^(\s*)[#;]+(\s*)([^\s#{k_v_s}]*)(\s*#{k_v_s}[ \t]*)(.*)\s*$/ + + @path = path @key_val_separator = key_val_separator @section_names = [] diff --git a/inifile/spec/acceptance/ini_setting_spec.rb b/inifile/spec/acceptance/ini_setting_spec.rb index 9aad0cc39..4e5898506 100644 --- a/inifile/spec/acceptance/ini_setting_spec.rb +++ b/inifile/spec/acceptance/ini_setting_spec.rb @@ -72,13 +72,7 @@ apply_manifest(pp, :catch_changes => true) end - describe file("#{tmpdir}/ini_setting.ini") do - it { should be_file } - #XXX Solaris 10 doesn't support multi-line grep - it("should contain four = five\n[one]\ntwo = three", :unless => fact('osfamily') == 'Solaris') { - should contain("four = five\n[one]\ntwo = three") - } - end + it_behaves_like 'has_content', "#{tmpdir}/ini_setting.ini", pp, "four = five\n[one]\ntwo = three" end context '=> absent for key/value' do @@ -113,40 +107,6 @@ end end - context '=> absent for section', :pending => "cannot ensure absent on a section" do - before :all do - if fact('osfamily') == 'Darwin' - shell("echo \"four = five\n[one]\ntwo = three\" > #{tmpdir}/ini_setting.ini") - else - shell("echo -e \"four = five\n[one]\ntwo = three\" > #{tmpdir}/ini_setting.ini") - end - end - after :all do - shell("cat #{tmpdir}/ini_setting.ini", :acceptable_exit_codes => [0,1,2]) - shell("rm #{tmpdir}/ini_setting.ini", :acceptable_exit_codes => [0,1,2]) - end - - pp = <<-EOS - ini_setting { 'ensure => absent for section': - ensure => absent, - path => "#{tmpdir}/ini_setting.ini", - section => 'one', - } - EOS - - it 'applies the manifest twice' do - apply_manifest(pp, :catch_failures => true) - apply_manifest(pp, :catch_changes => true) - end - - describe file("#{tmpdir}/ini_setting.ini") do - it { should be_file } - it { should contain('four = five') } - it { should_not contain('[one]') } - it { should_not contain('two = three') } - end - end - context '=> absent for global' do before :all do if fact('osfamily') == 'Darwin' @@ -282,27 +242,5 @@ it_behaves_like 'has_content', "#{tmpdir}/key_val_separator.ini", pp, content end end - - { - "key_val_separator => ''," => /must contain exactly one/, - "key_val_separator => ','," => /must contain exactly one/, - "key_val_separator => ' '," => /must contain exactly one/, - "key_val_separator => ' == '," => /must contain exactly one/, - }.each do |parameter, error| - context "with \"#{parameter}\" raises \"#{error}\"" do - pp = <<-EOS - ini_setting { "with #{parameter} raises #{error}": - ensure => present, - section => 'one', - setting => 'two', - value => 'three', - path => "#{tmpdir}/key_val_separator.ini", - #{parameter} - } - EOS - - it_behaves_like 'has_error', "#{tmpdir}/key_val_separator.ini", pp, error - end - end end end diff --git a/inifile/spec/unit/puppet/provider/ini_setting/ruby_spec.rb b/inifile/spec/unit/puppet/provider/ini_setting/ruby_spec.rb index 1ab84b974..0810bc284 100644 --- a/inifile/spec/unit/puppet/provider/ini_setting/ruby_spec.rb +++ b/inifile/spec/unit/puppet/provider/ini_setting/ruby_spec.rb @@ -495,39 +495,46 @@ def self.file_path EOS } - it "should fail if the separator doesn't include an equals sign" do - expect { - Puppet::Type::Ini_setting.new(common_params.merge( - :section => 'section2', - :setting => 'foo', - :value => 'yippee', - :key_val_separator => '+')) - }.to raise_error Puppet::Error, /must contain exactly one/ + it "should modify an existing setting" do + resource = Puppet::Type::Ini_setting.new(common_params.merge( + :section => 'section2', + :setting => 'foo', + :value => 'yippee', + :key_val_separator => '=')) + provider = described_class.new(resource) + provider.exists?.should be true + provider.value.should == 'bar' + provider.value=('yippee') + validate_file(<<-EOS +[section2] +foo=yippee + EOS + ) end - it "should fail if the separator includes more than one equals sign" do - expect { - Puppet::Type::Ini_setting.new(common_params.merge( - :section => 'section2', - :setting => 'foo', - :value => 'yippee', - :key_val_separator => ' = foo = ')) - }.to raise_error Puppet::Error, /must contain exactly one/ - end + end + + context "when overriding the separator to something other than =" do + let(:orig_content) { + <<-EOS +[section2] +foo: bar + EOS + } it "should modify an existing setting" do resource = Puppet::Type::Ini_setting.new(common_params.merge( :section => 'section2', :setting => 'foo', :value => 'yippee', - :key_val_separator => '=')) + :key_val_separator => ': ')) provider = described_class.new(resource) provider.exists?.should be true provider.value.should == 'bar' provider.value=('yippee') validate_file(<<-EOS [section2] -foo=yippee +foo: yippee EOS ) end @@ -537,14 +544,14 @@ def self.file_path :section => 'section2', :setting => 'bar', :value => 'baz', - :key_val_separator => '=')) + :key_val_separator => ': ')) provider = described_class.new(resource) provider.exists?.should be false provider.create validate_file(<<-EOS [section2] -foo=bar -bar=baz +foo: bar +bar: baz EOS ) end