-
-
Notifications
You must be signed in to change notification settings - Fork 77
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
Add new properties to firewalld_ipset
type and improve logging of changes
#170
Merged
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
6e0561e
Fix ipset documentation
jfroche 1b04338
Add constraint for ipset types
jfroche 69eb4ee
Add new options
jfroche 7dc8592
Remove /32 as they get removed by ipset
jfroche 3b94236
Improve logging of the ipset member changes
jfroche 0b3fe02
Use instances & prefetch to define ipset state
jfroche d97ea56
Add new firewalld_ipset option: `manage_entries`
jfroche f043611
Merge pull request #1 from jfroche/feature/manage-ipset-entries-option
jfroche ad8edb4
manage_entries should be a parameter
jfroche 5ae166c
Add option to remove unknown ipsets
jfroche 9b59f34
Merge pull request #2 from jfroche/feature/purge-unknown-ipset
jfroche dc0247f
Do not check if ipset exists again
jfroche 7b42412
Merge pull request #5 from jfroche/enhancement/ipset-exists-speedup
jfroche eece5e7
Verify if firewalld is online before self.execute_firewall_cmd
jfroche 25b7778
Merge pull request #6 from jfroche/bug/ipset-check-firewalld-enabled
jfroche 4b9b368
Merge branch 'master' into ipset-options
crayfishx File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
module PuppetX | ||
module Firewalld | ||
module Property | ||
class PositiveInteger < Puppet::Property | ||
def insync?(is) | ||
is.to_i == should.to_i | ||
end | ||
validate do |value| | ||
raise "#{name} should be an Integer" unless value.to_i.to_s == value.to_s | ||
raise "#{name} should be greater than 0" unless value.to_i > 0 | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
require 'spec_helper' | ||
|
||
provider_class = Puppet::Type.type(:firewalld_ipset).provider(:firewall_cmd) | ||
|
||
describe provider_class do | ||
let(:resource) do | ||
@resource = Puppet::Type.type(:firewalld_ipset).new( | ||
ensure: :present, | ||
name: 'white', | ||
type: 'hash:net', | ||
entries: ['8.8.8.8'], | ||
provider: described_class.name | ||
) | ||
end | ||
let(:provider) { resource.provider } | ||
before :each do | ||
provider.class.stubs(:execute_firewall_cmd).with(['--get-ipsets'], nil).returns('white black') | ||
provider.class.stubs(:execute_firewall_cmd).with(['--state'], nil, false, false, false).returns(Object.any_instance.stubs(exitstatus: 0)) | ||
provider.class.stubs(:execute_firewall_cmd).with(['--info-ipset=white'], nil).returns('white | ||
type: hash:ip | ||
options: maxelem=200 family=inet6 | ||
entries:') | ||
provider.class.stubs(:execute_firewall_cmd).with(['--info-ipset=black'], nil).returns('black | ||
type: hash:ip | ||
options: maxelem=400 family=inet hashsize=2048 | ||
entries:') | ||
provider.class.stubs(:execute_firewall_cmd).with(['--ipset=white', '--get-entries'], nil).returns('') | ||
end | ||
|
||
describe 'self.instances' do | ||
it 'returns an array of ip sets' do | ||
ipsets_names = provider.class.instances.collect(&:name) | ||
expect(ipsets_names).to include('black', 'white') | ||
ipsets_families = provider.class.instances.collect(&:family) | ||
expect(ipsets_families).to include('inet', 'inet6') | ||
ipsets_hashsize = provider.class.instances.collect(&:hashsize) | ||
expect(ipsets_hashsize).to include('2048') | ||
ipsets_maxelem = provider.class.instances.collect(&:maxelem) | ||
expect(ipsets_maxelem).to include('200', '400') | ||
end | ||
end | ||
|
||
describe 'when creating' do | ||
context 'basic ipset' do | ||
it 'should create a new ipset with entries' do | ||
resource.expects(:[]).with(:name).returns('white').at_least_once | ||
resource.expects(:[]).with(:type).returns('hash:net').at_least_once | ||
resource.expects(:[]).with(:family).returns('inet').at_least_once | ||
resource.expects(:[]).with(:hashsize).returns(1024).at_least_once | ||
resource.expects(:[]).with(:maxelem).returns(65_536).at_least_once | ||
resource.expects(:[]).with(:timeout).returns(nil).at_least_once | ||
resource.expects(:[]).with(:options).returns({}).at_least_once | ||
resource.expects(:[]).with(:manage_entries).returns(true) | ||
resource.expects(:[]).with(:entries).returns(['192.168.0/24', '10.0.0/8']) | ||
provider.expects(:execute_firewall_cmd).with(['--new-ipset=white', '--type=hash:net', '--option=family=inet', '--option=hashsize=1024', '--option=maxelem=65536'], nil) | ||
provider.expects(:execute_firewall_cmd).with(['--ipset=white', '--add-entry=192.168.0/24'], nil) | ||
provider.expects(:execute_firewall_cmd).with(['--ipset=white', '--add-entry=10.0.0/8'], nil) | ||
provider.create | ||
end | ||
end | ||
end | ||
|
||
describe 'when modifying' do | ||
context 'hashsize' do | ||
it 'should remove and create a new ipset' do | ||
resource.expects(:[]).with(:name).returns('white').at_least_once | ||
resource.expects(:[]).with(:type).returns('hash:net').at_least_once | ||
resource.expects(:[]).with(:family).returns('inet').at_least_once | ||
resource.expects(:[]).with(:hashsize).returns(nil) | ||
resource.expects(:[]).with(:hashsize).returns(2048) | ||
resource.expects(:[]).with(:maxelem).returns(nil).at_least_once | ||
resource.expects(:[]).with(:timeout).returns(nil).at_least_once | ||
resource.expects(:[]).with(:options).returns({}).at_least_once | ||
resource.expects(:[]).with(:manage_entries).returns(true).at_least_once | ||
resource.expects(:[]).with(:entries).returns(['192.168.0/24', '10.0.0/8']).at_least_once | ||
provider.expects(:execute_firewall_cmd).with(['--new-ipset=white', '--type=hash:net', '--option=family=inet'], nil) | ||
provider.expects(:execute_firewall_cmd).with(['--new-ipset=white', '--type=hash:net', '--option=family=inet', '--option=hashsize=2048'], nil) | ||
provider.expects(:execute_firewall_cmd).with(['--ipset=white', '--add-entry=192.168.0/24'], nil).at_least_once | ||
provider.expects(:execute_firewall_cmd).with(['--ipset=white', '--add-entry=10.0.0/8'], nil).at_least_once | ||
provider.expects(:execute_firewall_cmd).with(['--delete-ipset=white'], nil) | ||
provider.create | ||
provider.hashsize = 2048 | ||
end | ||
end | ||
context 'entries' do | ||
it 'should remove and add entries' do | ||
resource.expects(:[]).with(:name).returns('white').at_least_once | ||
resource.expects(:[]).with(:type).returns('hash:net').at_least_once | ||
resource.expects(:[]).with(:family).returns('inet').at_least_once | ||
resource.expects(:[]).with(:hashsize).returns(nil) | ||
resource.expects(:[]).with(:maxelem).returns(nil).at_least_once | ||
resource.expects(:[]).with(:timeout).returns(nil).at_least_once | ||
resource.expects(:[]).with(:options).returns({}).at_least_once | ||
resource.expects(:[]).with(:manage_entries).returns(true).at_least_once | ||
resource.expects(:[]).with(:entries).returns(['192.168.0.0/24', '10.0.0.0/8']).at_least_once | ||
provider.expects(:entries).returns(['192.168.0.0/24', '10.0.0.0/8']) | ||
provider.expects(:execute_firewall_cmd).with(['--new-ipset=white', '--type=hash:net', '--option=family=inet'], nil) | ||
provider.expects(:execute_firewall_cmd).with(['--ipset=white', '--add-entry=192.168.0.0/24'], nil).at_least_once | ||
provider.expects(:execute_firewall_cmd).with(['--ipset=white', '--add-entry=10.0.0.0/8'], nil).at_least_once | ||
provider.expects(:execute_firewall_cmd).with(['--ipset=white', '--add-entry=192.168.14.0/24'], nil) | ||
provider.expects(:execute_firewall_cmd).with(['--ipset=white', '--remove-entry=192.168.0.0/24'], nil) | ||
provider.create | ||
provider.entries = ['192.168.14.0/24', '10.0.0.0/8'] | ||
end | ||
it 'should ignore entries when manage_entries is false ' do | ||
resource.expects(:[]).with(:name).returns('white').at_least_once | ||
resource.expects(:[]).with(:type).returns('hash:net').at_least_once | ||
resource.expects(:[]).with(:family).returns('inet').at_least_once | ||
resource.expects(:[]).with(:hashsize).returns(nil) | ||
resource.expects(:[]).with(:maxelem).returns(nil).at_least_once | ||
resource.expects(:[]).with(:timeout).returns(nil).at_least_once | ||
resource.expects(:[]).with(:options).returns({}).at_least_once | ||
resource.expects(:[]).with(:manage_entries).returns(false).at_least_once | ||
provider.expects(:execute_firewall_cmd).with(['--new-ipset=white', '--type=hash:net', '--option=family=inet'], nil) | ||
provider.create | ||
provider.entries = ['192.168.14.0/24', '10.0.0.0/8'] | ||
end | ||
|
||
end | ||
end | ||
end |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it a bit overkill to create a PuppetX class for this property rather than just using a validate block in the type? This would fall outside of environment isolation provided by puppet generate types.....
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed, it is more code but
validate
is not specific to a field/property. We might want to reuse that validation for other fields and avoid code duplication