Permalink
Browse files

Test for and fix idempotency issues

* mounttab: atboot and options (with defaults/empty) fixed
* host, sysctl: comment property fixed
  • Loading branch information...
Dominic Cleal
Dominic Cleal committed Sep 3, 2012
1 parent b540657 commit 897b35d2a5fcf23f898037f569e39c6034c8a3cd
@@ -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
@@ -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
@@ -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
@@ -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

0 comments on commit 897b35d

Please sign in to comment.