desc <<-EOS
Purge unmanaged firewall rules in this chain
EOS
+ newvalues(:false, :true)
defaultto :false
end
def generate
return [] unless self.purge?
- self[:name].match(Nameformat)
+ value(:name).match(Nameformat)
chain = $1
table = $2
protocol = $3
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}
}
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
}
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
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
}
EOS
- expect(apply_manifest(pp, :catch_failures => true).exit_code).to eq(0)
+ apply_manifest(pp, :catch_changes => true)
end
end
end