Skip to content

Commit

Permalink
Merge pull request #476 from jonnytpuppet/fix_recent_os
Browse files Browse the repository at this point in the history
Fix recent os
  • Loading branch information
Morgan Haskel committed Jan 23, 2015
2 parents c6f061a + 94f8ec8 commit ca980a5
Show file tree
Hide file tree
Showing 5 changed files with 123 additions and 32 deletions.
9 changes: 8 additions & 1 deletion lib/facter/iptables_persistent_version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,14 @@
setcode do
# Throw away STDERR because dpkg >= 1.16.7 will make some noise if the
# package isn't currently installed.
cmd = "dpkg-query -Wf '${Version}' iptables-persistent 2>/dev/null"
os = Facter.value(:operatingsystem)
os_release = Facter.value(:operatingsystemrelease)
if (os == 'Debian' and (Puppet::Util::Package.versioncmp(os_release, '8.0') >= 0)) or
(os == 'Ubuntu' and (Puppet::Util::Package.versioncmp(os_release, '14.10') >= 0))
cmd = "dpkg-query -Wf '${Version}' netfilter-persistent 2>/dev/null"
else
cmd = "dpkg-query -Wf '${Version}' iptables-persistent 2>/dev/null"
end
version = Facter::Util::Resolution.exec(cmd)

