From 16e4bc8dc5aa12493da422a1a59c8df12cda9dcd Mon Sep 17 00:00:00 2001 From: Hunter Haugen Date: Tue, 28 Jan 2014 14:39:25 -0800 Subject: [PATCH] Update specs and make compatible with 1.8.7 `.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 | 7 ++++--- spec/acceptance/purge_spec.rb | 19 +++++++++++-------- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/lib/puppet/type/firewallchain.rb b/lib/puppet/type/firewallchain.rb index 35cb9ed..3e3c5d1 100644 --- a/lib/puppet/type/firewallchain.rb +++ b/lib/puppet/type/firewallchain.rb @@ -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} diff --git a/spec/acceptance/purge_spec.rb b/spec/acceptance/purge_spec.rb index 3c4df3f..6e245fc 100644 --- a/spec/acceptance/purge_spec.rb +++ b/spec/acceptance/purge_spec.rb @@ -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 -- 2.45.2