diff options
| author | Nick Lewis <nick@puppetlabs.com> | 2010-10-04 15:23:02 -0700 |
|---|---|---|
| committer | James Turnbull <james@lovedthanlost.net> | 2010-11-10 06:24:01 +1100 |
| commit | 4cbceab68f3d84b322d9b78ddb95c34615906bb9 (patch) | |
| tree | a3f2a36066e281f78c86d73a4b903c6b13c5a395 | |
| parent | 06c8748cbfed67b2440e11577a52f60c43277217 (diff) | |
| download | puppet-4cbceab68f3d84b322d9b78ddb95c34615906bb9.tar.gz puppet-4cbceab68f3d84b322d9b78ddb95c34615906bb9.tar.xz puppet-4cbceab68f3d84b322d9b78ddb95c34615906bb9.zip | |
(#4573) FreeBSD service provider now supports versions <7 and >8
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
| -rw-r--r-- | lib/puppet/provider/service/freebsd.rb | 5 | ||||
| -rw-r--r-- | spec/unit/provider/service/freebsd_spec.rb | 50 |
2 files changed, 54 insertions, 1 deletions
diff --git a/lib/puppet/provider/service/freebsd.rb b/lib/puppet/provider/service/freebsd.rb index c75c3c9ab..f8c7134f0 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 000000000..0330adbed --- /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 + @provider.stubs(:initscript) + end + + it "should correctly parse rcvar for FreeBSD < 7" do + @provider.stubs(:execute).returns <<OUTPUT +# ntpd +$ntpd_enable=YES +OUTPUT + @provider.rcvar.should == ['# ntpd', 'ntpd_enable=YES'] + end + + it "should correctly parse rcvar for FreeBSD 7 to 8" do + @provider.stubs(:execute).returns <<OUTPUT +# ntpd +ntpd_enable=YES +OUTPUT + @provider.rcvar.should == ['# ntpd', 'ntpd_enable=YES'] + end + + it "should correctly parse rcvar for FreeBSD >= 8.1" do + @provider.stubs(:execute).returns <<OUTPUT +# ntpd +# +ntpd_enable="YES" +# (default: "") +OUTPUT + @provider.rcvar.should == ['# ntpd', 'ntpd_enable="YES"', '# (default: "")'] + end + + it "should find the right rcvar_value for FreeBSD < 7" do + @provider.stubs(:rcvar).returns(['# ntpd', 'ntpd_enable=YES']) + + @provider.rcvar_value.should == "YES" + end + + it "should find the right rcvar_value for FreeBSD >= 7" do + @provider.stubs(:rcvar).returns(['# ntpd', 'ntpd_enable="YES"', '# (default: "")']) + + @provider.rcvar_value.should == "YES" + end +end |