if version.nil? or !version.match(/\d+\.\d+/)
Expand Down
2 changes: 1 addition & 1 deletion lib/puppet/type/firewall.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1113,7 +1113,7 @@ def insync?(is)
autorequire(:package) do
case value(:provider)
when :iptables, :ip6tables
%w{iptables iptables-persistent iptables-services}
%w{iptables iptables-persistent netfilter-persistent iptables-services}
else
[]
end
Expand Down
2 changes: 1 addition & 1 deletion lib/puppet/util/firewall.rb
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ def persist_iptables(proto)
when :Debian
case proto.to_sym
when :IPv4, :IPv6
if Puppet::Util::Package.versioncmp(persist_ver, '1.0') > 0
if (persist_ver and Puppet::Util::Package.versioncmp(persist_ver, '1.0') > 0)
%w{/usr/sbin/service netfilter-persistent save}
else
%w{/usr/sbin/service iptables-persistent save}
Expand Down
31 changes: 25 additions & 6 deletions manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,31 @@
}
}
'Debian': {
if $::operatingsystem == 'Debian' and versioncmp($::operatingsystemrelease, '8.0') >= 0 {
$service_name = 'netfilter-persistent'
$package_name = 'netfilter-persistent'
} else {
$service_name = 'iptables-persistent'
$package_name = 'iptables-persistent'
case $::operatingsystem {
'Debian': {
if versioncmp($::operatingsystemrelease, '8.0') >= 0 {
$service_name = 'netfilter-persistent'
$package_name = 'netfilter-persistent'
} else {
$service_name = 'iptables-persistent'
$package_name = 'iptables-persistent'
}

}
'Ubuntu': {
if versioncmp($::operatingsystemrelease, '14.10') >= 0 {
$service_name = 'netfilter-persistent'
$package_name = 'netfilter-persistent'
} else {
$service_name = 'iptables-persistent'
$package_name = 'iptables-persistent'
}

}
default: {
$service_name = 'iptables-persistent'
$package_name = 'iptables-persistent'
}
}
}
default: {
Expand Down
111 changes: 88 additions & 23 deletions spec/unit/facter/iptables_persistent_version_spec.rb
Original file line number Diff line number Diff line change
@@ -1,35 +1,100 @@
require 'spec_helper'

describe "Facter::Util::Fact iptables_persistent_version" do
before { Facter.clear }
let(:dpkg_cmd) { "dpkg-query -Wf '${Version}' iptables-persistent 2>/dev/null" }

{
"Debian" => "0.0.20090701",
"Ubuntu" => "0.5.3ubuntu2",
}.each do |os, ver|
describe "#{os} package installed" do


context "iptables-persistent applicable" do
before { Facter.clear }

let(:dpkg_cmd) { "dpkg-query -Wf '${Version}' iptables-persistent 2>/dev/null" }

{
"Debian" => "0.0.20090701",
"Ubuntu" => "0.5.3ubuntu2",
}.each do |os, ver|

if os == "Debian"
os_release = "7.0"
elsif os == "Ubuntu"
os_release = "14.04"
end

describe "#{os} package installed" do
before {
allow(Facter.fact(:operatingsystem)).to receive(:value).and_return(os)
allow(Facter.fact(:operatingsystemrelease)).to receive(:value).and_return(os_release)
allow(Facter::Util::Resolution).to receive(:exec).with(dpkg_cmd).
and_return(ver)
}
it { Facter.fact(:iptables_persistent_version).value.should == ver }
end
end

describe 'Ubuntu package not installed' do
before {
allow(Facter.fact(:operatingsystem)).to receive(:value).and_return(os)
allow(Facter.fact(:operatingsystem)).to receive(:value).and_return('Ubuntu')
allow(Facter.fact(:operatingsystemrelease)).to receive(:value).and_return('14.04')
allow(Facter::Util::Resolution).to receive(:exec).with(dpkg_cmd).
and_return(ver)
and_return(nil)
}
it { Facter.fact(:iptables_persistent_version).value.should == ver }
it { Facter.fact(:iptables_persistent_version).value.should be_nil }
end

describe 'CentOS not supported' do
before { allow(Facter.fact(:operatingsystem)).to receive(:value).
and_return("CentOS") }
it { Facter.fact(:iptables_persistent_version).value.should be_nil }
end
end

describe 'Ubuntu package not installed' do
before {
allow(Facter.fact(:operatingsystem)).to receive(:value).and_return('Ubuntu')
allow(Facter::Util::Resolution).to receive(:exec).with(dpkg_cmd).
and_return(nil)
}
it { Facter.fact(:iptables_persistent_version).value.should be_nil }
end

describe 'CentOS not supported' do
before { allow(Facter.fact(:operatingsystem)).to receive(:value).
and_return("CentOS") }
it { Facter.fact(:iptables_persistent_version).value.should be_nil }
context "netfilter-persistent applicable" do
before { Facter.clear }

let(:dpkg_cmd) { "dpkg-query -Wf '${Version}' netfilter-persistent 2>/dev/null" }

{
"Debian" => "0.0.20090701",
"Ubuntu" => "0.5.3ubuntu2",
}.each do |os, ver|

if os == "Debian"
os_release = "8.0"
elsif os == "Ubuntu"
os_release = "14.10"
end

describe "#{os} package installed" do
before {
allow(Facter.fact(:operatingsystem)).to receive(:value).and_return(os)
allow(Facter.fact(:operatingsystemrelease)).to receive(:value).and_return(os_release)
allow(Facter::Util::Resolution).to receive(:exec).with(dpkg_cmd).
and_return(ver)
}
it { Facter.fact(:iptables_persistent_version).value.should == ver }
end
end

describe 'Ubuntu package not installed' do
os_release = "14.10"
before {
allow(Facter.fact(:operatingsystem)).to receive(:value).and_return('Ubuntu')
allow(Facter.fact(:operatingsystemrelease)).to receive(:value).and_return(os_release)
allow(Facter::Util::Resolution).to receive(:exec).with(dpkg_cmd).
and_return(nil)
}
it { Facter.fact(:iptables_persistent_version).value.should be_nil }
end

describe 'CentOS not supported' do
before { allow(Facter.fact(:operatingsystem)).to receive(:value).
and_return("CentOS") }
it { Facter.fact(:iptables_persistent_version).value.should be_nil }
end

end




end

0 comments on commit ca980a5

Please sign in to comment.