diff options
author | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2006-12-20 19:41:38 +0000 |
---|---|---|
committer | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2006-12-20 19:41:38 +0000 |
commit | 299bdc1b23bbf39e436f5e67b598d60606ca6513 (patch) | |
tree | 26f5d2ae6807a6e2fae1f4aa8f58f56883042333 | |
parent | e605c4aadd3a3c4cccbd01661c21a715ec3f0773 (diff) | |
download | puppet-299bdc1b23bbf39e436f5e67b598d60606ca6513.tar.gz puppet-299bdc1b23bbf39e436f5e67b598d60606ca6513.tar.xz puppet-299bdc1b23bbf39e436f5e67b598d60606ca6513.zip |
Fixing #380. The problem was that a method was sometimes returning :absent when I expected it to return nil when the group was not found. All fixed, yay.
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@1960 980ebf18-57e1-0310-9a29-db15c13687c0
-rwxr-xr-x | lib/puppet/type/pfile/group.rb | 7 | ||||
-rwxr-xr-x | lib/puppet/type/pfile/uid.rb | 3 | ||||
-rwxr-xr-x | lib/puppet/util/posix.rb | 7 | ||||
-rwxr-xr-x | test/util/utiltest.rb | 19 |
4 files changed, 34 insertions, 2 deletions
diff --git a/lib/puppet/type/pfile/group.rb b/lib/puppet/type/pfile/group.rb index 27ca5c2ff..81059db91 100755 --- a/lib/puppet/type/pfile/group.rb +++ b/lib/puppet/type/pfile/group.rb @@ -7,6 +7,12 @@ module Puppet @event = :file_changed def id2name(id) + if id > 70000 + return nil + end + if id.is_a?(Symbol) + return id.to_s + end begin group = Etc.getgrgid(id) rescue ArgumentError @@ -63,7 +69,6 @@ module Puppet if gid = Puppet::Util.gid(value) return gid else - warning "could not find %s" % value return false end end diff --git a/lib/puppet/type/pfile/uid.rb b/lib/puppet/type/pfile/uid.rb index 72d2a7e03..891bd56fd 100755 --- a/lib/puppet/type/pfile/uid.rb +++ b/lib/puppet/type/pfile/uid.rb @@ -9,6 +9,9 @@ module Puppet if id.is_a?(Symbol) return id.to_s end + if id > 70000 + return nil + end begin user = Etc.getpwuid(id) rescue TypeError diff --git a/lib/puppet/util/posix.rb b/lib/puppet/util/posix.rb index 01c3e25aa..37ec298bb 100755 --- a/lib/puppet/util/posix.rb +++ b/lib/puppet/util/posix.rb @@ -43,7 +43,12 @@ module Puppet::Util::POSIX if obj.provider begin - return obj.provider.send(field) + val = obj.provider.send(field) + if val == :absent + return nil + else + return val + end rescue => detail if Puppet[:trace] puts detail.backtrace diff --git a/test/util/utiltest.rb b/test/util/utiltest.rb index 74a29d56f..3f2532fc2 100755 --- a/test/util/utiltest.rb +++ b/test/util/utiltest.rb @@ -307,6 +307,25 @@ class TestPuppetUtil < Test::Unit::TestCase # assert_equal(group.gid, File.stat(file).gid, "gid was not set correctly") end end + + # This is mostly to test #380. + def test_get_provider_value + group = Puppet::Type.type(:group).create :name => "yayness", :ensure => :present + + root = Puppet::Type.type(:user).create :name => "root", :ensure => :present + + val = nil + assert_nothing_raised do + val = Puppet::Util.get_provider_value(:group, :gid, "yayness") + end + assert_nil(val, "returned a value on a missing group") + + # Now make sure we get a value for one we know exists + assert_nothing_raised do + val = Puppet::Util.get_provider_value(:user, :uid, "root") + end + assert_equal(0, val, "got invalid uid for root") + end end # $Id$ |