Skip to content

Commit

Permalink
Merge pull request #169 from jfroche/add-service-description-short
Browse files Browse the repository at this point in the history
Add description and short option for firewalld zone
  • Loading branch information
crayfishx authored Jun 13, 2018
2 parents e0d913d + 6e08dce commit 7ad9cdf
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ pkg/
.project
Gemfile.lock
.vagrant
spec/fixtures
19 changes: 18 additions & 1 deletion lib/puppet/provider/firewalld_zone/firewall_cmd.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ def create
self.sources=(@resource[:sources]) if @resource[:sources]
self.interfaces=@resource[:interfaces]
self.icmp_blocks=(@resource[:icmp_blocks]) if @resource[:icmp_blocks]
self.description=(@resource[:description]) if @resource[:description]
self.short=(@resource[:short]) if @resource[:short]
end

def destroy
Expand Down Expand Up @@ -185,5 +187,20 @@ def get_icmp_types
execute_firewall_cmd(['--get-icmptypes'], nil).split(' ')
end

end
def description
execute_firewall_cmd(['--get-description'], @resource[:name], true, false)
end

def description=(new_description)
execute_firewall_cmd(['--set-description', new_description], @resource[:name], true, false)
end

def short
execute_firewall_cmd(['--get-short'], @resource[:name], true, false)
end

def short=(new_short)
execute_firewall_cmd(['--set-short', new_short], @resource[:name], true, false)
end

end
8 changes: 8 additions & 0 deletions lib/puppet/type/firewalld_zone.rb
Original file line number Diff line number Diff line change
Expand Up @@ -245,5 +245,13 @@ def purge_ports
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

62 changes: 62 additions & 0 deletions spec/unit/puppet/provider/firewalld_zone_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
require 'spec_helper'

provider_class = Puppet::Type.type(:firewalld_zone).provider(:firewall_cmd)

describe provider_class do
let(:resource) do
@resource = Puppet::Type.type(:firewalld_zone).new(
ensure: :present,
name: 'internal',
description: 'Interface for management',
interfaces: ["eth0"],
provider: described_class.name
)
end
let(:provider) { resource.provider }

before :each do
provider.class.stubs(:execute_firewall_cmd).returns(Object.any_instance.stubs(:exitstatus => 0))
provider.class.stubs(:execute_firewall_cmd).with(['--list-interfaces']).returns(Object.any_instance.stubs(:exitstatus => 0, :chomp => ""))
end

describe 'when creating' do
context 'with name white' do
it "should execute firewall_cmd with new-zone" do
resource.expects(:[]).with(:name).returns('white').at_least_once
resource.expects(:[]).with(:target).returns(nil).at_least_once
resource.expects(:[]).with(:sources).returns(nil).at_least_once
resource.expects(:[]).with(:interfaces).returns(["eth0"]).at_least_once
resource.expects(:[]).with(:icmp_blocks).returns(nil).at_least_once
resource.expects(:[]).with(:description).returns(nil).at_least_once
resource.expects(:[]).with(:short).returns("little description").at_least_once
provider.expects(:execute_firewall_cmd).with(["--list-interfaces"])
provider.expects(:execute_firewall_cmd).with(["--add-interface", 'eth0'])
provider.expects(:execute_firewall_cmd).with(["--new-zone", 'white'], nil)
provider.expects(:execute_firewall_cmd).with(["--set-short", 'little description'], "white", true, false)
provider.create
end
end
end

describe "when modifying" do
context "type" do
it "should remove and create a new ipset" do
resource.expects(:[]).with(:name).returns('white').at_least_once
resource.expects(:[]).with(:target).returns(nil).at_least_once
resource.expects(:[]).with(:sources).returns(nil).at_least_once
resource.expects(:[]).with(:interfaces).returns(["eth0"]).at_least_once
resource.expects(:[]).with(:icmp_blocks).returns(nil).at_least_once
resource.expects(:[]).with(:description).returns(nil).at_least_once
resource.expects(:[]).with(:short).returns("little description").at_least_once
provider.expects(:execute_firewall_cmd).with(["--list-interfaces"])
provider.expects(:execute_firewall_cmd).with(["--add-interface", 'eth0'])
provider.expects(:execute_firewall_cmd).with(["--new-zone", 'white'], nil)
provider.expects(:execute_firewall_cmd).with(["--set-short", 'little description'], "white", true, false)
provider.expects(:execute_firewall_cmd).with(["--set-description", :"Better description"], "white", true, false)
provider.create

provider.description = :'Better description'
end
end
end
end

0 comments on commit 7ad9cdf

Please sign in to comment.