| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| # Class: firewall | ||
| # | ||
| # Manages the installation of packages for operating systems that are | ||
| # currently supported by the firewall type. | ||
| # | ||
| class firewall { | ||
| case $::kernel { | ||
| 'Linux': { | ||
| class { "${title}::linux": } | ||
| } | ||
| default: { | ||
| fail("${title}: Kernel '${::kernel}' is not currently supported") | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| class firewall::linux { | ||
| package { 'iptables': | ||
| ensure => present, | ||
| } | ||
|
|
||
| case $::operatingsystem { | ||
| 'RedHat', 'CentOS', 'Fedora': { | ||
| class { "${title}::redhat": | ||
| require => Package['iptables'], | ||
| } | ||
| } | ||
| 'Debian', 'Ubuntu': { | ||
| class { "${title}::debian": | ||
| require => Package['iptables'], | ||
| } | ||
| } | ||
| default: {} | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| class firewall::linux::debian { | ||
| package { 'iptables-persistent': | ||
| ensure => present, | ||
| } | ||
|
|
||
| # This isn't a real service/daemon. The start action loads rules, so just | ||
| # needs to be called on system boot. | ||
| service { 'iptables-persistent': | ||
| ensure => undef, | ||
| enable => true, | ||
| require => Package['iptables-persistent'], | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| class firewall::linux::redhat { | ||
| service { 'iptables': | ||
| ensure => running, | ||
| enable => true, | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| require 'spec_helper' | ||
|
|
||
| describe 'firewall::linux::debian' do | ||
| it { should contain_package('iptables-persistent').with( | ||
| :ensure => 'present' | ||
| )} | ||
| it { should contain_service('iptables-persistent').with( | ||
| :ensure => nil, | ||
| :enable => 'true', | ||
| :require => 'Package[iptables-persistent]' | ||
| )} | ||
| end |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| require 'spec_helper' | ||
|
|
||
| describe 'firewall::linux::redhat' do | ||
| it { should contain_service('iptables').with( | ||
| :ensure => 'running', | ||
| :enable => 'true' | ||
| )} | ||
| end |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| require 'spec_helper' | ||
|
|
||
| describe 'firewall::linux' do | ||
| let(:facts_default) {{ :kernel => 'Linux' }} | ||
| it { should contain_package('iptables').with_ensure('present') } | ||
|
|
||
| context 'RedHat like' do | ||
| %w{RedHat CentOS Fedora}.each do |os| | ||
| context "operatingsystem => #{os}" do | ||
| let(:facts) { facts_default.merge({ :operatingsystem => os }) } | ||
| it { should contain_class('firewall::linux::redhat').with_require('Package[iptables]') } | ||
| end | ||
| end | ||
| end | ||
|
|
||
| context 'Debian like' do | ||
| %w{Debian Ubuntu}.each do |os| | ||
| context "operatingsystem => #{os}" do | ||
| let(:facts) { facts_default.merge({ :operatingsystem => os }) } | ||
| it { should contain_class('firewall::linux::debian').with_require('Package[iptables]') } | ||
| end | ||
| end | ||
| end | ||
| end |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| require 'spec_helper' | ||
|
|
||
| describe 'firewall' do | ||
| context 'kernel => Linux' do | ||
| let(:facts) {{ :kernel => 'Linux' }} | ||
| it { should include_class('firewall::linux') } | ||
| end | ||
| end |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| ../../../../lib |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| ../../../../manifests |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| require 'spec_helper' | ||
|
|
||
| describe "Facter::Util::Fact iptables_persistent_version" do | ||
| before { Facter.clear } | ||
| let(:dpkg_cmd) { "dpkg-query -Wf '${Version}' iptables-persistent" } | ||
|
|
||
| { | ||
| "Debian" => "0.0.20090701", | ||
| "Ubuntu" => "0.5.3ubuntu2", | ||
| }.each do |os, ver| | ||
| describe "#{os} package installed" do | ||
| before { | ||
| Facter.fact(:operatingsystem).stubs(:value).returns(os) | ||
| Facter::Util::Resolution.stubs(:exec).with(dpkg_cmd).returns(ver) | ||
| } | ||
| it { Facter.fact(:iptables_persistent_version).value.should == ver } | ||
| end | ||
| end | ||
|
|
||
| describe 'Ubuntu package not installed' do | ||
| before { | ||
| Facter.fact(:operatingsystem).stubs(:value).returns("Ubuntu") | ||
| Facter::Util::Resolution.stubs(:exec).with(dpkg_cmd).returns(nil) | ||
| } | ||
| it { Facter.fact(:iptables_persistent_version).value.should be_nil } | ||
| end | ||
|
|
||
| describe 'CentOS not supported' do | ||
| before { Facter.fact(:operatingsystem).stubs(:value).returns("CentOS") } | ||
| it { Facter.fact(:iptables_persistent_version).value.should be_nil } | ||
| end | ||
| end |