]> review.fuel-infra Code Review - puppet-modules/puppetlabs-firewall.git/commitdiff
Update specs and make compatible with 1.8.7
authorHunter Haugen <hunter@puppetlabs.com>
Tue, 28 Jan 2014 22:39:25 +0000 (14:39 -0800)
committerHunter Haugen <hunter@puppetlabs.com>
Tue, 28 Jan 2014 23:04:29 +0000 (15:04 -0800)
`.keep_if` is not in Ruby 1.8.7
The resource was trying to change from chain INPUT to OUTPUT which isn't
supported.

lib/puppet/type/firewallchain.rb
spec/acceptance/purge_spec.rb

index 35cb9ed80f2a73310efbebfa59995a5200a81325..3e3c5d1370696593ff844fbc14ca54363f0ce19e 100644 (file)
@@ -109,6 +109,7 @@ Puppet::Type.newtype(:firewallchain) do
     desc <<-EOS
       Purge unmanaged firewall rules in this chain
     EOS
+    newvalues(:false, :true)
     defaultto :false
   end
 
@@ -192,7 +193,7 @@ Puppet::Type.newtype(:firewallchain) do
   def generate
     return [] unless self.purge?
 
-    self[:name].match(Nameformat)
+    value(:name).match(Nameformat)
     chain = $1
     table = $2
     protocol = $3
@@ -208,10 +209,10 @@ Puppet::Type.newtype(:firewallchain) do
     rules_resources = Puppet::Type.type(:firewall).instances
 
     # Keep only rules in this chain
-    rules_resources.keep_if {|res| res[:provider] == provider and res.provider.properties[:table].to_s == table and res.provider.properties[:chain] == chain}
+    rules_resources.delete_if { |res| (res[:provider] != provider or res.provider.properties[:table].to_s != table or res.provider.properties[:chain] != chain) }
 
     # Remove rules which match our ignore filter
-    rules_resources.delete_if {|res| self[:ignore].find_index{|f| res.provider.properties[:line].match(f)}} if self[:ignore]
+    rules_resources.delete_if {|res| value(:ignore).find_index{|f| res.provider.properties[:line].match(f)}} if value(:ignore)
 
     # We mark all remaining rules for deletion, and then let the catalog override us on rules which should be present
     rules_resources.each {|res| res[:ensure] = :absent}
index 3c4df3f62873118e26ae8bfb8621586910139e08..6e245fcf793c4a8bb43325b24fdeb003019a1962 100644 (file)
@@ -18,13 +18,13 @@ describe "purge tests:" do
         }
       EOS
 
-      expect(apply_manifest(pp, :catch_failures => true).exit_code).to eq(2)
+      apply_manifest(pp, :expect_changes => true)
     end
 
     it 'saves' do
       shell('/sbin/iptables-save') do |r|
-        r.stdout.should_not =~ /1\.2\.1\.2/
-        r.stderr.should be_empty
+        expect(r.stdout).to_not match(/1\.2\.1\.2/)
+        expect(r.stderr).to eq("")
       end
     end
   end
@@ -45,11 +45,12 @@ describe "purge tests:" do
         }
       EOS
 
-      expect(apply_manifest(pp, :catch_failures => true).exit_code).to eq(2)
+      apply_manifest(pp, :expect_changes => true)
 
       shell('/sbin/iptables-save') do |r|
-        r.stdout.should =~ /010 output-1\.2\.1\.2/
-        r.stderr.should be_empty
+        expect(r.stdout).to match(/010 output-1\.2\.1\.2/)
+        expect(r.stdout).to_not match(/1\.2\.1\.1/)
+        expect(r.stderr).to eq("")
       end
     end
 
@@ -60,11 +61,13 @@ describe "purge tests:" do
           purge => true,
         }
         firewall { '010 output-1.2.1.2':
+          chain  => 'OUTPUT',
+          proto  => 'all',
           source => '1.2.1.2',
         }
       EOS
 
-      expect(apply_manifest(pp, :catch_failures => true).exit_code).to eq(0)
+      apply_manifest(pp, :catch_changes => true)
     end
 
     it 'ignores specified rules' do
@@ -78,7 +81,7 @@ describe "purge tests:" do
         }
       EOS
 
-      expect(apply_manifest(pp, :catch_failures => true).exit_code).to eq(0)
+      apply_manifest(pp, :catch_changes => true)
     end
   end
 end