Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make native types autorequire the firewalld service #234

Merged
merged 3 commits into from
Oct 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/puppet/type/firewalld_direct_chain.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,8 @@ def self.title_patterns
desc 'Name of the table type to add (e.g: filter, nat, mangle, raw)'
isnamevar
end

autorequire(:service) do
['firewalld']
end
end
4 changes: 4 additions & 0 deletions lib/puppet/type/firewalld_direct_passthrough.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,8 @@
isnamevar
desc 'Name of the passthroughhrough to add (e.g: -A OUTPUT -j OUTPUT_filter)'
end

autorequire(:service) do
['firewalld']
end
end
4 changes: 4 additions & 0 deletions lib/puppet/type/firewalld_direct_purge.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ def generate
newvalues('chain', 'passthrough', 'rule')
end

autorequire(:service) do
['firewalld']
end

def purge?
!@purge_resources.empty?
end
Expand Down
4 changes: 4 additions & 0 deletions lib/puppet/type/firewalld_direct_rule.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,8 @@
newparam(:args) do
desc '<args> can be all iptables, ip6tables and ebtables command line arguments'
end

autorequire(:service) do
['firewalld']
end
end
4 changes: 4 additions & 0 deletions lib/puppet/type/firewalld_ipset.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,8 @@ def change_to_s(current, desire)
raise(Puppet::Error, "Ipset should not declare entries if it doesn't manage entries")
end
end

autorequire(:service) do
['firewalld']
end
end
4 changes: 4 additions & 0 deletions lib/puppet/type/firewalld_port.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,8 @@
autorequire(:firewalld_zone) do
self[:zone]
end

autorequire(:service) do
['firewalld']
end
end
4 changes: 4 additions & 0 deletions lib/puppet/type/firewalld_rich_rule.rb
Original file line number Diff line number Diff line change
Expand Up @@ -127,4 +127,8 @@ def elements
autorequire(:ipset) do
self[:source]['ipset'] if self[:source].is_a?(Hash)
end

autorequire(:service) do
['firewalld']
end
end
7 changes: 4 additions & 3 deletions lib/puppet/type/firewalld_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,9 @@
end

autorequire(:service) do
catalog.resources.select do |res|
res.title == "Firewalld::Custom_service[#{self[:service]}]"
end
['firewalld'] +
catalog.resources.select do |res|
res.title == "Firewalld::Custom_service[#{self[:service]}]"
end
end
end
20 changes: 12 additions & 8 deletions lib/puppet/type/firewalld_zone.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,14 @@ def generate
desc 'Name of the zone'
end

newparam(:description) do
desc 'Description of the zone to add'
end

newparam(:short) do
desc 'Short description of the zone to add'
end

newproperty(:target) do
desc 'Specify the target for the zone'
end
Expand Down Expand Up @@ -151,6 +159,10 @@ def retrieve
end
end

autorequire(:service) do
['firewalld']
end

def purge_resource(res_type)
if Puppet.settings[:noop] || self[:noop]
Puppet.debug "Would have purged #{res_type.ref}, (noop)"
Expand Down Expand Up @@ -233,12 +245,4 @@ def purge_ports
@ports_purgable = true
end
end

newparam(:description) do
desc 'Description of the zone to add'
end

newparam(:short) do
desc 'Short description of the zone to add'
end
end
17 changes: 17 additions & 0 deletions spec/unit/puppet/type/firewalld_direct_chain_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,21 @@
end
end
end

context 'autorequires' do
# rubocop:disable RSpec/InstanceVariable
before do
@firewalld_service = Puppet::Type.type(:service).new(name: 'firewalld')
@catalog = Puppet::Resource::Catalog.new
@catalog.add_resource(@firewalld_service)
end

it 'autorequires the firewalld service' do
@resource = described_class.new(name: 'ipv4:filter:LOG_DROPS')
@catalog.add_resource(@resource)

expect(@resource.autorequire.map { |rp| rp.source.to_s }).to include('Service[firewalld]')
end
# rubocop:enable RSpec/InstanceVariable
end
end
17 changes: 17 additions & 0 deletions spec/unit/puppet/type/firewalld_direct_passthrough_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,21 @@
provider.destroy
end
end

context 'autorequires' do
# rubocop:disable RSpec/InstanceVariable
before do
@firewalld_service = Puppet::Type.type(:service).new(name: 'firewalld')
@catalog = Puppet::Resource::Catalog.new
@catalog.add_resource(@firewalld_service)
end

it 'autorequires the firewalld service' do
@resource = described_class.new(name: '-A OUTPUT -j OUTPUT_filter')
@catalog.add_resource(@resource)

expect(@resource.autorequire.map { |rp| rp.source.to_s }).to include('Service[firewalld]')
end
# rubocop:enable RSpec/InstanceVariable
end
end
28 changes: 28 additions & 0 deletions spec/unit/puppet/type/firewalld_direct_rule_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,32 @@
end
end
end

