Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Test for and fix idempotency issues

* mounttab: atboot and options (with defaults/empty) fixed
* host, sysctl: comment property fixed
  • Loading branch information...
commit 897b35d2a5fcf23f898037f569e39c6034c8a3cd 1 parent b540657
@domcleal authored
View
2  lib/puppet/provider/host/augeas.rb
@@ -175,7 +175,7 @@ def comment
path = "/files#{self.class.file(resource)}"
begin
aug = self.class.augopen(resource)
- aug.get("#{path}/*[canonical = '#{resource[:name]}']/#comment")
+ aug.get("#{path}/*[canonical = '#{resource[:name]}']/#comment") || ""
ensure
aug.close if aug
end
View
33 lib/puppet/provider/mounttab/augeas.rb
@@ -159,7 +159,16 @@ def options
opt = "#{opt}=#{optv}" if optv
opts << opt
end
- opts.join(",")
+ opts = opts.join(",")
+
+ # [] and ["defaults"] are synonyms, so return what the user requested if
+ # the current value is one of these to avoid changes
+ empties = ["", "defaults"]
+ if empties.include?(opts) and empties.include?(resource.should(:options))
+ resource.should(:options)
+ else
+ opts
+ end
ensure
aug.close if aug
end
@@ -267,30 +276,10 @@ def pass=(value)
end
def atboot
- aug = nil
- path = "/files#{self.class.file(resource)}"
- begin
- aug = self.class.augopen(resource)
- aug.get("#{path}/*[file = '#{resource[:name]}']/atboot")
- ensure
- aug.close if aug
- end
+ resource.should(:atboot)
end
def atboot=(value)
return # FIXME: not written
- aug = nil
- path = "/files#{self.class.file(resource)}"
- begin
- aug = self.class.augopen(resource)
- # Ensure dump is always set if passno is being set
- if aug.match("#{path}/*[file = '#{resource[:name]}']/dump").empty?
- aug.set("#{path}/*[file = '#{resource[:name]}']/dump", "0")
- end
- aug.set("#{path}/*[file = '#{resource[:name]}']/passno", value.to_s)
- aug.save!
- ensure
- aug.close if aug
- end
end
end
View
4 lib/puppet/provider/sysctl/augeas.rb
@@ -129,8 +129,8 @@ def comment
begin
aug = self.class.augopen(resource)
comment = aug.get("#{path}/#comment[following-sibling::*[1][self::#{resource[:name]}]][. =~ regexp('#{resource[:name]}:.*')]")
- comment.sub(/^#{resource[:name]}:\s*/, "") if comment
- comment
+ comment.sub!(/^#{resource[:name]}:\s*/, "") if comment
+ comment || ""
ensure
aug.close if aug
end
View
9 spec/lib/augeas_spec/fixtures.rb
@@ -29,6 +29,15 @@ def apply!(resource)
# Check for transaction success after, as it's less informative
txn.any_failed?.should_not be_true
+
+ # Run the exact same resource, but this time ensure there were absolutely
+ # no changes (as seen by logs) to indicate if it was idempotent or not
+ @logs.clear
+ txn_idempotent = apply(resource)
+ loglevels = Puppet::Util::Log.levels[2, 999]
+ @logs.select { |log| loglevels.include? log.level }.should == []
+ txn_idempotent.any_failed?.should_not be_true
+
txn
end
Please sign in to comment.
Something went wrong with that request. Please try again.