]> review.fuel-infra Code Review - puppet-modules/puppetlabs-firewall.git/commitdiff
(#9583) Fix provider detection for gentoo and unsupported linuxes for the iptables...
authorKen Barber <ken@bob.sh>
Sun, 18 Sep 2011 21:28:11 +0000 (22:28 +0100)
committerKen Barber <ken@bob.sh>
Sun, 18 Sep 2011 21:28:11 +0000 (22:28 +0100)
Previously we had fairly specific confine settings for named distributions
of linux for the iptables provider. This was silly, since the commands
defined in the provider should be enough to confine the provider to Linux
only systems.

I've removed the confine, and replaced the defaultfor to be:

  :kernel => :linux

Which should avoid the need to keep adding extra Linux distributions.

I've also added some spec tests for provider detection which should help
catch any failures around the command based detection in the future.

lib/puppet/provider/firewall/iptables.rb
spec/unit/provider/iptables_prov_spec.rb

index e941090755d42aec5b7fe6b0320ee188af2db190..a6efda85fb3a466021dfa8be94343d483af2faa3 100644 (file)
@@ -19,8 +19,7 @@ Puppet::Type.type(:firewall).provide :iptables, :parent => Puppet::Provider::Fir
   commands :iptables => '/sbin/iptables'
   commands :iptables_save => '/sbin/iptables-save'
 
-  defaultfor :operatingsystem => [:redhat, :debian, :ubuntu, :fedora, :suse, :centos, :sles, :oel, :ovm]
-  confine :operatingsystem => [:redhat, :debian, :ubuntu, :fedora, :suse, :centos, :sles, :oel, :ovm]
+  defaultfor :kernel => :linux
 
   @resource_map = {
     :burst => "--limit-burst",
index 3b32132c32e09d5cac4e2288aeee6824b4629d92..aef682e7d9c2662cf83231ff97b7eb755aeb96a9 100644 (file)
@@ -1,5 +1,46 @@
 require 'spec_helper'
 
+describe 'iptables provider detection' do
+  before :each do
+    require 'puppet/provider/confine/exists'
+    @exists = Puppet::Provider::Confine::Exists
+
+    # Reset the default provider
+    Puppet::Type.type(:firewall).defaultprovider = nil
+  end
+
+  it "should default to iptables provider if /sbin/iptables[-save] exists" do
+    # Stub lookup for /sbin/iptables & /sbin/iptables-save
+    @exists.any_instance.stubs(:which).with("/sbin/iptables").
+      returns "/sbin/iptables"
+    @exists.any_instance.stubs(:which).with("/sbin/iptables-save").
+      returns "/sbin/iptables-save"
+
+    # Every other command should return false so we don't pick up any
+    # other providers
+    @exists.any_instance.stubs(:which).with() { |value|
+      ! ["/sbin/iptables","/sbin/iptables-save"].include?(value)
+    }.returns false
+
+    # Create a resource instance and make sure the provider is iptables
+    resource = Puppet::Type.type(:firewall).new({
+      :name => '000 test foo',
+    })
+    resource.provider.class.to_s.should == "Puppet::Type::Firewall::ProviderIptables"
+  end
+
+  it "should raise a default provider error when there are no commands" do
+    # Stub all commands lookups so they return nothing 
+    @exists.any_instance.stubs(:which).returns false
+
+    # Instantiate a resource instance and make sure it raises an exception
+    lambda { resource = Puppet::Type.type(:firewall).new({ 
+      :name => '000 test foo' }) }.should raise_error(Puppet::DevError, 
+      "Could not find a default provider for firewall")
+  end
+
+end
+
 describe 'iptables provider' do
   before :each do
     @provider = Puppet::Type.type(:firewall).provider(:iptables)