This family of errors could appear because Puppet parses every line in fstab into resources, even lines that are not specifically managed by Puppet, and fstab files are much more permissive than Puppet in what constitutes a valid mount. This change makes several fields optional that were previously mandatory. Also, it ignores lines in fstab that have fewer than the required number of parameters.
Includes a more readable regex than the previous patch. Signed-off-by: Jesse Wolfe <[email protected]> --- lib/puppet/provider/mount/parsed.rb | 11 ++++++++++- spec/unit/provider/mount/parsed.rb | 9 +++++++++ 2 files changed, 19 insertions(+), 1 deletions(-) diff --git a/lib/puppet/provider/mount/parsed.rb b/lib/puppet/provider/mount/parsed.rb index c660807..b30de2b 100755 --- a/lib/puppet/provider/mount/parsed.rb +++ b/lib/puppet/provider/mount/parsed.rb @@ -31,6 +31,15 @@ Puppet::Type.type(:mount).provide(:parsed, text_line :comment, :match => /^\s*#/ text_line :blank, :match => /^\s*$/ - record_line self.name, :fields => @fields, :separator => /\s+/, :joiner => "\t", :optional => [:pass, :dump] + optional_fields = @fields - [:device, :name, :blockdevice] + mandatory_fields = @fields - optional_fields + + # fstab will ignore lines that have fewer than the mandatory number of columns, + # so we should, too. + field_pattern = '(\s*(?>\S+))' + text_line :incomplete, :match => /^(?!#{field_pattern}{#{mandatory_fields.length}})/ + + record_line self.name, :fields => @fields, :separator => /\s+/, :joiner => "\t", :optional => optional_fields + end diff --git a/spec/unit/provider/mount/parsed.rb b/spec/unit/provider/mount/parsed.rb index 10329e4..d394b29 100755 --- a/spec/unit/provider/mount/parsed.rb +++ b/spec/unit/provider/mount/parsed.rb @@ -108,6 +108,15 @@ describe provider_class do end Puppet::Type.type(:mount).provider(:parsed).default_target.should == should end + + it "should not crash on incomplete lines in fstab" do + parse = @provider_class.parse <<-FSTAB +/dev/incomplete +/dev/device name + FSTAB + + lambda{ @provider_class.to_line(parse[0]) }.should_not raise_error + end end describe provider_class, " when mounting an absent filesystem" do -- 1.6.5
-- You received this message because you are subscribed to the Google Groups "Puppet Developers" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/puppet-dev?hl=en.