context 'autorequires' do
# rubocop:disable RSpec/InstanceVariable
before do
@firewalld_service = Puppet::Type.type(:service).new(name: 'firewalld')
@catalog = Puppet::Resource::Catalog.new
@catalog.add_resource(@firewalld_service)
end

let(:attrs) do
{
title: 'Allow SSH',
ensure: 'present',
table: 'filter',
chain: 'OUTPUT',
priority: 1,
args: '-p tcp ---dport=22 -j ACCEPT'
}
end

it 'autorequires the firewalld service' do
@resource = described_class.new(attrs)
@catalog.add_resource(@resource)

expect(@resource.autorequire.map { |rp| rp.source.to_s }).to include('Service[firewalld]')
end
# rubocop:enable RSpec/InstanceVariable
end
end
17 changes: 17 additions & 0 deletions spec/unit/puppet/type/firewalld_ipset_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -155,4 +155,21 @@
end.to raise_error(%r{Ipset should not declare entries if it doesn't manage entries})
end
end

context 'autorequires' do
# rubocop:disable RSpec/InstanceVariable
before do
@firewalld_service = Puppet::Type.type(:service).new(name: 'firewalld')
@catalog = Puppet::Resource::Catalog.new
@catalog.add_resource(@firewalld_service)
end

it 'autorequires the firewalld service' do
@resource = described_class.new(name: 'test', hashsize: 128)
@catalog.add_resource(@resource)

expect(@resource.autorequire.map { |rp| rp.source.to_s }).to include('Service[firewalld]')
end
# rubocop:enable RSpec/InstanceVariable
end
end
17 changes: 17 additions & 0 deletions spec/unit/puppet/type/firewalld_port_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,21 @@
end
end
end

context 'autorequires' do
# rubocop:disable RSpec/InstanceVariable
before do
@firewalld_service = Puppet::Type.type(:service).new(name: 'firewalld')
@catalog = Puppet::Resource::Catalog.new
@catalog.add_resource(@firewalld_service)
end

it 'autorequires the firewalld service' do
@resource = described_class.new(name: 'test', port: 1234)
@catalog.add_resource(@resource)

expect(@resource.autorequire.map { |rp| rp.source.to_s }).to include('Service[firewalld]')
end
# rubocop:enable RSpec/InstanceVariable
end
end
29 changes: 29 additions & 0 deletions spec/unit/puppet/type/firewalld_rich_rule_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -204,4 +204,33 @@
end
end
end

context 'autorequires' do
# rubocop:disable RSpec/InstanceVariable
before do
@firewalld_service = Puppet::Type.type(:service).new(name: 'firewalld')
@catalog = Puppet::Resource::Catalog.new
@catalog.add_resource(@firewalld_service)
end

let(:attrs) do
{
title: 'SSH from barny',
ensure: 'present',
zone: 'restricted',
source: '192.168.1.2/32',
dest: '192.168.99.2/32',
service: 'ssh',
action: 'accept'
}
end

it 'autorequires the firewalld service' do
@resource = described_class.new(attrs)
@catalog.add_resource(@resource)

expect(@resource.autorequire.map { |rp| rp.source.to_s }).to include('Service[firewalld]')
end
# rubocop:enable RSpec/InstanceVariable
end
end
17 changes: 17 additions & 0 deletions spec/unit/puppet/type/firewalld_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,21 @@
end
end
end

context 'autorequires' do
# rubocop:disable RSpec/InstanceVariable
before do
@firewalld_service = Puppet::Type.type(:service).new(name: 'firewalld')
@catalog = Puppet::Resource::Catalog.new
@catalog.add_resource(@firewalld_service)
end

it 'autorequires the firewalld service' do
@resource = described_class.new(name: 'test', service: 'test')
@catalog.add_resource(@resource)

expect(@resource.autorequire.map { |rp| rp.source.to_s }).to include('Service[firewalld]')
end
# rubocop:enable RSpec/InstanceVariable
end
end
17 changes: 17 additions & 0 deletions spec/unit/puppet/type/firewalld_zone_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -161,4 +161,21 @@
end
end
end

context 'autorequires' do
# rubocop:disable RSpec/InstanceVariable
before do
@firewalld_service = Puppet::Type.type(:service).new(name: 'firewalld')
@catalog = Puppet::Resource::Catalog.new
@catalog.add_resource(@firewalld_service)
end

it 'autorequires the firewalld service' do
@resource = described_class.new(name: 'test')
@catalog.add_resource(@resource)

expect(@resource.autorequire.map { |rp| rp.source.to_s }).to include('Service[firewalld]')
end
# rubocop:enable RSpec/InstanceVariable
end
end