summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLuke Kanies <luke@madstop.com>2009-10-26 22:54:38 -0700
committerJames Turnbull <james@lovedthanlost.net>2009-10-27 16:59:12 +1100
commit20e5222de71f68780063d774e83fd1debe64ba86 (patch)
tree9a6e69dabe9e2ce34d7a49687bb2cdf232aa6b00
parent09fb3f707dfce31a11eda2f35bd77e65c911c15f (diff)
downloadpuppet-20e5222de71f68780063d774e83fd1debe64ba86.tar.gz
puppet-20e5222de71f68780063d774e83fd1debe64ba86.tar.xz
puppet-20e5222de71f68780063d774e83fd1debe64ba86.zip
Fixing #2689 - file owner warnings are reduced
We now only warn when there's an actual change to make, and we only make one warning per process run. Signed-off-by: Luke Kanies <luke@madstop.com>
-rwxr-xr-xlib/puppet/type/file/owner.rb11
-rwxr-xr-xspec/unit/type/file/owner.rb14
2 files changed, 17 insertions, 8 deletions
diff --git a/lib/puppet/type/file/owner.rb b/lib/puppet/type/file/owner.rb
index 1dff59cb3..e5ca06a86 100755
--- a/lib/puppet/type/file/owner.rb
+++ b/lib/puppet/type/file/owner.rb
@@ -28,10 +28,7 @@ module Puppet
end
def insync?(current)
- unless Puppet::Util::SUIDManager.uid == 0
- warning "Cannot manage ownership unless running as root"
- return true
- end
+ return true unless should
@should.each do |value|
if value =~ /^\d+$/
@@ -44,6 +41,12 @@ module Puppet
return true if uid == current
end
+
+ unless Puppet::Util::SUIDManager.uid == 0
+ warnonce "Cannot manage ownership unless running as root"
+ return true
+ end
+
return false
end
diff --git a/spec/unit/type/file/owner.rb b/spec/unit/type/file/owner.rb
index 1ea01cbc7..62f7b0ae5 100755
--- a/spec/unit/type/file/owner.rb
+++ b/spec/unit/type/file/owner.rb
@@ -55,11 +55,13 @@ describe property do
describe "when determining if the file is in sync" do
describe "and not running as root" do
- it "should warn and return true" do
- @owner.should = 10
+ it "should warn once and return true" do
Puppet::Util::SUIDManager.expects(:uid).returns 1
- @owner.expects(:warning)
- @owner.must be_insync("whatever")
+
+ @owner.expects(:warnonce)
+
+ @owner.should = [10]
+ @owner.must be_insync(20)
end
end
@@ -67,6 +69,10 @@ describe property do
Puppet::Util::SUIDManager.stubs(:uid).returns 0
end
+ it "should be in sync if 'should' is not provided" do
+ @owner.must be_insync(10)
+ end
+
it "should directly compare the owner values if the desired owner is an integer" do
@owner.should = [10]
@owner.must be_insync(10)