diff options
author | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2007-03-08 07:09:42 +0000 |
---|---|---|
committer | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2007-03-08 07:09:42 +0000 |
commit | b6df3369bc8a1dadfab2c7baa6d4572785c075fb (patch) | |
tree | 78c91084dd33aa0cda93a9ea459c6881c4e1f7b7 | |
parent | 0925fb0cd9b7d370a57247b00f402d33f6f0d78b (diff) | |
download | puppet-b6df3369bc8a1dadfab2c7baa6d4572785c075fb.tar.gz puppet-b6df3369bc8a1dadfab2c7baa6d4572785c075fb.tar.xz puppet-b6df3369bc8a1dadfab2c7baa6d4572785c075fb.zip |
Looks like [2265] was not a complete solution -- it resulted in failures when the config set modes via integers. Everything is working now, and tested more completely.
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@2268 980ebf18-57e1-0310-9a29-db15c13687c0
-rwxr-xr-x | lib/puppet/type/pfile/mode.rb | 1 | ||||
-rw-r--r-- | lib/puppet/util/config.rb | 13 | ||||
-rwxr-xr-x | test/ral/types/file.rb | 18 | ||||
-rwxr-xr-x | test/util/config.rb | 42 |
4 files changed, 55 insertions, 19 deletions
diff --git a/lib/puppet/type/pfile/mode.rb b/lib/puppet/type/pfile/mode.rb index 0a796239e..96e29aabb 100755 --- a/lib/puppet/type/pfile/mode.rb +++ b/lib/puppet/type/pfile/mode.rb @@ -43,6 +43,7 @@ module Puppet raise Puppet::Error, "File modes can only be numbers, not %s" % value.inspect end + # Make sure our number looks like octal. unless value =~ /^0/ value = "0" + value end diff --git a/lib/puppet/util/config.rb b/lib/puppet/util/config.rb index 6110d686d..afec4c943 100644 --- a/lib/puppet/util/config.rb +++ b/lib/puppet/util/config.rb @@ -281,7 +281,11 @@ class Puppet::Util::Config when /^\s*$/: next # Skip blanks when /^\s*(\w+)\s*=\s*(.+)$/: # settings var = $1.intern - value = mungearg($2) + if var == :mode + value = $2 + else + value = mungearg($2) + end # Only warn if we don't know what this config var is. This # prevents exceptions later on. @@ -304,7 +308,6 @@ class Puppet::Util::Config if var == :group and section == Puppet[:name] and @config.include?(:group) @config[:group].value = value end - next end # Don't override set parameters, since the file is parsed @@ -905,9 +908,9 @@ Generated on #{Time.now}. end [:mode].each { |var| if value = self.send(var) - # Convert it to a string, and the object will correctly - # convert it to octal. - obj[var] = value.to_s + # Don't both converting the mode, since the file type + # can handle it any old way. + obj[var] = value end } diff --git a/test/ral/types/file.rb b/test/ral/types/file.rb index 647b1e185..c9ba6d835 100755 --- a/test/ral/types/file.rb +++ b/test/ral/types/file.rb @@ -31,11 +31,11 @@ class TestFile < Test::Unit::TestCase super @file = Puppet::Type.type(:file) $method = @method_name - begin - initstorage - rescue - system("rm -rf %s" % Puppet[:statefile]) - end +# begin +# initstorage +# rescue +# system("rm -rf %s" % Puppet[:statefile]) +# end end def teardown @@ -1009,12 +1009,16 @@ class TestFile < Test::Unit::TestCase :ensure => "file", :mode => "0777" ) + assert_equal(0777, file.should(:mode), + "Mode did not get set correctly") assert_apply(file) - assert_equal(0777, File.stat(path).mode & 007777) + assert_equal(0777, File.stat(path).mode & 007777, + "file mode is incorrect") File.unlink(path) file[:ensure] = "directory" assert_apply(file) - assert_equal(0777, File.stat(path).mode & 007777) + assert_equal(0777, File.stat(path).mode & 007777, + "directory mode is incorrect") end def test_followlinks diff --git a/test/util/config.rb b/test/util/config.rb index a3092c6ec..58f74f5c9 100755 --- a/test/util/config.rb +++ b/test/util/config.rb @@ -981,22 +981,50 @@ inttest = 27 # #489 def test_modes Puppet[:name] = "puppet" - file = tempfile config = tempfile() + + check = Proc.new do |string, int| + trans = @config.section_to_transportable(:puppet) + ssldir = trans.find { |o| o.type == "file" } + assert(ssldir, "could not find trans object") + + if ssldir[:mode].is_a?(Fixnum) + assert_equal(int, ssldir[:mode], "mode not set correctly") + else + assert_equal(string, ssldir[:mode], "mode not set correctly") + end + + obj = nil + assert_nothing_raised { obj = ssldir.to_type } + + assert(obj, "did not create object") + assert_equal(int, obj.should(:mode), + "did not pass mode correctly to file") + + obj.class.clear + end + + file = tempfile @config.setdefaults(:puppet, :mode => ["644", "yay"]) - @config.setdefaults(:puppet, :ssldir => ["/some/file", "yay"]) + @config.setdefaults(:puppet, :ssldir => { + :mode => 0644, + :desc => "yay", + :default => "/some/file"}) + + # Convert it first using the number + check.call("644", 0644) + File.open(config, "w") { |f| f.puts "[puppet] - mode = 755 + mode = 750 ssldir = #{file} "} @config.parse(config) - trans = @config.section_to_transportable(:puppet) - ssldir = trans.find { |o| o.type == "file" and o.name == file } - assert(ssldir, "could not find trans object") + assert_equal("750", @config[:mode], + "Did not parse mode correctly") - assert_equal("755", ssldir[:mode], "mode got munged in parsing") + check.call("750", 0750) end end |