+1 having paired with Nick on this, although I'd very much like to see that Russell or someone else using FreeBSD test this patch. We rewrote some of the regexes from the patches that Russell submitted to make them more readable, and we wrote tests and tried the patch on a couple versions of FreeBSD, but neither Nick nor I are big FreeBSD users.
On Mon, Oct 4, 2010 at 3:45 PM, Nick Lewis <[email protected]> wrote: > Running "/etc/rc.d/SERVICE rcvar" outputs different formats for > different versions of FreeBSD. This patch adds support for those > formats, as well as tests. > > Based on patches from: > o Joost van Beurden > o Russell Jackson > > Paired-With: Matt Robinson > > Signed-off-by: Nick Lewis <[email protected]> > --- > lib/puppet/provider/service/freebsd.rb | 5 ++- > spec/unit/provider/service/freebsd_spec.rb | 50 > ++++++++++++++++++++++++++++ > 2 files changed, 54 insertions(+), 1 deletions(-) > create mode 100644 spec/unit/provider/service/freebsd_spec.rb > > diff --git a/lib/puppet/provider/service/freebsd.rb > b/lib/puppet/provider/service/freebsd.rb > index c75c3c9..f8c7134 100644 > --- a/lib/puppet/provider/service/freebsd.rb > +++ b/lib/puppet/provider/service/freebsd.rb > @@ -18,6 +18,9 @@ Puppet::Type.type(:service).provide :freebsd, :parent => > :init do > def rcvar > rcvar = execute([self.initscript, :rcvar], :failonfail => true, :squelch > => false) > rcvar = rcvar.split("\n") > + rcvar.delete_if {|str| str =~ /^#\s*$/} > + rcvar[1] = rcvar[1].gsub(/^\$/, '') > + rcvar > end > > # Extract service name > @@ -44,7 +47,7 @@ Puppet::Type.type(:service).provide :freebsd, :parent => > :init do > def rcvar_value > value = self.rcvar[1] > self.error("No rcvar value found in rcvar") if value.nil? > - value = value.gsub!(/(.*)_enable=\"?(.*)\"?/, '\2') > + value = value.gsub!(/(.*)_enable="?(\w+)"?/, '\2') > self.error("rcvar value is empty") if value.nil? > self.debug("rcvar value is #{value}") > value > diff --git a/spec/unit/provider/service/freebsd_spec.rb > b/spec/unit/provider/service/freebsd_spec.rb > new file mode 100644 > index 0000000..0330adb > --- /dev/null > +++ b/spec/unit/provider/service/freebsd_spec.rb > @@ -0,0 +1,50 @@ > +#!/usr/bin/env ruby > + > +require File.dirname(__FILE__) + '/../../../spec_helper' > + > +provider_class = Puppet::Type.type(:service).provider(:freebsd) > + > +describe provider_class do > + before :each do > + �...@provider = provider_class.new > + �[email protected](:initscript) > + end > + > + it "should correctly parse rcvar for FreeBSD < 7" do > + �[email protected](:execute).returns <<OUTPUT > +# ntpd > +$ntpd_enable=YES > +OUTPUT > + �[email protected] == ['# ntpd', 'ntpd_enable=YES'] > + end > + > + it "should correctly parse rcvar for FreeBSD 7 to 8" do > + �[email protected](:execute).returns <<OUTPUT > +# ntpd > +ntpd_enable=YES > +OUTPUT > + �[email protected] == ['# ntpd', 'ntpd_enable=YES'] > + end > + > + it "should correctly parse rcvar for FreeBSD >= 8.1" do > + �[email protected](:execute).returns <<OUTPUT > +# ntpd > +# > +ntpd_enable="YES" > +# (default: "") > +OUTPUT > + �[email protected] == ['# ntpd', 'ntpd_enable="YES"', '# > (default: "")'] > + end > + > + it "should find the right rcvar_value for FreeBSD < 7" do > + �[email protected](:rcvar).returns(['# ntpd', 'ntpd_enable=YES']) > + > + �[email protected]_value.should == "YES" > + end > + > + it "should find the right rcvar_value for FreeBSD >= 7" do > + �[email protected](:rcvar).returns(['# ntpd', 'ntpd_enable="YES"', '# > (default: "")']) > + > + �[email protected]_value.should == "YES" > + end > +end > -- > 1.7.2.3 > > -- > 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. > > -- 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.
